# HG changeset patch # User Edouard Tisserant # Date 1642578829 -3600 # Node ID 2e84a27822957faf8a3cfe1b2b81f55d353ba6c5 # Parent 04c4835ca376ff20b3da97cf6542631ca6eafb4d SVGHMI: Add pushbutton widget, that can take reflect short press in variable, but has no garantee on consistency. diff -r 04c4835ca376 -r 2e84a2782295 svghmi/svghmi.js --- a/svghmi/svghmi.js Wed Jan 19 08:51:45 2022 +0100 +++ b/svghmi/svghmi.js Wed Jan 19 08:53:49 2022 +0100 @@ -332,8 +332,10 @@ }; function apply_hmi_value(index, new_val) { - let old_val = cache[index]; - if(new_val != undefined && old_val != new_val) + // Similarly to previous comment, taking decision to update based + // on cache content is bad and can lead to inconsistency + /*let old_val = cache[index];*/ + if(new_val != undefined /*&& old_val != new_val*/) send_hmi_value(index, new_val); return new_val; } diff -r 04c4835ca376 -r 2e84a2782295 svghmi/widget_button.ysl2 --- a/svghmi/widget_button.ysl2 Wed Jan 19 08:51:45 2022 +0100 +++ b/svghmi/widget_button.ysl2 Wed Jan 19 08:53:49 2022 +0100 @@ -28,6 +28,41 @@ gen_index_xhtml { +const "_push_button_fsm" fsm { + state "init" { + on_dispatch "false" jump "reflect_off"; + on_dispatch "true" jump "reflect_on"; + } + + state "reflect_on" { + show "active"; + on_mouse "down" jump "on"; + on_mouse "up" jump "off"; + on_dispatch "false" jump "reflect_off"; + } + + state "on" { + hmi_value "true"; + show "active"; + on_mouse "up" jump "off"; + on_dispatch "false" jump "reflect_off"; + } + + state "reflect_off" { + show "inactive"; + on_mouse "down" jump "on"; + on_mouse "up" jump "off"; + on_dispatch "true" jump "reflect_on"; + } + + state "off" { + hmi_value "false"; + show "inactive"; + on_mouse "down" jump "on"; + on_dispatch "true" jump "reflect_on"; + } +} + // State machine to drive HMI_BOOL on a potentially laggy connection const "_button_fsm" fsm { state "init" { @@ -111,7 +146,7 @@ } template "state", mode="actions" { | «@name»_action(){ - //| console.log("Entering state «@name»"); + | console.log("Entering state «@name»"); apply "*", mode="actions"; | } } @@ -125,26 +160,24 @@ } -widget_class("Button"){ - const "fsm","exsl:node-set($_button_fsm)"; + +function "generated_button_class" { + param "fsm"; | frequency = 5; | display = "inactive"; | state = "init"; | dispatch(value) { - // | console.log("dispatch"+value); apply "$fsm", mode="dispatch_transition"; | } | onmouseup(evt) { | svg_root.removeEventListener("pointerup", this.bound_onmouseup, true); - // | console.log("onmouseup"); apply "$fsm", mode="mouse_transition" with "position", "'up'"; | } | onmousedown(evt) { | svg_root.addEventListener("pointerup", this.bound_onmouseup, true); - // | console.log("onmousedown"); apply "$fsm", mode="mouse_transition" with "position", "'down'"; | } @@ -167,6 +200,22 @@ | } } + +widget_class("Button"){ + const "fsm","exsl:node-set($_button_fsm)"; + call "generated_button_class" with "fsm", "$fsm"; +} + widget_defs("Button") { optional_labels("active inactive"); } + +widget_class("PushButton"){ + const "fsm","exsl:node-set($_push_button_fsm)"; + call "generated_button_class" with "fsm", "$fsm"; +} + +widget_defs("PushButton") { + optional_labels("active inactive"); +} +