avr: implemented motion detector module.

This commit is contained in:
Martin Preuss
2024-10-28 23:44:34 +01:00
parent d28e20b179
commit 8904d33789
2 changed files with 77 additions and 32 deletions

View File

@@ -154,6 +154,10 @@ initModules:
rcall SK6812_Init
#endif
#ifdef MODULES_MOTION
rcall Motion_Init
#endif
; done
ret
@@ -203,6 +207,10 @@ runModules_ComEnd:
rcall Ds18b20_Run
#endif
#ifdef MODULES_MOTION
rcall Motion_Run
#endif
; add more modules here
ret

View File

@@ -7,42 +7,14 @@
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; - check motion
; - motion detected?
; - yes:
; - set motion HW bit
; - reset motion timeout counter
; - SW bit set?
; - no:
; - report motion
; - reset motionReportTimeout (use lower value to repeat motion message once)
; - set motion SW bit
; - yes
; - dec motionReportTimeout
; - 0?
; - report current SW state
; - reset motionReportTimeout (use higher value since motion should already be known)
; - no:
; - clear motion hw bit
; - dec motionTimeout
; - 0?
; - yes:
; - clear SW motion bit
; - report no motion
.equ MOTION_STATE_MOTION_HW_BIT = 0
.equ MOTION_STATE_MOTION_SW_BIT = 1
.equ MOTION_TIMER_REPORT = 30 ; report motion at most every 3s
.dseg
motionDataBegin:
motionState: .byte 1
motionTimeout: .byte 1
motionReportTimeout: .byte 1
motionTimer: .byte 1
motionDataEnd:
@@ -50,12 +22,77 @@ motionDataEnd:
.cseg
Motion_Init:
; preset SRAM data area
ldi xh, HIGH(motionDataBegin)
ldi xl, LOW(motionDataBegin)
clr r16
ldi r17, (motionDataEnd-motionDataBegin)
rcall Utils_FillSram
; setup pins
cbi MOTION_DDR, MOTION_PIN ; set DATA port as input
cbi MOTION_OUTPUT, MOTION_PIN ; disable internal pullup for TXD
sec
ret
Motion_Fini:
Motion_Run:
Motion_Every100ms:
cbi MOTION_DDR, MOTION_PIN ; set DATA port as input
cbi MOTION_OUTPUT, MOTION_PIN ; disable internal pullup for TXD
ret
Motion_Run:
clc
ret
Motion_Every100ms:
sbis MOTION_INPUT, MOTION_PIN
rjmp Motion_Every100ms_skipReport
; pin high
lds r16, motionTimer
tst r16
brne Motion_Every100ms_skipReport
; timer was 0
ldi r18, 1
rcall Motion_SendReport
brcc Motion_Every100ms_end
ldi r16, MOTION_TIMER_REPORT ; reset report timer
sts motionTimer, r16
Motion_Every100ms_skipReport:
lds r16, motionTimer
tst r16
breq Motion_Every100ms_end
dec r16
sts motionTimer, r16
Motion_Every100ms_end:
ret
; @param R18 sensor value
Motion_SendReport:
ldi r16, 0xff ; destination address
ldi r17, VALUE_ID_MOTION ; value id
ldi r22, AQHOME_VALUETYPE_MOTION
clr r19
ldi r20, 1 ; denominator
clr r21
ldi xl, LOW(com2SendBuffer)
ldi xh, HIGH(com2SendBuffer)
rcall CPRO_WriteReportValue
rjmp COM2_SendPacket