Files
aqhomecontrol/avr/modules/motion/main.asm
2024-10-31 22:23:28 +01:00

99 lines
2.0 KiB
NASM

; ***************************************************************************
; copyright : (C) 2024 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
.equ MOTION_TIMER_REPORT = 20 ; report motion at most every 2s
.dseg
motionDataBegin:
motionTimer: .byte 1
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:
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