V6RgbCctCommandHandler.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <V6RgbCctCommandHandler.h>
  2. bool V6RgbCctCommandHandler::handleCommand(
  3. MiLightClient* client,
  4. uint16_t deviceId,
  5. uint8_t group,
  6. uint32_t command,
  7. uint32_t commandArg)
  8. {
  9. const uint8_t cmd = command & 0xFF;
  10. const uint8_t arg = commandArg >> 24;
  11. client->prepare(MilightRgbCctConfig, deviceId, group);
  12. if (cmd == V2_STATUS) {
  13. switch (arg) {
  14. case V2_RGB_CCT_ON:
  15. case V2_RGB_CCT_OFF:
  16. client->updateStatus(arg == V2_RGB_CCT_ON ? ON : OFF);
  17. break;
  18. case V2_RGB_NIGHT_MODE:
  19. client->updateBrightness(0);
  20. break;
  21. case V2_RGB_CCT_SPEED_DOWN:
  22. client->modeSpeedDown();
  23. break;
  24. case V2_RGB_CCT_SPEED_UP:
  25. client->modeSpeedUp();
  26. break;
  27. default:
  28. return false;
  29. }
  30. return true;
  31. }
  32. switch (cmd) {
  33. case V2_COLOR:
  34. handleUpdateColor(client, commandArg);
  35. break;
  36. case V2_KELVIN:
  37. client->updateTemperature(100 - arg);
  38. break;
  39. case V2_BRIGHTNESS:
  40. client->updateBrightness(arg);
  41. break;
  42. case V2_SATURATION:
  43. client->updateSaturation(100 - arg);
  44. break;
  45. case V2_MODE:
  46. client->updateMode(arg-1);
  47. break;
  48. default:
  49. return false;
  50. }
  51. return true;
  52. }
  53. /*
  54. * Arguments are 32 bits. Most commands use the first byte, but color arguments
  55. * can use all four. Triggered in app when quickly transitioning through colors.
  56. */
  57. void V6RgbCctCommandHandler::handleUpdateColor(MiLightClient *client, uint32_t color) {
  58. for (int i = 3; i >= 0; i--) {
  59. const uint8_t argValue = (color >> (i*8)) & 0xFF;
  60. if (argValue == 0) {
  61. return;
  62. }
  63. client->updateColorRaw(argValue);
  64. }
  65. }