kopia lustrzana https://github.com/botheredbybees/kilnController
Minor JS refactoring
rodzic
30b450c9d3
commit
8f5967479d
|
@ -33,6 +33,7 @@ border-color: #000000;
|
||||||
|
|
||||||
.ds-num {
|
.ds-num {
|
||||||
font-family: "LCDN";
|
font-family: "LCDN";
|
||||||
|
line-height: 38px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#main_status {
|
#main_status {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
var state = "IDLE";
|
var state = "IDLE";
|
||||||
|
var state_last = "";
|
||||||
var graph = [ 'profile', 'live'];
|
var graph = [ 'profile', 'live'];
|
||||||
var points = [];
|
var points = [];
|
||||||
var profiles = [];
|
var profiles = [];
|
||||||
|
@ -271,10 +272,6 @@ ws_status.onclose = function()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
eta=0;
|
|
||||||
|
|
||||||
|
|
||||||
ws_status.onmessage = function(e)
|
ws_status.onmessage = function(e)
|
||||||
{
|
{
|
||||||
x = JSON.parse(e.data);
|
x = JSON.parse(e.data);
|
||||||
|
@ -298,6 +295,7 @@ ws_status.onclose = function()
|
||||||
|
|
||||||
updateProgress(parseFloat(x.runtime)/parseFloat(x.totaltime)*100);
|
updateProgress(parseFloat(x.runtime)/parseFloat(x.totaltime)*100);
|
||||||
$('#state').html(parseInt(parseFloat(x.runtime)/parseFloat(x.totaltime)*100) + '% ' + eta);
|
$('#state').html(parseInt(parseFloat(x.runtime)/parseFloat(x.totaltime)*100) + '% ' + eta);
|
||||||
|
$('#target_temp').html(parseInt(x.target) + ' \xB0C');
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -307,25 +305,13 @@ ws_status.onclose = function()
|
||||||
$('#state').html(state);
|
$('#state').html(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$('#act_temp').html(parseInt(x.temperature) + ' \xB0C');
|
$('#act_temp').html(parseInt(x.temperature) + ' \xB0C');
|
||||||
$('#heat').css("background-color", (x.heat > 0.5 ? "rgba(233, 28, 0, 0.84)" : "rgba(46, 12, 12, 0.62") );
|
$('#heat').css("background-color", (x.heat > 0.5 ? "rgba(233, 28, 0, 0.84)" : "rgba(46, 12, 12, 0.62") );
|
||||||
$('#air').css("background-color", (x.air > 0.5 ? "rgba(240, 199, 67, 0.84)" : "rgba(46, 38, 12, 0.62)") );
|
$('#air').css("background-color", (x.air > 0.5 ? "rgba(240, 199, 67, 0.84)" : "rgba(46, 38, 12, 0.62)") );
|
||||||
$('#cool').css("background-color", (x.cool > 0.5 ? "rgba(74, 159, 255, 0.84)" : "rgba(12, 28, 46, 0.62)") );
|
$('#cool').css("background-color", (x.cool > 0.5 ? "rgba(74, 159, 255, 0.84)" : "rgba(12, 28, 46, 0.62)") );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (x.target == 0)
|
|
||||||
{
|
|
||||||
$('#target_temp').html('OFF');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$('#target_temp').html(parseInt(x.target) + ' \xB0C');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -339,15 +325,16 @@ ws_control.onopen = function()
|
||||||
console.log (e.data);
|
console.log (e.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Control Socket has been opened");
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Storage Socket ///////////////////////////////
|
// Storage Socket ///////////////////////////////
|
||||||
|
|
||||||
ws_storage.onopen = function()
|
ws_storage.onopen = function()
|
||||||
{
|
{
|
||||||
console.log("Storage Socket has been opened");
|
ws_storage.send('GET');
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
ws_storage.onmessage = function(e)
|
ws_storage.onmessage = function(e)
|
||||||
{
|
{
|
||||||
|
@ -357,24 +344,26 @@ ws_storage.onopen = function()
|
||||||
{
|
{
|
||||||
if(message.resp == "FAIL")
|
if(message.resp == "FAIL")
|
||||||
{
|
{
|
||||||
if (confirm('Overwrite?')) {
|
if (confirm('Overwrite?'))
|
||||||
|
{
|
||||||
message.force=true;
|
message.force=true;
|
||||||
console.log("Sending: " + JSON.stringify(message));
|
console.log("Sending: " + JSON.stringify(message));
|
||||||
ws_storage.send(JSON.stringify(message));
|
ws_storage.send(JSON.stringify(message));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//the message is an array of profiles
|
//the message is an array of profiles
|
||||||
//FIXME: this should be better, maybe a {"profiles": ...} container?
|
//FIXME: this should be better, maybe a {"profiles": ...} container?
|
||||||
profiles = message;
|
profiles = message;
|
||||||
//delete old options in select
|
//delete old options in select
|
||||||
$('#e2')
|
$('#e2').find('option').remove().end();
|
||||||
.find('option')
|
|
||||||
.remove()
|
|
||||||
.end();
|
|
||||||
|
|
||||||
// fill select with new options from websocket
|
// fill select with new options from websocket
|
||||||
for (var i=0; i<profiles.length; i++)
|
for (var i=0; i<profiles.length; i++)
|
||||||
|
@ -392,25 +381,19 @@ ws_storage.onopen = function()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
console.log('Requesting stored profiles');
|
|
||||||
ws_storage.send('GET');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
$("#e2").select2(
|
||||||
$("#e2").select2({
|
{
|
||||||
placeholder: "Select Profile",
|
placeholder: "Select Profile",
|
||||||
allowClear: false
|
allowClear: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$("#e2").on("change", function(e) {
|
$("#e2").on("change", function(e)
|
||||||
|
{
|
||||||
update_profile(e.val);
|
update_profile(e.val);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<div class="pull-left" style="margin: 14px">
|
<div class="pull-left" style="margin: 14px">
|
||||||
<span id="act_temp" class="display ds-num" style="color: #75890c">25 °C</span>
|
<span id="act_temp" class="display ds-num" style="color: #75890c">25 °C</span>
|
||||||
<span id="target_temp" class="display ds-num">OFF</span>
|
<span id="target_temp" class="display ds-num">OFF</span>
|
||||||
<span id="state" class="display" style="font-size: 14px; text-align: center; padding-right:0">Idle</span>
|
<span id="state" class="display ds-num" style="text-align: center; padding-right:0">Idle</span>
|
||||||
<span id="heat" class="display" style="width: 35px; background: rgba(46, 12, 12, 0.62)"> </span>
|
<span id="heat" class="display" style="width: 35px; background: rgba(46, 12, 12, 0.62)"> </span>
|
||||||
<span id="air" class="display" style="width: 35px; background: rgba(46, 38, 12, 0.62)"> </span>
|
<span id="air" class="display" style="width: 35px; background: rgba(46, 38, 12, 0.62)"> </span>
|
||||||
<span id="cool" class="display" style="width: 35px; background: rgba(12, 28, 46, 0.62)"> </span>
|
<span id="cool" class="display" style="width: 35px; background: rgba(12, 28, 46, 0.62)"> </span>
|
||||||
|
|
Ładowanie…
Reference in New Issue