Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

management of timeout for jgauge #191

Merged
merged 1 commit into from
Feb 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions widget/jgauge/jgauge_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ function jgauge_widgetlist()
{
"offsetx":-80,"offsety":-80,"width":160,"height":160,
"menu":"Widgets",
"options":["feedid", "scale", "max", "min", "units"],
"optionstype":["feedid","value","value","value","value"],
"optionsname":[_Tr("Feed"),_Tr("Scale"),_Tr("Max value"),_Tr("Min value"),_Tr("Units")],
"optionshint":[_Tr("Feed"),_Tr("Scale applied to value"),_Tr("Max value to show"),_Tr("Min value to show"),_Tr("Units to show")]
"options":["feedid", "scale", "max", "min", "units","timeout","errormessagedisplayed"],
"optionstype":["feedid","value","value","value","value","value","value"],
"optionsname":[_Tr("Feed"),_Tr("Scale"),_Tr("Max value"),_Tr("Min value"),_Tr("Units"),_Tr("Timeout"),_Tr("Error Message")],
"optionshint":[_Tr("Feed"),_Tr("Scale applied to value"),_Tr("Max value to show"),_Tr("Min value to show"),_Tr("Units to show"),_Tr("Timeout without feed update in seconds (empty is never)"),_Tr("Error message displayed when timeout is reached")]

}
}
Expand All @@ -43,16 +43,35 @@ function jgauge_draw()
{
$('.jgauge').each(function(index)
{
var errorMessage = $(this).attr("errormessagedisplayed");
if (errorMessage === "" || errorMessage === undefined){ //Error Message parameter is empty
errorMessage = "TO Error";
}
var errorTimeout = $(this).attr("timeout");
if (errorTimeout === "" || errorTimeout === undefined){ //Timeout parameter is empty
errorTimeout = 0;
}

var errorCode = "0";

var feedid = $(this).attr("feedid");
if (assocfeed[feedid]!=undefined) feedid = assocfeed[feedid]; // convert tag:name to feedid
if (associd[feedid] === undefined) { console.log("Review config for feed id of " + $(this).attr("class")); return; }
var val = curve_value(feedid,dialrate).toFixed(3);

if (errorTimeout !== 0)
{
if (((new Date()).getTime() / 1000 - offsetofTime - (associd[feedid]["time"] * 1)) > errorTimeout)
{
errorCode = "1";
}
}
// ONLY UPDATE ON CHANGE
if (val != (associd[feedid]['value'] * 1).toFixed(3) || redraw == 1)
if (val != (associd[feedid]['value'] * 1).toFixed(3) || redraw == 1 || errorTimeout != 0)
{
var id = "can-"+$(this).attr("id");
var scale = 1*$(this).attr("scale") || 1;
draw_jgauge(widgetcanvas[id],0,0,$(this).width(),$(this).height(),val*scale,$(this).attr("max"),$(this).attr("min"),$(this).attr("units"));
draw_jgauge(widgetcanvas[id],0,0,$(this).width(),$(this).height(),val*scale,$(this).attr("max"),$(this).attr("min"),$(this).attr("units"),errorCode,errorMessage);
}
});
}
Expand All @@ -67,7 +86,7 @@ function jgauge_fastupdate()
jgauge_draw();
}

function draw_jgauge(ctx,x,y,width,height,value,max,min,units)
function draw_jgauge(ctx,x,y,width,height,value,max,min,units,errorCode,errorMessage)
{
if (!max) max = 1000;
if (!min) min = 0;
Expand Down Expand Up @@ -125,8 +144,14 @@ function draw_jgauge(ctx,x,y,width,height,value,max,min,units)
ctx.font = "14pt Calibri,Geneva,Arial";
ctx.strokeStyle = "rgb(255,255,255)";
ctx.fillStyle = "rgb(255,255,255)";
if (errorCode!= "1"){
value = Number(value.toFixed(decimalPlaces));
ctx.fillText(value+units, 50*(size/100), 85*(size/100));
}
else
{
ctx.fillText(errorMessage, 50*(size/100), 85*(size/100));
}

// Save the current drawing state
ctx.save();
Expand All @@ -135,7 +160,9 @@ function draw_jgauge(ctx,x,y,width,height,value,max,min,units)
// Rotate around this point
ctx.rotate((position + offset) * (Math.PI / 180));
// Draw the image back and up
if (errorCode!= "1"){
ctx.drawImage(needle, -(size/2), -(size/2), size, size);
}

// Restore the previous drawing state
ctx.restore();
Expand Down