Added missing files from previous commit

pull/173/head
tmcdos 8 years ago
parent 95d7e8e391
commit 7b677b8f1f
  1. 42
      html/console_main.js
  2. 73
      html/flash/flash.html
  3. 227
      html/flash/flash.js
  4. 8
      html/home.js
  5. 31
      html/log_main.js

@ -0,0 +1,42 @@
console_url = "/console/text";
onLoad(function() {
fetchText(100, true);
$("#reset-button").addEventListener("click", function(e) {
e.preventDefault();
var co = $("#console");
co.innerHTML = "";
ajaxSpin('POST', "/console/reset",
function(resp) { showNotification("uC reset"); co.textEnd = 0; },
function(s, st) { showWarning("Error resetting uC"); }
);
});
$("#clear-button").addEventListener("click", function(e) {
e.preventDefault();
var co = $("#console");
co.innerHTML = "";
});
ajaxJson('GET', "/console/baud",
function(data) { $("#baud-sel").value = data.rate; },
function(s, st) { showNotification(st); }
);
bnd($("#baud-sel"), "change", function(ev) {
ev.preventDefault();
var baud = $("#baud-sel").value;
ajaxSpin('POST', "/console/baud?rate="+baud,
function(resp) { showNotification("" + baud + " baud set"); },
function(s, st) { showWarning("Error setting baud rate: " + st); }
);
});
consoleSendInit();
addClass($('html')[0], "height100");
addClass($('body')[0], "height100");
addClass($('#layout'), "height100");
addClass($('#layout'), "flex-vbox");
});

@ -0,0 +1,73 @@
<!doctype html>
<html><head>
<title>esp-link</title>
<link rel="stylesheet" href="../pure.css">
<link rel="stylesheet" href="../style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="layout">
<div id="main">
<div class="header">
<h1>Firmware</h1>
</div>
<div class="content">
<div style="float:left; padding:2px">
<div class="card">
<h1>Upgrade firmware
<div id="firmware-spinner" class="spinner spinner-small"></div>
</h1>
<form id="firmware-form" class="pure-form" hidden>
<div class="pure-form-stacked">
<label>Filename (<span id="firmware-name" style="color:red"></span>)</label>
<input type="file" name="firmware_file" id="firmware_file" size="25" style="border:1px solid black;background-color:#F0CAA6;" />
<div class="popup">Provide appropriate BIN file with firmware (either user1 or user2)</div>
</div>
<button id="flash-start" type="button" class="pure-button button-primary">
Flash firmware
</button>
&nbsp;
<button id="flash-stop" type="button" class="pure-button button-primary pure-button-disabled" disabled>
Stop flashing
</button>
<div id="progress" hidden>
<div align="center" width="100%">
<progress id="progressbar" value="0" style="width:100%"></progress>
</div>
<div id="up-count" align="center"></div>
</div>
</form>
</div>
</div>
<div style="float:left; padding:2px">
<div class="card">
<h1>HTTP authentication
<div id="auth-spinner" class="spinner spinner-small"></div>
</h1>
<form action="#" id="auth-form" class="pure-form" hidden>
<div class="pure-form-stacked">
<div>
<label>Username</label>
<input type="text" id="auth_user" name="auth_user" maxlength="30" />
<div class="popup">Username for HTTP basic authentication to protect <b>/flash</b> and <b>/wifi</b> pages</div>
</div>
<div>
<label>Password</label>
<input type="text" id="auth_pass" name="auth_pass" maxlength="63" />
<div class="popup">Password for HTTP basic authentication to protect <b>/flash</b> and <b>/wifi</b> pages</div>
</div>
</div>
<button id="auth-button" type="submit" class="pure-button button-primary">
Update settings
</button>
</form>
</div>
</div>
</div>
</div>
</div>
<iframe id='frame_up' name='frame_up' src='' style="width:0;height:0;border:0px solid #fff;" frameborder="0" scrolling="auto"></iframe>
<script src="../ui.js"></script>
<script src="flash.js"></script>
</body></html>

