Page screensaver
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Locked                              : no
        Swide up page ID                    : disabled
        Swide down page ID                  : disabled
        Swide left page ID                  : disabled
        Swide right page ID                 : disabled
    
    Events
        Preinitialize Event
            recmod=1
            bauds=115200
            vis tInstruction,0
            vis tTmp,0
            vis p0,0
            //load gloabl time string from pageIcons
            //tTime.txt=vaTime.txt
            spstr pageIcons.vaTime.txt,tTime.txt,"?",0
            spstr pageIcons.vaTime.txt,tAMPM.txt,"?",1
            if(tAMPM.txt=="")
            {
                vis tAMPM,0
            }
            tDate.txt=pageIcons.vaDate.txt
            dim=dimValue
            vis tSend,0
            //page open event
            // clear weather elements, to keep example content in HMI
            tMainIcon.txt=""
            tMainText.txt=""
            tForecast1.txt=""
            tF1Icon.txt=""
            tForecast1Val.txt=""
            tForecast2.txt=""
            tF2Icon.txt=""
            tForecast2Val.txt=""
            //tSend.txt="event,screensaverOpen"
            //send calc crc
            //btlen tSend.txt,sys0
            //crcrest 1,0xffff // reset CRC
            //crcputh 55 bb
            //crcputs sys0,1
            //crcputs tSend.txt,0
            //send cmd
            //printh 55 bb
            //prints sys0,2
            //prints tSend.txt,0
            //prints crcval,2
        
Variable (string) strCommand
    Attributes
        Scope         : local
        Text          : 
        Max. Text Size: 200
    
Variable (string) tId
    Attributes
        Scope         : local
        Text          : 
        Max. Text Size: 25
    
Variable (int32) vaTap
    Attributes
        Scope: local
        Value: 0
    
Text tInstruction
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 
        Max. Text Size                      : 50
    
Text tTmp
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 
        Max. Text Size                      : 50
    
Text tTime
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 21:32   
        Max. Text Size                      : 15
    
Text tDate
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : Tuesday, 08. March 2022
        Max. Text Size                      : 30
    
Text tSend
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 
        Max. Text Size                      : 50
    
Text tMainIcon
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : î
        Max. Text Size                      : 10
    
Text tMainText
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 2,3 Â°C
        Max. Text Size                      : 10
    
Text tForecast1
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : Mi
        Max. Text Size                      : 10
    
Text tForecast1Val
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 9,3 Â°C
        Max. Text Size                      : 10
    
Text tF1Icon
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : î
        Max. Text Size                      : 10
    
Text tForecast2
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : Do
        Max. Text Size                      : 10
    
Text tF2Icon
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : î
        Max. Text Size                      : 10
    
Text tForecast2Val
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 11,9 Â°C
        Max. Text Size                      : 10
    
Text t10
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : |
        Max. Text Size                      : 10
    
Text tAMPM
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : PM
        Max. Text Size                      : 10
    
Text tForecast3Val
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 
        Max. Text Size                      : 10
    
Text tF3Icon
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 
        Max. Text Size                      : 10
    
Text tForecast3
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 
        Max. Text Size                      : 10
    
Text tForecast4
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 
        Max. Text Size                      : 10
    
Text tF4Icon
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 
        Max. Text Size                      : 10
    
Text tForecast4Val
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Associated Keyboard                 : none
        Text                                : 
        Max. Text Size                      : 10
    
Picture p0
    Attributes
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
    
