diff --git a/apps/c1p/all.xml b/apps/c1p/all.xml
index cd752a2d1..7833c5e49 100644
--- a/apps/c1p/all.xml
+++ b/apps/c1p/all.xml
@@ -21,4 +21,5 @@
- SPACEWAR
Load File
+
diff --git a/apps/c1p/samples.xml b/apps/c1p/samples.xml
index db168eb20..bb0b268be 100644
--- a/apps/c1p/samples.xml
+++ b/apps/c1p/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 fb1c898b7..d9b457c1a 100644
--- a/my_modules/c1pjs-client/lib/serial.js
+++ b/my_modules/c1pjs-client/lib/serial.js
@@ -124,6 +124,40 @@ C1PSerialPort.prototype.setBinding = function(c, t, s, e)
};
}(this);
return true;
+ case "uploadSerial":
+ // Check for availability of FileReader
+ if (window.FileReader && window.File && window.FileList && window.Blob ) {
+ var serial = this;
+ this.bindings[s] = e;
+
+ // Enable "Load Local File" button only if a file is actually selected
+ e.addEventListener('change', function () {
+ var fieldset = e.children[0];
+ var files = fieldset.children[0].files;
+ var submit = fieldset.children[1];
+
+ submit.disabled = (files.length == 0);
+ });
+
+ e.onsubmit = function (event) {
+ var file = event.currentTarget[1].files[0];
+
+ var reader = new FileReader();
+ reader.onload = function () {
+ // serial.println("uploading " + file.name + "...");
+ serial.loadFile(file.name, reader.result.toString(), 0);
+ };
+ reader.readAsText(file);
+
+ // Prevent reloading of web page after form submission
+ return false;
+ };
+ }
+ else {
+ this.println("FileReader support not available, disabling local file upload");
+ e.parentNode.removeChild(e);
+ }
+ return true;
default:
break;
}
diff --git a/my_modules/c1pjs-client/templates/components.xsl b/my_modules/c1pjs-client/templates/components.xsl
index 282d2a6d1..581c05743 100644
--- a/my_modules/c1pjs-client/templates/components.xsl
+++ b/my_modules/c1pjs-client/templates/components.xsl
@@ -285,6 +285,14 @@
+
+
+