# HG changeset patch # User Edouard Tisserant # Date 1608825643 -3600 # Node ID 5823b73b132fc49e0366bc6bd51409db6c25129a # Parent a098b2dd9dff387f040eb4368a414cb29a0c1d4c SVGHMI: decoupled operation string evaluation from HMI variable uptdate in change_hmi_variable(), paving the way for min/max boundaries enforcement diff -r a098b2dd9dff -r 5823b73b132f svghmi/svghmi.js --- a/svghmi/svghmi.js Thu Dec 24 16:56:19 2020 +0100 +++ b/svghmi/svghmi.js Thu Dec 24 17:00:43 2020 +0100 @@ -267,21 +267,20 @@ const quotes = {"'":null, '"':null}; -function change_hmi_value(index, opstr) { +function eval_operation_string(old_val, opstr) { let op = opstr[0]; let given_val; if(opstr.length < 2) - return undefined; // TODO raise + return undefined; if(opstr[1] in quotes){ if(opstr.length < 3) - return undefined; // TODO raise + return undefined; if(opstr[opstr.length-1] == opstr[1]){ given_val = opstr.slice(2,opstr.length-1); } } else { given_val = Number(opstr.slice(1)); } - let old_val = cache[index]; let new_val; switch(op){ case "=": @@ -300,11 +299,19 @@ new_val = old_val / given_val; break; } + return new_val; +} + +/* +function change_hmi_value(index, opstr) { + let old_val = cache[index]; + let new_val = eval_operation_string(old_val, opstr); if(new_val != undefined && old_val != new_val) send_hmi_value(index, new_val); // TODO else raise return new_val; } +*/ var current_visible_page; var current_subscribed_page; diff -r a098b2dd9dff -r 5823b73b132f svghmi/widgets_common.ysl2 --- a/svghmi/widgets_common.ysl2 Thu Dec 24 16:56:19 2020 +0100 +++ b/svghmi/widgets_common.ysl2 Thu Dec 24 17:00:43 2020 +0100 @@ -182,10 +182,13 @@ } return index; } + change_hmi_value(index, opstr) { let realindex = this.get_variable_index(index); if(realindex == undefined) return undefined; - return change_hmi_value(realindex, opstr); + let old_val = cache[realindex]; + let new_val = eval_operation_string(old_val, opstr); + return apply_hmi_value(realindex, new_val); } apply_hmi_value(index, new_val) {