From 73bafd4b5d3f7b496c7d49fe90314d2f8b9950e6 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Tue, 2 Aug 2022 11:28:14 +0100 Subject: [PATCH] 0.02: Add 'pre' code that can erase the device Wait more between sending code snippets Now force use of 'Storage' (assume 2v00 or later) --- apps/espruinoprog/ChangeLog | 3 +++ apps/espruinoprog/README.md | 7 +++--- apps/espruinoprog/app.js | 34 ++++++++++++++++---------- apps/espruinoprog/custom.html | 42 ++++++++++++++++++++++++++++----- apps/espruinoprog/metadata.json | 2 +- 5 files changed, 66 insertions(+), 22 deletions(-) diff --git a/apps/espruinoprog/ChangeLog b/apps/espruinoprog/ChangeLog index 5560f00bc..6fdcad1d6 100644 --- a/apps/espruinoprog/ChangeLog +++ b/apps/espruinoprog/ChangeLog @@ -1 +1,4 @@ 0.01: New App! +0.02: Add 'pre' code that can erase the device + Wait more between sending code snippets + Now force use of 'Storage' (assume 2v00 or later) diff --git a/apps/espruinoprog/README.md b/apps/espruinoprog/README.md index a8f15d3e9..aef4cccad 100644 --- a/apps/espruinoprog/README.md +++ b/apps/espruinoprog/README.md @@ -13,6 +13,9 @@ Click on the Customise button in the app loader to set up the programmer. * First you need to choose the kind of devices you want to upload to. This is the text that should match the Bluetooth advertising name. So `Puck.js` for Puck.js devices, or `Bangle.js` for Bangles. +* In the next box, you have code to run before the upload of the main code. By default +the code `require("Storage").list().forEach(f=>require("Storage").erase(f));reset();` will +erase all files on the device and reset it. * Now paste in the code you want to write to the device. This is automatically written to flash (`.bootcde`). See https://www.espruino.com/Saving#save-on-send-to-flash- for more information. @@ -35,8 +38,6 @@ To stop scanning, long-press the button to return to the clock. ## Notes -* Right now the Espruino Tools used here are unaware of the device they're writing to, -and as a result they don't use Storage and so the size of the files you can -write to the device are quite limited. You should be find with up to 4k of code. +* This assumes the device being written to is at least version 2v00 of Espruino * Currently, code is not minified before upload (so you need to supply pre-minified code if you want that) diff --git a/apps/espruinoprog/app.js b/apps/espruinoprog/app.js index b939d4007..58fac4a0b 100644 --- a/apps/espruinoprog/app.js +++ b/apps/espruinoprog/app.js @@ -58,21 +58,31 @@ function scanAndConnect() { term.print("Connected...\r\n"); uart.removeAllListeners(); uart.on('data', function(d) { term.print(d); }); - uart.write(json.code+"\n").then(() => { - term.print("\r\nUpload Complete...\r\n"); - // main upload completed - wait a bit + term.print("Upload initial...\r\n"); + uart.write((json.pre||"")+"\n").then(() => { + term.print("\r\Done.\r\n"); uploadTimeout = setTimeout(function() { - term.print("\r\nFinal Upload...\r\n"); - // now upload the code to run after... - uart.write(json.post+"\n").then(() => { - term.print("\r\nDone.\r\n"); - // now wait and disconnect (if not already done!) + uploadTimeout = undefined; + term.print("\r\nUpload Code...\r\n"); + uart.write((json.code||"")+"\n").then(() => { + term.print("\r\Done.\r\n"); + // main upload completed - wait a bit uploadTimeout = setTimeout(function() { - term.print("\r\nDisconnecting...\r\n"); - if (uart) uart.disconnect(); - }, 500); + uploadTimeout = undefined; + term.print("\r\Upload final...\r\n"); + // now upload the code to run after... + uart.write((json.post||"")+"\n").then(() => { + term.print("\r\nDone.\r\n"); + // now wait and disconnect (if not already done!) + uploadTimeout = setTimeout(function() { + uploadTimeout = undefined; + term.print("\r\nDisconnecting...\r\n"); + if (uart) uart.disconnect(); + }, 500); + }); + }, 2000); }); - }, 1000); + }, 2000); }); }); }).catch(err => { diff --git a/apps/espruinoprog/custom.html b/apps/espruinoprog/custom.html index c994aaea7..a12189707 100644 --- a/apps/espruinoprog/custom.html +++ b/apps/espruinoprog/custom.html @@ -17,6 +17,8 @@

Upload code to devices with names starting with:

+

Enter the code to send before upload here:

+

Enter your program to upload here:

Enter the code to send after upload here:

@@ -24,12 +26,17 @@

Then click  

Click here to reset to defaults.