; ***************************************************************************
; copyright   : (C) 2026 by Martin Preuss
; email       : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome".                              *
; * Please see toplevel file COPYING of that project for license details.   *
; ***************************************************************************

#ifndef AQH_AVR_DEVICE_C03_APP_ASM
#define AQH_AVR_DEVICE_C03_APP_ASM


; ***************************************************************************
; defines


.equ APPC03_SEL_BUTTON_CLIMATE = 1
.equ APPC03_SEL_BUTTON_NETWORK = 2



; ***************************************************************************
; data

.dseg

appC03_ramdata:
  .byte GUIAPP_SD_SIZE


testRootWin_ramdata:
  .byte WIDGET_SD_SIZE



; ***************************************************************************
; code

.cseg



appC03:
  ; OBJECT
  .db 0x55, 0xaa               ; magic
  .dw 0                        ; next
  .dw 0                        ; parent
  .dw 0                        ; first child
  .dw 0                        ; target
  .dw 0                        ; selector (ony lower 8 bits used)
  .dw appC03_signalmap*2      ; signal map
  ; GUIAPP
  .dw appC03_ramdata          ; SDRAM data
  .dw winRoot*2  ; root widget

appC03_signalmap:
  .db 0,                         OBJECT_SIGNAL_TIMER,   LOW(GuiApp_OnTimer),          HIGH(GuiApp_OnTimer)
  .db 0,                         WIDGET_SIGNAL_TOUCH,   LOW(GuiApp_OnTouch),          HIGH(GuiApp_OnTouch)
  .db 0,                         OBJECT_SIGNAL_RECVMSG, LOW(GuiApp_OnMsgReceived),    HIGH(GuiApp_OnMsgReceived)
  .db 0,                         OBJECT_SIGNAL_CREATE,  LOW(GuiApp_OnCreate),         HIGH(GuiApp_OnCreate)
  .db APPC03_SEL_BUTTON_NETWORK, WIDGET_SIGNAL_CLICKED, LOW(AppC03_OnClickedNetwork), HIGH(AppC03_OnClickedNetwork)
  .db APPC03_SEL_BUTTON_CLIMATE, WIDGET_SIGNAL_CLICKED, LOW(AppC03_OnClickedClimate), HIGH(AppC03_OnClickedClimate)
  .db 0, 0, 0, 0           ; end of table



winRoot:
  ; OBJECT
  .db 0x55, 0xaa                ; magic
  .dw 0                         ; next
  .dw 0                         ; parent
  .dw winClimate*2              ; first child
  .dw appC03*2       ; target
  .dw 0                         ; selector (ony lower 8 bits used)
  .dw testRootWin_signalmap*2   ; signal map
  ; WIDGET
  .db 0, 0                      ; opts lo, hi
  .dw 0                         ; X
  .dw 0                         ; Y
  .dw DISPLAY_WIDTH             ; W
  .dw DISPLAY_HEIGHT            ; H
  .dw STYLE_WIN_FOREGROUND      ; front color
  .dw STYLE_WIN_BACKGROUND      ; back color
  .dw STYLE_WIN_FONT*2          ; font
  .dw testRootWin_ramdata       ; ptr to SDRAM
  ; ROOTWIDGET
  .dw appC03*2                  ; GuiApp

testRootWin_signalmap:
  .db 0, OBJECT_SIGNAL_CREATE, LOW(Widget_OnCreate),  HIGH(Widget_OnCreate)
  .db 0, WIDGET_SIGNAL_DRAW,   LOW(Widget_OnDrawNop), HIGH(Widget_OnDrawNop)
  .db 0, 0, 0, 0  ; end of table





AppC03_OnClickedNetwork:
  ldi xl, LOW(winNetwork*2)
  ldi xh, HIGH(winNetwork*2)
  bigcall GuiApp_ShowView
  sec
  ret



AppC03_OnClickedClimate:
  ldi xl, LOW(winClimate*2)
  ldi xh, HIGH(winClimate*2)
  bigcall GuiApp_ShowView
  sec
  ret




#endif


