motion: repeat messages.
This commit is contained in:
@@ -8,13 +8,17 @@
|
|||||||
; ***************************************************************************
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
.equ MOTION_TIMER_REPORT = 50 ; report motion at most every 5s
|
.equ MOTION_SEND_1_AFTER = 1 ; send motion message after 100ms
|
||||||
|
.equ MOTION_SEND_2_AFTER = 11 ; send motion message after 1100ms
|
||||||
|
.equ MOTION_SEND_3_AFTER = 50 ; repeat motion message after 5s
|
||||||
|
.equ MOTION_RESTART_AFTER = 150 ; restart motion report counter after 15s
|
||||||
|
|
||||||
|
|
||||||
.dseg
|
.dseg
|
||||||
|
|
||||||
motionDataBegin:
|
motionDataBegin:
|
||||||
motionTimer: .byte 1
|
motionCurrentState: .byte 1
|
||||||
|
motionStateCounter: .byte 1
|
||||||
motionDataEnd:
|
motionDataEnd:
|
||||||
|
|
||||||
|
|
||||||
@@ -53,25 +57,42 @@ Motion_Run:
|
|||||||
|
|
||||||
|
|
||||||
Motion_Every100ms:
|
Motion_Every100ms:
|
||||||
sbis MOTION_INPUT, MOTION_PIN
|
clr r16
|
||||||
rjmp Motion_Every100ms_skipReport
|
sbic MOTION_INPUT, MOTION_PIN
|
||||||
; pin high
|
inc r16
|
||||||
lds r16, motionTimer
|
; check against stored state
|
||||||
tst r16
|
lds r17, motionCurrentState
|
||||||
brne Motion_Every100ms_skipReport
|
cp r16, r17
|
||||||
; timer was 0
|
brne Motion_Every100ms_stateChanged
|
||||||
ldi r18, 1
|
; state not changed
|
||||||
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
|
tst r16
|
||||||
breq Motion_Every100ms_end
|
breq Motion_Every100ms_end
|
||||||
dec r16
|
; state unchanged, active motion
|
||||||
sts motionTimer, r16
|
lds r16, motionStateCounter
|
||||||
|
inc r16
|
||||||
|
sts motionStateCounter, r16
|
||||||
|
cpi r16, MOTION_SEND_1_AFTER
|
||||||
|
breq Motion_Every100ms_send
|
||||||
|
cpi r16, MOTION_SEND_2_AFTER
|
||||||
|
breq Motion_Every100ms_send
|
||||||
|
; cpi r16, MOTION_SEND_3_AFTER
|
||||||
|
; breq Motion_Every100ms_send
|
||||||
|
cpi r16, MOTION_RESTART_AFTER
|
||||||
|
brne Motion_Every100ms_end
|
||||||
|
clr r16
|
||||||
|
sts motionStateCounter, r16 ; restart motion state counter (thus report again on motion)
|
||||||
|
ret
|
||||||
|
Motion_Every100ms_stateChanged:
|
||||||
|
sts motionCurrentState, r16
|
||||||
|
clr r16
|
||||||
|
sts motionStateCounter, r16
|
||||||
|
ret ; only send according to timers above
|
||||||
|
Motion_Every100ms_send:
|
||||||
|
lds r18, motionCurrentState
|
||||||
|
; only send if state is != 0
|
||||||
|
tst r18
|
||||||
|
breq Motion_Every100ms_end
|
||||||
|
rjmp Motion_SendReport
|
||||||
Motion_Every100ms_end:
|
Motion_Every100ms_end:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user