From baf200f67296c10476f652bc41413b01ff94390e Mon Sep 17 00:00:00 2001 From: Aymeric THIBAUT Date: Sun, 10 Feb 2019 23:11:07 +0100 Subject: [PATCH] management of timeout for jgauge --- widget/jgauge/jgauge_render.js | 41 ++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/widget/jgauge/jgauge_render.js b/widget/jgauge/jgauge_render.js index 76acda1..19ed3d6 100644 --- a/widget/jgauge/jgauge_render.js +++ b/widget/jgauge/jgauge_render.js @@ -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")] } } @@ -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); } }); } @@ -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; @@ -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(); @@ -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();