equal
deleted
inserted
replaced
1 // svghmi.js |
1 // svghmi.js |
|
2 |
|
3 var cache = hmitree_types.map(_ignored => undefined); |
2 |
4 |
3 function dispatch_value(index, value) { |
5 function dispatch_value(index, value) { |
4 let widgets = subscribers[index]; |
6 let widgets = subscribers[index]; |
5 |
7 |
6 // TODO : value cache |
|
7 |
|
8 if(widgets.size > 0) { |
8 if(widgets.size > 0) { |
9 for(let widget of widgets){ |
9 for(let widget of widgets){ |
10 let idxidx = widget.indexes.indexOf(index); |
10 let idxidx = widget.indexes.indexOf(index); |
11 if(idxidx == -1){ |
11 if(idxidx == -1){ |
12 throw new Error("Dispatching to widget not interested, should not happen."); |
12 throw new Error("Dispatching to widget not interested, should not happen."); |
20 /*else { |
20 /*else { |
21 throw new Error("Dunno how to dispatch to widget at index = " + index); |
21 throw new Error("Dunno how to dispatch to widget at index = " + index); |
22 }*/ |
22 }*/ |
23 } |
23 } |
24 } |
24 } |
|
25 |
|
26 cache[index] = value; |
|
27 |
25 }; |
28 }; |
26 |
29 |
27 function init_widgets() { |
30 function init_widgets() { |
28 Object.keys(hmi_widgets).forEach(function(id) { |
31 Object.keys(hmi_widgets).forEach(function(id) { |
29 let widget = hmi_widgets[id]; |
32 let widget = hmi_widgets[id]; |
145 send_blob([ |
148 send_blob([ |
146 new Uint8Array([0]), /* setval = 0 */ |
149 new Uint8Array([0]), /* setval = 0 */ |
147 new Uint32Array([index]), |
150 new Uint32Array([index]), |
148 new jstype([value])]); |
151 new jstype([value])]); |
149 |
152 |
|
153 cache[index] = value; |
150 }; |
154 }; |
151 |
155 |
152 function change_hmi_value(index, opstr) { |
156 function change_hmi_value(index, opstr) { |
153 let op = opstr[0]; |
157 let op = opstr[0]; |
154 if(op == "=") |
158 let given_val = opstr.slice(1); |
155 return send_hmi_value(index, Number(opstr.slice(1))); |
159 let old_val = cache[index] |
156 |
160 let new_val; |
157 alert('Change '+opstr+" TODO !!! (index :"+index+")"); |
161 switch(op){ |
|
162 case "=": |
|
163 eval("new_val"+opstr); |
|
164 break; |
|
165 case "+": |
|
166 case "-": |
|
167 case "*": |
|
168 case "/": |
|
169 if(old_val != undefined) |
|
170 new_val = eval("old_val"+opstr); |
|
171 break; |
|
172 } |
|
173 if(new_val != undefined && old_val != new_val) |
|
174 return send_hmi_value(index, new_val); |
158 } |
175 } |
159 |
176 |
160 var current_page; |
177 var current_page; |
161 |
178 |
162 function switch_page(page_name) { |
179 function switch_page(page_name) { |