8 decl jump(state); |
8 decl jump(state); |
9 decl show(eltname); |
9 decl show(eltname); |
10 decl hmi_value(value); |
10 decl hmi_value(value); |
11 |
11 |
12 // State machine to drive HMI_BOOL on a potentially laggy connection |
12 // State machine to drive HMI_BOOL on a potentially laggy connection |
13 // TODO: make more robust in case other widget or PLC change value on their own |
|
14 const "_button_fsm" fsm { |
13 const "_button_fsm" fsm { |
15 state "init" { |
14 state "init" { |
16 on_dispatch "false" jump "released"; |
15 on_dispatch "false" jump "released"; |
17 on_dispatch "true" jump "pressed"; |
16 on_dispatch "true" jump "pressed"; |
18 } |
17 } |
55 apply "state", mode="dispatch_transition"; |
54 apply "state", mode="dispatch_transition"; |
56 | } |
55 | } |
57 } |
56 } |
58 template "state", mode="dispatch_transition" { |
57 template "state", mode="dispatch_transition" { |
59 | case "«@name»": |
58 | case "«@name»": |
60 apply "on-dispatch"; |
59 apply "on-dispatch"; |
61 | break; |
60 | break; |
62 } |
61 } |
63 template "on-dispatch" { |
62 template "on-dispatch" { |
64 | if(value == «@value») { |
63 | if(value == «@value») { |
65 apply "jump", mode="transition"; |
64 apply "jump", mode="transition"; |
66 | } |
65 | } |
67 } |
66 } |
68 |
67 |
69 template "fsm", mode="mouse_transition" { |
68 template "fsm", mode="mouse_transition" { |
70 param "position"; |
69 param "position"; |
71 | switch (this.state) { |
70 | switch (this.state) { |
77 | case "«@name»": |
76 | case "«@name»": |
78 apply "on-mouse[@position = $position]"; |
77 apply "on-mouse[@position = $position]"; |
79 | break; |
78 | break; |
80 } |
79 } |
81 template "on-mouse" { |
80 template "on-mouse" { |
82 // up or down state is already assumed because apply statement filters it |
81 // up or down state is already assumed because apply statement filters it |
83 apply "jump", mode="transition"; |
82 apply "jump", mode="transition"; |
84 } |
83 } |
85 |
84 |
86 template "jump", mode="transition" { |
85 template "jump", mode="transition" { |
87 | this.state = "«@state»"; |
86 | this.state = "«@state»"; |
88 | this.«@state»_action(); |
87 | this.«@state»_action(); |
90 |
89 |
91 template "fsm", mode="actions" { |
90 template "fsm", mode="actions" { |
92 apply "state", mode="actions"; |
91 apply "state", mode="actions"; |
93 } |
92 } |
94 template "state", mode="actions" { |
93 template "state", mode="actions" { |
95 | «@name»_action(){ |
94 | «@name»_action(){ |
96 //| console.log("Entering state «@name»"); |
95 //| console.log("Entering state «@name»"); |
97 apply "*", mode="actions"; |
96 apply "*", mode="actions"; |
98 | } |
97 | } |
99 } |
98 } |
100 template "show", mode="actions" { |
99 template "show", mode="actions" { |
101 | this.display = "«@eltname»"; |
100 | this.display = "«@eltname»"; |
102 | this.request_animate(); |
101 | this.request_animate(); |
103 } |
102 } |
104 template "hmi-value", mode="actions" { |
103 template "hmi-value", mode="actions" { |
105 | this.apply_hmi_value(0, «@value»); |
104 | this.apply_hmi_value(0, «@value»); |
106 } |
105 } |
107 |
106 |
108 template "widget[@type='Button']", mode="widget_class"{ |
107 template "widget[@type='Button']", mode="widget_class"{ |
109 const "fsm","exsl:node-set($_button_fsm)"; |
108 const "fsm","exsl:node-set($_button_fsm)"; |
110 | class ButtonWidget extends Widget{ |
109 | class ButtonWidget extends Widget{ |