# HG changeset patch
# User Edouard Tisserant
# Date 1583502183 -3600
# Node ID 84c16ece8e108a0a762909c7b1fb2e1d169bf738
# Parent b7650c6abeda0c0f89c3a8e9bbd4d3ace8a8c576
SVGHMI: fixed repeated error when Input widget is missing 'value' element
diff -r b7650c6abeda -r 84c16ece8e10 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Fri Mar 06 14:42:08 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Fri Mar 06 14:43:03 2020 +0100
@@ -625,6 +625,8 @@
var updates = {};
+ var page_switch = null;
+
function dispatch_value_to_widget(widget, index, value, oldval) {
@@ -753,9 +755,21 @@
// Apply updates recieved through ws.onmessage to subscribed widgets
- // Called on requestAnimationFram, modifies DOM
-
- function apply_pending_updates() {
+ // Do the page swith if any one pending
+
+ // Called on requestAnimationFrame, modifies DOM
+
+ function animate() {
+
+ if(page_switch != null){
+
+ do_switch_page(page_switch);
+
+ page_switch=null;
+
+ }
+
+
for(let index in updates){
@@ -773,6 +787,24 @@
+ var requestAnimationFrameID = null;
+
+ function requestHMIAnimation() {
+
+ if(requestAnimationFrameID != null){
+
+ window.cancelAnimationFrame(requestAnimationFrameID);
+
+ requestAnimationFrameID = null;
+
+ }
+
+ requestAnimationFrameID = window.requestAnimationFrame(animate);
+
+ }
+
+
+
// Message reception handler
// Hash is verified and HMI values updates resulting from binary parsing
@@ -833,7 +865,7 @@
// register for rendering on next frame, since there are updates
- window.requestAnimationFrame(apply_pending_updates);
+ window.requestAnimationFrame(animate);
} catch(err) {
@@ -1103,6 +1135,16 @@
function switch_page(page_name) {
+ page_switch = page_name;
+
+ window.requestAnimationFrame(animate);
+
+ }
+
+
+
+ function do_switch_page(page_name) {
+
let old_desc = page_desc[current_page];
let new_desc = page_desc[page_name];
@@ -1195,11 +1237,13 @@
svg_root.setAttribute('viewBox',new_desc.bbox.join(" "));
+
+
current_page = page_name;
- update_subscriptions();
+ window.setTimeout(update_subscriptions,0);
};
@@ -1408,14 +1452,15 @@
+
-
+
frequency: 5,
dispatch: function(value) {
-
+
this.value_elt.textContent = String(value);
@@ -1445,7 +1490,11 @@
");
- this.value_elt.textContent = String(new_val);});
+
+ this.value_elt.textContent = String(new_val);
+
+
+ });
},
diff -r b7650c6abeda -r 84c16ece8e10 svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.ysl2 Fri Mar 06 14:42:08 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2 Fri Mar 06 14:43:03 2020 +0100
@@ -755,13 +755,14 @@
const "value_elt" {
optional_labels("value");
}
+ const "have_value","string-length($value_elt)>0";
value "$value_elt";
- if "$value_elt"
+ if "$have_value"
| frequency: 5,
| dispatch: function(value) {
- if "$value_elt"
+ if "$have_value"
| this.value_elt.textContent = String(value);
| },
@@ -776,7 +777,10 @@
| id("«@id»").addEventListener(
| "click",
| evt => {let new_val = change_hmi_value(this.indexes[0], "«func:escape_quotes(@inkscape:label)»");
- | this.value_elt.textContent = String(new_val);});
+ if "$have_value"{
+ | this.value_elt.textContent = String(new_val);
+ }
+ | });
/* TODO gray out value until refreshed */
}
| },