Files
aqhomecontrol/avr/apps/ma_light/recv.asm
Martin Preuss 67be74d2ac avr: move timing control from ma_light to sk6812.
This allows for better control over the LED strip. We can now trigger the
LED strip externally (e.g. by setting a new RGBW value).
2026-03-24 23:13:28 +01:00

148 lines
4.9 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:
ldi zl, LOW(appMotionLightMsgTable*2)
ldi zh, HIGH(appMotionLightMsgTable*2)
rjmp Main_HandleValueMsg
; ---------------------------------------------------------------------------
; @routine appMotionLightHandleReport
;
appMotionLightHandleReport:
rcall appMotionLightIsBrightnessSource ; (R16)
brcs appMotionLightHandleReport_brightness
; motion source?
mov r16, r18
or r16, r19
breq appMotionLightHandleReport_ret ; zero value, ignore
rcall appMotionLightHasSource ; (r16, r24, Y)
brcc appMotionLightHandleReport_ret
; motion detected, check for brightness source
lds r16, appMotionLightLSourceAddr ; do we have a source for brightness value?
tst r16
breq appMotionLightHandleReport_trigger ; no, jmp and don't check brightness
; we have a brightness source configured, do we have a value?
lds r16, appMotionLightFlags ; check last brightness reported
andi r16, APP_MOTIONLIGHT_FLAGS_HAVELIGHT
breq appMotionLightHandleReport_ret ; no brightness, yet
appMotionLightHandleReport_checkBrightness:
lds r16, appMotionLightLSourceValue ; check last brightness reported
lds r17, appMotionLightLSourceValue+1
lds r24, appMotionLightLastBrightness ; r25:r24>r17:r16?
lds r25, appMotionLightLastBrightness+1 ; appMotionLightLastBrightness>appMotionLightLSourceValue?
sub r16, r24
sbc r17, r25
brcs appMotionLightHandleReport_ret ; yes, too bright to turn on
appMotionLightHandleReport_trigger:
bigcall SK6812_Trigger
rjmp appMotionLightHandleReport_ret
; received report is our brightness source
appMotionLightHandleReport_brightness:
sts appMotionLightLastBrightness, r18
sts appMotionLightLastBrightness+1, r19
lds r16, appMotionLightFlags
ori r16, APP_MOTIONLIGHT_FLAGS_HAVELIGHT
sts appMotionLightFlags, r16
appMotionLightHandleReport_ret:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightSetValueOnTime
;
appMotionLightSetValueOnTime:
rcall SK6812_SetAutoTimerReload
rjmp appMotionLightSetValueReturn
; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightSetValueSource1
;
appMotionLightSetValueSource1:
sts appMotionLightSources, r18 ; peerAddr
sts appMotionLightSources+1, r19 ; valueId
rjmp appMotionLightSetValueReturn
; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightSetValueSource2
;
appMotionLightSetValueSource2:
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE, r18 ; peerAddr
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+1, r19 ; valueId
rjmp appMotionLightSetValueReturn
; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightSetValueBValue
;
appMotionLightSetValueBValue:
sts appMotionLightSources, r18 ; peerAddr
sts appMotionLightSources+1, r19 ; valueId
rjmp appMotionLightSetValueReturn
; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightSetValueReturn
;
; Common return code
appMotionLightSetValueReturn:
rcall appMotionLightWriteConfToEeprom
ldi r23, NETMSG_CMD_VALUE_SET_ACK
sec
ret
; @end
appMotionLightMsgTable:
.db NETMSG_CMD_VALUE_REPORT, 0, LOW(appMotionLightHandleReport), HIGH(appMotionLightHandleReport)
.db NETMSG_CMD_VALUE_SET, VALUE_ID_MAL_ONTIME, LOW(appMotionLightSetValueOnTime), HIGH(appMotionLightSetValueOnTime)
.db NETMSG_CMD_VALUE_SET, VALUE_ID_MAL_SOURCE1, LOW(appMotionLightSetValueSource1), HIGH(appMotionLightSetValueSource1)
.db NETMSG_CMD_VALUE_SET, VALUE_ID_MAL_SOURCE2, LOW(appMotionLightSetValueSource2), HIGH(appMotionLightSetValueSource2)
.db NETMSG_CMD_VALUE_SET, VALUE_ID_MAL_BVALUE, LOW(appMotionLightSetValueBValue), HIGH(appMotionLightSetValueBValue)
.db 0, 0, 0, 0