Let's build a simple Simulator for #BL602 ... With #uLisp, #WebAssembly and #Blockly
We stub out the GPIO Functions in #uLisp #WebAssembly ... They shall be simulated with JavaScript in our #BL602 Simulator
https://github.com/lupyuen/ulisp-bl602/blob/wasm/src/ulisp.c#L48-L57
#uLisp #WebAssembly shall send #BL602 Simulator a JSON Stream of Simulation Events ... Looks like a MIDI Stream 🤔
Here's the JSON Stream of #BL602 Simulation Events in #WebAssembly ... When #uLisp sets the GPIO Output, a Simulation Event gets added to the JSON Stream
https://github.com/lupyuen/ulisp-bl602/blob/wasm/wasm/wasm.c#L7-L32
Here's how #uLisp #WebAssembly adds a Simulation Event to the JSON Stream ... For #BL602 GPIO Output
https://github.com/lupyuen/ulisp-bl602/blob/wasm/wasm/wasm.c#L54-L71
#uLisp #WebAssembly generates this JSON Stream of #BL602 Simulation Events ... Now we interpret the Simulation Events and blink the Simulated #BL602 LED
How we return a String from #WebAssembly to JavaScript ... In our #BL602 Simulator
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/ulisp.html#L1339-L1379
Our #BL602 Simulator needs a board pic ... Let's use this wriggly sketch for now 😬
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/pinecone.png
How we render our #BL602 Simulator pic to the HTML Canvas 🎨
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/ulisp.html#L1334-L1358
How we handle the #BL602 Simulation Events generated by #uLisp #WebAssembly
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/ulisp.html#L1407-L1454
How we render the Simulated LED in our #BL602 #WebAssembly Simulator
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/ulisp.html#L1437-L1459
To blink the Simulated #BL602 LED ... We need to Simulate the Delays too ... Here's how
https://github.com/lupyuen/ulisp-bl602/blob/wasm/docs/ulisp.html#L1467-L1472
Simulating #uLisp Loops ... We can't allow uLisp to emit an Infinite List of #BL602 Simulation Events ... So we stop uLisp Loops before the Event List gets too long
https://github.com/lupyuen/ulisp-bl602/blob/wasm/wasm/wasm.c#L34-L46
Let's add our #BL602 Simulator to #Blockly for uLisp ... So that we can preview Blockly Apps in the Web Browser!
https://github.com/AppKaki/blockly-ulisp/blob/wasm/demos/simulator/index.html
#BL602 #WebAssembly Simulator now works with #uLisp #Blockly Apps yay! 🎉
Try it here: https://appkaki.github.io/blockly-ulisp/demos/simulator/
Simulating #BL602 in a Web Browser ... With #WebAssembly, uLisp and Blockly ... All shall be explained here
@lupyuen No more mysterious pins to chase down now?
#BL602 Simulator is super helpful ... For catching, fixing and testing tricky firmware bugs like this
https://github.com/lupyuen/ulisp-bl602/blob/wasm/src/ulisp.c#L5346-L5373