Files
aqhomecontrol/avr/modules/lcd2/gui2/guicntrl.asm
2026-01-12 22:47:08 +01:00

261 lines
5.5 KiB
NASM

; ***************************************************************************
; 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_GUI2_GUICNTRL_ASM
#define AQH_AVR_GUI2_GUICNTRL_ASM
; ***************************************************************************
; defines
; ***************************************************************************
; data
.dseg
guicntl_touch_event:
.byte WIDGET_DATA_TOUCH_SIZE
guicntl_current_app:
.byte 2
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine GuiApp_ShowFirstChild @global
;
; @param Z byte address of guiapp object (for LPM!)
GuiCntrl_ShowFirstApp:
; select first child (GuiApp) as current app
bigcall OBJ_GetFirstChild
mov xl, r18
mov xh, r19
or r18, r19
breq GuiCntrl_ShowFirstApp_ret
rcall GuiCntlr_ShowApp
GuiCntrl_ShowFirstApp_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine GuiCntrl_ShowApp @global
;
; @param Z byte address of object (for LPM!)
; @param X byte address of object to raise (for LPM!)
; @return CFLAG set if signal handled
; @clobbers any, !Z
GuiCntlr_ShowApp:
lds r18, guicntl_current_app
lds r19, guicntl_current_app+1
cp r18, xl
brne GuiCntlr_ShowApp_changed
cp r19, xh
breq GuiCntlr_ShowApp_secRet ; already current app
GuiCntlr_ShowApp_changed:
push zl
push zh
push xl
push xh
; hide previous app
mov zl, r18
mov zh, r19
or r18, r19
breq GuiCntlr_ShowApp_l1
bigcall GuiApp_Hide
GuiCntlr_ShowApp_l1:
pop zh
pop zl
; show new app
mov r16, zl
or r16, zh
breq GuiCntlr_ShowApp_l2
bigcall GuiApp_Show
GuiCntlr_ShowApp_l2:
pop zh
pop zl
GuiCntlr_ShowApp_secRet:
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine GuiCntrl_Every100ms @global
;
; @param Z byte address of guiapp object (for LPM!)
GuiCntrl_Every100ms:
rcall guiCntrlCheckTouch
rcall guiCntrlSendTimer
ret
; @end
; ---------------------------------------------------------------------------
; @routine guiCntrlCheckTouch
;
; @param Z byte address of guiapp object (for LPM!)
guiCntrlCheckTouch:
bigcall Display_InputGetState ; r16=flags, r5:r4=x, r7:r6=y
mov r17, r16
andi r17, (1<<DISPLAY_IFLAGS_CHGCOORD_BIT) | (1<<DISPLAY_IFLAGS_CHGPRESS_BIT)
breq guiCntrlCheckTouch_ret
ldi xl, LOW(guicntl_touch_event)
ldi xh, HIGH(guicntl_touch_event)
st X+, r4 ; X
st X+, r5
st X+, r6 ; Y
st X+, r7
st X, r16 ; flags
sbiw xh:xl, 4 ; (4 times incremented)
push zl
push zh
lds zl, guicntl_current_app
lds zh, guicntl_current_app+1
mov r16, zl
or r16, zh
breq guiCntrlCheckTouch_l1
bigcall GuiApp_Touch
guiCntrlCheckTouch_l1:
pop zh
pop zl
guiCntrlCheckTouch_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine guiCntrlSendTimer
;
; @param Z byte address of guiapp object (for LPM!)
guiCntrlSendTimer:
push zl
push zh
bigcall OBJ_GetFirstChild
guiCntrlSendTimer_loop:
mov zl, r18
mov zh, r19
or r18, r19
breq guiCntrlSendTimer_loopEnd
bigcall GuiApp_Every100ms
bigcall OBJ_GetNext
rjmp guiCntrlSendTimer_loop
guiCntrlSendTimer_loopEnd:
pop zh
pop zl
ret
; @end
; ---------------------------------------------------------------------------
; @routine GuiApp_Init @global
;
; @param Z byte address of guiapp object (for LPM!)
GuiCntrl_Init:
clr r16
sts guicntl_current_app, r16
sts guicntl_current_app+1, r16
ret
; @end
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; signal handlers (to directly be used in signal maps)
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; ---------------------------------------------------------------------------
; @routine GuiCntrl_OnCreate @global
;
; @param Z byte address of object (for LPM!)
; @return CFLAG set if signal handled
; @clobbers any, !Z
GuiCntlr_OnCreate:
rcall GuiCntrl_Init
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine GuiCntrl_OnRaise @global
;
; @param Z byte address of object (for LPM!)
; @param X byte address of object to raise (for LPM!)
; @return CFLAG set if signal handled
; @clobbers any, !Z
GuiCntlr_OnRaise:
lds r18, guicntl_current_app
lds r19, guicntl_current_app+1
cp r18, xl
brne GuiCntlr_OnRaise_changed
cp r19, xh
breq GuiCntlr_OnRaise_secRet ; already current app
GuiCntlr_OnRaise_changed:
push zl
push zh
push xl
push xh
mov zl, r18
mov zh, r19
or r18, r19
breq GuiCntlr_OnRaise_l1
bigcall GuiApp_Hide
GuiCntlr_OnRaise_l1:
pop zh
pop zl
mov r16, zl
or r16, zh
breq GuiCntlr_OnRaise_l2
bigcall GuiApp_Show
GuiCntlr_OnRaise_l2:
pop zh
pop zl
GuiCntlr_OnRaise_secRet:
sec
ret
; @end
#endif