Page screensaver
    Attributes
        Scope              : local
        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
            baud=115200
            vis tInstruction,0
            vis tTmp,0
            vis p0,0
            vis tNotifyHead,0
            vis tNotifyText,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
        
        Postinitialize Event
            click m0,1
        
Variable (string) strCommand
    Attributes
        Scope         : local
        Text          : 
        Max. Text Size: 600
    
Variable (string) strTmp
    Attributes
        Scope         : local
        Text          : 
        Max. Text Size: 2
    
Variable (string) tId
    Attributes
        Scope         : local
        Text          : 
        Max. Text Size: 25
    
Variable (string) tInstruction
    Attributes
        Scope         : local
        Text          : 
        Max. Text Size: 50
    
Variable (string) tSend
    Attributes
        Scope         : local
        Text          : 
        Max. Text Size: 50
    
Variable (string) tTmp
    Attributes
        Scope         : local
        Text          : 
        Max. Text Size: 50
    
Variable (int32) vaTap
    Attributes
        Scope: local
        Value: 0
    
Variable (int32) xc1
    Attributes
        Scope: local
        Value: 0
    
Variable (int32) xc2
    Attributes
        Scope: local
        Value: 0
    
Variable (int32) xcR
    Attributes
        Scope: local
        Value: 0
    
Variable (int32) yc1
    Attributes
        Scope: local
        Value: 0
    
Variable (int32) yc2
    Attributes
        Scope: local
        Value: 0
    
Variable (int32) ycR
    Attributes
        Scope: local
        Value: 0
    
Text m0
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
    Events
        Touch Press Event
            tTmp.txt="change model conf to us-l/p "
            strlen tTmp.txt,sys1
            sya1=sys1*11+m0.h-48/2
            for(sys0=0;sys0<sys1;sys0++)
            {
                substr tTmp.txt,strTmp.txt,sys0,1
                xstr m0.x-5,sys0*-11+m0.y+sya1,23,20,6,WHITE,RED,2,1,3,strTmp.txt
            }
        
Text t10
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : |
        Max. Text Size     : 10
    
Text tAMPM
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : PM
        Max. Text Size     : 10
    
Text tDate
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : Tuesday, 08. March 2022
        Max. Text Size     : 40
    
Text tF1Icon
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tF2Icon
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tF3Icon
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tF4Icon
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 5
    
Text tForecast1
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tForecast1Val
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tForecast2
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tForecast2Val
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tForecast3
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tForecast3Val
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tForecast4
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tForecast4Val
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tIcon1
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tIcon2
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tMainIcon
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tMainIconAlt
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tMainIconAlt2
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tMainText
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tMainTextAlt
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tMainTextAlt2
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 10
    
Text tNotifyHead
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 35
    
Text tNotifyText
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 120
    
Text tTime
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 21:32
        Max. Text Size     : 15
    
Text tTimeAdd
    Attributes
        Scope              : local
        Dragging           : 0
        Send Component ID  : disabled
        Associated Keyboard: none
        Text               : 
        Max. Text Size     : 40
    
Picture p0
    Attributes
        Scope            : local
        Dragging         : 0
        Send Component ID: disabled
    
