; ***************************************************************************
; 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_APPS_LIGHT_CONTROL_RECV_ASM
#define AQH_AVR_APPS_LIGHT_CONTROL_RECV_ASM


.cseg


; ---------------------------------------------------------------------------
; @routine AppLightControl_OnPacketReceived @global
;
; @clobbers any, -X

AppLightControl_OnPacketReceived:
  ldi zl, LOW(appLightControlObjectFlash*2)
  ldi zh, HIGH(appLightControlObjectFlash*2)
  push zl
    push zh
      lpm yl, Z+
      lpm yh, Z
      ldi zl, LOW(appLightControlMsgTable*2)
      ldi zh, HIGH(appLightControlMsgTable*2)
      bigcall Main_HandleValueMsg
    pop zh
  pop zl
AppLightControl_OnPacketReceived_ret:
  ret
; @end



; ---------------------------------------------------------------------------
; @routine appLightControlSetValue
;
; @clobbers any, -X

appLightControlSetValue:
  std Y+APP_LIGHTCONTROL_RAM_OFFS_VALUE_RED, r18
  std Y+APP_LIGHTCONTROL_RAM_OFFS_VALUE_GREEN, r19
  std Y+APP_LIGHTCONTROL_RAM_OFFS_VALUE_BLUE, r20
  std Y+APP_LIGHTCONTROL_RAM_OFFS_VALUE_WHITE, r21
  bigjmp TCA_SetValueACK
; @end



; ---------------------------------------------------------------------------
; @routine appLightControlSetNumLeds
;
; @clobbers any, -X

appLightControlSetNumLeds:
  std Y+APP_LIGHTCONTROL_RAM_OFFS_LEDCOUNT_LO, r18
  std Y+APP_LIGHTCONTROL_RAM_OFFS_LEDCOUNT_HI, r19
  bigjmp TCA_SetValueACK
; @end




appLightControlMsgTable:
  .db NETMSG_CMD_VALUE_REPORT, 0,                              LOW(TCA_HandleMsg),               HIGH(TCA_HandleMsg)
  .db NETMSG_CMD_VALUE_SET,    VALUE_ID_LIGHTCTRL_GUARDSRC,    LOW(TCA_SetValue_GuardSrc),       HIGH(TCA_SetValue_GuardSrc)
  .db NETMSG_CMD_VALUE_SET,    VALUE_ID_LIGHTCTRL_GUARDLIM,    LOW(TCA_SetValue_GuardLimits),    HIGH(TCA_SetValue_GuardLimits)
  .db NETMSG_CMD_VALUE_SET,    VALUE_ID_LIGHTCTRL_TRIGGER1SRC, LOW(TCA_SetValue_Trigger1Src),    HIGH(TCA_SetValue_Trigger1Src)
  .db NETMSG_CMD_VALUE_SET,    VALUE_ID_LIGHTCTRL_TRIGGER1LIM, LOW(TCA_SetValue_Trigger1Limits), HIGH(TCA_SetValue_Trigger1Limits)
  .db NETMSG_CMD_VALUE_SET,    VALUE_ID_LIGHTCTRL_TRIGGER2SRC, LOW(TCA_SetValue_Trigger2Src),    HIGH(TCA_SetValue_Trigger2Src)
  .db NETMSG_CMD_VALUE_SET,    VALUE_ID_LIGHTCTRL_TRIGGER2LIM, LOW(TCA_SetValue_Trigger2Limits), HIGH(TCA_SetValue_Trigger2Limits)
  .db NETMSG_CMD_VALUE_SET,    VALUE_ID_LIGHTCTRL_HOLDTIME,    LOW(TCA_SetValue_HoldTime),       HIGH(TCA_SetValue_HoldTime)
  .db NETMSG_CMD_VALUE_SET,    VALUE_ID_LIGHTCTRL_MODE,        LOW(TCA_SetValue_Mode),           HIGH(TCA_SetValue_Mode)
  .db NETMSG_CMD_VALUE_SET,    VALUE_ID_LIGHTCTRL_VALUE,       LOW(appLightControlSetValue),     HIGH(appLightControlSetValue)
  .db NETMSG_CMD_VALUE_SET,    VALUE_ID_LIGHTCTRL_NUMLEDS,     LOW(appLightControlSetNumLeds),   HIGH(appLightControlSetNumLeds)
  .db 0, 0, 0, 0





#endif

