Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
base/firmware/web-firmware-script.inc@157:57bd76aa5e97, 2021-02-01 (annotated)
- Committer:
- andrewboyson
- Date:
- Mon Feb 01 13:24:09 2021 +0000
- Revision:
- 157:57bd76aa5e97
- Parent:
- 156:005785e4740e
- Child:
- 158:80441390de93
Updated firmware page to align bytes sent.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 50:edd44fe9320f | 1 | "'use strict';\n" |
andrewboyson | 50:edd44fe9320f | 2 | "\n" |
andrewboyson | 48:4e678727c4c9 | 3 | "var file;\n" |
andrewboyson | 46:1822fdbe6c0c | 4 | "var xhr;\n" |
andrewboyson | 48:4e678727c4c9 | 5 | "\n" |
andrewboyson | 55:3d1e52e3e9b7 | 6 | "function logUpload(text)\n" |
andrewboyson | 50:edd44fe9320f | 7 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 8 | " document.getElementById('uploadresult').textContent = text;\n" |
andrewboyson | 50:edd44fe9320f | 9 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 10 | "function xhrUploadResponse()\n" |
andrewboyson | 51:c605b2794b44 | 11 | "{\n" |
andrewboyson | 51:c605b2794b44 | 12 | " var topics = xhr.responseText.split('\\f');\n" |
andrewboyson | 55:3d1e52e3e9b7 | 13 | " logUpload(topics[0]);\n" |
andrewboyson | 51:c605b2794b44 | 14 | " if (topics.length > 1) document.getElementById('list').textContent = topics[1];\n" |
andrewboyson | 51:c605b2794b44 | 15 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 16 | "function xhrUploadOnLoad()\n" |
andrewboyson | 46:1822fdbe6c0c | 17 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 18 | " if (xhr.status == 200) xhrUploadResponse();\n" |
andrewboyson | 55:3d1e52e3e9b7 | 19 | " else logUpload('Upload failed');\n" |
andrewboyson | 46:1822fdbe6c0c | 20 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 21 | "function xhrUploadOnError()\n" |
andrewboyson | 46:1822fdbe6c0c | 22 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 23 | " logUpload('Upload error');\n" |
andrewboyson | 46:1822fdbe6c0c | 24 | "}\n" |
andrewboyson | 149:24365666d28d | 25 | "function xhrUploadProgress(e)\n" |
andrewboyson | 149:24365666d28d | 26 | "{\n" |
andrewboyson | 152:edbf676b08ca | 27 | " logUpload('Uploading...\\r\\n' +\n" |
andrewboyson | 157:57bd76aa5e97 | 28 | " 'Total ' + e.total + ' bytes\\r\\n' +\n" |
andrewboyson | 157:57bd76aa5e97 | 29 | " 'Sent ' + e.loaded.toString().padStart(e.total.toString().length, ' ') + ' bytes');\n" |
andrewboyson | 149:24365666d28d | 30 | "}\n" |
andrewboyson | 156:005785e4740e | 31 | "function xhrUploadComplete(e)\n" |
andrewboyson | 156:005785e4740e | 32 | "{\n" |
andrewboyson | 156:005785e4740e | 33 | " logUpload('Saving ' + e.loaded + ' bytes...');\n" |
andrewboyson | 156:005785e4740e | 34 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 35 | "function xhrUploadStart()\n" |
andrewboyson | 48:4e678727c4c9 | 36 | "{\n" |
andrewboyson | 149:24365666d28d | 37 | " logUpload('Upload starting...');\n" |
andrewboyson | 48:4e678727c4c9 | 38 | " \n" |
andrewboyson | 48:4e678727c4c9 | 39 | " xhr = new XMLHttpRequest();\n" |
andrewboyson | 48:4e678727c4c9 | 40 | "\n" |
andrewboyson | 55:3d1e52e3e9b7 | 41 | " xhr.onload = xhrUploadOnLoad;\n" |
andrewboyson | 55:3d1e52e3e9b7 | 42 | " xhr.onerror = xhrUploadOnError;\n" |
andrewboyson | 149:24365666d28d | 43 | " xhr.upload.onprogress = xhrUploadProgress;\n" |
andrewboyson | 156:005785e4740e | 44 | " xhr.upload.onload = xhrUploadComplete;\n" |
andrewboyson | 48:4e678727c4c9 | 45 | "\n" |
andrewboyson | 53:27d56a22a450 | 46 | " xhr.open('POST', '/firmware-ajax'); //Defaults to async=true\n" |
andrewboyson | 48:4e678727c4c9 | 47 | " xhr.send(file);\n" |
andrewboyson | 48:4e678727c4c9 | 48 | "}\n" |
andrewboyson | 46:1822fdbe6c0c | 49 | "function startUpload()\n" |
andrewboyson | 46:1822fdbe6c0c | 50 | "{\n" |
andrewboyson | 46:1822fdbe6c0c | 51 | " var fileInput = document.getElementById('fileInput');\n" |
andrewboyson | 46:1822fdbe6c0c | 52 | "\n" |
andrewboyson | 46:1822fdbe6c0c | 53 | " if (fileInput.files.length == 0)\n" |
andrewboyson | 46:1822fdbe6c0c | 54 | " {\n" |
andrewboyson | 55:3d1e52e3e9b7 | 55 | " logUpload('Please choose a file');\n" |
andrewboyson | 46:1822fdbe6c0c | 56 | " return;\n" |
andrewboyson | 46:1822fdbe6c0c | 57 | " }\n" |
andrewboyson | 46:1822fdbe6c0c | 58 | "\n" |
andrewboyson | 46:1822fdbe6c0c | 59 | " if (fileInput.files.length > 1)\n" |
andrewboyson | 46:1822fdbe6c0c | 60 | " {\n" |
andrewboyson | 55:3d1e52e3e9b7 | 61 | " logUpload('Please choose just one file');\n" |
andrewboyson | 46:1822fdbe6c0c | 62 | " return;\n" |
andrewboyson | 46:1822fdbe6c0c | 63 | " }\n" |
andrewboyson | 48:4e678727c4c9 | 64 | " \n" |
andrewboyson | 48:4e678727c4c9 | 65 | " file = fileInput.files[0];\n" |
andrewboyson | 48:4e678727c4c9 | 66 | " \n" |
andrewboyson | 55:3d1e52e3e9b7 | 67 | " xhrUploadStart();\n" |
andrewboyson | 55:3d1e52e3e9b7 | 68 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 69 | "function logRestart(text)\n" |
andrewboyson | 55:3d1e52e3e9b7 | 70 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 71 | " document.getElementById('restartresult').textContent = text;\n" |
andrewboyson | 55:3d1e52e3e9b7 | 72 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 73 | "function redirect()\n" |
andrewboyson | 55:3d1e52e3e9b7 | 74 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 75 | " location.href = '/firmware';\n" |
andrewboyson | 55:3d1e52e3e9b7 | 76 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 77 | "function xhrRestartOnLoad()\n" |
andrewboyson | 55:3d1e52e3e9b7 | 78 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 79 | " if (xhr.status == 200) logRestart('Restart should never have returned');\n" |
andrewboyson | 55:3d1e52e3e9b7 | 80 | " else logRestart('Restart failed');\n" |
andrewboyson | 55:3d1e52e3e9b7 | 81 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 82 | "function xhrRestartStart()\n" |
andrewboyson | 55:3d1e52e3e9b7 | 83 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 84 | " logRestart('Restarting...');\n" |
andrewboyson | 55:3d1e52e3e9b7 | 85 | " \n" |
andrewboyson | 55:3d1e52e3e9b7 | 86 | " xhr = new XMLHttpRequest();\n" |
andrewboyson | 55:3d1e52e3e9b7 | 87 | "\n" |
andrewboyson | 55:3d1e52e3e9b7 | 88 | " xhr.onload = xhrRestartOnLoad;\n" |
andrewboyson | 55:3d1e52e3e9b7 | 89 | "\n" |
andrewboyson | 55:3d1e52e3e9b7 | 90 | " xhr.open('GET', '/firmware-ajax?restart='); //Defaults to async=true\n" |
andrewboyson | 55:3d1e52e3e9b7 | 91 | " xhr.send();\n" |
andrewboyson | 55:3d1e52e3e9b7 | 92 | " \n" |
andrewboyson | 55:3d1e52e3e9b7 | 93 | " setTimeout(redirect, 2000);\n" |
andrewboyson | 55:3d1e52e3e9b7 | 94 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 95 | "function restart()\n" |
andrewboyson | 55:3d1e52e3e9b7 | 96 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 97 | " xhrRestartStart();\n" |
andrewboyson | 48:4e678727c4c9 | 98 | "}\n" |
andrewboyson | 149:24365666d28d | 99 | "\n" |
andrewboyson | 48:4e678727c4c9 | 100 | "" |