26 decl show(eltname); |
26 decl show(eltname); |
27 decl hmi_value(value); |
27 decl hmi_value(value); |
28 |
28 |
29 gen_index_xhtml { |
29 gen_index_xhtml { |
30 |
30 |
|
31 const "_push_button_fsm" fsm { |
|
32 state "init" { |
|
33 on_dispatch "false" jump "reflect_off"; |
|
34 on_dispatch "true" jump "reflect_on"; |
|
35 } |
|
36 |
|
37 state "reflect_on" { |
|
38 show "active"; |
|
39 on_mouse "down" jump "on"; |
|
40 on_mouse "up" jump "off"; |
|
41 on_dispatch "false" jump "reflect_off"; |
|
42 } |
|
43 |
|
44 state "on" { |
|
45 hmi_value "true"; |
|
46 show "active"; |
|
47 on_mouse "up" jump "off"; |
|
48 on_dispatch "false" jump "reflect_off"; |
|
49 } |
|
50 |
|
51 state "reflect_off" { |
|
52 show "inactive"; |
|
53 on_mouse "down" jump "on"; |
|
54 on_mouse "up" jump "off"; |
|
55 on_dispatch "true" jump "reflect_on"; |
|
56 } |
|
57 |
|
58 state "off" { |
|
59 hmi_value "false"; |
|
60 show "inactive"; |
|
61 on_mouse "down" jump "on"; |
|
62 on_dispatch "true" jump "reflect_on"; |
|
63 } |
|
64 } |
|
65 |
31 // State machine to drive HMI_BOOL on a potentially laggy connection |
66 // State machine to drive HMI_BOOL on a potentially laggy connection |
32 const "_button_fsm" fsm { |
67 const "_button_fsm" fsm { |
33 state "init" { |
68 state "init" { |
34 on_dispatch "false" jump "released"; |
69 on_dispatch "false" jump "released"; |
35 on_dispatch "true" jump "pressed"; |
70 on_dispatch "true" jump "pressed"; |
109 template "fsm", mode="actions" { |
144 template "fsm", mode="actions" { |
110 apply "state", mode="actions"; |
145 apply "state", mode="actions"; |
111 } |
146 } |
112 template "state", mode="actions" { |
147 template "state", mode="actions" { |
113 | «@name»_action(){ |
148 | «@name»_action(){ |
114 //| console.log("Entering state «@name»"); |
149 | console.log("Entering state «@name»"); |
115 apply "*", mode="actions"; |
150 apply "*", mode="actions"; |
116 | } |
151 | } |
117 } |
152 } |
118 template "show", mode="actions" { |
153 template "show", mode="actions" { |
119 | this.display = "«@eltname»"; |
154 | this.display = "«@eltname»"; |
123 | this.apply_hmi_value(0, «@value»); |
158 | this.apply_hmi_value(0, «@value»); |
124 } |
159 } |
125 |
160 |
126 } |
161 } |
127 |
162 |
128 widget_class("Button"){ |
163 |
129 const "fsm","exsl:node-set($_button_fsm)"; |
164 function "generated_button_class" { |
|
165 param "fsm"; |
130 | frequency = 5; |
166 | frequency = 5; |
131 |
167 |
132 | display = "inactive"; |
168 | display = "inactive"; |
133 | state = "init"; |
169 | state = "init"; |
134 |
170 |
135 | dispatch(value) { |
171 | dispatch(value) { |
136 // | console.log("dispatch"+value); |
|
137 apply "$fsm", mode="dispatch_transition"; |
172 apply "$fsm", mode="dispatch_transition"; |
138 | } |
173 | } |
139 |
174 |
140 | onmouseup(evt) { |
175 | onmouseup(evt) { |
141 | svg_root.removeEventListener("pointerup", this.bound_onmouseup, true); |
176 | svg_root.removeEventListener("pointerup", this.bound_onmouseup, true); |
142 // | console.log("onmouseup"); |
|
143 apply "$fsm", mode="mouse_transition" with "position", "'up'"; |
177 apply "$fsm", mode="mouse_transition" with "position", "'up'"; |
144 | } |
178 | } |
145 | onmousedown(evt) { |
179 | onmousedown(evt) { |
146 | svg_root.addEventListener("pointerup", this.bound_onmouseup, true); |
180 | svg_root.addEventListener("pointerup", this.bound_onmouseup, true); |
147 // | console.log("onmousedown"); |
|
148 apply "$fsm", mode="mouse_transition" with "position", "'down'"; |
181 apply "$fsm", mode="mouse_transition" with "position", "'down'"; |
149 | } |
182 | } |
150 |
183 |
151 apply "$fsm", mode="actions"; |
184 apply "$fsm", mode="actions"; |
152 |
185 |
165 | this.bound_onmouseup = this.onmouseup.bind(this); |
198 | this.bound_onmouseup = this.onmouseup.bind(this); |
166 | this.element.addEventListener("pointerdown", this.onmousedown.bind(this)); |
199 | this.element.addEventListener("pointerdown", this.onmousedown.bind(this)); |
167 | } |
200 | } |
168 } |
201 } |
169 |
202 |
|
203 |
|
204 widget_class("Button"){ |
|
205 const "fsm","exsl:node-set($_button_fsm)"; |
|
206 call "generated_button_class" with "fsm", "$fsm"; |
|
207 } |
|
208 |
170 widget_defs("Button") { |
209 widget_defs("Button") { |
171 optional_labels("active inactive"); |
210 optional_labels("active inactive"); |
172 } |
211 } |
|
212 |
|
213 widget_class("PushButton"){ |
|
214 const "fsm","exsl:node-set($_push_button_fsm)"; |
|
215 call "generated_button_class" with "fsm", "$fsm"; |
|
216 } |
|
217 |
|
218 widget_defs("PushButton") { |
|
219 optional_labels("active inactive"); |
|
220 } |
|
221 |