avr: implemented motion detector module.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user