43 > «@index»`if "position()!=last()" > ,` |
43 > «@index»`if "position()!=last()" > ,` |
44 } |
44 } |
45 } |
45 } |
46 } |
46 } |
47 |
47 |
48 | "«@id»": new «$widget/@type»Widget ("«@id»",[«$args»],[«$indexes»],{ |
48 const "minmaxes" foreach "$widget/path" { |
|
49 choose { |
|
50 when "@min and @max" |
|
51 > [«@min»,«@max»] |
|
52 otherwise |
|
53 > undefined |
|
54 } |
|
55 if "position()!=last()" > , |
|
56 } |
|
57 |
|
58 | "«@id»": new «$widget/@type»Widget ("«@id»",[«$args»],[«$indexes»],[«$minmaxes»],{ |
49 apply "$widget", mode="widget_defs" with "hmi_element","."; |
59 apply "$widget", mode="widget_defs" with "hmi_element","."; |
50 | })`if "position()!=last()" > ,` |
60 | })`if "position()!=last()" > ,` |
51 } |
61 } |
52 |
62 |
53 def "func:unique_types" { |
63 def "func:unique_types" { |
123 offset = 0; |
133 offset = 0; |
124 frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */ |
134 frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */ |
125 unsubscribable = false; |
135 unsubscribable = false; |
126 pending_animate = false; |
136 pending_animate = false; |
127 |
137 |
128 constructor(elt_id,args,indexes,members){ |
138 constructor(elt_id,args,indexes,minmaxes,members){ |
129 this.element_id = elt_id; |
139 this.element_id = elt_id; |
130 this.element = id(elt_id); |
140 this.element = id(elt_id); |
131 this.args = args; |
141 this.args = args; |
132 this.indexes = indexes; |
142 this.indexes = indexes; |
|
143 this.minmaxes = minmaxes; |
133 Object.keys(members).forEach(prop => this[prop]=members[prop]); |
144 Object.keys(members).forEach(prop => this[prop]=members[prop]); |
134 } |
145 } |
135 |
146 |
136 unsub(){ |
147 unsub(){ |
137 /* remove subsribers */ |
148 /* remove subsribers */ |
181 } |
192 } |
182 } |
193 } |
183 return index; |
194 return index; |
184 } |
195 } |
185 |
196 |
|
197 overshot(new_val, max) { |
|
198 } |
|
199 |
|
200 undershot(new_val, min) { |
|
201 } |
|
202 |
|
203 clip_min_max(index, new_val) { |
|
204 let minmax = this.minmaxes[index]; |
|
205 if(minmax !== undefined && typeof new_val == "number") { |
|
206 let [min,max] = minmax; |
|
207 if(new_val < min){ |
|
208 this.undershot(new_val, min); |
|
209 return min; |
|
210 } |
|
211 if(new_val > max){ |
|
212 this.overshot(new_val, max); |
|
213 return max; |
|
214 } |
|
215 } |
|
216 return new_val; |
|
217 } |
|
218 |
186 change_hmi_value(index, opstr) { |
219 change_hmi_value(index, opstr) { |
187 let realindex = this.get_variable_index(index); |
220 let realindex = this.get_variable_index(index); |
188 if(realindex == undefined) return undefined; |
221 if(realindex == undefined) return undefined; |
189 let old_val = cache[realindex]; |
222 let old_val = cache[realindex]; |
190 let new_val = eval_operation_string(old_val, opstr); |
223 let new_val = eval_operation_string(old_val, opstr); |
|
224 new_val = this.clip_min_max(index, new_val); |
191 return apply_hmi_value(realindex, new_val); |
225 return apply_hmi_value(realindex, new_val); |
192 } |
226 } |
193 |
227 |
194 apply_hmi_value(index, new_val) { |
228 apply_hmi_value(index, new_val) { |
195 let realindex = this.get_variable_index(index); |
229 let realindex = this.get_variable_index(index); |
196 if(realindex == undefined) return undefined; |
230 if(realindex == undefined) return undefined; |
|
231 new_val = this.clip_min_max(index, new_val); |
197 return apply_hmi_value(realindex, new_val); |
232 return apply_hmi_value(realindex, new_val); |
198 } |
233 } |
199 |
234 |
200 new_hmi_value(index, value, oldval) { |
235 new_hmi_value(index, value, oldval) { |
201 // TODO avoid searching, store index at sub() |
236 // TODO avoid searching, store index at sub() |