SVGHMI: fix wrong updates of HMI variables on each change, especially when not subscribed. svghmi
authorEdouard Tisserant
Mon, 09 Mar 2020 13:43:34 +0100
branchsvghmi
changeset 2863 e120d6985a2f
parent 2862 a108677bd3d0
child 2864 36f78f6cfabd
SVGHMI: fix wrong updates of HMI variables on each change, especially when not subscribed.
svghmi/svghmi.c
--- a/svghmi/svghmi.c	Mon Mar 09 13:40:45 2020 +0100
+++ b/svghmi/svghmi.c	Mon Mar 09 13:43:34 2020 +0100
@@ -105,10 +105,13 @@
         if(__Is_a_string(dsc)){
             sz = ((STRING*)visible_value_p)->len + 1;
         }
-        if(dsc->wstate == buf_new || memcmp(dest_p, visible_value_p, sz) != 0){
+        if(dsc->wstate == buf_new /* just subscribed 
+           or already subscribed having value change */
+           || (dsc->refresh_period_ms > 0 && memcmp(dest_p, visible_value_p, sz) != 0)){
             /* copy and flag as set */
             memcpy(dest_p, visible_value_p, sz);
-            if(dsc->wstate == buf_new || dsc->wstate == buf_free) {
+            /* if not already marked/signaled, do it */
+            if(dsc->wstate != buf_set && dsc->wstate != buf_tosend) {
                 if(dsc->wstate == buf_new || ticktime_ms > dsc->refresh_period_ms){
                     dsc->wstate = buf_tosend;
                     global_write_dirty = 1;
@@ -179,13 +182,15 @@
 void update_refresh_period(hmi_tree_item_t *dsc, uint16_t refresh_period_ms)
 {
     while(AtomicCompareExchange(&dsc->wlock, 0, 1)) sched_yield();
-    dsc->refresh_period_ms = refresh_period_ms;
     if(refresh_period_ms) {
-        /* TODO : maybe only if was null before for optimization */
-        dsc->wstate = buf_new;
+        if(!dsc->refresh_period_ms)
+        {
+            dsc->wstate = buf_new;
+        }
     } else {
         dsc->wstate = buf_free;
     }
+    dsc->refresh_period_ms = refresh_period_ms;
     AtomicCompareExchange(&dsc->wlock, 1, 0);
 }