浏览代码

Manifest download and flashing via the UI

Andrew Chalkley 9 年之前
父节点
当前提交
99234012d1
共有 7 个文件被更改,包括 85 次插入68 次删除
  1. 0 0
      back-end/prepare_binaries.js
  2. 7 1
      front-end/index.html
  3. 70 2
      front-end/js/app.js
  4. 4 0
      front-end/js/port_select.js
  5. 4 4
      index.js
  6. 0 37
      manifestly/index.js
  7. 0 24
      manifestly/manifest.json

+ 0 - 0
manifestly/manifest.js → back-end/prepare_binaries.js


+ 7 - 1
front-end/index.html

@@ -17,7 +17,13 @@
         <div class="padded-more">
             <label for="ports">Select Port:</label>
             <select title="Select a Serial/COM Port" id="ports" name="ports" class="form-control" disabled>
-
+            
+            </select>
+        </div>
+        <div class="padded-more">
+            <label for="manifests">Select Binaries to Flash:</label>
+            <select title="Select Binaries to Flash" id="manifests" name="manifests" class="form-control" disabled>
+            
             </select>
         </div>
     </div>

+ 70 - 2
front-end/js/app.js

@@ -1,21 +1,31 @@
 "use strict";
 
+const URLS = {
+    manifestList: "http://flasher.thingssdk.com/v1/manifest-list.json"
+};
+
 //Relative to index.html not app.js
 const SerialScanner = require("../back-end/serial_scanner");
 const PortSelect = require("./js/port_select");
+const prepareBinaries = require("../back-end/prepare_binaries");
+const log = require("../back-end/logger");
+const RomComm = require("../back-end/rom_comm");
 
 function $(id) { return document.getElementById(id); }
 
 const flashButton = $("flash-button");
 const appStatus = $("status");
 const portsSelect = new PortSelect($("ports"));
+const manifestsSelect = $("manifests");
 const serialScanner = new SerialScanner();
 const pollTime = 1000; // One second
 
 var last_notification = "";
 
 flashButton.addEventListener("click", event => {
-    var notification = new Notification("Flash Finished!");
+    fetch(manifestsSelect.value)
+        .then(processJSON)
+        .then(flashWithManifest);
 });
 
 serialScanner.on("ports", (ports) => {
@@ -63,12 +73,70 @@ function onError(error){
     appStatus.textContent = error.message;
 }
 
+function processJSON(response) {
+    return response.json();
+}
+
+function generateManifestList(manifestsJSON) {
+    console.log(manifestsJSON); 
+    manifestsJSON.options.forEach((option) => {
+        option.versions.forEach((version) => {
+            const optionElement = document.createElement("option");
+            optionElement.textContent = `${option.name} - ${version.version}`;
+            optionElement.value = version.manifest;
+            manifestsSelect.appendChild(optionElement);
+            manifestsSelect.disabled = false;
+        });
+    });
+}
+
+function getManifests() {
+    fetch(URLS.manifestList)
+        .then(processJSON)
+        .then(generateManifestList).catch((error) => {
+            console.log(error); 
+            setTimeout(getManifests, pollTime);
+        });
+}
+
 /**
  * Sets up UI
  */
 function init() {
+    getManifests();
     serialScanner.scan();
     setInterval(serialScanner.checkForChanges.bind(serialScanner), pollTime);
 }
 
-init();
+init();
+
+function flashWithManifest(manifest) {
+    console.log(portsSelect.value);
+    prepareBinaries(manifest, (err, flashSpec) => {
+        if(err) throw err;
+
+        const esp = new RomComm({
+            portName: portsSelect.value,
+            baudRate: 115200
+        });
+
+        esp.open().then((result) => {
+            log.info("ESP is open", result);
+            let promise = Promise.resolve();
+
+            flashSpec.forEach((spec) => {
+               promise = promise.then(()=> {
+                   return esp.flashAddress(Number.parseInt(spec.address), spec.buffer)
+               });
+            });
+
+            return promise.then(() => esp.close())
+                .then((result) => {
+                    var notification = new Notification("Flash Finished!");        
+                    log.info("Flashed to latest Espruino build!", result);
+                });
+        }).catch((error) => {
+            log.error("Oh noes!", error);
+        });
+    });
+}

+ 4 - 0
front-end/js/port_select.js

@@ -58,4 +58,8 @@ module.exports = class PortSelect {
     set disabled (value) {
         this.selectElement.disabled = value;
     }
+    
+    get value() {
+        return this.selectElement.value;
+    }
 };

+ 4 - 4
index.js

@@ -23,10 +23,10 @@ app.on('window-all-closed', function() {
 app.on('ready', function() {
   // Create the browser window.
   mainWindow = new BrowserWindow({
-    width: 256,
-    height: 200,
-    'min-width': 256,
-    'min-height': 200,
+    width: 450,
+    height: 160,
+    'min-width': 450,
+    'min-height': 160,
     'max-width': 500,
     'max-height': 550,
     'accept-first-mouse': true,

+ 0 - 37
manifestly/index.js

@@ -1,37 +0,0 @@
-"use strict";
-
-const fs = require("fs");
-const fetch = require("node-fetch");
-const prepareBinaries = require("./manifest");
-const log = require("../back-end/logger");
-const RomComm = require("../back-end/rom_comm");
-
-fs.readFile("./manifest.json", (err, data) => {
-    if(err) throw err;
-    const manifest = JSON.parse(data);
-    prepareBinaries(manifest, (err, flashSpec) => {
-        if(err) throw err;
-
-        const esp = new RomComm({
-            portName: "/dev/cu.SLAB_USBtoUART",
-            baudRate: 115200
-        });
-
-        esp.open().then((result) => {
-            log.info("ESP is open", result);
-            let promise = Promise.resolve();
-
-            flashSpec.forEach((spec) => {
-               promise = promise.then(()=> {
-                   return esp.flashAddress(Number.parseInt(spec.address), spec.buffer)
-               });
-            });
-
-            return promise.then(() => esp.close())
-                .then((result) => log.info("Flashed to latest Espruino build!", result));
-        }).catch((error) => {
-            log.error("Oh noes!", error);
-        });
-    });
-});
-

+ 0 - 24
manifestly/manifest.json

@@ -1,24 +0,0 @@
-{
-  "name": "Espruino 1v85",
-  "board": "ESP8266 ESP-12",
-  "description": "Official Binaries for the Espruino Runtime for the ESP8266 MCU ESP-12",
-  "download": "http://www.espruino.com/files/espruino_1v85.zip",
-  "flash": [
-    {
-      "address": "0x0000",
-      "path": "espruino_1v85_esp8266/boot_v1.4(b1).bin"
-    },
-    {
-      "address": "0x1000",
-      "path": "espruino_1v85_esp8266/espruino_esp8266_user1.bin"
-    },
-    {
-      "address": "0x3FC000",
-      "path": "espruino_1v85_esp8266/esp_init_data_default.bin"
-    },
-    {
-      "address": "0x3FE000",
-      "path": "espruino_1v85_esp8266/blank.bin"
-    }
-  ]
-}