{"id":31776046,"url":"https://github.com/naereen/a-javascript-interpreter-for-the-numworks-calculator","last_synced_at":"2025-10-10T05:22:58.147Z","repository":{"id":295156983,"uuid":"989323565","full_name":"Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator","owner":"Naereen","description":"An experimental app to run tiny JavaScript files from the editable local storage of your NumWorks calculator! Download the .nwa app from https://perso.crans.org/besson/publis/Numworks-apps/javascript.nwa","archived":false,"fork":false,"pushed_at":"2025-06-02T07:16:37.000Z","size":2442,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-01T13:55:28.414Z","etag":null,"topics":["embedded-scripting-language","javascript","javascript-interpreter","numworks","numworks-calculators"],"latest_commit_sha":null,"homepage":"https://perso.crans.org/besson/publis/Numworks-apps/javascript.nwa","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Naereen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-23T21:55:49.000Z","updated_at":"2025-06-03T00:35:01.000Z","dependencies_parsed_at":"2025-05-24T00:32:24.401Z","dependency_job_id":null,"html_url":"https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator","commit_stats":null,"previous_names":["naereen/a-javascript-interpreter-for-the-numworks-calculator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Naereen%2FA-JavaScript-interpreter-for-the-NumWorks-calculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Naereen%2FA-JavaScript-interpreter-for-the-NumWorks-calculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Naereen%2FA-JavaScript-interpreter-for-the-NumWorks-calculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Naereen%2FA-JavaScript-interpreter-for-the-NumWorks-calculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Naereen","download_url":"https://codeload.github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Naereen%2FA-JavaScript-interpreter-for-the-NumWorks-calculator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002884,"owners_count":26083468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["embedded-scripting-language","javascript","javascript-interpreter","numworks","numworks-calculators"],"created_at":"2025-10-10T05:22:55.507Z","updated_at":"2025-10-10T05:22:58.139Z","avatar_url":"https://github.com/Naereen.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaScript interpreter for the NumWorks calculator\n\n[![Build](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/actions/workflows/build.yml/badge.svg)](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/actions/workflows/build.yml)\n\nThis apps lets you run a [JavaScript](https://en.wikipedia.org/wiki/JavaScript) script on your [NumWorks calculator](https://www.numworks.com)!\n[![JavaScript logo](./src/icon.png)](https://en.wikipedia.org/wiki/JavaScript)\n\n----\n\n## Install the app\n\n[![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)\n\nInstalling is rather easy:\n\n1. (not yet, see 2) Download the latest `javascript.nwa` file from the [Releases](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/releases) page ;\n2. 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) ;\n3. 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!\n\n----\n\n## How to use the app\n\nJust launch the app, and it will read and execute your script `javascript.py`!\n\nThis script should be located in the `javascript.py` file, that you can create, edit and save **from within your NumWorks!**.\n\nIf you want a demo, use [this `javascript.py` script](https://my.numworks.com/python/lilian-besson-1/javascript), that you can install on your NumWorks calculator, directly from their website (from my user space).\n\n[![TODO: Video documentation showing the icon in my list of applications](screenshot-documentations/video-documentation-icon-of-application.gif)](screenshot-documentations/video-documentation-icon-of-application.gif)\n\n----\n\n## Dependencies\n\nThis 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.\n\n### My fork of Espruino\n\nI'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.\n*It's a work in progress!*\n\nTo rebuild the two `espruino_embedded.c` and `espruino_embedded.h` files from Espruino's source code, you must run this in its main directory (of my fork, not the main project):\n\n```bash\nBOARD=EMBED RELEASE=1 V=1 make\n```\n\nThen remove these lines from the `espruino_embedded.c` file:\n\n```c\ntypedef unsigned char __u_char;\ntypedef unsigned short int __u_short;\n...\ntypedef __intmax_t intmax_t;\ntypedef __uintmax_t uintmax_t;\n```\n\nCopy 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!).\n\n----\n\n## Documentation of the `Eadk` module accessible in JavaScript on the NumWorks\n\nHere 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.\n\nI've exposed an `Eadk` module (see example in JavaScript below, or [here](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/issues/3#issuecomment-2910813161)), which comes ready with these functions and constants:\n\n\u003e *Legend:*\n\u003e - ✅ = code written, function tested!\n\u003e - ✅? = code written, function not yet working!\n\u003e - ❌ = code written, function unavailable / or code not yet written!!\n\n### ✅? Eadk predefined colors\n`Eadk.color_black`, `Eadk.color_white`, `Eadk.color_red`, `Eadk.color_green`, `Eadk.color_blue` are the five predefined colors.\n\n### ✅ Screen width and height\n`Eadk.SCREEN_WIDTH` and `Eadk.SCREEN_HEIGHT` are the screen's width and height, respectively.\n\n### ✅ Controlling the screen's brightness\n#### ✅ `int Eadk.backlight_brightness()`\n\nReturns 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).\n\n#### ✅ `void Eadk.backlight_set_brightness(int brightness)`\n\nSets the screen's brightness to this value.\n`brightness` **must** be an integer value which fits inside a `uint8_t`, between 0 and 256.\n\n### ✅ Accessing the Battery levels\n\n#### ✅ `bool Eadk.battery_is_charging()`\n\nIndicates whether the battery is charging.\n\n#### ✅ `uint8_t Eadk.battery_level()`\n\nReturns a 8 bits integer giving the battery level.\n\n#### ✅ `float Eadk.battery_voltage()`\n\nReturns a floating value of the battery voltage (in Volt, I guess?).\n\n\u003e These functions are missing from the hardware!\n\u003e See [this issue on NumWorks/epsilon's repository](https://github.com/numworks/epsilon/issues/2326)\n\u003e DONE: [I just implemented them myself, by SVC calls](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/issues/5)\n\n### ❌✅ Display\n\n#### ❌✅ `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)`\n\nDisplays a given `text` string, at a `{x,y}` position, in large/small font (`large_font`?), with the text in `text_color` and the background in `background_color`.\n\n```javascript\nEadk.display_draw_string(text, x, y, large, text_color, background_color);\n```\n\n\u003e TODO: it's still a bit buggy!\n\u003e See [this issue](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/issues/1#issuecomment-2910837059)\n\n#### ✅ `void Eadk.display_push_rect_uniform(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)`\n\nFills a rectangle on the display with a uniform color.\nThis can also be used to draw a single pixel by setting width and height to 1.\n\n- `x`: X coordinate of the top-left corner,\n- `y`: Y coordinate of the top-left corner,\n- `width`: Width of the rectangle,\n- `height`: Height of the rectangle,\n- `color`: Color of the rectangle (e.g., `0xFFFF` for white, `0xF800` for red).\n\nFor instance:\n```javascript\nEadk.display_push_rect_uniform(0, 0, 10, 20, 0xF800); // Fills a 10x20 red rectangle at (0,0)\nEadk.display_push_rect_uniform(50, 50, 1, 1, 0x07E0); // Draws a single green pixel at (50,50)\n```\n\n#### ✅ `bool Eadk.display_wait_for_vblank(void)`\n\nDisplay: wait for vblank? It is not documented in eadk.h so not documented here (we don't really know what it does)\n\n#### ❌ Missing funtions\n\n- `Eadk.display_push_rect`: is missing.\n- `Eadk.display_pull_rect`: is missing.\n\n### ✅ Timing\n\n#### ✅ `void Eadk.timing_usleep(uint32_t us)`\n\nSleep for `us` micro-seconds\n\n#### ✅ `void Eadk.timing_msleep(uint32_t ms)`\n\nSleep for `ms` micro-seconds\n\n#### ✅ `uint64_t Eadk.timing_millis()`\n\nTime since boot of the machine? Not clear. FIXME:\n\n### ✅ Miscellanious\n\n#### ✅ `bool Eadk.usb_is_plugged()`\n\nIndicates whether the USB is plugged.\n\n\u003e This function is missing from the hardware!\n\u003e See [this issue on NumWorks/epsilon's repository](https://github.com/numworks/epsilon/issues/2326)\n\u003e DONE: [I just implemented it myself, by SVC calls](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/issues/5)\n\n#### ✅ `uint32_t Eadk.random()`\n\nReturns an almost truly random number, generated from the hardware RNG (a uint32_t, unsigned 32 bits integer).\n\n\n### How to add new functions to Espruino JavaScript's `Eadk` module?\n\nTo 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).\nThe functions already present should give a good direction to follow!\n\n----\n\n## Example of a tiny JavaScript test file\n\nThe example below runs now correctly and showcases a few iterations of decrease then increase in brightness, with small pauses between every change:\n\nFor a more complete and length example, see [`src/test.js`](src/test.js).\n\n```javascript\n// Save this to `javascript.py` on your NumWorks, and run it with\n// the \"JS interpreter\" NumWorks application!\n\nconsole.log(\"Hello world from JavaScript!\\n\");\nconsole.log(\"Testing some Eadk functions:\\n\");\nEadk.timing_msleep(5000);\n\nconst brightness = Eadk.backlight_brightness();\nconsole.log(\"Eadk.backlight_brightness() =\", Eadk.backlight_brightness());\nEadk.timing_msleep(2000);\n\nfor (let a = 1; a \u003c= 10; a++) {\n    for (let b = brightness; b \u003e= 0; b=b-16) {\n        Eadk.set_backlight_brightness(b);\n        console.log(\"Eadk.backlight_brightness() =\", Eadk.backlight_brightness());\n        Eadk.timing_msleep(50);\n    }\n\n    for (let b = 0; b \u003c= brightness; b=b+16) {\n        Eadk.set_backlight_brightness(b);\n        console.log(\"Eadk.backlight_brightness() =\", Eadk.backlight_brightness());\n        Eadk.timing_msleep(50);\n    }\n}\n```\n\n----\n\n## Build the app\n\nTo 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).\n\n```shell\nbrew install numworks/tap/arm-none-eabi-gcc node # Or equivalent on your OS\nnpm install -g nwlink\nmake clean \u0026\u0026 make build\n```\n\n----\n\n## :scroll: License ? [![GitHub license](https://img.shields.io/github/license/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator.svg)](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/blob/master/LICENSE)\n\n[MIT Licensed](https://lbesson.mit-license.org/) (file [LICENSE](LICENSE)).\n© [Lilian Besson](https://GitHub.com/Naereen), 2025.\n\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/graphs/commit-activity)\n[![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)](https://GitHub.com/Naereen/ama)\n\n[![ForTheBadge built-with-swag](http://ForTheBadge.com/images/badges/built-with-swag.svg)](https://GitHub.com/Naereen/)\n[![ForTheBadge uses-badges](http://ForTheBadge.com/images/badges/uses-badges.svg)](http://ForTheBadge.com)\n[![ForTheBadge uses-git](http://ForTheBadge.com/images/badges/uses-git.svg)](https://GitHub.com/)\n[![ForTheBadge uses-js](http://ForTheBadge.com/images/badges/uses-js.svg)](http://ForTheBadge.com)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaereen%2Fa-javascript-interpreter-for-the-numworks-calculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaereen%2Fa-javascript-interpreter-for-the-numworks-calculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaereen%2Fa-javascript-interpreter-for-the-numworks-calculator/lists"}