svghmi/svghmi.js
branchsvghmi
changeset 2801 390acff12755
parent 2800 68cee1366b9c
child 2802 64e6f73b9859
equal deleted inserted replaced
2800:68cee1366b9c 2801:390acff12755
     1 // svghmi.js
     1 // svghmi.js
     2 
     2 
     3 function dispatch_value(index, value) {
     3 function dispatch_value(index, value) {
     4     let widgets = subscribers[index];
     4     let widgets = subscribers[index];
     5 
     5 
       
     6     // TODO : value cache
       
     7     
     6     if(widgets.size > 0) {
     8     if(widgets.size > 0) {
     7         for(let widget of widgets){
     9         for(let widget of widgets){
     8             let idxidx = widget.indexes.indexOf(index);
    10             let idxidx = widget.indexes.indexOf(index);
     9             if(idxidx == -1){
    11             if(idxidx == -1){
    10                 throw new Error("Dispatching to widget not interested, should not happen.");
    12                 throw new Error("Dispatching to widget not interested, should not happen.");
    18             /*else {
    20             /*else {
    19                 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);
    20             }*/
    22             }*/
    21         }
    23         }
    22     }
    24     }
       
    25 };
       
    26 
       
    27 function init_widgets() {
       
    28     Object.keys(hmi_widgets).forEach(function(id) {
       
    29         let widget = hmi_widgets[id];
       
    30         let init = widget.init;
       
    31         if(typeof(init) == "function"){
       
    32             return init.call(widget);
       
    33         }
       
    34     });
    23 };
    35 };
    24 
    36 
    25 // Open WebSocket to relative "/ws" address
    37 // Open WebSocket to relative "/ws" address
    26 var ws = new WebSocket(window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws'));
    38 var ws = new WebSocket(window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws'));
    27 ws.binaryType = 'arraybuffer';
    39 ws.binaryType = 'arraybuffer';
   125         
   137         
   126     }
   138     }
   127     send_blob(delta);
   139     send_blob(delta);
   128 };
   140 };
   129 
   141 
   130 function update_value(index, value) {
   142 function send_hmi_value(index, value) {
   131     iectype = hmitree_types[index];
   143     iectype = hmitree_types[index];
   132     jstype = typedarray_types[iectypes];
   144     jstype = typedarray_types[iectype];
   133     send_blob([
   145     send_blob([
   134         new Uint8Array([0]),  /* setval = 0 */
   146         new Uint8Array([0]),  /* setval = 0 */
   135         new jstype([value])
   147         new jstype([value])
   136         ]);
   148         ]);
   137 
   149 
   138 };
   150 };
       
   151 
       
   152 function change_hmi_value(index, opstr) {
       
   153     let op = opstr[0];
       
   154     if(op == "=")
       
   155         return send_hmi_value(index, Number(opstr.slice(1)));
       
   156 
       
   157     alert('Change '+opstr+" TODO !!! (index :"+index+")");
       
   158 }
   139 
   159 
   140 var current_page;
   160 var current_page;
   141 
   161 
   142 function switch_page(page_name) {
   162 function switch_page(page_name) {
   143     let old_desc = page_desc[current_page];
   163     let old_desc = page_desc[current_page];
   164 };
   184 };
   165 
   185 
   166 
   186 
   167 // Once connection established
   187 // Once connection established
   168 ws.onopen = function (evt) {
   188 ws.onopen = function (evt) {
       
   189     init_widgets();
   169     send_reset();
   190     send_reset();
   170     // show main page
   191     // show main page
   171     switch_page(default_page);
   192     switch_page(default_page);
   172 };
   193 };
   173 
   194