add progress bar for fw flashing

This commit is contained in:
Connor Rigby 2017-11-17 12:49:26 -08:00
parent e51e667ee0
commit 3940fe1c35
3 changed files with 47 additions and 20 deletions

View file

@ -46,7 +46,7 @@ config :farmbot, Farmbot.System.ConfigStorage,
config :farmbot, :behaviour,
authorization: Farmbot.Bootstrap.Authorization,
system_tasks: Farmbot.Host.SystemTasks,
update_handler: Farmbot.Host.UpdateHandler,
firmware_handler: Farmbot.Firmware.UartHandler
update_handler: Farmbot.Host.UpdateHandler
# firmware_handler: Farmbot.Firmware.UartHandler
config :farmbot, :uart_handler, tty: "/dev/ttyACM0"

View file

@ -51,22 +51,8 @@ defmodule Farmbot.Host.TargetConfiguratorTest do
end
post "/configure_firmware" do
{:ok, _, conn} = read_body(conn)
case conn.body_params do
%{"firmware_hardware" => hw} when hw in ["arduino", "farmduino"] ->
ConfigStorage.update_config_value(:string, "hardware", "firmware_hardware", hw)
# TODO Flash firmware here.
# If Application.get_env(:farmbot, :uart_handler, :tty) do...
redir(conn, "/credentials")
%{"firmware_hardware" => "custom"} ->
ConfigStorage.update_config_value(:string, "hardware", "firmware_hardware", "custom")
redir(conn, "/credentials")
_ ->
send_resp(conn, 500, "Bad firmware_hardware!")
end
Process.sleep(15000)
redir(conn, "/credentials")
end
post "/configure_credentials" do

View file

@ -5,12 +5,54 @@
<link rel="stylesheet" href="/styles.css">
</head>
<style>
#myProgress {
width: 100%;
background-color: #ddd;
}
#myBar {
width: 1%;
height: 30px;
background-color: #4CAF50;
}
</style>
<script>
var num_dots = 0;
function button_click() {
document.getElementById("loading_thing").hidden = false;
moveBar();
}
function moveBar() {
var elem = document.getElementById("myBar");
var width = 1;
var id = setInterval(frame, 300);
function frame() {
if (width >= 100) {
clearInterval(id);
} else {
width++;
elem.style.width = width + '%';
}
}
}
</script>
<body>
<h1>Configure your FarmBot</h1>
<div class="widget">
<div class="widget-header">
<h5>Firmware</h5>
</div>
<div class="widget-content" hidden=true id="loading_thing">
Your firmware is flashing.
<div id="myProgress">
<div id="myBar"></div>
</div>
</div>
<div class="widget-content">
<form action=configure_firmware method=post>
<fieldset>
@ -21,10 +63,9 @@
</fieldset>
</div>
</div>
<div class="button">
<div class="button" onclick="button_click()">
<input type=submit value="next">
</div>
</form>
</body>
</html>