; ***************************************************************************
; copyright   : (C) 2026 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.   *
; ***************************************************************************

#ifndef AQH_AVR_MODULES_MULTIFAN_RECV_ASM
#define AQH_AVR_MODULES_MULTIFAN_RECV_ASM


; ---------------------------------------------------------------------------
; @routine MultiFan_OnPacketReceived @global
;
; @clobbers any, !X

MultiFan_OnPacketReceived:
  ldi zl, LOW(multiFanMsgTable*2)
  ldi zh, HIGH(multiFanMsgTable*2)
  rjmp Main_HandleValueMsg
; @end



multiFanSetValueFan1Duty:                   ; value is in R18-R21 (R16, R17, X)
  mov r16, r18
  rcall MultiFan_SetFan1Duty
  rjmp multiFanSetValueACK
; @end



.if MULTIFAN_FANS > 1
multiFanSetValueFan2Duty:                   ; value is in R18-R21 (R16, R17, X)
  mov r16, r18
  rcall MultiFan_SetFan2Duty
  rjmp multiFanSetValueACK
; @end
.endif



.if MULTIFAN_FANS > 2
multiFanSetValueFan3Duty:                   ; value is in R18-R21 (R16, R17, X)
  mov r16, r18
  rcall MultiFan_SetFan3Duty
  rjmp multiFanSetValueACK
; @end
.endif




multiFanSetValueACK:
  ldi r23, NETMSG_CMD_VALUE_SET_ACK
  sec
  ret
; @end



multiFanSetValueNACK:
  ldi r23, NETMSG_CMD_VALUE_SET_NACK
  sec
  ret
; @end




multiFanMsgTable:
  .db NETMSG_CMD_VALUE_SET, VALUE_ID_FAN1_DUTY, LOW(multiFanSetValueFan1Duty), HIGH(multiFanSetValueFan1Duty)
.if MULTIFAN_FANS > 1
  .db NETMSG_CMD_VALUE_SET, VALUE_ID_FAN2_DUTY, LOW(multiFanSetValueFan2Duty), HIGH(multiFanSetValueFan2Duty)
.endif
.if MULTIFAN_FANS > 2
  .db NETMSG_CMD_VALUE_SET, VALUE_ID_FAN3_DUTY, LOW(multiFanSetValueFan3Duty), HIGH(multiFanSetValueFan3Duty)
.endif
  .db 0, 0, 0, 0



#endif

