# HG changeset patch
# User Edouard Tisserant
# Date 1571441010 -7200
# Node ID 68cee1366b9c7b7c8365b007e279d57a48b75960
# Parent f5da343b9b63f27b2ea1f3898f01b185f8bfc2e4
SVGHMI: dispatching data to minimalist "Display" text widget.
diff -r f5da343b9b63 -r 68cee1366b9c svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Thu Oct 17 15:48:09 2019 +0200
+++ b/svghmi/gen_index_xhtml.xslt Sat Oct 19 01:23:30 2019 +0200
@@ -198,10 +198,6 @@
",
- frequency:
-
- ,
-
args: [
@@ -236,8 +232,15 @@
- ]
-
+ ],
+
+ element: document.getElementById("
+
+ "),
+
+
+
+
}
,
@@ -319,7 +322,43 @@
function dispatch_value(index, value) {
- console.log("dispatch_value("+index+", "+value+")");
+ let widgets = subscribers[index];
+
+
+
+ if(widgets.size > 0) {
+
+ for(let widget of widgets){
+
+ let idxidx = widget.indexes.indexOf(index);
+
+ if(idxidx == -1){
+
+ throw new Error("Dispatching to widget not interested, should not happen.");
+
+ }
+
+ let d = widget.dispatch;
+
+ if(typeof(d) == "function" && idxidx == 0){
+
+ return d.call(widget,value);
+
+ }else if(typeof(d) == "object" && d.length >= idxidx){
+
+ d[idxidx].call(widget,value);
+
+ }/* else dispatch_0, ..., dispatch_n ? */
+
+ /*else {
+
+ throw new Error("Dunno how to dispatch to widget at index = " + index);
+
+ }*/
+
+ }
+
+ }
};
@@ -357,7 +396,7 @@
let i = 0;
- console.log("Recv something.");
+ //console.log("Recv something.");
try {
@@ -365,7 +404,7 @@
if(hash_int != dv.getUint8(i)){
- throw new Error("Hash doesn't match")
+ throw new Error("Hash doesn't match");
};
@@ -375,7 +414,7 @@
- console.log("Recv something GOOD.");
+ //console.log("Recv something GOOD.");
@@ -383,7 +422,7 @@
let index = dv.getUint32(i, true);
- console.log("Recv something index is "+index);
+ //console.log("Recv something index is "+index);
i += 4;
@@ -722,16 +761,30 @@
-
- 10
-
-
- 10
-
-
- 5
-
-
- 5
+
+
+ frequency: 5,
+
+ dispatch: function(value) {
+
+
+
+ this.element.textContent = String(value);
+
+
+
+ Display widget as a group not implemented
+
+
+ },
+
+
+
+ frequency: 10,
+
+
+
+ frequency: 5,
+
diff -r f5da343b9b63 -r 68cee1366b9c svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.ysl2 Thu Oct 17 15:48:09 2019 +0200
+++ b/svghmi/gen_index_xhtml.ysl2 Sat Oct 19 01:23:30 2019 +0200
@@ -191,7 +191,6 @@
const "widget", "func:parselabel(@inkscape:label)/widget";
| «@id»: {
| type: "«$widget/@type»",
- | frequency: `apply "$widget", mode="refresh_frequency"`,
| args: [
foreach "$widget/arg"
| "«@value»"`if "position()!=last()" > ,`
@@ -204,7 +203,9 @@
error > No match for HMI «$hmipath»;
| «$hmitree_match/@index»`if "position()!=last()" > ,`
}
- | ]
+ | ],
+ | element: document.getElementById("«@id»"),
+ apply "$widget", mode="widget_defs" with "hmi_element",".";
| }`if "position()!=last()" > ,`
}
| }
@@ -306,8 +307,33 @@
};
}
- template "widget", mode="refresh_frequency" > 10
+ template "widget[@type='Display']", mode="widget_defs" {
+ param "hmi_element";
+ | frequency: 5,
+ | dispatch: function(value) {
+ choose {
+ when "$hmi_element[self::svg:text]"{
+ // TODO : care about ?
+ | this.element.textContent = String(value);
+ }
+ otherwise {
+ error "Display widget as a group not implemented";
+ }
+ }
+ | },
+
+ }
+ template "widget[@type='Meter']", mode="widget_defs" {
+ | frequency: 10,
+ }
+ template "widget[@type='Input']", mode="widget_defs" {
+ | frequency: 5,
+ }
+ // | frequency: 10`apply ".", mode="refresh_frequency"`,
+ // template "widget", mode="refresh_frequency" > 10
+ /*
template "widget[@type='Meter']", mode="refresh_frequency" > 10
template "widget[@type='Display']", mode="refresh_frequency" > 5
template "widget[@type='Input']", mode="refresh_frequency" > 5
+ */
}
diff -r f5da343b9b63 -r 68cee1366b9c svghmi/svghmi.js
--- a/svghmi/svghmi.js Thu Oct 17 15:48:09 2019 +0200
+++ b/svghmi/svghmi.js Sat Oct 19 01:23:30 2019 +0200
@@ -1,7 +1,25 @@
// svghmi.js
function dispatch_value(index, value) {
- console.log("dispatch_value("+index+", "+value+")");
+ let widgets = subscribers[index];
+
+ if(widgets.size > 0) {
+ for(let widget of widgets){
+ let idxidx = widget.indexes.indexOf(index);
+ if(idxidx == -1){
+ throw new Error("Dispatching to widget not interested, should not happen.");
+ }
+ let d = widget.dispatch;
+ if(typeof(d) == "function" && idxidx == 0){
+ return d.call(widget,value);
+ }else if(typeof(d) == "object" && d.length >= idxidx){
+ d[idxidx].call(widget,value);
+ }/* else dispatch_0, ..., dispatch_n ? */
+ /*else {
+ throw new Error("Dunno how to dispatch to widget at index = " + index);
+ }*/
+ }
+ }
};
// Open WebSocket to relative "/ws" address
@@ -23,14 +41,13 @@
try {
for(let hash_int of hmi_hash) {
if(hash_int != dv.getUint8(i)){
- throw new Error("Hash doesn't match")
+ throw new Error("Hash doesn't match");
};
i++;
};
while(i < data.byteLength){
let index = dv.getUint32(i, true);
- console.log("Recv something index is "+index);
i += 4;
let iectype = hmitree_types[index];
if(iectype != undefined){