Skip to content

Commit 3c4cb42

Browse files
committed
Improved documentation, and almost done for EADK functions, but some fail on the linker part.
1 parent b3d9ebf commit 3c4cb42

File tree

3 files changed

+132
-40
lines changed

3 files changed

+132
-40
lines changed

README.md

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
This apps lets you run a [JavaScript](https://en.wikipedia.org/wiki/JavaScript) script on your [NumWorks calculator](https://www.numworks.com)!
66
[![JavaScript logo](./src/icon.png)](https://en.wikipedia.org/wiki/JavaScript)
77

8+
----
9+
810
## Install the app
911

1012
[![Screenshot documentation showing the icon in my list of applications](screenshot-documentations/screenshot-documentation-icon-of-application.png)](screenshot-documentations/screenshot-documentation-icon-of-application.png)
@@ -15,6 +17,8 @@ Installing is rather easy:
1517
2. This Release page is not-yet ready, on this project, use [this folder instead](https://perso.crans.org/besson/publis/Numworks-apps/), and [this direct link](https://perso.crans.org/besson/publis/Numworks-apps/javascript.nwa) ;
1618
3. Head to [my.numworks.com/apps](https://my.numworks.com/apps) to send the `nwa` file on your calculator (on Google Chrome browser). On [this page](https://my.numworks.com/python/lilian-besson-1/javascript) you will be able to also send a default example of a JavaScript file (a tiny test script), and you can edit it yourself later on, on your calculator!
1719

20+
----
21+
1822
## How to use the app
1923

2024
Just launch the app, and it will read and execute your script `javascript.py`!
@@ -42,42 +46,84 @@ To rebuild the two `espruino_embedded.c` and `espruino_embedded.h` files from Es
4246
BOARD=EMBED RELEASE=1 V=1 make
4347
```
4448

49+
Then remove these lines from the `espruino_embedded.c` file:
50+
51+
```c
52+
typedef unsigned char __u_char;
53+
typedef unsigned short int __u_short;
54+
...
55+
typedef __intmax_t intmax_t;
56+
typedef __uintmax_t uintmax_t;
57+
```
58+
59+
Copy the files you obtained to the `./src/javascript/` folder on this project (they are included, you shouldn't have to do this, unless you want to help me developping this!).
60+
4561
----
4662

4763
## Documentation of the `Eadk` module accessible in JavaScript on the NumWorks
4864

4965
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.
5066

51-
### Eadk predefined colors
67+
### ✅? Eadk predefined colors
5268
`Eadk.color_black`, `Eadk.color_white`, `Eadk.color_red`, `Eadk.color_green`, `Eadk.color_blue` are the five predefined colors.
5369

54-
### Screen width and height
70+
### ✅? Screen width and height
5571
`Eadk.SCREEN_WIDTH` and `Eadk.SCREEN_HEIGHT` are the screen's width and height, respectively.
5672

5773
### ✅ Controlling the screen's brightness
5874
#### `int Eadk.backlight_brightness()`
5975

6076
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).
6177

62-
#### `void Eadk.set_backlight_brightness(int brightness)`
78+
#### `void Eadk.backlight_set_brightness(int brightness)`
6379

6480
Sets the screen's brightness to this value.
6581
`brightness` **must** be an integer value which fits inside a `uint8_t`, between 0 and 256.
6682

67-
### Accessing the Battery levels
83+
### Accessing the Battery levels
6884

69-
### `bool eadk_battery_is_charging()`
85+
#### `bool Eadk.battery_is_charging()`
7086

7187
Indicates whether the battery is charging.
7288

73-
### `uint8_t eadk_battery_level()`
89+
#### `uint8_t Eadk.battery_level()`
7490

7591
Returns a 8 bits integer giving the battery level.
7692

77-
### `float eadk_battery_voltage()`
93+
#### `float Eadk.battery_voltage()`
7894

7995
Returns a floating value of the battery voltage (in Volt, I guess?).
8096

97+
### Display
98+
99+
#### `void Eadk.display_draw_string(const char* text, uint16_t x, uint16_t y, bool large_font, uint16_t text_color, uint16_t background_color)`
100+
101+
TODO: I still haven't been able to define this one correctly, due to the `char* text` that I don't know how to declare in JSON (in the JSON to C process used by `jswrap_` to generate the corresponding C code).
102+
103+
### Timing
104+
105+
#### ✅? `void Eadk.timing_usleep(uint32_t us)`
106+
107+
Sleep for `us` micro-seconds
108+
109+
#### ✅? `void Eadk.timing_msleep(uint32_t ms)`
110+
111+
Sleep for `ms` micro-seconds
112+
113+
#### `uint64_t Eadk.timing_millis()`
114+
115+
Time since boot of the machine? Not clear. FIXME:
116+
117+
### Miscellanious
118+
119+
#### `bool Eadk.usb_is_plugged()`
120+
121+
Indicates whether the USB is plugging.
122+
123+
#### ✅? `uint32_t Eadk.random()`
124+
125+
Returns an almost truly random number, generated from the hardware RNG (a uint32_t, unsigned 32 bits integer).
126+
81127

82128
### How to add new functions to Espruino JavaScript's `Eadk` module?
83129

src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ void __exidx_end() { }
2424
void jshKickSoftWatchDog() {
2525
}
2626

27-
// XXX: do we need this, for our app?
27+
// We don't need this, for our app, but apparently Espruino needs it
2828
uint64_t ejs_get_microseconds() {
2929
return (uint64_t) (eadk_timing_millis() * 1000);
3030
}
3131

32-
// TODO: do we need this, for our app?
32+
// We don't need this, for our app, but apparently Espruino needs it
3333
void ejs_print(const char *str) {
3434
printf("%s", str);
3535
}
@@ -38,7 +38,7 @@ void ejs_print(const char *str) {
3838
// int main(int argc, char ** argv) {
3939
int main() {
4040

41-
printf("NumWorks's Embedded JavaScript interpreter v0.0.2\n");
41+
printf("NumWorks's Embedded JavaScript interpreter v0.0.3\n");
4242
eadk_timing_msleep(1000);
4343
printf("Based on Espruino, by Naereen\n");
4444
eadk_timing_msleep(1000);

src/test.js

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// This is NOT a Python script
22
// This is a JavaScript file!
33

4-
// A bit hacky experimental: just a for loop, to sleep
4+
// A function around timing_msleep
55
function msleep(s) {
66
if (Eadk.timing_msleep instanceof Function) {
7-
Eadk.timing_msleep(s);
7+
Eadk.timing_msleep(s);
88
} else {
9+
// A bit hacky experimental: just a for loop, to sleep
910
for (let j = 1; j <= s; j++) {
1011
// Just a comment here
1112
}
@@ -16,12 +17,14 @@ console.log("Hello world from JavaScript!");
1617
console.log("Testing Eadk functions:");
1718
msleep(5000);
1819

20+
// Brightness
21+
1922
const brightness = Eadk.backlight_brightness();
2023
console.log("Eadk.backlight_brightness() =", Eadk.backlight_brightness());
2124
msleep(2000);
2225

2326
// Iterate some times from full brightness to zero brightness
24-
const number_of_dwarfs = 13;
27+
const number_of_dwarfs = 3;
2528
for (let dwarf = 1; dwarf <= number_of_dwarfs; dwarf++) {
2629

2730
// Let's go into the dark
@@ -39,46 +42,89 @@ for (let dwarf = 1; dwarf <= number_of_dwarfs; dwarf++) {
3942
}
4043
}
4144

42-
msleep(1000);
45+
msleep(5000);
4346

47+
//
4448
// Let's test the constants SCREEN_WIDTH, SCREEN_HEIGHT
49+
//
4550
console.log("Eadk.SCREEN_WIDTH =", Eadk.SCREEN_WIDTH);
46-
msleep(1000);
51+
msleep(5000);
4752
console.log("Eadk.SCREEN_HEIGHT =", Eadk.SCREEN_HEIGHT);
48-
msleep(1000);
53+
msleep(5000);
4954

55+
// FIXME: these functions seem to not be available in NumWorks' EADK library.
56+
//
5057
// Let's test the battery API
58+
//
5159
console.log("Eadk.battery_is_charging() =", Eadk.battery_is_charging());
52-
msleep(1000);
60+
msleep(5000);
5361
console.log("Eadk.battery_level() =", Eadk.battery_level());
54-
msleep(1000);
62+
msleep(5000);
5563
console.log("Eadk.battery_voltage() =", Eadk.battery_voltage());
56-
msleep(1000);
64+
msleep(5000);
5765

66+
//
67+
// Display
68+
//
5869

59-
// Let's test the colors and display_draw_string
60-
// First display on white background, and big text
61-
const big_text = 1; // 1 for big text
62-
Eadk.display_draw_string("Hello in red on white ?", 20, 10, big_text, Eadk.color_red, Eadk.color_white);
63-
msleep(1000);
64-
Eadk.display_draw_string("Hello in green on white ?", 40, 10, big_text, Eadk.color_green, Eadk.color_white);
65-
msleep(1000);
66-
Eadk.display_draw_string("Hello in blue on white ?", 60, 10, big_text, Eadk.color_blue, Eadk.color_white);
67-
msleep(1000);
68-
Eadk.display_draw_string("Hello in black on white ?", 60, 10, big_text, Eadk.color_black, Eadk.color_white);
69-
msleep(1000);
70+
// // Let's test the colors and display_draw_string
71+
// // First display on white background, and big text
72+
// const big_text = 1; // 1 for big text
73+
// Eadk.display_draw_string("Hello in red on white ?", 20, 10, big_text, Eadk.color_red, Eadk.color_white);
74+
// msleep(1000);
75+
// Eadk.display_draw_string("Hello in green on white ?", 40, 10, big_text, Eadk.color_green, Eadk.color_white);
76+
// msleep(1000);
77+
// Eadk.display_draw_string("Hello in blue on white ?", 60, 10, big_text, Eadk.color_blue, Eadk.color_white);
78+
// msleep(1000);
79+
// Eadk.display_draw_string("Hello in black on white ?", 60, 10, big_text, Eadk.color_black, Eadk.color_white);
80+
// msleep(1000);
7081

71-
// Then display on black background, and small text
72-
const small_text = 0; // 0 for small text
73-
Eadk.display_draw_string("Hello in red on black ?", 20, 10, small_text, Eadk.color_red, Eadk.color_black);
74-
msleep(1000);
75-
Eadk.display_draw_string("Hello in green on black ?", 40, 10, small_text, Eadk.color_green, Eadk.color_black);
76-
msleep(1000);
77-
Eadk.display_draw_string("Hello in blue on black ?", 60, 10, small_text, Eadk.color_blue, Eadk.color_black);
78-
msleep(1000);
79-
Eadk.display_draw_string("Hello in white on black ?", 60, 10, small_text, Eadk.color_white, Eadk.color_black);
80-
msleep(1000);
82+
// // Then display on black background, and small text
83+
// const small_text = 0; // 0 for small text
84+
// Eadk.display_draw_string("Hello in red on black ?", 20, 10, small_text, Eadk.color_red, Eadk.color_black);
85+
// msleep(1000);
86+
// Eadk.display_draw_string("Hello in green on black ?", 40, 10, small_text, Eadk.color_green, Eadk.color_black);
87+
// msleep(1000);
88+
// Eadk.display_draw_string("Hello in blue on black ?", 60, 10, small_text, Eadk.color_blue, Eadk.color_black);
89+
// msleep(1000);
90+
// Eadk.display_draw_string("Hello in white on black ?", 60, 10, small_text, Eadk.color_white, Eadk.color_black);
91+
// msleep(1000);
92+
93+
//
94+
// Timing
95+
//
96+
97+
// Let's test the function Eadk.timing_usleep(5000000)
98+
console.log("Eadk.timing_usleep(5000000)...");
99+
Eadk.timing_usleep(5000000);
100+
101+
// Let's test the function Eadk.timing_msleep(5000)
102+
console.log("Eadk.timing_msleep(5000)...");
103+
Eadk.timing_msleep(5000);
81104

105+
// FIXME: these functions seem to not be available in NumWorks' EADK library.
106+
// Let's test the function Eadk.timing_millis()
107+
console.log("Eadk.timing_millis() =", Eadk.timing_millis());
108+
msleep(5000);
109+
110+
//
111+
// Misc
112+
//
113+
114+
// FIXME: these functions seem to not be available in NumWorks' EADK library.
115+
// Let's test the function Eadk.eadk_usb_is_plugged()
116+
console.log("Eadk.eadk_usb_is_plugged() =", Eadk.eadk_usb_is_plugged());
117+
msleep(5000);
118+
119+
// Let's test the function Eadk.eadk_random()
120+
for (let index = 0; index < 100; index++) {
121+
console.log("Eadk.eadk_random() =", Eadk.eadk_random());
122+
msleep(50);
123+
}
124+
125+
//
82126
// Finish for this test script
127+
//
128+
83129
console.log("End for the tests of Eadk functions!");
84130
msleep(1000);

0 commit comments

Comments
 (0)