### Build helloworld Example (Windows) Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp8266.md Command to verify the ESP8266 setup by building the 'helloworld' example. Ensure you are in the example's directory. ```bash cd %MODDABLE%\examples\helloworld mcconfig -d -m -p esp ``` -------------------------------- ### Build Helloworld Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp32.md Verify the ESP32 setup by building the 'helloworld' example for your device target. The toolchain may prompt for configuration options on the first build. ```bash cd ${MODDABLE}/examples/helloworld mcconfig -d -m -p esp32/ ``` -------------------------------- ### Run Example on Simulator Source: https://github.com/moddable-opensource/moddable/blob/public/examples/packages/readme.md Command to install dependencies and build/run a package example on the simulator. ```bash cd $MODDABLE/examples/package/hello npm install mcpack mcconfig -d -m -p sim ``` -------------------------------- ### Build helloworld Example (Linux) Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp8266.md Command to verify the ESP8266 setup by building the 'helloworld' example on Linux. Replace with the appropriate subplatform. ```bash cd $MODDABLE/examples/helloworld mcconfig -d -m -p esp/ ``` -------------------------------- ### Build and Run helloworld Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/Moddable SDK - Getting Started.md Verify the host environment setup by building and running the starter helloworld application for the desktop simulator target. ```text cd %MODDABLE%\examples\helloworld mcconfig -d -m -p win ``` -------------------------------- ### Build helloworld Example (macOS) Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/Moddable SDK - Getting Started.md Verifies the host environment setup by building the 'helloworld' application for the desktop simulator. ```text cd ${MODDABLE}/examples/helloworld mcconfig -d -m -p mac ``` -------------------------------- ### Build helloworld Example for ESP32 Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp32.md Verifies the ESP32 setup by building the 'helloworld' example. The toolchain may prompt for configuration options on the first build; accept the defaults. ```bash cd $MODDABLE/examples/helloworld mcconfig -d -m -p esp32/ ``` -------------------------------- ### Build helloworld Example for nRF52 Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/nrf52.md Verify the Moddable SDK setup by building the 'helloworld' example for a specific nRF52 subplatform. Replace with the appropriate target. ```shell cd ${MODDABLE}/examples/helloworld mcconfig -d -m -p nrf52/ ``` -------------------------------- ### Build helloworld Example (Windows) Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/nrf52.md Builds the 'helloworld' example for the Moddable Four device using the mcconfig tool. Ensure the Moddable SDK and necessary tools are installed and configured. ```text cd %MODDABLE%\examples\piu\balls mcconfig -d -m -p nrf52/moddable_four ``` -------------------------------- ### Install Button Callbacks Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/m5core_ink.md Install callbacks for button presses. This example iterates through all available buttons and logs their state when pushed. ```javascript for (let name in device.peripheral.button) { new device.peripheral.button[name]({ onPush() { trace(`Button ${name}: ${this.pressed}\n`); } }) } ``` -------------------------------- ### Install Firmware via DFU OTA Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/nrf52.md Example output during the DFU OTA firmware installation process. ```shell Sending DFU start packet Sending DFU init packet Sending firmware file ######################################## ######################################## ... ######################################## ########################### Activating new firmware DFU upgrade took 69.43805122375488s Device programmed. ``` -------------------------------- ### Build helloworld example for nrf52/moddable_four Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/nrf52.md Use `mcconfig` to build and run the `helloworld` example on the nRF52 platform. Ensure the Moddable SDK and its tools are installed. ```text mcconfig -d -m -p nrf52/moddable_four ``` -------------------------------- ### Build and Install Giphy Example on Moddable Two Source: https://github.com/moddable-opensource/moddable/blob/public/contributed/giphy/readme.md Navigate to the Giphy project directory and use `mcconfig` to build and install the example on your Moddable Two device. ```text cd $MODDABLE/contributed/giphy mcconfig -d -m -p esp32/moddable_two ``` -------------------------------- ### Build and Run Drag Example for ESP8266 Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/displays/wiring-guide-generic-2.8-CPT-spi.md Use this command to build and run the 'drag' example with the ESP8266 and the BuyDisplay CTP. Ensure you are in the example's directory. ```bash cd $MODDABLE/examples/piu/drag mcconfig -d -m -p esp/buydisplay_ctp ``` -------------------------------- ### Build and Run helloworld Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/Moddable SDK - Getting Started.md Compiles and runs the 'helloworld' example application for the desktop simulator target. ```bash cd $MODDABLE/examples/helloworld mcconfig -d -m -p lin ``` -------------------------------- ### Build and run the FFI host example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/xs/XS FFI.md This command sequence navigates to the FFI host example directory and builds/runs the host application using `mcconfig`. This is a prerequisite for testing the FFI mod example. ```shell cd $MODDABLE/examples/ffi/ffi-host mcconfig -d -m ``` -------------------------------- ### Build helloworld Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp8266.md Build the 'helloworld' example for your ESP8266 device target. Replace `` with the appropriate subplatform for your device. ```bash cd ${MODDABLE}/examples/helloworld mcconfig -d -m -p esp/ ``` -------------------------------- ### Run Network Example with Credentials Source: https://github.com/moddable-opensource/moddable/blob/public/examples/packages/readme.md Command to build and run a network-dependent package example, specifying Wi-Fi credentials. ```bash mcpack mcconfig -d -m -p esp/moddable_one ssid="My Wi-Fi" password=secret ``` -------------------------------- ### Install test-examples Dependencies Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/tools/tools.md Before running test-examples, install its Node.js dependencies and those for xsdb (xsbug-log). ```shell cd $MODDABLE/tools/test-examples npm install cd $MODDABLE/tools/xsbug-log npm install ``` -------------------------------- ### Build fetch example for simulator Source: https://github.com/moddable-opensource/moddable/blob/public/examples/io/streams/readme.md Builds the fetch example for the simulator. No special configuration is needed. ```shell mcconfig -d -m ``` -------------------------------- ### Run DotStar Example on ESP Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/displays/wiring-guide-dotstar.md Navigate to the DotStar example directory and use mcconfig to build and run the example on an ESP device. Ensure you are in the correct directory before executing. ```shell cd $MODDABLE/examples/drivers/dotstar ``` ```shell mcconfig -d -m -p esp ``` -------------------------------- ### Build and Deploy Example App with mcconfig Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/moddable-four.md Use `mcconfig` to build and deploy the `piu/balls` example to the Moddable Four. Ensure you are in the example's directory and have the Moddable environment set up. ```bash cd $MODDABLE/examples/piu/balls mcconfig -d -m -p nrf52/moddable_four ``` -------------------------------- ### Build Touch Example Source: https://github.com/moddable-opensource/moddable/blob/public/examples/io/streams/readme.md Build command for the touch example, which uses sensor streams to read touch input. This example demonstrates using async iterators with streams for sensor data. ```shell cd /path/to/streams/examples/touch mcconfig -d -m -p esp32/moddable_two_io ``` -------------------------------- ### Install Pico SDK Components (Linux) Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/pico.md Install necessary components for Pico development using `apt` on Ubuntu. ```text sudo apt update sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential ``` -------------------------------- ### Basic Setup Module Implementation Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/base/setup.md Implement a setup module by exporting a function that accepts a `done` callback. Call `done()` when setup operations are complete, especially for asynchronous tasks. ```javascript export default function (done) { setupOperation(); done(); } ``` -------------------------------- ### Configure and Install OpenOCD Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/qca4020/README.md Download, configure with FTDI support, and install OpenOCD for flashing the QCA4020. Install libusb-dev if prompted. ```bash cd open-ocd-0.10.0 ./configure --enable-ftdi make install ``` ```bash sudo apt-get install libusb-1.0-0.dev ``` -------------------------------- ### Build Button Example Source: https://github.com/moddable-opensource/moddable/blob/public/examples/io/streams/readme.md Build command for the button example, which uses IO streams to control an LED based on button input. This example demonstrates stream integration with hardware. ```shell cd /path/to/streams/examples/button mcconfig -d -m -p esp32/moddable_two_io ``` -------------------------------- ### Install ESP-IDF Build Tools Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp32.md Navigate to the ESP-IDF directory and run the install script to install the cross-compilation toolchain and other necessary utilities. ```bash cd $IDF_PATH ./install.sh ``` -------------------------------- ### Install Zephyr SDK Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/zephyr.md Install the Zephyr SDK after initializing the repository. This command downloads and installs the necessary toolchains and SDK components. ```bash cd ~/zephyrproject/zephyr west sdk install ``` -------------------------------- ### Run Example on ESP32 Node-MCU Source: https://github.com/moddable-opensource/moddable/blob/public/examples/packages/readme.md Command to build and run a package example on an ESP32 Node-MCU board. ```bash mcpack mcconfig -d -m -p esp32/nodemcu ``` -------------------------------- ### Build and Run love-e-ink Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/displays/wiring-guide-crystalfontz-eink.md Use this command to build and run the 'love-e-ink' example for the Crystalfontz monochrome ePaper display on an ESP8266. Ensure you are in the example's directory and have the Moddable SDK configured. ```shell cd $MODDABLE/examples/piu/love-e-ink/ mcconfig -d -m -p esp/crystalfontz_monochrome_epaper -r 270 ``` -------------------------------- ### Install ESP-IDF Build Tools Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp32.md Runs the ESP-IDF install script to install the cross-compilation toolchain and other necessary utilities. This should be run after cloning the repository. ```bash cd $IDF_PATH sh ./install.sh ``` -------------------------------- ### File Class Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/xs/XS in C.md Example demonstrating the creation of a `File` class using XS host macros in C. ```APIDOC ## File Class Example This example creates a `File` class using the host macros of XS in C. This is a low-level technique that provides the most flexibility. Most projects do not create classes directly using XS in C, but instead use the [`@` syntax extension](#syntax-extension) or [`Native` API](#native) to declare classes because it is simpler. This code uses the `File` class from JavaScript to open and close a file: ```javascript const f = new File("/Users/user/test.js", "rb"); f.close(); ``` The following code builds the `File` class. The XS in C host macro calls appear in the block between `xsBeginHost` and `xsEndHost`. Two variable slots are used to store the `File` host object and constructor. The `File` object includes a single host function, `close`, that has no arguments. The `prototype` is a host object which includes the native destructor `xs_file_destructor` to be invoked when the object is garbage collected. This prototype is provided to `xsNewHostConstructor` along with the native constructor `xs_file_constructor`. This example adds the `close` function to the prototype after creating the constructor. It may be added before instead. This example also adds a getter accessor function for the property `isOpen`. ```c #define kPrototype (0) #define kConstructor (1) xsBeginHost(the); xsVars(2); xsVar(kPrototype) = xsNewHostObject(xs_file_destructor); xsVar(kConstructor) = xsNewHostConstructor(xs_file_constructor, 0, xsVar(kPrototype)); xsSet(xsGlobal, xsID("File"), xsVar(kConstructor)); xsDefine(xsVar(kPrototype), xsID("close"), xsNewHostFunction(xs_file_close, xsDefault)); xsDefine(xsVar(kPrototype), xsID("isOpen"), xsNewHostFunction(xs_file_get_isOpen, xsIsGetter)); xsEndHost(the); ``` The `xs_file_constructor` function implements the host constructor. The constructor instantiates an instance of the `File` object prototype, opens the requested file, and stores the associated `xsFileRecord`, containing the stdio `FILE` pointer, as host data. Note that the implementation of a constructor created by calling `xsNewHostConstructor` is slightly different from one created using the `@` syntax. Specifically, the constructor created by `xsNewHostConstructor` must create the instance whereas XS creates the instance for constructors declared with the `@` syntax. Here the constructor uses `xsNewHostInstance` to create the instance and assign it to the return value `xsResult`. The prototype passed to `xsNewHostInstance` is taken from the prototype of the constructor, accessed through `xsTarget`. The `xsTarget` value is the XS in C equivalent to the [`new.target`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target) pseudo-property in JavaScript. ```c typedef struct { FILE *fd; } xsFileRecord, *xsFile; static void xs_file_constructor(xsMachine *the) { xsFileRecord f; FILE *fd; xsResult = xsGet(xsTarget, xsID("prototype")); xsResult = xsNewHostInstance(xsResult); fd = fopen(xsToString(xsArg(0)), xsToString(xsArg(1))); if (!fd) xsUnknownError("can't open"); f = malloc(sizeof(xsFileRecord)); if (!f) { fclose(fd); fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT); } f->fd = fd; xsSetHostData(xsResult, f); } ``` The `xs_file_destructor` function implements the host object's destructor. The destructor closes the file and frees the host data: ```c static void xs_file_destructor(void *data) { xsFile f = data; if (f) { fclose(f->fd); free(f); } } ``` > Note: The destructor function is called by XS when the `File` instance is garbage collected. The `xs_file_close` function closes the file immediately, rather than waiting for the instance to be freed by the garbage collector. The function retrieves the associated `xsFileRecord` record from the object instance host data and calls the host object destructor to close the file. ```c static void xs_file_close(xsMachine *the) { xsFile f = xsGetHostData(xsThis); if (!f) return; xs_file_destructor(f); xsSetHostData(xsThis, NULL); } ``` The `xs_file_get_isOpen` getter accessor function sets the result to `true` or `false` depending on whether the file is open. ```c static void xs_file_get_isOpen(xsMachine *the) { xsFile f = xsGetHostData(xsThis); xsResult = f ? xsTrue : xsFalse; } ``` ``` -------------------------------- ### Build fetch example for ESP32 Source: https://github.com/moddable-opensource/moddable/blob/public/examples/io/streams/readme.md Builds the fetch example for the ESP32 platform. Requires Wi-Fi credentials. ```shell cd /path/to/streams/examples/fetch mcconfig -d -m -p esp32/moddable_two_io ssid= password= ``` -------------------------------- ### Build Host on Simulator Source: https://github.com/moddable-opensource/moddable/blob/public/examples/piu/round-bme68x/readme.md Builds and installs the host application on the simulator. Leave the simulator running after installation. ```shell cd $MODDABLE/examples/piu/round-bme68x mcconfig -d -m ``` -------------------------------- ### Run a Single Example on Simulator Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/tools/tools.md Execute test-examples to run a single specified example on the simulator. ```shell node ./index.js sim/moddable_six --example $MODDABLE/examples/base/timers ``` -------------------------------- ### Get Ethernet IP address Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/network/ethernet.md Example demonstrating how to start the Ethernet connection and retrieve the IP address once assigned. ```APIDOC ## Example: Get Ethernet IP address ### Description The following example begins the process of connecting to Ethernet and traces to the console when the connection succeeds with an IP address being assigned to the Ethernet device. The `Net.get` method can be used to get the IP and MAC addresses of the Ethernet interface, as with Wi-Fi. An optional second argument to `Net.get` specifies which interface to query: `"ethernet"`, `"ap"`, or `"station"`. If no second argument is provided, `Net.get` defaults to the active network interface (for example, when the only network connection is Ethernet, the Ethernet interface is the default). ### Code ```js Ethernet.start(); let monitor = new Ethernet((msg) => { switch (msg) { case Ethernet.connected: trace(`Physical link established. Waiting for IP address.\n`); break; case Ethernet.gotIP: let ip = Net.get("IP", "ethernet"); trace(`Ethernet connected. IP address ${ip}\n`); break; case Ethernet.disconnected: trace(`Ethernet connection lost.\n`); break; } }); ``` ``` -------------------------------- ### Build 'balls' Example for Pico SPI Display Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/displays/wiring-guide-generic-2.4-spi-pico.md Use this command to build the 'balls' example with debug and memory logging enabled for the Pico with an ILI9341 SPI display. Ensure you are in the example's directory. ```bash cd $MODDABLE/examples/piu/balls mcconfig -d -m -p pico/ili9341 ``` -------------------------------- ### Clone Pico Examples Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/pico.md Clones the Pico SDK examples repository from GitHub. Ensure you are in the correct directory before running. ```bash cd $HOME/pico git clone -b sdk-2.2.0 https://github.com/raspberrypi/pico-examples ``` -------------------------------- ### Build and Test 'balls' Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/wasm.md Build the 'balls' example for the 'wasm' target using mcconfig. This prepares the application for testing. ```bash cd $MODDABLE/examples/piu/balls mcconfig -d -m -p wasm ``` -------------------------------- ### HTTP GET Request Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/network/network.md Demonstrates making a simple HTTP GET request using the Socket object. It traces the response, including headers, to the console. This is a basic example and not a full-featured HTTP client. ```javascript let host = "www.example.com"; let port = 80; let socket = new Socket({host, port}); socket.callback = function(message, value) { if (1 == message) { this.write("GET / HTTP/1.1\r\n"); this.write("Host: ", host, "\r\n"); this.write("Connection: close\r\n"); this.write("\r\n"); } else if (2 == message) trace(this.read(String)); } ``` -------------------------------- ### Build and Deploy helloworld Example on Pico (macOS) Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/pico.md Use `mcconfig` to build and deploy the `helloworld` example to the Pico. This command also launches `xsbug` for debugging. ```text cd $MODDABLE/examples/helloworld mcconfig -d -m -p pico ``` -------------------------------- ### Building camera-server Example Source: https://github.com/moddable-opensource/moddable/blob/public/examples/io/imagein/readme.md Command to build the camera-server example, requiring network credentials. Replace 'xxx' with your Wi-Fi SSID and password. ```bash mcconfig -d -m -p esp32/m5atom_s3r_cam ssid=xxx password=xxx ``` -------------------------------- ### BLE Example Apps Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/network/ble/ble.md Overview of the BLE example applications included with the Moddable SDK, recommended for starting new BLE projects. ```APIDOC ## BLE Example Apps The Moddable SDK includes many BLE client and server example apps to build from. We recommend starting from an example app, since the apps demonstrate how to implement common use cases: ``` -------------------------------- ### Build and Run Example App on macOS/Linux Source: https://github.com/moddable-opensource/moddable/blob/public/examples/readme.md Navigate to the example app directory and use `mcconfig -m` to build and run the app on macOS or Linux. The `-m` flag automatically runs make. ```shell cd $MODDABLE/examples/piu/balls mcconfig -m ``` -------------------------------- ### Build and run the FFI app example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/xs/XS FFI.md This command sequence navigates to the FFI app example directory and builds/runs the application using `mcconfig`. This is used to test FFI integration in a standalone app. ```shell cd $MODDABLE/examples/ffi/ffi-app mcconfig -d -m ``` -------------------------------- ### Get Localized String Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/piu/localization.md Example of retrieving a localized string using the Locals class. The 'get' method takes the string key and returns the localized version. ```javascript var what = locals.get("I love you"); // what == "I love you" locals.language = "fr"; var quoi = locals.get("I love you"); // quoi == "Je t'aime" ``` -------------------------------- ### Start xsbug and serial2xsbug for Debugging Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/qca4020/README.md Launch xsbug in the background and start serial2xsbug to bridge the serial connection to a network socket. This setup is used for debugging the ECMAScript side of the application. ```bash xsbug & serial2xsbug /dev/ttyUSB1 115200 8N1 ``` -------------------------------- ### Clone Bootloader Repository Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/nrf52.md Clone the Adafruit nRF52 Bootloader repository, including submodules, to get started. ```bash git clone https://github.com/Moddable-OpenSource/Adafruit_nRF52_Bootloader --recurse-submodules ``` -------------------------------- ### Build Host on Device Source: https://github.com/moddable-opensource/moddable/blob/public/examples/piu/round-bme68x/readme.md Builds and installs the host application on a specified device, using 'esp32/moddable_two_io' as an example platform target. ```shell cd $MODDABLE/examples/piu/round-bme68x mcconfig -d -m -p esp32/moddable_two_io ``` -------------------------------- ### Get MAC address of Ethernet device Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/network/ethernet.md Example showing how to retrieve the MAC address of the Ethernet device using the `Net.get` method. ```APIDOC ## Example: Get MAC address of Ethernet device ### Description The following example gets the MAC address of the Ethernet device and traces it to the console. The `Net.get` method is documented in the **Net** section of the [networking documentation](./network.md). Note that there is a second argument passed into the `Net.get` function in this example: the string `"ethernet"`. This specifies that you want to get the MAC address of the ethernet device, not the MAC address of the Wi-Fi device on the ESP32. ### Code ```js let mac = Net.get("MAC", "ethernet"); trace(`Ethernet MAC address is ${mac}\n`); ``` ``` -------------------------------- ### Build and Run ESP8266 Example with mcconfig Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp8266.md Use this command to build and run the `helloworld` example on your ESP8266 device. The `-p` argument specifies the platform identifier for your development board. ```text mcconfig -d -m -p esp/moddable_one ``` -------------------------------- ### TCP Socket Client Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/io/io.md Connects to an HTTP server, sends a GET request, and traces the response. Ensure the host is resolved externally before use. ```js new TCP({ address: "93.184.216.34", // www.example.com resolved outside this example port: 80, onWritable() { if (this.requested) return; this.write(ArrayBuffer.fromString("GET / HTTP/1.1\r\n")); this.write(ArrayBuffer.fromString("Host: www.example.com\r\n")); this.write(ArrayBuffer.fromString("Connection: close\r\n")); this.write(ArrayBuffer.fromString("\r\n")); this.requested = true; } onReadable(count) { race(String.fromArrayBuffer(this.read())); } onError() { race("\n\n** Disconnected **\n"); } }); ``` -------------------------------- ### Build and Run Example App on Windows Source: https://github.com/moddable-opensource/moddable/blob/public/examples/readme.md Use the Developer Command Prompt for VS 2017 on Windows. Navigate to the app directory and run `mcconfig -m` to build and run. ```shell cd %MODDABLE%\examples\piu\balls mcconfig -m ``` -------------------------------- ### Get ArrayBuffer Data Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/xs/XS in C.md Copies bytes from an ArrayBuffer starting at a specified offset. Ensure `theData` points to a buffer large enough to hold `theSize` bytes. ```c void xsGetArrayBufferData(xsSlot theSlot, xsIntegerValue theOffset, void *theData, xsIntegerValue theSize) ``` ```c void xsmcGetArrayBufferData(xsSlot theSlot, xsIntegerValue theOffset, void *theData, xsIntegerValue theSize) ``` -------------------------------- ### Get Ethernet IP Address Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/network/ethernet.md Starts the Ethernet connection and traces the IP address to the console once assigned. Uses Net.get with the 'ethernet' interface specifier to retrieve the IP address. ```javascript Ethernet.start(); let monitor = new Ethernet((msg) => { sswitch (msg) { case Ethernet.connected: trace(`Physical link established. Waiting for IP address.\n`); break; case Ethernet.gotIP: let ip = Net.get("IP", "ethernet"); trace(`Ethernet connected. IP address ${ip}\n`); break; case Ethernet.disconnected: trace(`Ethernet connection lost.\n`); break; } }); ``` -------------------------------- ### Build and run the FFI mod example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/xs/XS FFI.md This command sequence navigates to the FFI mod example directory and builds/runs the mod using `mcrun`. This is used to test FFI integration within a mod, after the host has been launched. ```shell cd $MODDABLE/examples/ffi/ffi-mod mcrun -d -m ``` -------------------------------- ### Create and Run a 'from' Tween Animation Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/piu/piu.md Use the 'from' function to animate properties from specified starting values to the target object's original values. This example animates the 'x' position and 'state' of two labels. ```javascript let sampleStyle = new Style({ font: "600 28px Open Sans", color: ["blue", "white"] }); let sampleColumn = new Column(null, { top: 0, bottom: 0, left: 0, right: 0, skin: new Skin({ fill: "white" }), style: sampleStyle, contents: [ Label(null, { top: 90, height: 28, left: 80, string: "Hello", state: 0 }), Label(null, { top: 2, height: 28, left: 80, string: "Moddable", state: 0 }), ], Behavior: class extends Behavior { onDisplaying(column) { let timeline = this.timeline = new Timeline(); timeline.from(column.first, { x: -column.first.width, state: 1 }, 1000, Math.quadEaseOut, 0) .from(column.last, { x: application.width, state: 1 }, 800, Math.quadEaseOut, -800); column.duration = timeline.duration; timeline.seekTo(0); column.time = 0; column.start(); } onTimeChanged(column) { this.timeline.seekTo(column.time); } } }); application.add(sampleColumn); ``` -------------------------------- ### Enable GPS and Get Reading Source: https://github.com/moddable-opensource/moddable/blob/public/contributed/serial/drivers/sim7100/SIM7100.md Enable the GPS functionality and set the onGPSEnabled callback. Inside the callback, call getGPS to retrieve a single GPS reading. Ensure the SIM7100 module is started and ready before enabling GPS. ```javascript sim7100.onGPSEnabled = function(device) { device.getGPS(); // read GPS once. } sim7100.enableGPS(); ``` -------------------------------- ### Create a Basic Application Instance Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/piu/piu.md Instantiates a new application with specified layout and skin. Use this for the root of your application. ```javascript export default new Application(null, { top: 0, bottom: 0, left: 0, right: 0, skin: new Skin({ fill: "blue" }), }); ``` -------------------------------- ### Draw External Custom Rendering Element Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/commodetto/poco.md Installs a custom rendering element into the Poco display list. The `data` argument describes the operation and is copied into the list. Poco does not perform clipping or rotation; these must be handled by the caller or the rendering callback. The `xphase` parameter is relevant for multi-bit-per-pixel formats to indicate the starting pixel within a byte. ```c void PocoDrawExternal(Poco poco, PocoRenderExternal doDrawExternal, uint8_t *data, uint8_t dataSize, PocoCoordinate x, PocoCoordinate y, PocoDimension w, PocoDimension h); ``` ```c typedef void (*PocoRenderExternal)(Poco poco, uint8_t *data, PocoPixel *dst, PocoDimension w, PocoDimension h, uint8_t xphase); ``` -------------------------------- ### Build Helloworld Example with Moddable SDK Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/zephyr.md Build the 'helloworld' example using the Moddable SDK, targeting a Zephyr-based board. This command configures and compiles the Moddable application for the specified platform. ```bash cd ${MODDABLE}/examples/helloworld mcconfig -d -m -p zephyr/nucleo_f413zh ``` -------------------------------- ### Install Homebrew Packages and PySerial Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp32.md Update Homebrew and install essential development tools including Python, CMake, Ninja, and dfu-util. Upgrade existing installations and install the pyserial Python package. ```bash brew update brew install python3 cmake ninja dfu-util brew upgrade python3 cmake ninja dfu-util pip install pyserial ``` -------------------------------- ### SIM7100 Initialization and Usage Source: https://github.com/moddable-opensource/moddable/blob/public/contributed/serial/drivers/sim7100/SIM7100.md Demonstrates how to import, instantiate, and start the SIM7100 module. It also shows how to set up the `onReady` callback to perform actions once the device is initialized. ```APIDOC ## class SIM7100 ### Description This class interfaces with the SIM7100 module. ### Initialization To use the SIM7100, import the module, create an object and start the device. ```js import SIM7100 from "sim7100"; let sim7100 = new SIM7100(); sim7100.onReady = function() { // can perform sim7100 actions now } sim7100.start(); ``` #### `onReady` Set an `onReady` function to be notified when the SIM7100 has been started and is ready to accept commands. ``` -------------------------------- ### Install SoftDevice and Flash Bootloader Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/nrf52.md Install the SoftDevice first, then flash the bootloader to the 'moddable_four' board. This is part of the initial bootloader installation process. ```bash make BOARD=moddable_four sd make BOARD=moddable_four flash ``` -------------------------------- ### Install Python and Packages Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp8266.md Install Python using Homebrew and then install the 'pyserial' package using pip. This is necessary for serial communication with the ESP8266 device. ```bash brew install python sudo easy_install pip pip install --user pyserial ``` -------------------------------- ### Build Debug Version of Drag Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/displays/wiring-guide-generic-2.4-spi.md Use this command to build a debug version of the drag example for testing the display. Ensure you are in the example's directory. ```bash cd $MODDABLE/examples/piu/drag mcconfig -d -m -p esp/moddable_zero ``` -------------------------------- ### Build Moddable Drag Example for ESP32 Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/displays/wiring-guide-generic-2.4-spi-esp32.md Use this command to build the drag example with debug mode enabled for the ESP32. Ensure you are in the example's directory. ```shell cd $MODDABLE/examples/piu/drag mcconfig -d -m -p esp32/moddable_zero ``` -------------------------------- ### Build and Install FreeRTOS Library Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/qca4020/README.md Build the FreeRTOS library and copy it to the target directory. Navigate to the FreeRTOS demo directory before building. ```bash cd ~/qualcomm/FreeRTOS/1.0/FreeRTOS/Demo/QUARTZ make all cp output/free_rtos.lib ~/qualcomm/qca4020/target/lib/cortex-m4IPT/freertos/ ``` -------------------------------- ### xsdb: Install Node.js Debugger Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/tools/tools.md Before running xsdb for the first time, you must install its Node.js dependencies. This command navigates to the xsbug-log directory and installs the necessary packages. ```shell cd $MODDABLE/tools/xsbug-log npm install ``` -------------------------------- ### Update Homebrew and Install Tools Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp32.md Update Homebrew and ensure necessary tools like Python, CMake, and Ninja are installed and up-to-date. Also, install or upgrade pyserial. ```bash brew update brew install python cmake ninja brew upgrade python cmake ninja pip install pyserial ``` -------------------------------- ### Build helloworld example for Moddable Two Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp32.md Use `mcconfig` to build and run the `helloworld` example for a specific ESP32 board. The `-p` argument specifies the platform identifier. ```text mcconfig -d -m -p esp32/moddable_two ``` -------------------------------- ### Build Example with PSRAM Source: https://github.com/moddable-opensource/moddable/blob/public/build/devices/pico/lib/sparkfun-pico/README.md Standard build process for pico-sdk examples, specifying the target SparkFun board. Ensure PICO_SDK_PATH is set. ```sh export PICO_SDK_PATH= cd examples/has_psram mkdir build cmake .. -DPICO_BOARD=sparkfun_promicro_rp2350 make ``` -------------------------------- ### Run Network Example with Wi-Fi Credentials Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/tools/tools.md Provide Wi-Fi credentials to test-examples for embedded device tests that use Wi-Fi. ```shell node ./index.js sim/moddable_six --dir $MODDABLE/examples/network.http --ssid "My Wi-Fi" --password "[secret]" ``` -------------------------------- ### Run Debug Build for Balls Example Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/displays/wiring-guide-adafruit-1.8-st7735.md Use this command to run a debug build of the 'balls' example with the Adafruit ST7735 display. Ensure you are in the example's directory. ```shell cd $MODDABLE/examples/piu/balls mcconfig -d -m -p esp/adafruit_st7735 ``` -------------------------------- ### Piu UI Framework Example Source: https://context7.com/moddable-opensource/moddable/llms.txt Demonstrates the basic structure of a Piu application, including skin definitions, behavior for handling touch events, and the main UI hierarchy. ```js import {} from "piu/MC"; // Piu runtime for microcontrollers // --- Skin and Style definitions --- const backgroundSkin = new Skin({ fill: "#1a1a2e" }); const buttonSkin = new Skin({ fill: ["#16213e", "#0f3460"] }); const labelStyle = new Style({ font: "semibold 18px Open Sans", color: "white" }); // --- Behavior: handle tap events --- class ButtonBehavior extends Behavior { onTouchEnded(button) { button.state = 0; trace("Button tapped!\n"); application.distribute("onAction"); } onTouchBegan(button) { button.state = 1; } } // --- Main app hierarchy --- const MainScreen = Column.template($ => ({ left: 0, right: 0, top: 0, bottom: 0, skin: backgroundSkin, contents: [ Label($, { string: "Moddable SDK", style: labelStyle, top: 40 }), Content($, { height: 20 }), Container($, { width: 120, height: 44, skin: buttonSkin, active: true, Behavior: ButtonBehavior, contents: [ Label($, { string: "Tap Me", style: labelStyle }) ] }) ] })); // Mount to application application.add(new MainScreen({})); ``` -------------------------------- ### Build Moddable Example for TeensyView Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/displays/wiring-guide-sparkFun-teensyview-spi.md Use this command to build the `balls` example for the TeensyView display on an ESP8266. Ensure you are in the example's directory and have the Moddable SDK environment set up. ```shell cd $MODDABLE/examples/piu/balls mcconfig -d -m -p esp/teensyview ``` -------------------------------- ### Build helloworld for ESP8266 Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp8266.md Build the 'helloworld' example for your ESP8266 device target using the mcconfig tool. Replace with your specific subplatform. ```bash cd %MODDABLE%\examples\helloworld mcconfig -d -m -p esp/ ``` -------------------------------- ### Keyboard Constructor and Usage Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/piu/keyboard.md Demonstrates how to import and instantiate the Keyboard module, configuring its appearance and behavior. ```APIDOC ## Keyboard Constructor ### Description Creates a new Keyboard instance. ### Constructor Signature `Keyboard(behaviorData, dictionary)` ### Parameters #### `behaviorData` - Type: `*` - Description: Data passed to the `onCreate` function of the keyboard's behavior. #### `dictionary` - Type: `object` - Description: Configuration options for the keyboard. ### Returns - Type: `keyboard` instance (a `Port` object) - Description: A keyboard instance configured with the provided options. ### Example ```js import {Keyboard} from "keyboard"; import {Style} let OpenSans18 = new Style({ font: "semibold 18px Open Sans", color: "black" }); let keyboard = new Keyboard(null, {style: OpenSans18, doTransition: false}); ``` ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/devices/esp32.md Run this command in the 'x86 Native Tools Command Prompt for VS 2022' to install missing Python dependencies if the ESP-IDF installer fails due to permissions. ```bash python -m pip install -r %IDF_PATH%\requirements.txt ``` -------------------------------- ### Example of XS Machine Creation and Deletion Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/xs/XS in C.md Illustrates the typical usage of `xsCreateMachine` to initialize an XS machine with custom creation parameters and `xsDeleteMachine` to clean it up. Includes basic error handling. ```c int main(int argc, char* argv[]) { xsCreation aCreation = { 128 * 1024 * 1024, /* initialChunkSize */ 16 * 1024 * 1024, /* incrementalChunkSize */ 4 * 1024 * 1024, /* initialHeapCount */ 1 * 1024 * 1024, /* incrementalHeapCount */ 1024, /* stack count */ 2048+1024, /* key count */ 1993, /* name modulo */ 127 /* symbol modulo */ }; xsMachine* aMachine; aMachine = xsCreateMachine(&aCreation, "machine", NULL); if (aMachine) { xsMainContext(aMachine, argc, argv); xsDeleteMachine(aMachine); } else fprintf(stderr, "### Cannot allocate machine\n"); return 0; } ``` -------------------------------- ### Build the zip file Source: https://github.com/moddable-opensource/moddable/blob/public/contributed/httpbridge/README.md Install dependencies and build the project's zip file. Navigate to the 'site' directory before running these commands. ```bash cd site npm install npm run build ``` -------------------------------- ### Build Countdown Example for Adafruit OLED Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/displays/wiring-guide-adafruit-OLED.md Use this command to build the countdown example for the Adafruit OLED display on an ESP8266. Ensure you are in the example directory and have the Moddable SDK environment set up. ```bash cd $MODDABLE/examples/piu/countdown mcconfig -d -m -p esp/adafruit_oled ``` -------------------------------- ### Build Moddable Example for Sharp Memory Display Source: https://github.com/moddable-opensource/moddable/blob/public/documentation/displays/wiring-guide-sharp-memory-2.7-spi.md Use this command to build the 'balls' example with debug mode enabled for the Sharp Memory display on an ESP8266. Ensure you are in the example's directory. ```shell cd $MODDABLE/examples/piu/balls mcconfig -d -m -p esp/sharp_memory ```