Page pageStartup
    Attributes
        ID                                  : 0
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        Width                               : 320
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Locked                              : no
        Swide up page ID                    : disabled
        Swide down page ID                  : disabled
        Swide left page ID                  : disabled
        Swide right page ID                 : disabled
        Fill                                : solid color
        Back. Color                         : 6371
    
    Events
        Preinitialize Event
            vis p0,0
            recmod=1
            bauds=115200
            vis tSend,0
            vis tInstruction,0
            vis tTmp,0
            vis tId,0
            vis bSendStartup,0
            vis frame_ptr,0
            vis spinner_w,0
            vis frapic_w,0
            vis usual_cnt,0
            vis tMsg2,0
            vis tMsg3,0
            vis tVersion,0
            dim=100
        
        Postinitialize Event
            //send messages by clicking button
            click bSendStartup,1
        
Variable (string) strCommand
    Attributes
        ID            : 5
        Scope         : local
        Text          : 
        Max. Text Size: 50
    
Number frame_ptr
    Attributes
        ID                                  : 10
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 6
        y coordinate                        : 78
        Width                               : 100
        Height                              : 30
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 65535
        Font Color                          : 0
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Value                               : 0
        Significant digits shown            : all
        Format                              : decimal
        Word wrap                           : enabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Number spinner_w
    Attributes
        ID                                  : 11
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 6
        y coordinate                        : 111
        Width                               : 100
        Height                              : 30
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 65535
        Font Color                          : 0
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Value                               : 140
        Significant digits shown            : all
        Format                              : decimal
        Word wrap                           : enabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Number frapic_w
    Attributes
        ID                                  : 12
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 6
        y coordinate                        : 144
        Width                               : 100
        Height                              : 30
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 65535
        Font Color                          : 0
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Value                               : 1960
        Significant digits shown            : all
        Format                              : decimal
        Word wrap                           : enabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Number usual_cnt
    Attributes
        ID                                  : 15
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 7
        y coordinate                        : 178
        Width                               : 100
        Height                              : 30
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 65535
        Font Color                          : 0
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Value                               : 0
        Significant digits shown            : all
        Format                              : decimal
        Word wrap                           : enabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Text tSend
    Attributes
        ID                                  : 2
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 0
        y coordinate                        : 0
        Width                               : 230
        Height                              : 23
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 65535
        Font Color                          : 0
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Input Type                          : character
        Text                                : newtxt
        Max. Text Size                      : 100
        Word wrap                           : disabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Text tTmp
    Attributes
        ID                                  : 3
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 127
        y coordinate                        : 24
        Width                               : 34
        Height                              : 30
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 65535
        Font Color                          : 0
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Input Type                          : character
        Text                                : 
        Max. Text Size                      : 10
        Word wrap                           : disabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Text tInstruction
    Attributes
        ID                                  : 6
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 163
        y coordinate                        : 0
        Width                               : 119
        Height                              : 30
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 65535
        Font Color                          : 0
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Input Type                          : character
        Text                                : 
        Max. Text Size                      : 20
        Word wrap                           : disabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Text tId
    Attributes
        ID                                  : 7
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 0
        y coordinate                        : 25
        Width                               : 125
        Height                              : 30
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 65535
        Font Color                          : 0
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Input Type                          : character
        Text                                : 
        Max. Text Size                      : 20
        Word wrap                           : disabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Text tMsg1
    Attributes
        ID                                  : 8
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 0
        y coordinate                        : 399
        Width                               : 320
        Height                              : 30
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 1
        Back. Color                         : 6371
        Font Color                          : 65535
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Input Type                          : character
        Text                                : Waiting for content ...
        Max. Text Size                      : 40
        Word wrap                           : disabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Text tMsg2
    Attributes
        ID                                  : 13
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 0
        y coordinate                        : 432
        Width                               : 320
        Height                              : 25
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 6371
        Font Color                          : 65535
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Input Type                          : character
        Text                                : This is taking longer than usual,
        Max. Text Size                      : 100
        Word wrap                           : enabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Text tMsg3
    Attributes
        ID                                  : 14
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 0
        y coordinate                        : 454
        Width                               : 320
        Height                              : 25
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 6371
        Font Color                          : 65535
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Input Type                          : character
        Text                                : pls check your backend configuration
        Max. Text Size                      : 100
        Word wrap                           : enabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Text tVersion
    Attributes
        ID                                  : 18
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 240
        y coordinate                        : 138
        Width                               : 78
        Height                              : 72
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : flat
        Associated Keyboard                 : none
        Font ID                             : 0
        Back. Color                         : 65535
        Font Color                          : 0
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        Input Type                          : character
        Text                                : 32
        Max. Text Size                      : 10
        Word wrap                           : disabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
