Skip to content

Commit

Permalink
auto update screen while serial port is still open
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcottle committed Dec 15, 2024
1 parent ff7b16c commit abff26c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
42 changes: 35 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
isFlashing: false,
flashingProgress: 0,

currentSerialPort: null,
rnodeDisplayImage: null,

selectedProduct: null,
Expand Down Expand Up @@ -806,11 +807,23 @@
return null;
}

// close existing serial port
if(this.currentSerialPort){
try {
this.currentSerialPort.close();
this.currentSerialPort = null;
} catch(e) {
console.log(e);
}
}

// ask user to select device
return await navigator.serial.requestPort({
this.currentSerialPort = await navigator.serial.requestPort({
filters: [],
});

return this.currentSerialPort;

},
async enterDfuMode() {

Expand Down Expand Up @@ -1172,14 +1185,29 @@
return;
}

// read display
const displayBuffer = await rnode.readDisplay();
// update screen every second
const interval = setInterval(async () => {

// disconnect from rnode
await rnode.close();
// stop reloading display when disconnected from serial port
if(!serialPort.readable){
clearInterval(interval);
this.rnodeDisplayImage = null;
return;
}

try {

// read display
const displayBuffer = await rnode.readDisplay();

// update ui
this.rnodeDisplayImage = this.rnodeDisplayBufferToPng(displayBuffer);

} catch(e) {
console.log(e);
}

// update ui
this.rnodeDisplayImage = this.rnodeDisplayBufferToPng(displayBuffer);
}, 1000);

},
async dumpEeprom() {
Expand Down
3 changes: 3 additions & 0 deletions js/rnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,9 @@ class RNode {

// read response from device
const [ command, ...displayBuffer ] = await this.readFromSerialPort();
if(command !== this.CMD_DISP_READ){
throw `unexpected command response: ${command}`;
}

return displayBuffer;

Expand Down

0 comments on commit abff26c

Please sign in to comment.