svghmi/widget_input.ysl2
author Edouard Tisserant
Tue, 07 Apr 2020 10:01:23 +0200
branchsvghmi
changeset 2921 2670f5c53caf
parent 2917 c8d923dd707f
child 2929 9179cbc6fc49
permissions -rw-r--r--
SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.

HMI variable cache in JS was changed in advance for more responsive behaviour when updating a HMI tree variable. This was leading to display value different from hmi tree variable in case the expected update did not happen because PLC program did revert it.
// widget_input.ysl2

template "widget[@type='Input']", mode="widget_defs" {
    param "hmi_element";
    const "value_elt" {
        optional_labels("value");
    }
    const "have_value","string-length($value_elt)>0";
    value "$value_elt";
    if "$have_value"
    |     frequency: 5,
    |     last_val: undefined,
    |     dispatch: function(value) {
    |         this.last_val = value;
    if "$have_value"
    |         this.value_elt.textContent = String(value);

    |     },
    const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id";
    |     init: function() {
    if "$edit_elt_id" {
    |         id("«$edit_elt_id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_edit_click()");
    }
    foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
    |         id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_op_click('«func:escape_quotes(@inkscape:label)»')");
    }
    |     },
    |     on_op_click: function(opstr) {
    |         let new_val = change_hmi_value(this.indexes[0], opstr);
    //     if "$have_value"{
    // |         this.value_elt.textContent = String(new_val);
    //           /* TODO gray out value until refreshed */
    //     }
    |     },
    |     on_edit_click: function(opstr) {
    |         edit_value("«path/@value»", "«path/@type»", this, this.last_val);
    |     },

    |     edit_callback: function(new_val) {
    |         apply_hmi_value(this.indexes[0], new_val);
    //     if "$have_value"{
    // |         this.value_elt.textContent = String(new_val);
    //           /* TODO gray out value until refreshed */
    //     }
    |     },
}