avr: optimized app MA_LIGHT (from 3295 to 3222 words).
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
; ***************************************************************************
|
||||
; copyright : (C) 2025 by Martin Preuss
|
||||
; copyright : (C) 2026 by Martin Preuss
|
||||
; email : martin@libchipcard.de
|
||||
;
|
||||
; ***************************************************************************
|
||||
@@ -30,33 +30,43 @@ AppMotionLight_OnPacketReceived:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightHandleReport
|
||||
;
|
||||
; @param R17 value id
|
||||
; @param R19:R18 value
|
||||
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100)
|
||||
; @param R22 source address
|
||||
; @param R23 command
|
||||
; @param R25:R24 message id
|
||||
|
||||
appMotionLightHandleReport:
|
||||
rcall appMotionLightIsBrightnessSource ; (R16)
|
||||
; is brightness source?
|
||||
rcall appMotionLightIsBrightnessSource ; (R16, Y)
|
||||
brcs appMotionLightHandleReport_brightness
|
||||
; motion source?
|
||||
; is motion source?
|
||||
rcall appMotionLightHasSource ; (r16, r24, Y)
|
||||
brcc appMotionLightHandleReport_ret
|
||||
; motion detected?
|
||||
mov r16, r18
|
||||
or r16, r19
|
||||
breq appMotionLightHandleReport_ret ; zero value, ignore
|
||||
rcall appMotionLightHasSource ; (r16, r24, Y)
|
||||
brcc appMotionLightHandleReport_ret
|
||||
breq appMotionLightHandleReport_ret ; zero value, ignore
|
||||
|
||||
; motion detected, check for brightness source
|
||||
lds r16, appMotionLightLSourceAddr ; do we have a source for brightness value?
|
||||
lds r16, (appMotionLightLSource+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR) ; do we have a source for brightness value?
|
||||
tst r16
|
||||
breq appMotionLightHandleReport_trigger ; no, jmp and don't check brightness
|
||||
breq appMotionLightHandleReport_trigger ; no, jmp and don't check brightness
|
||||
cpi r16, 0xff
|
||||
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
|
||||
lds r16, appMotionLightFlags ; check last brightness reported
|
||||
andi r16, APP_MOTIONLIGHT_FLAGS_HAVELIGHT
|
||||
breq appMotionLightHandleReport_ret ; no brightness, yet
|
||||
breq appMotionLightHandleReport_ret ; no brightness, yet
|
||||
appMotionLightHandleReport_checkBrightness:
|
||||
lds r16, appMotionLightLSourceValue ; check last brightness reported
|
||||
lds r16, appMotionLightLSourceValue ; check last brightness reported
|
||||
lds r17, appMotionLightLSourceValue+1
|
||||
lds r24, appMotionLightLastBrightness ; r25:r24>r17:r16?
|
||||
lds r25, appMotionLightLastBrightness+1 ; appMotionLightLastBrightness>appMotionLightLSourceValue?
|
||||
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
|
||||
brcs appMotionLightHandleReport_ret ; yes, too bright to turn on
|
||||
appMotionLightHandleReport_trigger:
|
||||
bigcall SK6812_Trigger
|
||||
rjmp appMotionLightHandleReport_ret
|
||||
@@ -68,7 +78,7 @@ appMotionLightHandleReport_brightness:
|
||||
ori r16, APP_MOTIONLIGHT_FLAGS_HAVELIGHT
|
||||
sts appMotionLightFlags, r16
|
||||
appMotionLightHandleReport_ret:
|
||||
clc
|
||||
clc ; don't send ACK
|
||||
ret
|
||||
; @end
|
||||
|
||||
@@ -77,20 +87,35 @@ appMotionLightHandleReport_ret:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightSetValueOnTime
|
||||
;
|
||||
; @param R17 value id
|
||||
; @param R19:R18 value
|
||||
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100)
|
||||
; @param R22 source address
|
||||
; @param R23 command
|
||||
; @param R25:R24 message id
|
||||
|
||||
appMotionLightSetValueOnTime:
|
||||
sts appMotionLightOnTime, r18
|
||||
sts appMotionLightOnTime+1, r19
|
||||
rcall SK6812_SetAutoTimerReload
|
||||
rjmp appMotionLightSetValueReturn
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightSetValueSource1
|
||||
;
|
||||
; @param R17 value id
|
||||
; @param R19:R18 value
|
||||
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100)
|
||||
; @param R22 source address
|
||||
; @param R23 command
|
||||
; @param R25:R24 message id
|
||||
|
||||
appMotionLightSetValueSource1:
|
||||
sts appMotionLightSources, r18 ; peerAddr
|
||||
sts appMotionLightSources+1, r19 ; valueId
|
||||
sts (appMotionLightMSources+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR), r18 ; peerAddr
|
||||
sts (appMotionLightMSources+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID), r19 ; valueId
|
||||
rjmp appMotionLightSetValueReturn
|
||||
; @end
|
||||
|
||||
@@ -99,10 +124,16 @@ appMotionLightSetValueSource1:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightSetValueSource2
|
||||
;
|
||||
; @param R17 value id
|
||||
; @param R19:R18 value
|
||||
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100)
|
||||
; @param R22 source address
|
||||
; @param R23 command
|
||||
; @param R25:R24 message id
|
||||
|
||||
appMotionLightSetValueSource2:
|
||||
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE, r18 ; peerAddr
|
||||
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+1, r19 ; valueId
|
||||
sts (appMotionLightMSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR), r18 ; peerAddr
|
||||
sts (appMotionLightMSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID), r19 ; valueId
|
||||
rjmp appMotionLightSetValueReturn
|
||||
; @end
|
||||
|
||||
@@ -111,10 +142,16 @@ appMotionLightSetValueSource2:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightSetValueBValue
|
||||
;
|
||||
; @param R17 value id
|
||||
; @param R19:R18 value
|
||||
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100)
|
||||
; @param R22 source address
|
||||
; @param R23 command
|
||||
; @param R25:R24 message id
|
||||
|
||||
appMotionLightSetValueBValue:
|
||||
sts appMotionLightSources, r18 ; peerAddr
|
||||
sts appMotionLightSources+1, r19 ; valueId
|
||||
sts (appMotionLightMSources+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR), r18 ; peerAddr
|
||||
sts (appMotionLightMSources+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID), r19 ; valueId
|
||||
rjmp appMotionLightSetValueReturn
|
||||
; @end
|
||||
|
||||
@@ -126,7 +163,7 @@ appMotionLightSetValueBValue:
|
||||
; Common return code
|
||||
|
||||
appMotionLightSetValueReturn:
|
||||
rcall appMotionLightWriteConfToEeprom
|
||||
rcall appMotionLightWriteConfToEeprom ; (r16, r17, X, Y)
|
||||
ldi r23, NETMSG_CMD_VALUE_SET_ACK
|
||||
sec
|
||||
ret
|
||||
|
||||
Reference in New Issue
Block a user