svghmi/widget_display.ysl2
author Edouard Tisserant
Wed, 01 Mar 2023 10:54:54 +0100
changeset 3740 ac0e6de439b5
parent 3524 27d298c6f961
permissions -rw-r--r--
Linux runtime: overrun detection for real-time timers and for plc execution.

If real-time timer wakes-up PLC thread too late (10% over period), then
warning is logged.

If PLC code (IO retreive, execution, IO publish) takes longer than requested
PLC execution cycle, then warning is logged, and CPU hoogging is mitigated
by delaying next PLC execution a few cylces more until having at least
1ms minimal idle time.
// widget_display.ysl2

widget_desc("Display") {
    longdesc
    ||
    If Display widget is a svg:text element, then text content is replaced by
    value of given variables, space separated.

    Otherwise, if Display widget is a group containing a svg:text element
    labelled "format", then text content is replaced by printf-like formated
    string. In other words, if "format" labeled text is "%d %s %f", then 3
    variables paths are expected : HMI_IN, HMI_STRING and HMI_REAL.

    In case Display widget is a svg::text element, it is also possible to give
    format string as first argument.
    ||

    shortdesc > Printf-like formated text display

    arg name="format" count="optional" accepts="string" > printf-like format string when not given as svg:text

    path name="fields" count="many" accepts="HMI_INT,HMI_REAL,HMI_STRING,HMI_BOOL" > variables to be displayed

}


widget_class("Display")
    ||
        frequency = 5;
        dispatch(value, oldval, index) {
            this.fields[index] = value;
            if(!this.ready){
                this.readyfields[index] = true;
                this.ready = this.readyfields.every(x=>x);
            }
            this.request_animate();
        }
    ||

widget_defs("Display") {
    const "format" optional_labels("format");
    const "has_format","string-length($format)>0";
    value "$format";

    if "$hmi_element[not(self::svg:text)] and not($has_format)"
        error > Display Widget id="«$hmi_element/@id»" must be a svg::text element itself or a group containing a svg:text element labelled "format"

    const "field_initializer" foreach "path" {
        choose{
            when "@type='HMI_STRING'" > ""
            otherwise > 0
        }
        if "position()!=last()" > ,
    }
    |     fields: [«$field_initializer»],
    const "readyfield_initializer" foreach "path" {
        > false
        if "position()!=last()" > ,
    }
    |     readyfields: [«$readyfield_initializer»],
    |     ready: false,
    |     animate: function(){
    choose {
        when "$has_format" {
    |       if(this.format_elt.getAttribute("lang")) {
    |           this.format = svg_text_to_multiline(this.format_elt);
    |           this.format_elt.removeAttribute("lang");
    |       }
    |       let str = vsprintf(this.format,this.fields);
    |       multiline_to_svg_text(this.format_elt, str, !this.ready);
        }
        otherwise {
    |       let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' ');
    |       multiline_to_svg_text(this.element, str, !this.ready);
        }
    }
    |     },
    |
    |     init: function() {
    if "$has_format" {
    |       this.format = svg_text_to_multiline(this.format_elt);
    }
    |       this.animate();
    |     },
}