svghmi/svghmi.js
branchsvghmi
changeset 3006 bbffdefd2eed
parent 3005 ff9ae4f4e3be
child 3017 15e2df3e5610
child 3018 22b969b409b0
equal deleted inserted replaced
3005:ff9ae4f4e3be 3006:bbffdefd2eed
     2 
     2 
     3 var cache = hmitree_types.map(_ignored => undefined);
     3 var cache = hmitree_types.map(_ignored => undefined);
     4 var updates = {};
     4 var updates = {};
     5 var need_cache_apply = []; 
     5 var need_cache_apply = []; 
     6 
     6 
     7 function dispatch_value_to_widget(widget, index, value, oldval) {
       
     8     try {
       
     9         let idx = widget.offset ? index - widget.offset : index;
       
    10         let idxidx = widget.indexes.indexOf(idx);
       
    11         let d = widget.dispatch;
       
    12         if(typeof(d) == "function" && idxidx == 0){
       
    13             d.call(widget, value, oldval);
       
    14         }
       
    15         else if(typeof(d) == "object" && d.length >= idxidx){
       
    16             d[idxidx].call(widget, value, oldval);
       
    17         }
       
    18         /* else dispatch_0, ..., dispatch_n ? */
       
    19         /*else {
       
    20             throw new Error("Dunno how to dispatch to widget at index = " + index);
       
    21         }*/
       
    22     } catch(err) {
       
    23         console.log(err);
       
    24     }
       
    25 }
       
    26 
     7 
    27 function dispatch_value(index, value) {
     8 function dispatch_value(index, value) {
    28     let widgets = subscribers[index];
     9     let widgets = subscribers[index];
    29 
    10 
    30     let oldval = cache[index];
    11     let oldval = cache[index];
    31     cache[index] = value;
    12     cache[index] = value;
    32 
    13 
    33     if(widgets.size > 0) {
    14     if(widgets.size > 0) {
    34         for(let widget of widgets){
    15         for(let widget of widgets){
    35             dispatch_value_to_widget(widget, index, value, oldval);
    16             widget.new_hmi_value(index, value, oldval);
    36         }
    17         }
    37     }
    18     }
    38 };
    19 };
    39 
    20 
    40 function init_widgets() {
    21 function init_widgets() {
   188 // PLC will periodically send variable at given frequency
   169 // PLC will periodically send variable at given frequency
   189 subscribers[heartbeat_index].add({
   170 subscribers[heartbeat_index].add({
   190     /* type: "Watchdog", */
   171     /* type: "Watchdog", */
   191     frequency: 1,
   172     frequency: 1,
   192     indexes: [heartbeat_index],
   173     indexes: [heartbeat_index],
   193     dispatch: function(value) {
   174     new_hmi_value: function(index, value, oldval) {
   194         apply_hmi_value(heartbeat_index, value+1);
   175         apply_hmi_value(heartbeat_index, value+1);
   195     }
   176     }
   196 });
   177 });
   197 
   178 
   198 function update_subscriptions() {
   179 function update_subscriptions() {