From 14944bb108ee9b7366df91ef86b48d2d958a6703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sat, 1 Nov 2014 22:51:11 +0100 Subject: [PATCH] Add file upload button to C1Pjs --- configs/c1p/serial/all.xml | 1 + configs/c1p/serial/samples.xml | 1 + my_modules/c1pjs-client/lib/serial.js | 13 +++++++++++++ my_modules/c1pjs-client/templates/components.xsl | 3 +++ 4 files changed, 18 insertions(+) diff --git a/configs/c1p/serial/all.xml b/configs/c1p/serial/all.xml index cd752a2d1..0f342cb87 100644 --- a/configs/c1p/serial/all.xml +++ b/configs/c1p/serial/all.xml @@ -21,4 +21,5 @@ SPACEWAR Load File + diff --git a/configs/c1p/serial/samples.xml b/configs/c1p/serial/samples.xml index db168eb20..dafaff9a3 100644 --- a/configs/c1p/serial/samples.xml +++ b/configs/c1p/serial/samples.xml @@ -10,4 +10,5 @@ PRESIDENTS Load File + diff --git a/my_modules/c1pjs-client/lib/serial.js b/my_modules/c1pjs-client/lib/serial.js index c21a91f0b..71c2f9cdc 100644 --- a/my_modules/c1pjs-client/lib/serial.js +++ b/my_modules/c1pjs-client/lib/serial.js @@ -124,6 +124,19 @@ C1PSerialPort.prototype.setBinding = function(c, t, s, e) }; }(this); return true; + case "uploadSerial": + this.bindings[s] = e; + var serial = this; + e.addEventListener('change', function () { + var file = e.files[0]; + var reader = new FileReader(); + reader.onload = function () { + // serial.println("uploading " + file.name + "..."); + serial.loadFile(file.name, reader.result, 0); + }; + reader.readAsText(file); + }); + return true; default: break; } diff --git a/my_modules/c1pjs-client/templates/components.xsl b/my_modules/c1pjs-client/templates/components.xsl index abdb87994..ec4a38463 100644 --- a/my_modules/c1pjs-client/templates/components.xsl +++ b/my_modules/c1pjs-client/templates/components.xsl @@ -285,6 +285,9 @@
+ + +