; ***************************************************************************
; 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.   *
; ***************************************************************************



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

SK6812_OnPacketReceived:
  adiw xh:xl, NETMSG_OFFS_CMD               ; command
  ld r16, X
  sbiw xh:xl, NETMSG_OFFS_CMD
  cpi r16, NETMSG_CMD_VALUE_SET
  breq SK6812_OnPacketReceived_set
  clc                                       ; unexpected msg
  ret
SK6812_OnPacketReceived_set:
  rcall NETMSG_ValueRead                    ; (none)
  cpi r17, VALUE_ID_LED_RGBW_VALUE
  breq SK6812_OnPacketReceived_setRGBW
  cpi r17, VALUE_ID_LED_NUMLEDS
  breq SK6812_OnPacketReceived_setNumLeds
  cpi r17, VALUE_ID_LED_STATE
  breq SK6812_OnPacketReceived_setState
  cpi r17, VALUE_ID_LED_MODE
  breq SK6812_OnPacketReceived_setMode
  clc
  ret
SK6812_OnPacketReceived_setRGBW:
  push r17
    push r24
      push r25
        rcall SK6812_SetRGBW                      ; value is in R18-R21 (R16, R17, X)
      pop r25
    pop r24
  pop r17
  rjmp SK6812_OnPacketReceived_sendAck
SK6812_OnPacketReceived_setState:
  push r17
    push r24
      push r25
        rcall SK6812_SetState                     ; value is in R18 (r16, r17, r18, r19, r20, r21, r23, r24, r25)
      pop r25
    pop r24
  pop r17
  rjmp SK6812_OnPacketReceived_sendAck
SK6812_OnPacketReceived_setMode:
  push r17
    push r24
      push r25
        rcall SK6812_SetMode                      ; value is in R18 (r16, r17, r18, r19, r20, r21, r23, r24, r25)
      pop r25
    pop r24
  pop r17
  rjmp SK6812_OnPacketReceived_sendAck
SK6812_OnPacketReceived_setNumLeds:
  sts sk6812NumLeds, r18
SK6812_OnPacketReceived_sendAck:
  push xl
    push xh
      ldi r23, NETMSG_CMD_VALUE_SET_ACK
      rcall Main_SendValueResponse
    pop xh
  pop xl
  sec
  ret
; @end


