Skip to content

Commit 6439b7a

Browse files
committed
Update example
1 parent 02c078e commit 6439b7a

File tree

18 files changed

+125
-169
lines changed

18 files changed

+125
-169
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This library can be used with
1010
## Supported devices
1111
The library was verified to work with:
1212

13-
`ESP8266`, `ESP32`, `Arduino 101`, `MKR1000`, `RTL8711`, `BluePill`, `Particle Photon`, `Particle Electron`, `nRF51`, `nRF52`, `Teensy 3.1/3.2`
13+
`ESP8266`, `ESP32`, `Arduino 101`, `MKR1000`, `RTL8711`, `ST Nucleo WB55RG`, `BluePill`, `Particle Photon`, `Particle Electron`, `nRF51`, `nRF52`, `Teensy 3.1/3.2`, `Teensy 4.0`
1414

1515
**Note:** it requires at least **~64Kb** Flash and **~10Kb** RAM even for minimal functionality.
1616

wasm_apps/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ To rebuild, use `build.sh`.
1919

2020
Before building the app, please install npm dependencies:
2121
```sh
22-
yarn install
23-
# or: npm install
22+
npm install # or yarn install
2423
```
25-
To rebuild, use `npm run build` or `build.sh`.
24+
To rebuild, use `npm run build`.
2625

2726
## TinyGo app
2827

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
.wat

wasm_apps/assemblyscript/app.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as dev from "./arduino";
22

3-
let LED: u32 = dev.getPinLED();
3+
let LED = dev.getPinLED();
44

55
function setup(): void {
66
dev.pinMode(LED, dev.OUTPUT);
@@ -18,6 +18,8 @@ function run(): void {
1818
*/
1919
export function _start(): void {
2020
setup();
21-
while (1) run();
21+
while (1) {
22+
run();
23+
}
2224
}
2325

wasm_apps/assemblyscript/app.wat

Lines changed: 0 additions & 38 deletions
This file was deleted.

wasm_apps/assemblyscript/arduino.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
export const LOW: u32 = 0;
2-
export const HIGH: u32 = 1;
1+
export const LOW = 0;
2+
export const HIGH = 1;
33

4-
export const INPUT: u32 = 0x0;
5-
export const OUTPUT: u32 = 0x1;
6-
export const INPUT_PULLUP: u32 = 0x2;
4+
export const INPUT = 0x0;
5+
export const OUTPUT = 0x1;
6+
export const INPUT_PULLUP = 0x2;
77

88

99
export declare function millis(): u32;
@@ -12,10 +12,10 @@ export declare function pinMode(pin: u32, mode: u32): void;
1212
export declare function digitalWrite(pin: u32, value: u32): void;
1313
export declare function getPinLED(): u32;
1414

15-
@external("print") declare function _print(ptr: usize, len: i32): void;
15+
@external("print") declare function _print(ptr: usize): void;
1616

1717
export function print(str: string): void {
18-
_print(changetype<usize>(String.UTF8.encode(str)), String.UTF8.byteLength(str))
18+
_print(changetype<usize>(String.UTF8.encode(str, true)))
1919
}
2020

2121
export function println(str: string): void {

wasm_apps/assemblyscript/build.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

wasm_apps/assemblyscript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"license": "MIT",
23
"scripts": {
34
"build": "npm run asbuild:optimized && xxd -i app.wasm > app.wasm.h",
45
"asbuild:optimized": "npx asc app.ts -b app.wasm -t app.wat -O3z --runtime half --noAssert --use abort="

wasm_apps/cpp/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ wasicc -Os \
66
-o app.wasm app.cpp
77

88
# Optimize (optional)
9-
#wasm-opt -O3 app.wasm -o app.wasm
9+
wasm-opt -O3 app.wasm -o app.wasm
1010
wasm-strip app.wasm
1111

1212
# Convert to WAT

wasm_apps/rust/app.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ struct App {
1010

1111
impl App {
1212
fn new() -> Self {
13-
let led = get_pin_led();
14-
pin_mode(led, OUTPUT);
13+
let led = getPinLED();
14+
pinMode(led, OUTPUT);
1515
Self { led }
1616
}
1717

18-
fn update(&self) {
19-
digital_write(self.led, HIGH);
18+
fn run(&self) {
19+
digitalWrite(self.led, HIGH);
2020
delay(100);
21-
digital_write(self.led, LOW);
21+
digitalWrite(self.led, LOW);
2222
delay(900);
2323
}
2424
}
2525

2626
#[no_mangle]
2727
pub extern fn _start() {
2828
let app = App::new();
29-
loop { app.update() };
30-
}
29+
loop {
30+
app.run()
31+
}
32+
}

0 commit comments

Comments
 (0)