@ -0,0 +1,227 @@
onLoad(function() {
bnd($("#auth-form"), "submit", changeAuth);
bnd($("#flash-start"), "click", startUpload);
bnd($("#flash-stop"), "click", stopUpload);
nextFlash();
fetchAuth();
});
// disable START button, enable STOP button, show spinner
function flash_start()
{
var cb = $("#flash-start");
addClass(cb, "pure-button-disabled");
cb.setAttribute("disabled", "");
var cb = $("#flash-stop");
removeClass(cb, "pure-button-disabled");
cb.removeAttribute("disabled");
$("#firmware-spinner").removeAttribute("hidden");
$("#progressbar").value = 0;
$("#up-count").innerHTML = '0 %';
$("#progress").removeAttribute("hidden");
}
// enable START button, disable STOP button, hide spinner
function flash_stop()
{
var cb = $("#flash-start");
removeClass(cb, "pure-button-disabled");
cb.removeAttribute("disabled");
var cb = $("#flash-stop");
addClass(cb, "pure-button-disabled");
cb.setAttribute("disabled", "true");
$("#firmware-spinner").setAttribute("hidden","true");
$("#progress").setAttribute("hidden","true");
}
function displayAuth(data) {
Object.keys(data).forEach(function (v) {
el = $("#" + v);
if (el != null) {
if (el.nodeName === "INPUT") el.value = data[v];
else el.innerHTML = data[v];
return;
}
el = document.querySelector('input[name="' + v + '"]');
if (el == null)
el = document.querySelector('select[name="' + v + '"]');
if (el != null) {
if (el.type == "checkbox") {
el.checked = data[v] == "enabled";
} else el.value = data[v];
}
});
$("#auth-spinner").setAttribute("hidden", "");
$("#auth-form").removeAttribute("hidden");
}
function fetchAuth() {
ajaxJson("GET", "/flash/auth", displayAuth, function () {
window.setTimeout(fetchAuth, 1000);
});
}
function showFlash(data) {
el = $("#firmware-name");
if (el != null) el.innerHTML = data;
$("#firmware-spinner").setAttribute("hidden", "");
$("#firmware-form").removeAttribute("hidden");
}
function nextFlash() {
ajaxReq("GET", "/flash/next", showFlash, function () {
window.setTimeout(nextFlash, 1000);
});
}
function showFlash2(data) {
el = $("#firmware-name");
if (el != null)
{
if(el.innerHTML != data) showNotification("Firmware successfully updated");
else showWarning("Flashing seems to have failed and it reverted to the old firmware?");
el.innerHTML = data;
}
// show uploading form
$("#firmware-spinner").setAttribute("hidden", "");
$("#firmware-form").removeAttribute("hidden");
}
// waiting module to come up after reboot
function checkFlash() {
ajaxReq("GET", "/flash/next", showFlash2, function () {
window.setTimeout(checkFlash, 1000);
});
}
function nextReboot() {
// hide uploading form
$("#firmware-spinner").removeAttribute("hidden");
$("#firmware-form").setAttribute("hidden","");
ajaxReq("GET", "/flash/reboot",
function(data)
{
showNotification("Waiting for ESP module to reboot");
window.setTimeout(checkFlash, 4000);
},
function (s,st)
{
showWarning("ERROR - "+st);
// show uploading form
$("#firmware-spinner").setAttribute("hidden", "");
$("#firmware-form").removeAttribute("hidden");
}
);
}
function changeAuth(e) {
e.preventDefault();
var url = "/flash/auth?1=1";
var i, inputs = document.querySelectorAll("#" + e.target.id + " input,select");
for (i = 0; i < inputs.length; i++)
{
if (inputs[i].type == "checkbox")
{
var val = (inputs[i].checked) ? 1 : 0;
url += "&" + inputs[i].name + "=" + val;
}
else url += "&" + inputs[i].name + "=" + inputs[i].value;
};
hideWarning();
var n = e.target.id.replace("-form", "");
var cb = $("#" + n + "-button");
addClass(cb, "pure-button-disabled");
ajaxSpin("POST", url, function (resp) {
showNotification("Settings updated");
removeClass(cb, "pure-button-disabled");
}, function (s, st) {
showWarning("Error: " + st);
removeClass(cb, "pure-button-disabled");
window.setTimeout(fetchAuth, 100);
});
}
function errUpload(evt)
{
flash_stop();
}
function startUpload()
{
hideWarning();
var file_input = $("#firmware_file");
if(file_input.files.length==0)
{
alert("Please choose a file");
return;
}
var progressBar = $("#progressbar");
flash_start();
var xhr = j();
xhr.upload.onabort = errUpload;
xhr.upload.onerror = errUpload;
xhr.upload.ontimeout = errUpload;
xhr.upload.onprogress = function (e) {
if (e.lengthComputable)
{
progressBar.max = e.total;
progressBar.value = e.loaded;
$("#up-count").innerHTML = Math.floor((e.loaded / e.total) * 100) + '%';
}
}
xhr.upload.onloadstart = function (e) {
progressBar.value = 0;
}
xhr.upload.onloadend = function (e) {
progressBar.value = e.loaded;
}
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return;
clearTimeout(timeout);
if (xhr.status >= 200 && xhr.status < 300)
{
//console.log("XHR done:", method, url, "->", xhr.status);
flash_stop();
showNotification("Firmware updated - now rebooting");
window.setTimeout(nextReboot, 3000);
}
else
{
console.log("XHR ERR : POST /flash/upload -> ", xhr.status, xhr.responseText, xhr);
flash_stop();
showWarning("ERROR = " + xhr.responseText);
}
}
xhr.open("POST", "/flash/upload", true);
xhr.setRequestHeader('Content-Type', "application/octet-stream");
xhr.setRequestHeader('Content-Disposition', 'attachment; filename="' + $("#firmware-name").innerHTML + '"');
var timeout = setTimeout(function() {
xhr.abort();
console.log("XHR abort: POST /flash/upload");
xhr.status = 599;
xhr.responseText = "request time-out";
}, 9000);
//console.log("XHR send:", method, url);
try
{
xhr.send(file_input.files[0]);
}
catch(err)
{
console.log("XHR EXEC : POST /flash/upload -> ", err);
flash_stop();
showWarning("Error = " + err);
}
}
function stopUpload()
{
if(req) req.abort();
req = null;
flash_stop();
}

