Skip to content

Commit

Permalink
First tries to implement WASM + JS interface for WS LED
Browse files Browse the repository at this point in the history
  • Loading branch information
K0rdan committed Feb 13, 2024
1 parent 140754f commit 58b6713
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 10 deletions.
36 changes: 36 additions & 0 deletions examples/projects/browser/led/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions examples/projects/browser/led/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "led",
"version": "1.0.0",
"description": "Led project example :bulb:",
"main": "src/main.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"ws": "^8.16.0"
}
}
1 change: 1 addition & 0 deletions examples/projects/browser/led/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ build_flags =
-O3
-D LUOSHAL=BROWSER
-D WSHAL=BROWSER
-D WS_NETWORK_BROKER_ADDR=\"ws://127.0.0.1:8000/ws\"
19 changes: 19 additions & 0 deletions examples/projects/browser/led/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const program = require('../.pio/build/browser/program');
program
.then(({ Luos_Init, Led_Init, Luos_Loop, Led_Loop, Ws_Init, Ws_Loop }) => {
Luos_Init();
Ws_Init();
Led_Init();

const mainLoop = () => {
Luos_Loop();
Ws_Loop();
Led_Loop();
};

return new Promise(() => setInterval(mainLoop, 0));
})
.catch((err) => {
console.error('Error', err);
process.exit(-1);
});
2 changes: 1 addition & 1 deletion examples/projects/native/gate_wscom/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ build_flags =
-D GATEFORMAT=TinyJSON
-D PIPEMODE=WS
-D PIPEHAL=native
-D PIPE_WS_SERVER_ADDR=\"ws://localhost:9342\" ; Watch out you need to escape the " using \
-D PIPE_WS_SERVER_ADDR=\"ws://127.0.0.1:9342\" ; Watch out you need to escape the " using \
build_type = debug
25 changes: 16 additions & 9 deletions network/ws_network/HAL/BROWSER/ws_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,26 @@ void openEventCallback() {
console.log("PROGRAM, openEventCallback");
}

PUBLIC
void messageEventCallback() {
printf("MESSAGE !");
std::vector<uint8_t> wasmData{1, 2, 3, 4};
Ws_Reception(wasmData.data(), sizeof(wasmData));
}

[[cheerp::genericjs]]
void wsHALInitWeb()
{
console.log("TEST!", WS_NETWORK_BROKER_ADDR);
WebSocket* clientWebsocket = new WebSocket(WS_NETWORK_BROKER_ADDR);
console.log("TEST!", s_url);
__asm__("const WebSocket = require('ws')");
WebSocket *clientWebsocket = new WebSocket(s_url);
clientWebsocket->addEventListener(
"open",
cheerp::Callback(openEventCallback)
);
}

namespace [[cheerp::genericjs]] client
{
void WsHAL_Init(void);
cheerp::Callback(openEventCallback)
);
clientWebsocket->addEventListener(
"message",
cheerp::Callback(messageEventCallback));
}

/////////////////////////Luos Library Needed function///////////////////////////
Expand All @@ -74,6 +80,7 @@ void WsHAL_Init(void)
* @param None
* @return None
******************************************************************************/
PUBLIC
void WsHAL_Loop(void)
{
// Get the messages and put them on the reception function
Expand Down

0 comments on commit 58b6713

Please sign in to comment.