API §
NoomioJS Version: 0.3.0 (2020-01-31)
Duktape Version: 2.4.0 (2020-01-31)
Baseline TX3.0 (2020-01-31)
Document scope §
The NoomioJS consist of an integrated ECMAScript engine and an API that is fun to use, documented and fairly quickly to realise a simple application.
What has been implemented §
To get the ECMAScript engine running on a module a number of tasks were required to be taken and a number of code to be implemented. The initial step was to compile the ECMAScript engine with the minimal options as the targets have limited resources (See Compile for further details).
Function | Description |
---|---|
Dynamic Allocation |
malloc,calloc,realloc,free |
Serial Output |
retarget for serial output |
Minimal printf |
printf (without %f suppport) |
Event Loop |
The event loop to allow event based programming |
Peripherals |
A number of peripherals have been integrated using Duktape C API (See API). |
What's not implemented §
Whatever is available from Qualcomm QAPI and ThreadX in C
programming but isn't exposed on the API page (See API).
Module Loading §
Module loading with require() is not part of the standard JavaScript API and used by NodeJS for module loading (See NodeJS Modules).
To load your module, place the file in /datatx and use require().
app.js §
var pig = require('pig'); print(pig.who);
pig.js §
module.exports = { who: 'pig me!' };
Event Loop §
The ECMAScript specification aka JavaScript only describes the language standard and not how to handle events. For example all web browsers implement the event loop using native code; this is also done with NoomioJS using ThreadX and QAPI.
Function | Number |
---|---|
Concurent Timers |
6 |
Compilation §
This section summarises some of the options set when compiling Duktape. These options will limit Javascript functionality and most non important options have been disabled. Try and consult the low_memory.yaml file for all the options enabled/disabled.
Duktape Configuration §
Duktape has been compiled with the folowing options set below.
python.exe tools/configure.py --platform Linux --compiler clang --architecture arm32 --option-file ./tmp/output/low_memory.yaml --rom-support
Low Memory Options §
Please see low_memory.yaml for low memory options used when building the ECMAScript engine.
API calls by tag §
0.1.0 §
DigitalIn §
DigitalInOut §
DigitalOut §
InterruptIn §
at §
clearInterval §
i2c §
print §
setInterval §
setTimeout §
.DigitalIn() 0.1.0 DigitalIn §
Prototype §
Object DigitalIn(pin, mode); Object DigitalIn(pin);
Properties §
PIN4 PIN5 PIN6 PIN7 PIN18 PIN19 PIN22 PIN23 PIN26 PIN27 PIN28 PIN40 PIN41 PIN64 PullUp PullDown PullNone OpenDrain
Functions §
boolean read(); release();
Summary §
Digital input initialisation
When a mode isn't specified then the keeper mode is used (previously set mode).
Example §
var pin4 = DigitalIn(PIN4, PullUp); var state = pin4.read();
.DigitalInOut() 0.1.0 DigitalInOut §
Prototype §
Object DigitalInOut(pin, mode); Object DigitalInOut(pin);
Properties §
PIN4 PIN5 PIN6 PIN7 PIN18 PIN19 PIN22 PIN23 PIN26 PIN27 PIN28 PIN40 PIN41 PIN64 PullUp PullDown PullNone OpenDrain
Functions §
boolean read(); write(value); number output(); number input(); release();
Summary §
Digital input output initialisation
When a mode isn't specified then the keeper mode is used (previously set mode).
Use when you want to switch from an input to output or vice versa
Example §
var pin4 = DigitalInOut(PIN4, PullUp); pin4.output(); pin4.write(true); pin4.input(); var state = pin4.read();
.DigitalOut() 0.1.0 DigitalOut §
Prototype §
Object DigitalOut(pin, mode); Object DigitalOut(pin);
Properties §
PIN4 PIN5 PIN6 PIN7 PIN18 PIN19 PIN22 PIN23 PIN26 PIN27 PIN28 PIN40 PIN41 PIN64 PullUp PullDown PullNone OpenDrain
Functions §
write(value); release();
Summary §
Digital output initialisation
When a mode isn't specified then the keeper mode is used (previously set mode).
Example §
var pin4 = DigitalOut(PIN4, PullUp); pin4.write(true);
.InterruptIn() 0.1.0 InterruptIn §
Prototype §
Object InterruptIn(pin, mode); Object InterruptIn(pin);
Properties §
PIN4 PIN5 PIN6 PIN7 PIN18 PIN19 PIN22 PIN23 PIN26 PIN27 PIN28 PIN40 PIN41 PIN64 PullUp PullDown PullNone OpenDrain
Functions §
on(event,callback); trigger(); enable(); disable(); deactivate();
Events §
fall rise high low dual
Summary §
Interrupt initialisation
When a mode isn't specified then the keeper mode is used (previously set mode).
Example §
var sw1 = InterruptIn(PIN4); sw1.on("rise",function(){ print('rise!'); }); sw1.trigger();
.at() 0.1.0 at §
Prototype §
at(stream);
Properties §
PIPE0 PIPE1
Functions §
on(event,callback); write(string);
Events §
open close data error
Summary §
Write to the AT port directly.
Example §
var intervalId; const port = at(PIPE0); port.on('open',function(){ intervalId = setInterval(function () { port.write('ATE0\\r\\n'); }, 1000); }); port.on('data',function(data){ print(data); });
.clearInterval() 0.1.0 clearInterval §
Prototype §
clearInterval(id);
Summary §
Stop a periodic timer created with setInterval.
Example §
var id; id = setInterval(function () { clearInterval(id); }, 1000);
See also §
.i2c() 0.1.0 i2c §
Prototype §
i2c(channel);
Properties §
I2C1 I2C2
Functions §
on(event,callback); start(); stop(); frequency(khz); transfer(address,transmit,receive);
Function Details §
on(event,callback); Parameters: {string} event See available events listed at Events {function} callback Function callback attached to specific event frequency(khz); Parameters: {number} khz Clock frequency in kHz transfer(address,transmit,receive); Parameters: {number} address Slave address {Uint8Array} transmit Transmit data array Uint8Array receive Receive data array. Allocate the expected receive size from the slave
Events §
open close data error
Summary §
I2C communication.
Example §
var intervalId; var reg = Uint8Array.allocPlain(1); var recvd = Uint8Array.allocPlain(2); const sensor = i2c(I2C1); reg[0] = 0x06; sensor.frequency(150); sensor.on('open',function(){ intervalId = setInterval(function () { sensor.transfer(0x18,reg,recvd); }, 1000); sensor.on('data',function(data){ print(data[0]); print(data[1]); }); });
.print() 0.1.0 print §
Prototype §
print(arg1, arg1, ...)
Summary §
Write to stdout on serial port #2
Example §
print("Hello from Javascript!");
.setInterval() 0.1.0 setInterval §
Prototype §
setInterval(callback,timeout);
Function Details §
{function} callback Function callback attached to specific event {number} timeout Timeout in milliseconds
Summary §
Periodic timer
Example §
var count = 0; var intervalId; dout = DigitalOut(PIN4); var val = false; intervalId = setInterval(function () { print('interval', ++count); val = !val; dout.write(val); if (count >= 25) { clearInterval(intervalId); } }, 1000);
See also §
.setTimeout() 0.1.0 setTimeout §
Prototype §
setTimeout(callback,timeout);
Function Details §
{function} callback Function callback attached to specific event {number} timeout Timeout in milliseconds
Summary §
One shot timer
Example §
setTimeout(function cb() { print('one shot timer, called after 10 seconds'); }, 10000);