Timer tm0
    Attributes
        Scope      : local
        Period (ms): 50
        Enabled    : yes
    
    Events
        Timer Event
            if(tc0.val!=0)
            {
                xc2.val=tch0
                yc2.val=tch1
            }
        
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")
                                    {
                                        click tc0,1
                                    }
                                    if(tInstruction.txt=="dimmode")
                                    {
                                        // get value
                                        spstr strCommand.txt,tTmp.txt,"~",1
                                        covx tTmp.txt,dimValue,0,0
                                        dim=dimValue
                                        // get value normal
                                        spstr strCommand.txt,tTmp.txt,"~",2
                                        covx tTmp.txt,dimValueNormal,0,0
                                        // get background color
                                        spstr strCommand.txt,tTmp.txt,"~",3
                                        if(tTmp.txt!="")
                                        {
                                            covx tTmp.txt,defaultBcoColor,0,0
                                        }
                                        // get font color
                                        spstr strCommand.txt,tTmp.txt,"~",4
                                        if(tTmp.txt!="")
                                        {
                                            covx tTmp.txt,defaultFontColor,0,0
                                        }
                                    }
                                    if(tInstruction.txt=="time")
                                    {
                                        //click m0,1
                                        //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
                                        }else
                                        {
                                            vis tAMPM,1
                                        }
                                        spstr strCommand.txt,tTimeAdd.txt,"~",2
                                        ref tIcon1
                                        ref tIcon2
                                    }
                                    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=="statusUpdate")
                                    {
                                        //statusIcon1
                                        spstr strCommand.txt,tIcon1.txt,"~",1
                                        spstr strCommand.txt,tTmp.txt,"~",2
                                        covx tTmp.txt,tIcon1.pco,0,0
                                        //statusIcon2
                                        spstr strCommand.txt,tIcon2.txt,"~",3
                                        spstr strCommand.txt,tTmp.txt,"~",4
                                        covx tTmp.txt,tIcon2.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",5
                                        if(tTmp.txt!="")
                                        {
                                            tIcon1.font=3
                                        }
                                        spstr strCommand.txt,tTmp.txt,"~",6
                                        if(tTmp.txt!="")
                                        {
                                            tIcon2.font=3
                                        }
                                    }
                                    if(tInstruction.txt=="weatherUpdate"&&tNotifyHead.txt==""&&tNotifyText.txt=="")
                                    {
                                        //tMainIcon
                                        spstr strCommand.txt,tMainIcon.txt,"~",3
                                        tMainIconAlt.txt=tMainIcon.txt
                                        //tMainIcon Color
                                        spstr strCommand.txt,tTmp.txt,"~",4
                                        covx tTmp.txt,tMainIcon.pco,0,0
                                        tMainIconAlt.pco=tMainIcon.pco
                                        //tMainText
                                        spstr strCommand.txt,tMainText.txt,"~",6
                                        tMainTextAlt.txt=tMainText.txt
                                        //tForecast1
                                        spstr strCommand.txt,tForecast1.txt,"~",11
                                        //tF1Icon
                                        spstr strCommand.txt,tF1Icon.txt,"~",9
                                        //tF1Icon Color
                                        spstr strCommand.txt,tTmp.txt,"~",10
                                        covx tTmp.txt,tF1Icon.pco,0,0
                                        //tForecast1Val
                                        spstr strCommand.txt,tForecast1Val.txt,"~",12
                                        //tForecast2
                                        spstr strCommand.txt,tForecast2.txt,"~",17
                                        //tF2Icon
                                        spstr strCommand.txt,tF2Icon.txt,"~",15
                                        //tF2Icon Color
                                        spstr strCommand.txt,tTmp.txt,"~",16
                                        covx tTmp.txt,tF2Icon.pco,0,0
                                        //tForecast2Val
                                        spstr strCommand.txt,tForecast2Val.txt,"~",18
                                        //tForecast3
                                        spstr strCommand.txt,tForecast3.txt,"~",23
                                        //tF3Icon
                                        spstr strCommand.txt,tF3Icon.txt,"~",21
                                        //tF3Icon Color
                                        spstr strCommand.txt,tTmp.txt,"~",22
                                        covx tTmp.txt,tF3Icon.pco,0,0
                                        //tForecast3Val
                                        spstr strCommand.txt,tForecast3Val.txt,"~",24
                                        //tForecast4
                                        spstr strCommand.txt,tForecast4.txt,"~",29
                                        //tF4Icon
                                        spstr strCommand.txt,tF4Icon.txt,"~",27
                                        //tF4Icon Color
                                        spstr strCommand.txt,tTmp.txt,"~",28
                                        covx tTmp.txt,tF4Icon.pco,0,0
                                        //tForecast4Val
                                        spstr strCommand.txt,tForecast4Val.txt,"~",30
                                        //alternative layout
                                        //tMainTextAlt2
                                        spstr strCommand.txt,tMainTextAlt2.txt,"~",36
                                        //tMainIconAlt2
                                        spstr strCommand.txt,tMainIconAlt2.txt,"~",33
                                        //tMainIconAlt2 Color
                                        spstr strCommand.txt,tTmp.txt,"~",34
                                        covx tTmp.txt,tMainIconAlt2.pco,0,0
                                        if(tMainTextAlt2.txt!="")
                                        {
                                            //value for tMRIcon, activate alternative layout
                                            vis tMainIcon,0
                                            vis tMainText,0
                                            vis tMainTextAlt,1
                                            vis tMainIconAlt,1
                                            vis tMainTextAlt2,1
                                            vis tMainIconAlt2,1
                                            if(p0.w!=320)
                                            {
                                                vis tForecast1,0
                                                vis tF1Icon,0
                                                vis tForecast1Val,0
                                                //move forecast values to the right
                                                tForecast4.txt=tForecast3.txt
                                                tForecast3.txt=tForecast2.txt
                                                tForecast2.txt=tForecast1.txt
                                                tForecast4Val.txt=tForecast3Val.txt
                                                tForecast3Val.txt=tForecast2Val.txt
                                                tForecast2Val.txt=tForecast1Val.txt
                                                tF4Icon.txt=tF3Icon.txt
                                                tF3Icon.txt=tF2Icon.txt
                                                tF2Icon.txt=tF1Icon.txt
                                                tF4Icon.pco=tF3Icon.pco
                                                tF3Icon.pco=tF2Icon.pco
                                                tF2Icon.pco=tF1Icon.pco
                                            }
                                        }else
                                        {
                                            vis tMainIcon,1
                                            vis tMainIconAlt,0
                                            vis tMainText,1
                                            vis tMainTextAlt,0
                                            vis tMainTextAlt2,0
                                            vis tMainIconAlt2,0
                                            if(p0.w!=320)
                                            {
                                                vis tForecast1,1
                                                vis tF1Icon,1
                                                vis tForecast1Val,1
                                            }
                                        }
                                    }
                                    if(tInstruction.txt=="color"&&tNotifyHead.txt==""&&tNotifyText.txt=="")
                                    {
                                        spstr strCommand.txt,tTmp.txt,"~",1
                                        covx tTmp.txt,tTime.bco,0,0
                                        if(tTime.bco!=screensaver.bco)
                                        {
                                            screensaver.bco=tTime.bco
                                            tAMPM.bco=tTime.bco
                                            tDate.bco=tTime.bco
                                            tMainIcon.bco=tTime.bco
                                            tMainText.bco=tTime.bco
                                            tMainIconAlt.bco=tTime.bco
                                            tMainTextAlt.bco=tTime.bco
                                            tMainTextAlt2.bco=tTime.bco
                                            tMainIconAlt2.bco=tTime.bco
                                            tIcon1.bco=tTime.bco
                                            tIcon2.bco=tTime.bco
                                            tForecast1.bco=tTime.bco
                                            tForecast1Val.bco=tTime.bco
                                            tF1Icon.bco=tTime.bco
                                            tForecast2.bco=tTime.bco
                                            tForecast2Val.bco=tTime.bco
                                            tF2Icon.bco=tTime.bco
                                            tForecast3.bco=tTime.bco
                                            tForecast3Val.bco=tTime.bco
                                            tF3Icon.bco=tTime.bco
                                            tForecast4.bco=tTime.bco
                                            tForecast4Val.bco=tTime.bco
                                            tF4Icon.bco=tTime.bco
                                            tTimeAdd.bco=tTime.bco
                                        }
                                        spstr strCommand.txt,tTmp.txt,"~",2
                                        covx tTmp.txt,tTime.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",3
                                        covx tTmp.txt,tAMPM.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",4
                                        covx tTmp.txt,tDate.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",5
                                        covx tTmp.txt,tMainText.pco,0,0
                                        tMainTextAlt.pco=tMainText.pco
                                        spstr strCommand.txt,tTmp.txt,"~",6
                                        covx tTmp.txt,tForecast1.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",7
                                        covx tTmp.txt,tForecast2.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",8
                                        covx tTmp.txt,tForecast3.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",9
                                        covx tTmp.txt,tForecast4.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",10
                                        covx tTmp.txt,tForecast1Val.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",11
                                        covx tTmp.txt,tForecast2Val.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",12
                                        covx tTmp.txt,tForecast3Val.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",13
                                        covx tTmp.txt,tForecast4Val.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",14
                                        covx tTmp.txt,t10.bco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",15
                                        covx tTmp.txt,tMainTextAlt2.pco,0,0
                                        spstr strCommand.txt,tTmp.txt,"~",16
                                        covx tTmp.txt,tTimeAdd.pco,0,0
                                        if(tMainTextAlt2.txt!=""&&p0.w!=320)
                                        {
                                            tForecast4Val.pco=tForecast3Val.pco
                                            tForecast3Val.pco=tForecast2Val.pco
                                            tForecast2Val.pco=tForecast1Val.pco
                                            tForecast4.pco=tForecast3.pco
                                            tForecast3.pco=tForecast2.pco
                                            tForecast2.pco=tForecast1.pco
                                        }
                                    }
                                    if(tInstruction.txt=="notify")
                                    {
                                        spstr strCommand.txt,tNotifyHead.txt,"~",1
                                        spstr strCommand.txt,tNotifyText.txt,"~",2
                                        if(tNotifyHead.txt!=""||tNotifyText.txt!="")
                                        {
                                            vis tNotifyHead,1
                                            vis tNotifyText,1
                                        }else
                                        {
                                            vis tNotifyHead,0
                                            vis tNotifyText,0
                                        }
                                        tNotifyHead.bco=tTime.bco
                                        tNotifyText.bco=tTime.bco
                                        spstr strCommand.txt,tTmp.txt,"~",3
                                        if(tTmp.txt!="")
                                        {
                                            covx tTmp.txt,tNotifyHead.pco,0,0
                                        }
                                        spstr strCommand.txt,tTmp.txt,"~",4
                                        if(tTmp.txt!="")
                                        {
                                            covx tTmp.txt,tNotifyText.pco,0,0
                                        }
                                    }
                                    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
                                        spstr strCommand.txt,pageIcons.tTmp3.txt,"~",4
                                        //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 payloadLength-1
                                        bufferPos=0
                                        if(tId.txt=="pageStartup")
                                        {
                                            page pageStartup
                                        }
                                        if(tId.txt=="screensaver")
                                        {
                                            page screensaver
                                        }
                                        if(tId.txt=="screensaver2")
                                        {
                                            page screensaver2
                                        }
                                        if(tId.txt=="cardEntities")
                                        {
                                            page cardEntities
                                        }
                                        if(tId.txt=="cardGrid")
                                        {
                                            page cardGrid
                                        }
                                        if(tId.txt=="cardGrid2")
                                        {
                                            page cardGrid2
                                        }
                                        if(tId.txt=="popupLight")
                                        {
                                            pageIcons.tTmp1.txt=tTmp.txt
                                            page popupLight
                                        }
                                        if(tId.txt=="popupShutter")
                                        {
                                            pageIcons.tTmp1.txt=tTmp.txt
                                            page popupShutter
                                        }
                                        if(tId.txt=="popupNotify")
                                        {
                                            page popupNotify
                                        }
                                        if(tId.txt=="cardThermo")
                                        {
                                            page cardThermo
                                        }
                                        if(tId.txt=="cardMedia")
                                        {
                                            page cardMedia
                                        }
                                        if(tId.txt=="cardAlarm")
                                        {
                                            page cardAlarm
                                        }
                                        if(tId.txt=="cardQR")
                                        {
                                            page cardQR
                                        }
                                        if(tId.txt=="cardPower")
                                        {
                                            page cardPower
                                        }
                                        if(tId.txt=="cardChart")
                                        {
                                            page cardChart
                                        }
                                        if(tId.txt=="cardLChart")
                                        {
                                            page cardLChart
                                        }
                                    }
                                    if(tInstruction.txt=="timeout")
                                    {
                                        //set timeout to global var
                                        spstr strCommand.txt,tTmp.txt,"~",1
                                        covx tTmp.txt,sleepTimeout,0,0
                                    }
                                    // end of user code
                                    udelete payloadLength-1
                                    bufferPos=0
                                }
                            }
                        }
                    }
                    // next character
                    bufferPos++
                }
            }
        
