Skip to content

Commit aefb807

Browse files
committed
Starts to write the documentation for this tiny 'Eadk' module that I expose to JavaScript.
1 parent 5432857 commit aefb807

File tree

2 files changed

+90
-23
lines changed

2 files changed

+90
-23
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,72 @@ If you want a demo, use [this `javascript.py` script](https://my.numworks.com/py
2727

2828
This programs uses [the code generated by the Espruino project](https://github.com/espruino/Espruino/blob/master/README_Building.md#embedding-in-other-applications) (`espruino_embedded.c`, `espruino_embedded.h` etc), a portable JavaScript interpreter for microcontrolers.
2929

30+
I've started to work on [my fork of Espruino](https://github.com/Naereen/Espruino), in order to solve [this issue](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/issues/2): I wanted to give access to NumWorks's EADK library (see [`eadk.h`](https://github.com/numworks/epsilon/blob/master/eadk/include/eadk/eadk.h)) to the JavaScript files that are executed in this Espruino JS interpreter.
31+
*It's a work in progress!*
32+
33+
## Documentation of the `Eadk` module accessible in JavaScript on the NumWorks
34+
35+
Here is a short documentation for each function that I've ported from their interface in [`eadk.h`](https://github.com/numworks/epsilon/blob/master/eadk/include/eadk/eadk.h) to a working version in JavaScript.
36+
37+
### Controlling the screen's brightness
38+
#### `Eadk.backlight_brightness() -> int`
39+
40+
Returns the screen's brightness, it's a 8 bits integer (`uint8_t` in C), ranging between 0 (min brightness, screen almost shut down) to 240 (for max brightness).
41+
42+
#### `Eadk.set_backlight_brightness(int brightness)`
43+
44+
Sets the screen's brightness to this value.
45+
`brightness` **must** be an integer value which fits inside a `uint8_t`, between 0 and 256.
46+
47+
### Eadk predefined colors
48+
`Eadk.color_black`, `Eadk.color_white`, `Eadk.color_red`, `Eadk.color_green`, `Eadk.color_blue` are the five predefined colors.
49+
50+
### How to add new functions to Espruino JavaScript's `Eadk` module?
51+
52+
To add new functions, edit in [my fork of Espruino](https://github.com/Naereen/Espruino/) the files: [`libs/eadk/jswrap_eadk.c`](https://github.com/Naereen/Espruino/blob/master/libs/eadk/jswrap_eadk.c) and [`libs/eadk/jswrap_eadk.h`](https://github.com/Naereen/Espruino/blob/master/libs/eadk/jswrap_eadk.h).
53+
The functions already present should give a good direction to follow!
54+
55+
----
56+
57+
## Example of a tiny JavaScript test file
58+
59+
The example below runs now correctly and showcases a decreasing then increasing brightness, with small pauses between every change:
60+
61+
```javascript
62+
// Save this to `javascript.py` on your NumWorks, and run it with
63+
// the "JS interpreter" NumWorks application!
64+
65+
function msleep(s) {
66+
for (let j = 1; j <= s; j++) {
67+
// Just a comment here
68+
}
69+
}
70+
71+
console.log("Hello world from JavaScript!");
72+
console.log("Testing Eadk functions:");
73+
msleep(5000);
74+
75+
const brightness = Eadk.backlight_brightness();
76+
console.log("Eadk.backlight_brightness() =", Eadk.backlight_brightness());
77+
msleep(2000);
78+
79+
for (let dwarf = 1; dwarf <= 13; dwarf++) {
80+
for (let b = brightness; b >= 0; b=b-16) {
81+
Eadk.set_backlight_brightness(b);
82+
console.log("Eadk.backlight_brightness() =", Eadk.backlight_brightness());
83+
msleep(50);
84+
}
85+
86+
for (let b = 0; b <= brightness; b=b+16) {
87+
Eadk.set_backlight_brightness(b);
88+
console.log("Eadk.backlight_brightness() =", Eadk.backlight_brightness());
89+
msleep(50);
90+
}
91+
}
92+
```
93+
94+
----
95+
3096
## Build the app
3197

3298
To build this sample app, you will need to install the [embedded ARM toolchain](https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain) and [nwlink](https://www.npmjs.com/package/nwlink).

src/test2.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@
44
// Highly experimental: just a for loop, to sleep
55
function msleep(s) {
66
for (let j = 1; j <= s; j++) {
7-
// Just a comment here
7+
// Just a comment here
88
}
9-
}
10-
11-
console.log("Hello world from JavaScript!");
12-
console.log("Testing Eadk functions:");
13-
msleep(5000);
14-
15-
const brightness = Eadk.backlight_brightness();
16-
console.log("Eadk.backlight_brightness() =", Eadk.backlight_brightness());
17-
msleep(2000);
18-
19-
for (let b = brightness; b >= 0; b=b-1) {
20-
Eadk.set_backlight_brightness(b);
21-
console.log("Eadk.backlight_brightness() =", Eadk.backlight_brightness());
22-
msleep(100);
23-
}
24-
25-
for (let b = 0; b <= brightness; b=b+1) {
26-
Eadk.set_backlight_brightness(b);
27-
console.log("Eadk.backlight_brightness() =", Eadk.backlight_brightness());
28-
msleep(100);
29-
}
30-
9+
}
10+
11+
console.log("Hello world from JavaScript!");
12+
console.log("Testing Eadk functions:");
13+
msleep(5000);
14+
15+
const brightness = Eadk.backlight_brightness();
16+
console.log("Eadk.backlight_brightness() =", Eadk.backlight_brightness());
17+
msleep(2000);
18+
19+
for (let dwarf = 1; dwarf <= 13; dwarf++) {
20+
for (let b = brightness; b >= 0; b=b-16) {
21+
Eadk.set_backlight_brightness(b);
22+
console.log("Eadk.backlight_brightness() =", Eadk.backlight_brightness());
23+
msleep(50);
24+
}
25+
26+
for (let b = 0; b <= brightness; b=b+16) {
27+
Eadk.set_backlight_brightness(b);
28+
console.log("Eadk.backlight_brightness() =", Eadk.backlight_brightness());
29+
msleep(50);
30+
}
31+
}

0 commit comments

Comments
 (0)