V6RgbwCommandHandler.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <V6RgbwCommandHandler.h>
  2. bool V6RgbwCommandHandler::handlePreset(
  3. MiLightClient* client,
  4. uint8_t commandLsb,
  5. uint32_t commandArg)
  6. {
  7. if (commandLsb == 0) {
  8. client->updateColorRaw(commandArg >> 24);
  9. client->updateBrightness(commandArg >> 16);
  10. } else if (commandLsb == 1) {
  11. client->updateColorWhite();
  12. client->updateBrightness(commandArg >> 16);
  13. } else {
  14. return false;
  15. }
  16. return true;
  17. }
  18. bool V6RgbwCommandHandler::handleCommand(
  19. MiLightClient* client,
  20. uint32_t command,
  21. uint32_t commandArg)
  22. {
  23. const uint8_t cmd = command & 0xFF;
  24. const uint8_t arg = commandArg >> 24;
  25. if (cmd == V2_RGBW_COMMAND_PREFIX) {
  26. switch (arg) {
  27. case V2_RGBW_ON:
  28. client->updateStatus(ON);
  29. break;
  30. case V2_RGBW_OFF:
  31. client->updateStatus(OFF);
  32. break;
  33. case V2_RGBW_WHITE_ON:
  34. client->updateColorWhite();
  35. break;
  36. case V2_RGBW_NIGHT_LIGHT:
  37. client->updateColorWhite();
  38. client->updateBrightness(0);
  39. break;
  40. case V2_RGBW_SPEED_DOWN:
  41. client->modeSpeedDown();
  42. break;
  43. case V2_RGBW_SPEED_UP:
  44. client->modeSpeedUp();
  45. break;
  46. default:
  47. return false;
  48. }
  49. return true;
  50. } else if (cmd == V2_RGBW_COLOR_PREFIX) {
  51. client->updateColorRaw(arg);
  52. return true;
  53. } else if (cmd == V2_RGBW_BRIGHTNESS_PREFIX) {
  54. client->updateBrightness(arg);
  55. return true;
  56. } else if (cmd == V2_RGBW_MODE_PREFIX) {
  57. client->updateMode(arg);
  58. return true;
  59. }
  60. return false;
  61. }