Timer tmSleep
    Attributes
        Scope      : local
        Period (ms): 1000
        Enabled    : yes
    
    Events
        Timer Event
            if(sleepTimeout!=0&&dimValue!=dim)
            {
                sleepValue+=1
                if(sleepTimeout<=sleepValue)
                {
                    sleepValue=0
                    dim=dimValue
                    vaTap.val=0
                }
            }
        
TouchCap tc0
    Attributes
        Scope: local
        Value: 0
    
    Events
        Touch Press Event
            xc1.val=tch0
            yc1.val=tch1
            tm0.en=1
            if(tNotifyHead.txt!=""||tNotifyText.txt!="")
            {
                if(dim!=0)
                {
                    tNotifyHead.txt=""
                    tNotifyText.txt=""
                    vis tNotifyHead,0
                    vis tNotifyText,0
                }
            }
            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,2
            //crcputs tSend.txt,0
            //send cmd
            //printh 55 bb
            //prints sys0,2
            //prints tSend.txt,0
            //prints crcval,2
        
        Touch Release Event
            tm0.en=0
            if(tch0==0)
            // When this is zero we can interpret that as the real end of the drag event
            {
                xcR.val=xc1.val-xc2.val
                ycR.val=yc1.val-yc2.val
                // new method
                // one of the difference values should be low to be a valid direction, in case it has a high value it's not a valid swipe, because it's diagonal
                // x difference between -125 and 125 (swipe on y-axis)
                if(xcR.val>-125&&xcR.val<125)
                {
                    //tStatusNew.txt="x low, -> y"
                    // check if below minimum value (change is negative)
                    if(ycR.val<-80)
                    {
                        //tDirNew.txt="down"
                        tSend.txt="event,buttonPress2,screensaver,swipeDown"
                    }else if(ycR.val>80)
                    {
                        //tDirNew.txt="up"
                        tSend.txt="event,buttonPress2,screensaver,swipeUp"
                    }else
                    {
                        //tDirNew.txt="invalid"
                    }
                    // y difference between -125 and 125 (swipe on x-axis)
                }else if(ycR.val>-125&&ycR.val<125)
                {
                    //tStatusNew.txt="y low, -> x"
                    if(xcR.val<-80)
                    {
                        //tDirNew.txt="right"
                        tSend.txt="event,buttonPress2,screensaver,swipeRight"
                    }else if(xcR.val>80)
                    {
                        //tDirNew.txt="left"
                        tSend.txt="event,buttonPress2,screensaver,swipeLeft"
                    }else
                    {
                        //tDirNew.txt="invalid"
                    }
                    //diagonal swipe invalid
                }else
                {
                    //tStatusNew.txt="invalid"
                    //tDirNew.txt="diagonal"
                }
            }
            //send calc crc
            btlen tSend.txt,sys0
            crcrest 1,0xffff // reset CRC
            crcputh 55 bb
            crcputs sys0,2
            crcputs tSend.txt,0
            //send cmd
            printh 55 bb
            prints sys0,2
            prints tSend.txt,0
            prints crcval,2
        
