104 lines
4.0 KiB
NASM
104 lines
4.0 KiB
NASM
; ***************************************************************************
|
|
; copyright : (C) 2025 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. *
|
|
; ***************************************************************************
|
|
|
|
|
|
; ***************************************************************************
|
|
; code
|
|
|
|
.cseg
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine AppMotionLight_OnPacketReceived @global
|
|
;
|
|
; @clobbers any, -X
|
|
|
|
AppMotionLight_OnPacketReceived:
|
|
adiw xh:xl, 2 ; command
|
|
ld r16, X
|
|
sbiw xh:xl, 2
|
|
cpi r16, NETMSG_CMD_VALUE_SET
|
|
breq AppMotionLight_OnPacketReceived_set
|
|
cpi r16, NETMSG_CMD_VALUE_REPORT
|
|
breq AppMotionLight_OnPacketReceived_report
|
|
clc ; unexpected msg
|
|
ret
|
|
; "report value" message
|
|
AppMotionLight_OnPacketReceived_report:
|
|
rcall NETMSG_ValueRead ; (none)
|
|
mov r16, r18
|
|
or r16, r19
|
|
breq AppMotionLight_OnPacketReceived_clcRet ; zero value, ignore
|
|
rcall appMotionLightHasSource ; (r16, r24, Y)
|
|
brcs AppMotionLight_OnPacketReceived_turnOn
|
|
ret
|
|
AppMotionLight_OnPacketReceived_turnOn:
|
|
lds r16, appMotionLightTimer
|
|
lds r17, appMotionLightTimer+1
|
|
or r16, r17
|
|
brne AppMotionLight_OnPacketReceived_startTimer
|
|
rcall appMotionLightTurnOn ; (r16, r17, r18, r19, r20, r21, r23)
|
|
AppMotionLight_OnPacketReceived_startTimer:
|
|
rcall appMotionLightStartTimer
|
|
sec
|
|
ret
|
|
|
|
; "set value" message
|
|
AppMotionLight_OnPacketReceived_set:
|
|
rcall NETMSG_ValueRead ; (none)
|
|
cpi r17, VALUE_ID_MAL_RGBW_VALUE
|
|
breq AppMotionLight_OnPacketReceived_setRGBW
|
|
cpi r17, VALUE_ID_MAL_ONTIME
|
|
breq AppMotionLight_OnPacketReceived_setOnTime
|
|
cpi r17, VALUE_ID_MAL_SOURCE1
|
|
breq AppMotionLight_OnPacketReceived_setSource1
|
|
cpi r17, VALUE_ID_MAL_SOURCE2
|
|
breq AppMotionLight_OnPacketReceived_setSource2
|
|
AppMotionLight_OnPacketReceived_clcRet:
|
|
clc ; unexpected message
|
|
ret
|
|
AppMotionLight_OnPacketReceived_setRGBW: ; "setValue nodes/XXXXXXXX/MALRGBWVALUE GRWB"
|
|
sts appMotionLightColor, r18
|
|
sts appMotionLightColor+1, r19
|
|
sts appMotionLightColor+2, r20
|
|
sts appMotionLightColor+3, r21
|
|
push r24
|
|
push r25
|
|
rcall appMotionLightStartTimer ; immediately ON with new color (r16)
|
|
rcall appMotionLightTurnOn ; (r16, r17, r18, r19, r20, r21, r23)
|
|
pop r25
|
|
pop r24
|
|
rjmp AppMotionLight_OnPacketReceived_sendAck
|
|
AppMotionLight_OnPacketReceived_setOnTime: ; "setValue nodes/XXXXXXXX/MALONTIME n" (n in 1/10 secs)
|
|
sts appMotionLightOnTime, r18
|
|
sts appMotionLightOnTime+1, r19
|
|
rjmp AppMotionLight_OnPacketReceived_sendAck
|
|
AppMotionLight_OnPacketReceived_setSource1: ; setValue "nodes/XXXXXXXX/MALSOURCE1 0xVVNN" (VV=value id, NN=node addr)
|
|
sts appMotionLightSources, r18 ; peerAddr
|
|
sts appMotionLightSources+1, r19 ; valueId
|
|
rjmp AppMotionLight_OnPacketReceived_sendAck
|
|
AppMotionLight_OnPacketReceived_setSource2: ; setValue "nodes/XXXXXXXX/MALSOURCE2 0xVVNN" (VV=value id, NN=node addr)
|
|
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE, r18 ; peerAddr
|
|
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+1, r19 ; valueId
|
|
AppMotionLight_OnPacketReceived_sendAck:
|
|
push xl
|
|
push xh
|
|
ldi r23, NETMSG_CMD_VALUE_SET_ACK
|
|
rcall Main_SendValueResponse ; (clobbers all, including Y)
|
|
rcall appMotionLightWriteConfToEeprom ; (r16, r17, X)
|
|
pop xh
|
|
pop xl
|
|
sec
|
|
ret
|
|
; @end
|
|
|
|
|
|
|