Timer tmSerial
    Attributes
        Scope      : local
        Period (ms): 50
        Enabled    : yes
    
    Events
        Timer Event
            // data available
            if(usize>1)
            {
                bufferPos=0
                while(bufferPos<usize)
                {
                    // check for 0x55 0xBB - Command Init Secuence
                    if(u[bufferPos]==187&&u[bufferPos-1]==85)
                    {
                        //remove garbage at the start of the buffer if there's any to free buffer for command
                        if(u[bufferPos]!=1)
                        {
                            udelete bufferPos-1
                        }
                        //instruction is now aligned with buffer, because we deleted garbage before instrcution
                        //get length after init sequence (check if there are more than to bytes in buffer)
                        if(3<usize)
                        {
                            // check if serial buffer has reached the announced length
                            ucopy payloadLength,2,2,0
                            // we are only checking payload length so we have to skip first 3 bytes (init+payload length) (-1 because of < instead of <=)
                            payloadLength+=3
                            // payload length does also not contain crc, so we are adding another 2 bytes for crc
                            payloadLength+=2
                            if(payloadLength<usize)
                            {
                                // calculate crc
                                crcrest 1,0xFFFF
                                // u[2] contains payload legth at 3rd pos in buffer, we are calculating crc from 3rd pos with number of bytes from payload length
                                //crcputu 3,u[2]
                                // u[2] cotnains payload length, we are calculating a crc over the whole message, so we have to add 3 to the length from u[2]
                                crcputu 0,payloadLength-1
                                // get recived crc to be able to compare it
                                ucopy recvCrc,payloadLength-1,2,0
                                // compare crc with recived value
                                if(crcval==recvCrc)
                                {
                                    // crc is okay
                                    // here is the location where acual code should be
                                    // write command to variable strCommand
                                    ucopy strCommand.txt,4,payloadLength-5,0
                                    // write instruction to tInstuction (debug output, but used as variable here, ui elements will be disabled by default)
                                    spstr strCommand.txt,tInstruction.txt,",",0
                                    if(tInstruction.txt=="wake")
                                    {
                                        //dim=100
                                        click tc0,1
                                    }
                                    if(tInstruction.txt=="dimmode")
                                    {
                                        // get value
                                        spstr strCommand.txt,tTmp.txt,",",1
                                        covx tTmp.txt,dimValue,0,0
                                        dim=dimValue
                                    }
                                    if(tInstruction.txt=="time")
                                    {
                                        //get set time to global variable
                                        spstr strCommand.txt,pageIcons.vaTime.txt,",",1
                                        spstr pageIcons.vaTime.txt,tTime.txt,"?",0
                                        spstr pageIcons.vaTime.txt,tAMPM.txt,"?",1
                                        if(tAMPM.txt=="")
                                        {
                                            vis tAMPM,0
                                        }
                                    }
                                    if(tInstruction.txt=="date")
                                    {
                                        //get set date to global variable
                                        spstr strCommand.txt,pageIcons.vaDate.txt,"?",1
                                        tDate.txt=pageIcons.vaDate.txt
                                    }
                                    if(tInstruction.txt=="timeout")
                                    {
                                        //set timeout to global var
                                        spstr strCommand.txt,tTmp.txt,",",1
                                        covx tTmp.txt,sleepTimeout,0,0
                                    }
                                    if(tInstruction.txt=="weatherUpdate")
                                    {
                                        //tMainIcon
                                        spstr strCommand.txt,tTmp.txt,"?",1
                                        covx tTmp.txt,sys0,0,0
                                        substr pageIcons.tIcons.txt,tMainIcon.txt,sys0,1
                                        //tMainText
                                        spstr strCommand.txt,tMainText.txt,"?",2
                                        //tForecast1
                                        spstr strCommand.txt,tForecast1.txt,"?",3
                                        //tF1Icon
                                        spstr strCommand.txt,tTmp.txt,"?",4
                                        covx tTmp.txt,sys0,0,0
                                        substr pageIcons.tIcons.txt,tF1Icon.txt,sys0,1
                                        //tForecast1Val
                                        spstr strCommand.txt,tForecast1Val.txt,"?",5
                                        //tForecast2
                                        spstr strCommand.txt,tForecast2.txt,"?",6
                                        //tF2Icon
                                        spstr strCommand.txt,tTmp.txt,"?",7
                                        covx tTmp.txt,sys0,0,0
                                        substr pageIcons.tIcons.txt,tF2Icon.txt,sys0,1
                                        //tForecast2Val
                                        spstr strCommand.txt,tForecast2Val.txt,"?",8
                                        //tForecast3
                                        spstr strCommand.txt,tForecast3.txt,"?",9
                                        //tF3Icon
                                        spstr strCommand.txt,tTmp.txt,"?",10
                                        covx tTmp.txt,sys0,0,0
                                        substr pageIcons.tIcons.txt,tF3Icon.txt,sys0,1
                                        //tForecast3Val
                                        spstr strCommand.txt,tForecast3Val.txt,"?",11
                                        //tForecast4
                                        spstr strCommand.txt,tForecast4.txt,"?",12
                                        //tF4Icon
                                        spstr strCommand.txt,tTmp.txt,"?",13
                                        covx tTmp.txt,sys0,0,0
                                        substr pageIcons.tIcons.txt,tF4Icon.txt,sys0,1
                                        //tForecast4Val
                                        spstr strCommand.txt,tForecast4Val.txt,"?",14
                                    }
                                    if(tInstruction.txt=="pageType")
                                    {
                                        dim=100
                                        //command format pageType,specialPageName
                                        //write name of speical page to tId
                                        spstr strCommand.txt,tId.txt,",",1
                                        //save second arg if there's one
                                        spstr strCommand.txt,tTmp.txt,",",2
                                        //save third arg if there's one
                                        spstr strCommand.txt,pageIcons.tTmp2.txt,",",3
                                        //we are going to exit this page with this command, so we have to clear the buffer, so we are not getting into a stupid loop ...
                                        udelete u[2]+3
                                        bufferPos=0
                                        if(tId.txt=="popupLight")
                                        {
                                            pageIcons.tTmp1.txt=tTmp.txt
                                            page popupLight
                                        }
                                        if(tId.txt=="pageStartup")
                                        {
                                            page pageStartup
                                        }
                                        if(tId.txt=="cardThermo")
                                        {
                                            page cardThermo
                                        }
                                        if(tId.txt=="cardMedia")
                                        {
                                            page cardMedia
                                        }
                                        if(tId.txt=="pageStartup")
                                        {
                                            page pageStartup
                                        }
                                        if(tId.txt=="popupNotify")
                                        {
                                            page popupNotify
                                        }
                                        if(tId.txt=="cardGrid")
                                        {
                                            page cardGrid
                                        }
                                        if(tId.txt=="cardEntities")
                                        {
                                            page cardEntities
                                        }
                                        if(tId.txt=="cardAlarm")
                                        {
                                            page cardAlarm
                                        }
                                    }
                                    // end of user code
                                    udelete payloadLength-1
                                    bufferPos=0
                                }
                            }
                        }
                    }
                    // next character
                    bufferPos++
                }
            }
        
TouchCap tc0
    Attributes
        Scope: local
        Value: 0
    
    Events
        Touch Press Event
            dim=dimValueNormal
            vaTap.val+=1
            covx vaTap.val,tTmp.txt,0,0
            tSend.txt="event,buttonPress2,screensaver,bExit,"+tTmp.txt
            //send calc crc
            btlen tSend.txt,sys0
            crcrest 1,0xffff // reset CRC
            crcputh 55 bb
            crcputs sys0,1
            crcputs tSend.txt,0
            //send cmd
            printh 55 bb
            prints sys0,2
            prints tSend.txt,0
            prints crcval,2
        