Picture p0
    Attributes
        ID                                  : 1
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 0
        y coordinate                        : 0
        Width                               : 319
        Height                              : 479
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Picture ID                          : 0
    
Button bSendStartup
    Attributes
        ID                                  : 17
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 254
        y coordinate                        : 87
        Width                               : 63
        Height                              : 50
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
        Fill                                : solid color
        Style                               : 3D auto
        Font ID                             : 0
        Back. Color                         : 50712
        Back. Picture ID (Pressed)          : 65535
        Back. Color (Pressed)               : 1024
        Font Color (Unpressed)              : 0
        Font Color (Pressed)                : 65535
        Horizontal Alignment                : center
        Vertical Alignment                  : center
        State                               : unpressed
        Text                                : startup
        Max. Text Size                      : 10
        Word wrap                           : disabled
        Horizontal Spacing                  : 0
        Vertical Spacing                    : 0
    
    Events
        Touch Press Event
            recmod=1
            bauds=115200
            // startup event
            tSend.txt="event,startup,"+tVersion.txt+",us-p"
            //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
        
Hotspot mSpinner
    Attributes
        ID                                  : 16
        Scope                               : local
        Dragging                            : 0
        Disable release event after dragging: 0
        Send Component ID                   : disabled
        Opacity                             : 127
        x coordinate                        : 89
        y coordinate                        : 226
        Width                               : 140
        Height                              : 140
        Effect                              : load
        Effect Priority                     : 0
        Effect Time                         : 300
    
    Events
        Touch Press Event
            sys2=sys2+1
            sys2%=10
            //n0.val=sys2
            if(sys2==9)
            {
                page pageTest
            }
        
Timer tmSerial
    Attributes
        ID         : 4
        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=="time")
                                    {
                                        // get set time to global variable
                                        spstr strCommand.txt,pageIcons.vaTime.txt,"~",1
                                    }
                                    if(tInstruction.txt=="date")
                                    {
                                        // get set date to global variable
                                        spstr strCommand.txt,pageIcons.vaDate.txt,"~",1
                                    }
                                    if(tInstruction.txt=="dimmode")
                                    {
                                        // get value
                                        spstr strCommand.txt,tTmp.txt,"~",1
                                        covx tTmp.txt,dimValue,0,0
                                    }
                                    if(tInstruction.txt=="timeout")
                                    {
                                        //set timeout to global var
                                        spstr strCommand.txt,tTmp.txt,"~",1
                                        covx tTmp.txt,sleepTimeout,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
                                        //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=="cardThermo")
                                        {
                                            page cardThermo
                                        }
                                        if(tId.txt=="screensaver")
                                        {
                                            page screensaver
                                        }
                                        if(tId.txt=="popupLight")
                                        {
                                            pageIcons.tTmp1.txt=tTmp.txt
                                            page popupLight
                                        }
                                        if(tId.txt=="cardEntities")
                                        {
                                            page cardEntities
                                        }
                                        if(tId.txt=="pageStartup")
                                        {
                                            page pageStartup
                                        }
                                        if(tId.txt=="popupNotify")
                                        {
                                            page popupNotify
                                        }
                                        if(tId.txt=="cardMedia")
                                        {
                                            page cardMedia
                                        }
                                        if(tId.txt=="cardGrid")
                                        {
                                            page cardGrid
                                        }
                                        if(tId.txt=="cardAlarm")
                                        {
                                            page cardAlarm
                                        }
                                    }
                                    // end of user code
                                    udelete payloadLength-1
                                    bufferPos=0
                                }
                            }
                        }
                    }
                    // next character
                    bufferPos++
                }
            }
        
Timer tmSpinner
    Attributes
        ID         : 9
        Scope      : local
        Period (ms): 80
        Enabled    : yes
    
    Events
        Timer Event
            xpic mSpinner.x,mSpinner.y,spinner_w.val,140,frame_ptr.val,0,11 // draw the current frame
            frame_ptr.val+=spinner_w.val%frapic_w.val // advance the pointer to the next frame in the pic resource and roll over at the end
            doevents // finish drawing before next timer event triggers
            if(frame_ptr.val==1820)
            {
                usual_cnt.val+=1
                sys0=usual_cnt.val%5
                if(sys0==0)
                {
                    // retry sending startup messages by clicking button
                    click bSendStartup,1
                }
            }
            if(usual_cnt.val==10)
            {
                vis tMsg2,1
                vis tMsg3,1
            }
        
