avr: implemented motion detector module.
This commit is contained in:
@@ -154,6 +154,10 @@ initModules:
|
|||||||
rcall SK6812_Init
|
rcall SK6812_Init
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_MOTION
|
||||||
|
rcall Motion_Init
|
||||||
|
#endif
|
||||||
|
|
||||||
; done
|
; done
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@@ -203,6 +207,10 @@ runModules_ComEnd:
|
|||||||
rcall Ds18b20_Run
|
rcall Ds18b20_Run
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_MOTION
|
||||||
|
rcall Motion_Run
|
||||||
|
#endif
|
||||||
|
|
||||||
; add more modules here
|
; add more modules here
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|||||||
@@ -7,42 +7,14 @@
|
|||||||
; * Please see toplevel file COPYING of that project for license details. *
|
; * 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
|
.dseg
|
||||||
|
|
||||||
motionDataBegin:
|
motionDataBegin:
|
||||||
motionState: .byte 1
|
motionTimer: .byte 1
|
||||||
motionTimeout: .byte 1
|
|
||||||
motionReportTimeout: .byte 1
|
|
||||||
motionDataEnd:
|
motionDataEnd:
|
||||||
|
|
||||||
|
|
||||||
@@ -50,12 +22,77 @@ motionDataEnd:
|
|||||||
.cseg
|
.cseg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Motion_Init:
|
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_Fini:
|
||||||
Motion_Run:
|
cbi MOTION_DDR, MOTION_PIN ; set DATA port as input
|
||||||
Motion_Every100ms:
|
cbi MOTION_OUTPUT, MOTION_PIN ; disable internal pullup for TXD
|
||||||
ret
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user