2013-11-28 22:21:00 +00:00
var state = "IDLE" ;
2013-11-29 23:08:04 +00:00
var state _last = "" ;
2019-07-14 04:39:56 +00:00
var graph = [ 'profile' , 'live' , 'movingProfile' ] ;
2013-11-29 21:46:00 +00:00
var points = [ ] ;
2013-11-28 22:21:00 +00:00
var profiles = [ ] ;
2014-11-25 23:05:37 +00:00
var time _mode = 0 ;
2019-01-03 07:25:49 +00:00
var selected _profile = 2 ;
var selected _profile _name = 'bisque' ;
2016-07-08 04:41:06 +00:00
var temp _scale = "c" ;
2019-01-07 22:10:58 +00:00
var time _scale _slope = "m" ;
var time _scale _profile = "m" ;
var time _scale _long = "Minutes" ;
2016-07-08 04:41:06 +00:00
var temp _scale _display = "C" ;
var kwh _rate = 0.26 ;
2019-01-07 22:10:58 +00:00
var currency _type = "AUD" ;
2013-11-29 21:46:00 +00:00
2014-12-19 11:11:01 +00:00
var host = "ws://" + window . location . hostname + ":" + window . location . port ;
2013-11-28 22:21:00 +00:00
var ws _status = new WebSocket ( host + "/status" ) ;
var ws _control = new WebSocket ( host + "/control" ) ;
2016-07-08 04:41:06 +00:00
var ws _config = new WebSocket ( host + "/config" ) ;
2013-11-28 22:21:00 +00:00
var ws _storage = new WebSocket ( host + "/storage" ) ;
2016-07-08 04:41:06 +00:00
2013-12-06 18:12:49 +00:00
if ( window . webkitRequestAnimationFrame ) window . requestAnimationFrame = window . webkitRequestAnimationFrame ;
2013-11-28 22:21:00 +00:00
2013-11-29 21:46:00 +00:00
graph . profile =
{
label : "Profile" ,
data : [ ] ,
points : { show : false } ,
color : "#75890c" ,
draggable : false
} ;
graph . live =
{
label : "Live" ,
data : [ ] ,
points : { show : false } ,
color : "#d8d3c5" ,
draggable : false
} ;
2019-07-14 04:39:56 +00:00
graph . movingProfile =
{
label : "Live Profile" ,
data : [ ] ,
points : { show : false } ,
color : "#ffd300" ,
draggable : false
} ;
2013-11-29 21:46:00 +00:00
2013-12-09 11:51:08 +00:00
function updateProfile ( id )
2013-11-29 21:46:00 +00:00
{
selected _profile = id ;
2016-12-13 05:21:43 +00:00
selected _profile _name = profiles [ id ] . name ;
var job _seconds = profiles [ id ] . data . length === 0 ? 0 : parseInt ( profiles [ id ] . data [ profiles [ id ] . data . length - 1 ] [ 0 ] ) ;
2016-07-08 04:41:06 +00:00
var kwh = ( 3850 * job _seconds / 3600 / 1000 ) . toFixed ( 2 ) ;
var cost = ( kwh * kwh _rate ) . toFixed ( 2 ) ;
var job _time = new Date ( job _seconds * 1000 ) . toISOString ( ) . substr ( 11 , 8 ) ;
2013-11-29 21:46:00 +00:00
$ ( '#sel_prof' ) . html ( profiles [ id ] . name ) ;
2013-11-30 13:02:46 +00:00
$ ( '#sel_prof_eta' ) . html ( job _time ) ;
2016-07-08 04:41:06 +00:00
$ ( '#sel_prof_cost' ) . html ( kwh + ' kWh (' + currency _type + ': ' + cost + ')' ) ;
2013-11-29 21:46:00 +00:00
graph . profile . data = profiles [ id ] . data ;
2019-07-14 04:39:56 +00:00
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-11-28 16:17:15 +00:00
}
2013-11-29 21:46:00 +00:00
2013-12-09 11:51:08 +00:00
function deleteProfile ( )
{
2016-03-12 20:16:29 +00:00
var profile = { "type" : "profile" , "data" : "" , "name" : selected _profile _name } ;
var delete _struct = { "cmd" : "DELETE" , "profile" : profile } ;
var delete _cmd = JSON . stringify ( delete _struct ) ;
2013-12-09 11:51:08 +00:00
console . log ( "Delete profile:" + selected _profile _name ) ;
2016-03-12 20:16:29 +00:00
ws _storage . send ( delete _cmd ) ;
ws _storage . send ( 'GET' ) ;
2016-12-13 05:21:43 +00:00
selected _profile _name = profiles [ 0 ] . name ;
2016-03-12 20:16:29 +00:00
state = "IDLE" ;
$ ( '#edit' ) . hide ( ) ;
$ ( '#profile_selector' ) . show ( ) ;
$ ( '#btn_controls' ) . show ( ) ;
$ ( '#status' ) . slideDown ( ) ;
$ ( '#profile_table' ) . slideUp ( ) ;
$ ( '#e2' ) . select2 ( 'val' , 0 ) ;
graph . profile . points . show = false ;
graph . profile . draggable = false ;
2019-07-14 04:39:56 +00:00
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-12-09 11:51:08 +00:00
}
2013-11-29 21:46:00 +00:00
2013-11-29 22:20:13 +00:00
function updateProgress ( percentage )
2013-11-29 21:46:00 +00:00
{
if ( state == "RUNNING" )
{
if ( percentage > 100 ) percentage = 100 ;
$ ( '#progressBar' ) . css ( 'width' , percentage + '%' ) ;
2013-12-09 14:10:22 +00:00
if ( percentage > 5 ) $ ( '#progressBar' ) . html ( parseInt ( percentage ) + '%' ) ;
2013-11-29 21:46:00 +00:00
}
else
{
$ ( '#progressBar' ) . css ( 'width' , 0 + '%' ) ;
$ ( '#progressBar' ) . html ( '' ) ;
}
2013-11-28 16:17:15 +00:00
}
2013-12-01 00:51:45 +00:00
function updateProfileTable ( )
{
2013-12-06 22:36:40 +00:00
var dps = 0 ;
2013-12-07 12:56:31 +00:00
var slope = "" ;
2013-12-09 11:51:08 +00:00
var color = "" ;
2013-12-07 12:56:31 +00:00
var html = '<h3>Profile Points</h3><div class="table-responsive" style="scroll: none"><table class="table table-striped">' ;
2016-07-08 04:41:06 +00:00
html += '<tr><th style="width: 50px">#</th><th>Target Time in ' + time _scale _long + '</th><th>Target Temperature in °' + temp _scale _display + '</th><th>Slope in °' + temp _scale _display + '/' + time _scale _slope + '</th><th></th></tr>' ;
2013-12-01 00:51:45 +00:00
2013-12-01 01:05:24 +00:00
for ( var i = 0 ; i < graph . profile . data . length ; i ++ )
2013-12-01 00:51:45 +00:00
{
2016-07-08 04:41:06 +00:00
if ( i >= 1 ) dps = ( ( graph . profile . data [ i ] [ 1 ] - graph . profile . data [ i - 1 ] [ 1 ] ) / ( graph . profile . data [ i ] [ 0 ] - graph . profile . data [ i - 1 ] [ 0 ] ) * 10 ) / 10 ;
2013-12-09 11:51:08 +00:00
if ( dps > 0 ) { slope = "up" ; color = "rgba(206, 5, 5, 1)" ; } else
if ( dps < 0 ) { slope = "down" ; color = "rgba(23, 108, 204, 1)" ; dps *= - 1 ; } else
if ( dps == 0 ) { slope = "right" ; color = "grey" ; }
2013-12-07 12:56:31 +00:00
2013-12-09 14:10:22 +00:00
html += '<tr><td><h4>' + ( i + 1 ) + '</h4></td>' ;
2016-07-08 04:41:06 +00:00
html += '<td><input type="text" class="form-control" id="profiletable-0-' + i + '" value="' + timeProfileFormatter ( graph . profile . data [ i ] [ 0 ] , true ) + '" style="width: 60px" /></td>' ;
2013-12-07 16:41:34 +00:00
html += '<td><input type="text" class="form-control" id="profiletable-1-' + i + '" value="' + graph . profile . data [ i ] [ 1 ] + '" style="width: 60px" /></td>' ;
2016-07-08 04:41:06 +00:00
html += '<td><div class="input-group"><span class="glyphicon glyphicon-circle-arrow-' + slope + ' input-group-addon ds-trend" style="background: ' + color + '"></span><input type="text" class="form-control ds-input" readonly value="' + formatDPS ( dps ) + '" style="width: 100px" /></div></td>' ;
2013-12-07 12:56:31 +00:00
html += '<td> </td></tr>' ;
2013-12-01 00:51:45 +00:00
}
2013-12-07 12:56:31 +00:00
html += '</table></div>' ;
2013-12-05 18:53:18 +00:00
2013-12-01 00:51:45 +00:00
$ ( '#profile_table' ) . html ( html ) ;
2013-12-09 11:51:08 +00:00
2013-12-07 16:41:34 +00:00
//Link table to graph
$ ( ".form-control" ) . change ( function ( e )
{
2014-11-25 23:05:37 +00:00
var id = $ ( this ) [ 0 ] . id ; //e.currentTarget.attributes.id
2013-12-07 16:41:34 +00:00
var value = parseInt ( $ ( this ) [ 0 ] . value ) ;
var fields = id . split ( "-" ) ;
var col = parseInt ( fields [ 1 ] ) ;
var row = parseInt ( fields [ 2 ] ) ;
2016-07-08 04:41:06 +00:00
2016-12-13 05:21:43 +00:00
if ( graph . profile . data . length > 0 ) {
2016-07-08 04:41:06 +00:00
if ( col == 0 ) {
graph . profile . data [ row ] [ col ] = timeProfileFormatter ( value , false ) ;
}
else {
graph . profile . data [ row ] [ col ] = value ;
}
2019-07-14 04:39:56 +00:00
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2016-12-13 05:21:43 +00:00
}
2013-12-07 16:41:34 +00:00
updateProfileTable ( ) ;
2016-07-08 04:41:06 +00:00
2013-12-07 16:41:34 +00:00
} ) ;
2013-12-01 00:51:45 +00:00
}
2013-11-28 16:17:15 +00:00
2016-07-08 04:41:06 +00:00
function timeProfileFormatter ( val , down ) {
var rval = val
switch ( time _scale _profile ) {
case "m" :
if ( down ) { rval = val / 60 ; } else { rval = val * 60 ; }
break ;
case "h" :
if ( down ) { rval = val / 3600 ; } else { rval = val * 3600 ; }
break ;
}
return Math . round ( rval ) ;
}
function formatDPS ( val ) {
var tval = val ;
if ( time _scale _slope == "m" ) {
tval = val * 60 ;
}
if ( time _scale _slope == "h" ) {
tval = ( val * 60 ) * 60 ;
}
return Math . round ( tval ) ;
}
function hazardTemp ( ) {
if ( temp _scale == "f" ) {
return ( 45 * 9 / 5 ) + 32
}
else {
return 45
}
}
2014-11-25 23:05:37 +00:00
function timeTickFormatter ( val )
{
if ( val < 1800 )
{
return val ;
}
else
{
var hours = Math . floor ( val / ( 3600 ) ) ;
var div _min = val % ( 3600 ) ;
var minutes = Math . floor ( div _min / 60 ) ;
if ( hours < 10 ) { hours = "0" + hours ; }
if ( minutes < 10 ) { minutes = "0" + minutes ; }
return hours + ":" + minutes ;
}
}
2013-11-29 21:46:00 +00:00
function runTask ( )
{
2013-12-01 00:51:45 +00:00
var cmd =
2013-11-29 21:46:00 +00:00
{
"cmd" : "RUN" ,
"profile" : profiles [ selected _profile ]
}
graph . live . data = [ ] ;
2019-07-14 04:39:56 +00:00
graph . movingProfile . data = [ ] ;
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-11-28 16:17:15 +00:00
2013-12-01 00:51:45 +00:00
ws _control . send ( JSON . stringify ( cmd ) ) ;
2013-11-28 16:17:15 +00:00
}
2013-12-06 22:02:07 +00:00
function runTaskSimulation ( )
{
var cmd =
{
"cmd" : "SIMULATE" ,
"profile" : profiles [ selected _profile ]
}
graph . live . data = [ ] ;
2019-07-14 04:39:56 +00:00
graph . movingProfile . data = [ ] ;
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-12-06 22:02:07 +00:00
ws _control . send ( JSON . stringify ( cmd ) ) ;
}
2013-11-28 16:17:15 +00:00
2013-11-29 21:46:00 +00:00
function abortTask ( )
{
2013-12-01 00:51:45 +00:00
var cmd = { "cmd" : "STOP" } ;
ws _control . send ( JSON . stringify ( cmd ) ) ;
2013-11-28 16:17:15 +00:00
}
2013-12-01 00:51:45 +00:00
function enterNewMode ( )
{
state = "EDIT"
2013-12-05 23:47:43 +00:00
$ ( '#status' ) . slideUp ( ) ;
2013-12-01 00:51:45 +00:00
$ ( '#edit' ) . show ( ) ;
2013-12-05 18:53:18 +00:00
$ ( '#profile_selector' ) . hide ( ) ;
2013-12-01 00:51:45 +00:00
$ ( '#btn_controls' ) . hide ( ) ;
$ ( '#form_profile_name' ) . attr ( 'value' , '' ) ;
$ ( '#form_profile_name' ) . attr ( 'placeholder' , 'Please enter a name' ) ;
graph . profile . points . show = true ;
graph . profile . draggable = true ;
2013-12-01 01:05:24 +00:00
graph . profile . data = [ ] ;
2019-07-14 04:39:56 +00:00
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-12-01 00:51:45 +00:00
updateProfileTable ( ) ;
}
2013-11-28 16:17:15 +00:00
2013-12-01 00:51:45 +00:00
function enterEditMode ( )
{
2013-11-28 16:17:15 +00:00
state = "EDIT"
2013-12-05 23:47:43 +00:00
$ ( '#status' ) . slideUp ( ) ;
2013-12-01 00:51:45 +00:00
$ ( '#edit' ) . show ( ) ;
2013-12-05 18:53:18 +00:00
$ ( '#profile_selector' ) . hide ( ) ;
2013-12-01 00:51:45 +00:00
$ ( '#btn_controls' ) . hide ( ) ;
2016-03-12 20:16:29 +00:00
console . log ( profiles ) ;
2016-12-13 05:21:43 +00:00
$ ( '#form_profile_name' ) . val ( profiles [ selected _profile ] . name ) ;
2013-11-29 21:46:00 +00:00
graph . profile . points . show = true ;
graph . profile . draggable = true ;
2019-07-14 04:39:56 +00:00
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-12-01 00:51:45 +00:00
updateProfileTable ( ) ;
2013-11-28 16:17:15 +00:00
}
2013-11-29 21:46:00 +00:00
2013-12-01 00:51:45 +00:00
function leaveEditMode ( )
{
2013-12-07 15:57:31 +00:00
selected _profile _name = $ ( '#form_profile_name' ) . val ( ) ;
ws _storage . send ( 'GET' ) ;
2013-11-28 16:17:15 +00:00
state = "IDLE" ;
2013-12-01 00:51:45 +00:00
$ ( '#edit' ) . hide ( ) ;
2013-12-05 18:53:18 +00:00
$ ( '#profile_selector' ) . show ( ) ;
2013-12-01 00:51:45 +00:00
$ ( '#btn_controls' ) . show ( ) ;
2013-12-05 23:47:43 +00:00
$ ( '#status' ) . slideDown ( ) ;
2013-12-01 00:51:45 +00:00
$ ( '#profile_table' ) . slideUp ( ) ;
2013-11-29 21:46:00 +00:00
graph . profile . points . show = false ;
graph . profile . draggable = false ;
2019-07-14 04:39:56 +00:00
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-11-28 16:17:15 +00:00
}
2013-12-01 00:51:45 +00:00
function newPoint ( )
{
2013-12-01 01:05:24 +00:00
if ( graph . profile . data . length > 0 )
{
var pointx = parseInt ( graph . profile . data [ graph . profile . data . length - 1 ] [ 0 ] ) + 15 ;
}
else
{
var pointx = 0 ;
}
graph . profile . data . push ( [ pointx , Math . floor ( ( Math . random ( ) * 230 ) + 25 ) ] ) ;
2019-07-14 04:39:56 +00:00
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-12-01 00:51:45 +00:00
updateProfileTable ( ) ;
}
2013-11-29 21:46:00 +00:00
2013-12-01 00:51:45 +00:00
function delPoint ( )
{
graph . profile . data . splice ( - 1 , 1 )
2019-07-14 04:39:56 +00:00
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-12-01 00:51:45 +00:00
updateProfileTable ( ) ;
2013-11-30 17:03:04 +00:00
}
2013-11-29 21:46:00 +00:00
2013-12-01 00:51:45 +00:00
function toggleTable ( )
{
if ( $ ( '#profile_table' ) . css ( 'display' ) == 'none' )
{
$ ( '#profile_table' ) . slideDown ( ) ;
}
else
{
$ ( '#profile_table' ) . slideUp ( ) ;
}
}
2013-11-29 21:46:00 +00:00
function saveProfile ( )
{
2013-11-28 16:17:15 +00:00
name = $ ( '#form_profile_name' ) . val ( ) ;
2013-11-29 21:46:00 +00:00
var rawdata = graph . plot . getData ( ) [ 0 ] . data
2013-11-28 16:17:15 +00:00
var data = [ ] ;
2013-11-28 22:21:00 +00:00
var last = - 1 ;
2013-11-28 16:17:15 +00:00
for ( var i = 0 ; i < rawdata . length ; i ++ )
{
2013-11-29 21:46:00 +00:00
if ( rawdata [ i ] [ 0 ] > last )
2013-11-28 22:21:00 +00:00
{
2013-11-29 21:46:00 +00:00
data . push ( [ rawdata [ i ] [ 0 ] , rawdata [ i ] [ 1 ] ] ) ;
2013-11-28 22:21:00 +00:00
}
else
{
$ . bootstrapGrowl ( "<span class=\"glyphicon glyphicon-exclamation-sign\"></span> <b>ERROR 88:</b><br/>An oven is not a time-machine" , {
ele : 'body' , // which element to append to
type : 'alert' , // (null, 'info', 'error', 'success')
offset : { from : 'top' , amount : 250 } , // 'top', or 'bottom'
align : 'center' , // ('left', 'right', or 'center')
width : 385 , // (integer, or 'auto')
delay : 5000 ,
allow _dismiss : true ,
stackup _spacing : 10 // spacing between consecutively stacked growls.
} ) ;
return false ;
}
2013-11-29 21:46:00 +00:00
last = rawdata [ i ] [ 0 ] ;
2013-11-28 16:17:15 +00:00
}
var profile = { "type" : "profile" , "data" : data , "name" : name }
var put = { "cmd" : "PUT" , "profile" : profile }
var put _cmd = JSON . stringify ( put ) ;
ws _storage . send ( put _cmd ) ;
leaveEditMode ( ) ;
}
2013-11-29 21:46:00 +00:00
function getOptions ( )
{
2013-11-28 16:44:06 +00:00
2013-11-29 21:46:00 +00:00
var options =
{
2013-11-28 16:44:06 +00:00
2013-11-29 21:46:00 +00:00
series :
{
2013-12-09 22:52:17 +00:00
lines :
{
show : true
} ,
points :
{
show : true ,
radius : 5 ,
symbol : "circle"
} ,
shadowSize : 3
2013-11-29 21:46:00 +00:00
} ,
2013-11-28 16:44:06 +00:00
2013-11-29 21:46:00 +00:00
xaxis :
{
min : 0 ,
tickColor : 'rgba(216, 211, 197, 0.2)' ,
2014-11-25 23:05:37 +00:00
tickFormatter : timeTickFormatter ,
2013-11-29 21:46:00 +00:00
font :
{
2013-12-09 11:51:08 +00:00
size : 14 ,
2013-11-30 00:42:35 +00:00
lineHeight : 14 , weight : "normal" ,
2013-12-09 11:51:08 +00:00
family : "Digi" ,
2013-11-29 21:46:00 +00:00
variant : "small-caps" ,
color : "rgba(216, 211, 197, 0.85)"
}
} ,
2013-11-28 16:44:06 +00:00
2013-11-29 21:46:00 +00:00
yaxis :
{
min : 0 ,
tickDecimals : 0 ,
draggable : false ,
tickColor : 'rgba(216, 211, 197, 0.2)' ,
font :
{
2013-12-09 11:51:08 +00:00
size : 14 ,
2013-11-29 21:46:00 +00:00
lineHeight : 14 ,
weight : "normal" ,
2013-12-09 11:51:08 +00:00
family : "Digi" ,
2013-11-29 21:46:00 +00:00
variant : "small-caps" ,
color : "rgba(216, 211, 197, 0.85)"
}
} ,
2013-11-28 22:21:00 +00:00
2013-11-29 21:46:00 +00:00
grid :
{
color : 'rgba(216, 211, 197, 0.55)' ,
borderWidth : 1 ,
labelMargin : 10 ,
mouseActiveRadius : 50
} ,
2013-11-28 22:21:00 +00:00
2013-11-29 21:46:00 +00:00
legend :
{
show : false
}
}
2013-11-28 22:21:00 +00:00
2013-11-29 21:46:00 +00:00
return options ;
2013-11-28 22:21:00 +00:00
2013-11-29 21:46:00 +00:00
}
2013-11-28 22:21:00 +00:00
2013-11-29 21:46:00 +00:00
$ ( document ) . ready ( function ( )
2013-11-28 22:21:00 +00:00
{
2013-11-29 21:46:00 +00:00
if ( ! ( "WebSocket" in window ) )
{
$ ( '#chatLog, input, button, #examples' ) . fadeOut ( "fast" ) ;
$ ( '<p>Oh no, you need a browser that supports WebSockets. How about <a href="http://www.google.com/chrome">Google Chrome</a>?</p>' ) . appendTo ( '#container' ) ;
}
else
{
// Status Socket ////////////////////////////////
ws _status . onopen = function ( )
{
console . log ( "Status Socket has been opened" ) ;
2019-01-05 10:10:57 +00:00
$ . bootstrapGrowl ( "<span class=\"glyphicon glyphicon-exclamation-sign\"></span> <b>Initialising</b><br/>Give me a minute to get things together" ,
2013-11-29 21:46:00 +00:00
{
2013-11-29 18:39:11 +00:00
ele : 'body' , // which element to append to
type : 'success' , // (null, 'info', 'error', 'success')
offset : { from : 'top' , amount : 250 } , // 'top', or 'bottom'
align : 'center' , // ('left', 'right', or 'center')
width : 385 , // (integer, or 'auto')
delay : 2500 ,
allow _dismiss : true ,
stackup _spacing : 10 // spacing between consecutively stacked growls.
2013-11-29 21:46:00 +00:00
} ) ;
2013-11-29 23:08:04 +00:00
} ;
2013-11-28 22:21:00 +00:00
2013-11-29 23:08:04 +00:00
ws _status . onclose = function ( )
{
$ . bootstrapGrowl ( "<span class=\"glyphicon glyphicon-exclamation-sign\"></span> <b>ERROR 1:</b><br/>Status Websocket not available" , {
2013-11-28 22:21:00 +00:00
ele : 'body' , // which element to append to
2013-11-29 18:39:11 +00:00
type : 'error' , // (null, 'info', 'error', 'success')
2013-11-28 22:21:00 +00:00
offset : { from : 'top' , amount : 250 } , // 'top', or 'bottom'
align : 'center' , // ('left', 'right', or 'center')
width : 385 , // (integer, or 'auto')
delay : 5000 ,
allow _dismiss : true ,
stackup _spacing : 10 // spacing between consecutively stacked growls.
} ) ;
2013-11-29 23:08:04 +00:00
} ;
2013-11-29 21:46:00 +00:00
2013-11-29 23:08:04 +00:00
ws _status . onmessage = function ( e )
{
x = JSON . parse ( e . data ) ;
2013-11-29 21:46:00 +00:00
2013-11-30 00:42:35 +00:00
if ( x . type == "backlog" )
{
if ( x . profile )
{
selected _profile _name = x . profile . name ;
2015-07-02 00:37:03 +00:00
$ . each ( profiles , function ( i , v ) {
if ( v . name == x . profile . name ) {
updateProfile ( i ) ;
$ ( '#e2' ) . select2 ( 'val' , i ) ;
2015-07-02 00:40:23 +00:00
}
2015-07-02 00:37:03 +00:00
} ) ;
2013-11-30 00:42:35 +00:00
}
2013-11-30 11:26:05 +00:00
2013-11-30 00:42:35 +00:00
$ . each ( x . log , function ( i , v ) {
graph . live . data . push ( [ v . runtime , v . temperature ] ) ;
2019-07-14 04:39:56 +00:00
graph . movingProfile . data . push ( [ v . runtime , v . target ] ) ;
2013-11-30 00:42:35 +00:00
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live ] , getOptions ( ) ) ;
} ) ;
}
2013-11-30 11:26:05 +00:00
2013-11-29 23:08:04 +00:00
if ( state != "EDIT" )
{
state = x . state ;
2013-11-29 21:46:00 +00:00
2013-11-30 11:26:05 +00:00
if ( state != state _last )
{
2013-11-30 13:02:46 +00:00
if ( state _last == "RUNNING" )
{
$ ( '#target_temp' ) . html ( '---' ) ;
updateProgress ( 0 ) ;
2019-01-06 22:34:17 +00:00
$ . bootstrapGrowl ( "<b>Firing completed</b>" , {
2013-11-30 13:02:46 +00:00
ele : 'body' , // which element to append to
type : 'success' , // (null, 'info', 'error', 'success')
offset : { from : 'top' , amount : 250 } , // 'top', or 'bottom'
align : 'center' , // ('left', 'right', or 'center')
width : 385 , // (integer, or 'auto')
delay : 0 ,
allow _dismiss : true ,
stackup _spacing : 10 // spacing between consecutively stacked growls.
} ) ;
}
2013-11-30 11:26:05 +00:00
}
2013-11-29 23:08:04 +00:00
if ( state == "RUNNING" )
{
$ ( "#nav_start" ) . hide ( ) ;
$ ( "#nav_stop" ) . show ( ) ;
2013-11-29 21:46:00 +00:00
2013-11-29 23:08:04 +00:00
graph . live . data . push ( [ x . runtime , x . temperature ] ) ;
2019-07-14 04:39:56 +00:00
graph . movingProfile . data . push ( [ x . runtime , x . target ] ) ;
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-11-29 21:46:00 +00:00
2019-07-14 04:39:56 +00:00
timeElapsed = new Date ( parseInt ( x . runtime ) * 1000 ) . toISOString ( ) . substr ( 11 , 8 ) ;
2013-11-29 23:08:04 +00:00
left = parseInt ( x . totaltime - x . runtime ) ;
2019-07-14 04:39:56 +00:00
if ( left < 0 ) { left = 0 ; }
2016-07-08 04:41:06 +00:00
eta = new Date ( left * 1000 ) . toISOString ( ) . substr ( 11 , 8 ) ;
2013-11-29 21:46:00 +00:00
2013-11-29 23:08:04 +00:00
updateProgress ( parseFloat ( x . runtime ) / parseFloat ( x . totaltime ) * 100 ) ;
2019-01-05 10:10:57 +00:00
$ ( '#state' ) . html ( '<span class="" style="font-size: 22px; font-weight: normal"></span><span style="font-family: Digi; font-size: 40px;">' + eta + '</span>' ) ;
2019-07-14 04:39:56 +00:00
$ ( '#timeElapsed' ) . html ( '<span class="" style="font-size: 22px; font-weight: normal"></span><span style="font-family: Digi; font-size: 40px;">' + timeElapsed + '</span>' ) ;
2013-12-06 18:12:49 +00:00
$ ( '#target_temp' ) . html ( parseInt ( x . target ) ) ;
2013-11-29 23:08:04 +00:00
}
else
{
$ ( "#nav_start" ) . show ( ) ;
$ ( "#nav_stop" ) . hide ( ) ;
2013-12-09 14:10:22 +00:00
$ ( '#state' ) . html ( '<p class="ds-text">' + state + '</p>' ) ;
2019-07-14 04:39:56 +00:00
$ ( '#timeElapsed' ) . html ( '<p class="ds-text">' + state + '</p>' ) ;
2013-11-29 23:08:04 +00:00
}
2013-11-29 22:20:13 +00:00
2013-12-06 18:12:49 +00:00
$ ( '#act_temp' ) . html ( parseInt ( x . temperature ) ) ;
2016-07-08 04:41:06 +00:00
2013-12-10 14:10:56 +00:00
if ( x . heat > 0.5 ) { $ ( '#heat' ) . addClass ( "ds-led-heat-active" ) ; } else { $ ( '#heat' ) . removeClass ( "ds-led-heat-active" ) ; }
2019-01-05 10:10:57 +00:00
// the commented out icons below were from the old reflow oven code
// I don't worry about them for my kiln, but you might find a use for them some time
// if (x.cool > 0.5) { $('#cool').addClass("ds-led-cool-active"); } else { $('#cool').removeClass("ds-led-cool-active"); }
// if (x.air > 0.5) { $('#air').addClass("ds-led-air-active"); } else { $('#air').removeClass("ds-led-air-active"); }
// if (x.temperature > hazardTemp()) { $('#hazard').addClass("ds-led-hazard-active"); } else { $('#hazard').removeClass("ds-led-hazard-active"); }
// if ((x.door == "OPEN") || (x.door == "UNKNOWN")) { $('#door').addClass("ds-led-door-open"); } else { $('#door').removeClass("ds-led-door-open"); }
2013-11-29 21:46:00 +00:00
2013-11-30 11:26:05 +00:00
state _last = state ;
2013-11-29 23:08:04 +00:00
}
} ;
2013-11-29 21:46:00 +00:00
2016-07-08 04:41:06 +00:00
// Config Socket /////////////////////////////////
ws _config . onopen = function ( )
{
ws _config . send ( 'GET' ) ;
} ;
ws _config . onmessage = function ( e )
{
console . log ( e . data ) ;
x = JSON . parse ( e . data ) ;
temp _scale = x . temp _scale ;
time _scale _slope = x . time _scale _slope ;
time _scale _profile = x . time _scale _profile ;
kwh _rate = x . kwh _rate ;
currency _type = x . currency _type ;
if ( temp _scale == "c" ) { temp _scale _display = "C" ; } else { temp _scale _display = "F" ; }
$ ( '#act_temp_scale' ) . html ( 'º' + temp _scale _display ) ;
$ ( '#target_temp_scale' ) . html ( 'º' + temp _scale _display ) ;
switch ( time _scale _profile ) {
case "s" :
time _scale _long = "Seconds" ;
break ;
case "m" :
time _scale _long = "Minutes" ;
break ;
case "h" :
time _scale _long = "Hours" ;
break ;
}
}
2013-11-29 23:08:04 +00:00
// Control Socket ////////////////////////////////
2013-11-29 21:46:00 +00:00
2013-11-29 23:08:04 +00:00
ws _control . onopen = function ( )
{
2013-12-07 12:56:31 +00:00
2013-11-29 23:08:04 +00:00
} ;
2013-11-29 21:46:00 +00:00
2013-12-06 22:02:07 +00:00
ws _control . onmessage = function ( e )
{
//Data from Simulation
console . log ( e . data ) ;
x = JSON . parse ( e . data ) ;
graph . live . data . push ( [ x . runtime , x . temperature ] ) ;
2019-07-14 04:39:56 +00:00
graph . plot = $ . plot ( "#graph_container" , [ graph . profile , graph . live , graph . movingProfile ] , getOptions ( ) ) ;
2013-12-06 22:02:07 +00:00
}
2013-11-29 21:46:00 +00:00
2013-11-29 23:08:04 +00:00
// Storage Socket ///////////////////////////////
2013-11-28 22:21:00 +00:00
2013-11-29 23:08:04 +00:00
ws _storage . onopen = function ( )
{
ws _storage . send ( 'GET' ) ;
} ;
2013-11-28 22:21:00 +00:00
2013-11-29 23:08:04 +00:00
ws _storage . onmessage = function ( e )
{
message = JSON . parse ( e . data ) ;
2013-11-28 22:21:00 +00:00
2013-11-29 23:08:04 +00:00
if ( message . resp )
{
if ( message . resp == "FAIL" )
{
if ( confirm ( 'Overwrite?' ) )
{
message . force = true ;
console . log ( "Sending: " + JSON . stringify ( message ) ) ;
ws _storage . send ( JSON . stringify ( message ) ) ;
}
else
{
//do nothing
}
}
2013-11-28 22:21:00 +00:00
2013-11-29 23:08:04 +00:00
return ;
}
2013-11-28 22:21:00 +00:00
2013-11-29 23:08:04 +00:00
//the message is an array of profiles
//FIXME: this should be better, maybe a {"profiles": ...} container?
profiles = message ;
//delete old options in select
$ ( '#e2' ) . find ( 'option' ) . remove ( ) . end ( ) ;
2016-03-12 20:16:29 +00:00
// check if current selected value is a valid profile name
// if not, update with first available profile name
var valid _profile _names = profiles . map ( function ( a ) { return a . name ; } ) ;
if (
valid _profile _names . length > 0 &&
$ . inArray ( selected _profile _name , valid _profile _names ) === - 1
) {
selected _profile = 0 ;
selected _profile _name = valid _profile _names [ 0 ] ;
}
2013-11-28 22:21:00 +00:00
2013-11-29 23:08:04 +00:00
// fill select with new options from websocket
for ( var i = 0 ; i < profiles . length ; i ++ )
{
2013-11-28 22:21:00 +00:00
var profile = profiles [ i ] ;
2013-11-29 21:46:00 +00:00
//console.log(profile.name);
2013-11-28 22:21:00 +00:00
$ ( '#e2' ) . append ( '<option value="' + i + '">' + profile . name + '</option>' ) ;
if ( profile . name == selected _profile _name )
{
selected _profile = i ;
$ ( '#e2' ) . select2 ( 'val' , i ) ;
2013-12-09 11:51:08 +00:00
updateProfile ( i ) ;
2013-11-28 22:21:00 +00:00
}
2013-11-29 23:08:04 +00:00
}
} ;
2013-11-28 22:21:00 +00:00
2013-11-29 23:08:04 +00:00
$ ( "#e2" ) . select2 (
{
placeholder : "Select Profile" ,
2016-03-12 20:16:29 +00:00
allowClear : true ,
2013-12-05 18:53:18 +00:00
minimumResultsForSearch : - 1
2013-11-29 23:08:04 +00:00
} ) ;
2013-11-28 22:21:00 +00:00
2013-11-29 23:08:04 +00:00
$ ( "#e2" ) . on ( "change" , function ( e )
{
2013-12-09 11:51:08 +00:00
updateProfile ( e . val ) ;
2013-11-29 23:08:04 +00:00
} ) ;
2013-12-07 16:41:34 +00:00
2013-11-29 23:08:04 +00:00
}
2013-11-28 22:21:00 +00:00
} ) ;