svghmi/svghmi.js
branchsvghmi
changeset 3152 c80a5a7198ea
parent 3148 b8c0dfdf364b
child 3190 80dd371e15bb
equal deleted inserted replaced
3151:8e5d383a58cb 3152:c80a5a7198ea
    49     }
    49     }
    50 };
    50 };
    51 
    51 
    52 // Apply updates recieved through ws.onmessage to subscribed widgets
    52 // Apply updates recieved through ws.onmessage to subscribed widgets
    53 function apply_updates() {
    53 function apply_updates() {
    54     for(let index in updates){
    54     updates.forEach((value, index) => {
    55         // serving as a key, index becomes a string
    55         dispatch_value(index, value);
    56         // -> pass Number(index) instead
    56     });
    57         dispatch_value(Number(index), updates[index]);
    57     updates.clear();
    58         delete updates[index];
       
    59     }
       
    60 }
    58 }
    61 
    59 
    62 // Called on requestAnimationFrame, modifies DOM
    60 // Called on requestAnimationFrame, modifies DOM
    63 var requestAnimationFrameID = null;
    61 var requestAnimationFrameID = null;
    64 function animate() {
    62 function animate() {
   108             i += 4;
   106             i += 4;
   109             let iectype = hmitree_types[index];
   107             let iectype = hmitree_types[index];
   110             if(iectype != undefined){
   108             if(iectype != undefined){
   111                 let dvgetter = dvgetters[iectype];
   109                 let dvgetter = dvgetters[iectype];
   112                 let [value, bytesize] = dvgetter(dv,i);
   110                 let [value, bytesize] = dvgetter(dv,i);
   113                 updates[index] = value;
   111                 updates.set(index, value);
   114                 i += bytesize;
   112                 i += bytesize;
   115             } else {
   113             } else {
   116                 throw new Error("Unknown index "+index);
   114                 throw new Error("Unknown index "+index);
   117             }
   115             }
   118         };
   116         };
   290     send_blob(delta);
   288     send_blob(delta);
   291 };
   289 };
   292 
   290 
   293 function send_hmi_value(index, value) {
   291 function send_hmi_value(index, value) {
   294     if(index > last_remote_index){
   292     if(index > last_remote_index){
   295         updates[index] = value;
   293         updates.set(index, value);
   296 
   294 
   297         if(persistent_indexes.has(index)){
   295         if(persistent_indexes.has(index)){
   298             let varname = persistent_indexes.get(index);
   296             let varname = persistent_indexes.get(index);
   299             document.cookie = varname+"="+value+"; max-age=3153600000";
   297             document.cookie = varname+"="+value+"; max-age=3153600000";
   300         }
   298         }