@ -0,0 +1,8 @@
onLoad(function() {
makeAjaxInput("system", "description");
makeAjaxInput("system", "name");
fetchPins();
getWifiInfo();
getSystemInfo();
bnd($("#pinform"), "submit", setPins);
});

@ -0,0 +1,31 @@
console_url = "/log/text";
onLoad(function() {
fetchText(100, false);
$("#refresh-button").addEventListener("click", function(e) {
e.preventDefault();
fetchText(100, false);
});
$("#reset-button").addEventListener("click", function (e) {
e.preventDefault();
var co = $("#console");
co.innerHTML = "";
ajaxSpin('POST', "/log/reset",
function (resp) { showNotification("Resetting esp-link"); co.textEnd = 0; fetchText(2000, false); },
function (s, st) { showWarning("Error resetting esp-link"); }
);
});
["auto", "off", "on0", "on1"].forEach(function(mode) {
bnd($('#dbg-'+mode), "click", function(el) {
ajaxJsonSpin('POST', "/log/dbg?mode="+mode,
function(data) { showNotification("UART mode " + data.mode); showDbgMode(data.mode); },
function(s, st) { showWarning("Error setting UART mode: " + st); }
);
});
});
ajaxJson('GET', "/log/dbg", function(data) { showDbgMode(data.mode); }, function() {});
});
Loading…
Cancel
Save