318 lines
8.9 KiB
NASM
318 lines
8.9 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_SENSORWATCH_ASM
|
|
#define AQH_AVR_GUI2_SENSORWATCH_ASM
|
|
|
|
|
|
; ***************************************************************************
|
|
; defines
|
|
|
|
.equ SENSORWATCH_OFFS_BEGIN = VLAYOUT_SIZE
|
|
.equ SENSORWATCH_OFFS_BASEVALUEID = SENSORWATCH_OFFS_BEGIN+0
|
|
.equ SENSORWATCH_OFFS_EEPROMID = SENSORWATCH_OFFS_BEGIN+1
|
|
.equ SENSORWATCH_OFFS_NODEADDR = SENSORWATCH_OFFS_BEGIN+2
|
|
.equ SENSORWATCH_OFFS_VALUEID = SENSORWATCH_OFFS_BEGIN+3
|
|
.equ SENSORWATCH_OFFS_UPPER_LIMIT_WARN_LO = SENSORWATCH_OFFS_BEGIN+4
|
|
.equ SENSORWATCH_OFFS_UPPER_LIMIT_WARN_HI = SENSORWATCH_OFFS_BEGIN+5
|
|
.equ SENSORWATCH_OFFS_LOWER_LIMIT_WARN_LO = SENSORWATCH_OFFS_BEGIN+6
|
|
.equ SENSORWATCH_OFFS_LOWER_LIMIT_WARN_HI = SENSORWATCH_OFFS_BEGIN+7
|
|
.equ SENSORWATCH_OFFS_UPPER_LIMIT_CRIT_LO = SENSORWATCH_OFFS_BEGIN+8
|
|
.equ SENSORWATCH_OFFS_UPPER_LIMIT_CRIT_HI = SENSORWATCH_OFFS_BEGIN+9
|
|
.equ SENSORWATCH_OFFS_LOWER_LIMIT_CRIT_LO = SENSORWATCH_OFFS_BEGIN+10
|
|
.equ SENSORWATCH_OFFS_LOWER_LIMIT_CRIT_HI = SENSORWATCH_OFFS_BEGIN+11
|
|
.equ SENSORWATCH_OFFS_VALUE_LO = SENSORWATCH_OFFS_BEGIN+12
|
|
.equ SENSORWATCH_OFFS_VALUE_HI = SENSORWATCH_OFFS_BEGIN+13
|
|
.equ SENSORWATCH_OFFS_TYPE = SENSORWATCH_OFFS_BEGIN+14
|
|
.equ SENSORWATCH_SIZE = SENSORWATCH_OFFS_BEGIN+15
|
|
|
|
|
|
.equ SENSORWATCH_VALUE = WIDGET_VALUE_NEXTFREE+0
|
|
.equ SENSORWATCH_VALUE_NEXTFREE = SENSORWATCH_VALUE+1
|
|
|
|
|
|
.equ SENSORWATCH_TYPE_CO2 = 1
|
|
.equ SENSORWATCH_TYPE_TEMP = 2
|
|
.equ SENSORWATCH_TYPE_HUM = 3
|
|
.equ SENSORWATCH_TYPE_NEXTFREE = 4
|
|
|
|
|
|
; descriptors
|
|
.equ SENSORWATCH_DESCR_OFFS_TITLERES = 0
|
|
.equ SENSORWATCH_DESCR_OFFS_IMGRES = 2
|
|
.equ SENSORWATCH_DESCR_OFFS_POSTKOMMADIGITS = 4
|
|
|
|
|
|
|
|
; ***************************************************************************
|
|
; code
|
|
|
|
.cseg
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine SensorWatch_new @global
|
|
;
|
|
; @return CFLAG set of okay, cleared otherwise
|
|
; @return Y address of newly created object
|
|
; @param X parent widget
|
|
; @param r16 value for OBJECT_OFFS_OPTS
|
|
; @param r17 value for WIDGET_OFFS_PACK
|
|
; @param r20 base value id
|
|
; @param r21 eeprom id
|
|
; @param r22 type (see @ref SENSORWATCH_TYPE_CO2)
|
|
; @clobbers any
|
|
|
|
SensorWatch_new:
|
|
push r20
|
|
push r21
|
|
push r22
|
|
ldi r24, LOW(SENSORWATCH_SIZE)
|
|
ldi r25, HIGH(SENSORWATCH_SIZE)
|
|
bigcall Object_Alloc ; (!r16, !r17, !X)
|
|
pop r22
|
|
pop r21
|
|
pop r20
|
|
brcc SensorWatch_new_ret
|
|
rcall SensorWatch_Init ; (r16, r17, X)
|
|
sec
|
|
SensorWatch_new_ret:
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine SensorWatch_Init @global
|
|
;
|
|
; @param Y address of widget
|
|
; @param X parent widget (if any)
|
|
; @param r16 value for OBJECT_OFFS_OPTS
|
|
; @param r17 value for WIDGET_OFFS_PACK
|
|
; @param r20 base value id
|
|
; @param r21 eeprom id
|
|
; @param r22 type (see @ref SENSORWATCH_TYPE_CO2)
|
|
; @clobbers r16, r17, X
|
|
|
|
SensorWatch_Init:
|
|
push r20
|
|
push r21
|
|
push r22
|
|
; call base class
|
|
ldi r20, VLAYOUT_MODE_EXPAND
|
|
bigcall VLayout_Init
|
|
pop r22
|
|
pop r21
|
|
pop r20
|
|
|
|
; setup valueLabel data
|
|
std Y+SENSORWATCH_OFFS_BASEVALUEID, r20
|
|
std Y+SENSORWATCH_OFFS_EEPROMID, r21
|
|
std Y+SENSORWATCH_OFFS_TYPE, r22
|
|
|
|
; set default signal map
|
|
ldi r16, LOW(SensorWatch_DefaultSignalmap*2)
|
|
std Y+OBJECT_OFFS_SIGNALMAP_LO, r16
|
|
ldi r16, HIGH(SensorWatch_DefaultSignalmap*2)
|
|
std Y+OBJECT_OFFS_SIGNALMAP_HI, r16
|
|
|
|
; create sub windows
|
|
rcall sensorWatchCreateTitleLabel
|
|
rcall sensorWatchCreateImageViewer
|
|
rcall sensorWatchCreateValueLabel
|
|
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine sensorWatchGetTitleResId
|
|
;
|
|
; @param r16 sensor type (see @ref SENSORWATCH_TYPE_CO2)
|
|
; @return r21:r20 ressource for sensor title
|
|
|
|
sensorWatchGetTitleResId:
|
|
rcall sensorWatchGetDescriptor ; (r17, r18, r19)
|
|
adiw zh:zl, SENSORWATCH_DESCR_OFFS_TITLERES
|
|
lpm r20, Z+
|
|
lpm r21, Z
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine sensorWatchGetImgResId
|
|
;
|
|
; @param r16 sensor type (see @ref SENSORWATCH_TYPE_CO2)
|
|
; @return r21:r20 ressource for sensor title
|
|
|
|
sensorWatchGetImgResId:
|
|
rcall sensorWatchGetDescriptor ; (r17, r18, r19)
|
|
adiw zh:zl, SENSORWATCH_DESCR_OFFS_IMGRES
|
|
lpm r20, Z+
|
|
lpm r21, Z
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine sensorWatchGetPostKommaDigits
|
|
;
|
|
; @param r16 sensor type (see @ref SENSORWATCH_TYPE_CO2)
|
|
; @return r20 postkomma digits
|
|
|
|
sensorWatchGetPostKommaDigits:
|
|
rcall sensorWatchGetDescriptor ; (r17, r18, r19)
|
|
adiw zh:zl, SENSORWATCH_DESCR_OFFS_POSTKOMMADIGITS
|
|
lpm r20, Z
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine sensorWatchGetDescriptor
|
|
;
|
|
; @param r16 sensor type (see @ref SENSORWATCH_TYPE_CO2)
|
|
; @return Z byte address of start of descriptor for sensor type (for LPM!)
|
|
; @clobbers r17, r18, r19
|
|
|
|
sensorWatchGetDescriptor:
|
|
cpi r16, SENSORWATCH_TYPE_NEXTFREE
|
|
brcs sensorWatchGetDescriptor_get
|
|
clr r16 ; default to entry 0
|
|
sensorWatchGetDescriptor_get:
|
|
ldi zl, LOW(SensorWatch_Descriptors*2)
|
|
ldi zh, HIGH(SensorWatch_Descriptors*2)
|
|
clr r17
|
|
mov r18, r16
|
|
mov r19, r17
|
|
lsl r18 ; *2
|
|
rol r19
|
|
add r18, r16 ; *3
|
|
adc r19, r17
|
|
lsl r18 ; *6
|
|
rol r19
|
|
add zl, r18
|
|
adc zh, r19
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine sensorWatchCreateTitleLabel
|
|
;
|
|
; @param Y address of main window widget
|
|
; @param r21:r20 ressource id for title
|
|
; @return CFLAG set of okay, cleared otherwise
|
|
|
|
sensorWatchCreateTitleLabel:
|
|
push yl
|
|
push yh
|
|
ldd r16, Y+SENSORWATCH_OFFS_TYPE
|
|
rcall sensorWatchGetTitleResId ; r21:r20=ressource id for title
|
|
mov xl, yl
|
|
mov xh, yh
|
|
ldi r16, 0
|
|
ldi r17, (WIDGET_PACK_CENTER<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_BEGIN<<WIDGET_PACK_VSELF0_BIT) | \
|
|
(WIDGET_PACK_CENTER<<WIDGET_PACK_HCONTENT0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VCONTENT0_BIT)
|
|
bigcall Label_new
|
|
pop yh
|
|
pop yl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine sensorWatchCreateImageViewer
|
|
;
|
|
; @param Y address of main window widget
|
|
; @param r21:r20 ressource id for image
|
|
; @return CFLAG set of okay, cleared otherwise
|
|
|
|
sensorWatchCreateImageViewer:
|
|
push yl
|
|
push yh
|
|
ldd r16, Y+SENSORWATCH_OFFS_TYPE
|
|
rcall sensorWatchGetImgResId ; r21:r20=ressource id for image
|
|
mov xl, yl
|
|
mov xh, yh
|
|
ldi r16, 0
|
|
ldi r17, (WIDGET_PACK_CENTER<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_BEGIN<<WIDGET_PACK_VSELF0_BIT) | \
|
|
(WIDGET_PACK_CENTER <<WIDGET_PACK_HCONTENT0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VCONTENT0_BIT)
|
|
bigcall ImageView_new
|
|
pop yh
|
|
pop yl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine sensorWatchCreateValueLabel
|
|
;
|
|
; @param Y address of main window widget
|
|
; @return CFLAG set of okay, cleared otherwise
|
|
|
|
sensorWatchCreateValueLabel:
|
|
push yl
|
|
push yh
|
|
ldd r16, Y+SENSORWATCH_OFFS_TYPE
|
|
rcall sensorWatchGetPostKommaDigits ; r20=postkomma digits
|
|
mov xl, yl
|
|
mov xh, yh
|
|
ldi r16, 0
|
|
ldi r17, (WIDGET_PACK_CENTER<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_BEGIN<<WIDGET_PACK_VSELF0_BIT) | \
|
|
(WIDGET_PACK_CENTER <<WIDGET_PACK_HCONTENT0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VCONTENT0_BIT)
|
|
bigcall ValueLabel_new
|
|
pop yh
|
|
pop yl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; ***************************************************************************
|
|
; data in FLASH
|
|
|
|
SensorWatch_DefaultSignalmap:
|
|
; header
|
|
.dw VLayout_DefaultSignalmap*2 ; next table to use
|
|
; entries
|
|
.db 0, WIDGET_SIGNAL_DRAW, LOW(Widget_OnDraw), HIGH(Widget_OnDraw)
|
|
.db 0, 0, 0, 0 ; end of table
|
|
|
|
|
|
|
|
SensorWatch_Descriptors:
|
|
; res for title res for image post-komma digits
|
|
.dw RESSSOURCE_TXT_UNKNOWN_S, RESSSOURCE_IMG_CLOUD96, 0 ; unknown
|
|
.dw RESSSOURCE_TXT_CO2_S, RESSSOURCE_IMG_CLOUD96, 0 ; co2
|
|
.dw RESSSOURCE_TXT_TEMP_S, RESSSOURCE_IMG_TEMP96, 2 ; temp
|
|
.dw RESSSOURCE_TXT_HUM_S, RESSSOURCE_IMG_HUMIDITY96, 0 ; hum
|
|
|
|
|
|
#endif
|
|
|