V6RgbwCommandHandler.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 & 0x7F;
  24. const uint8_t arg = commandArg >> 24;
  25. client->setHeld((command & 0x80) == 0x80);
  26. if (cmd == V2_RGBW_COMMAND_PREFIX) {
  27. switch (arg) {
  28. case V2_RGBW_ON:
  29. client->updateStatus(ON);
  30. break;
  31. case V2_RGBW_OFF:
  32. client->updateStatus(OFF);
  33. break;
  34. case V2_RGBW_WHITE_ON:
  35. client->updateColorWhite();
  36. break;
  37. case V2_RGBW_NIGHT_LIGHT:
  38. client->updateColorWhite();
  39. client->updateBrightness(0);
  40. break;
  41. case V2_RGBW_SPEED_DOWN:
  42. client->modeSpeedDown();
  43. break;
  44. case V2_RGBW_SPEED_UP:
  45. client->modeSpeedUp();
  46. break;
  47. default:
  48. return false;
  49. }
  50. return true;
  51. } else if (cmd == V2_RGBW_COLOR_PREFIX) {
  52. client->updateColorRaw(arg);
  53. return true;
  54. } else if (cmd == V2_RGBW_BRIGHTNESS_PREFIX) {
  55. client->updateBrightness(arg);
  56. return true;
  57. } else if (cmd == V2_RGBW_MODE_PREFIX) {
  58. client->updateMode(arg);
  59. return true;
  60. }
  61. return false;
  62. }