V6ComamndHandler.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <V6CommandHandler.h>
  2. #include <V6RgbCctCommandHandler.h>
  3. #include <V6RgbwCommandHandler.h>
  4. #include <V6RgbCommandHandler.h>
  5. #include <V6CctCommandHandler.h>
  6. #include <Size.h>
  7. V6CommandHandler* V6CommandHandler::ALL_HANDLERS[] = {
  8. new V6RgbCctCommandHandler() PROGMEM,
  9. new V6RgbwCommandHandler() PROGMEM,
  10. new V6RgbCommandHandler() PROGMEM,
  11. new V6CctCommandHandler() PROGMEM,
  12. };
  13. const size_t V6CommandHandler::NUM_HANDLERS = size(ALL_HANDLERS);
  14. bool V6CommandHandler::handleCommand(MiLightClient* client,
  15. uint16_t deviceId,
  16. uint8_t group,
  17. uint8_t commandType,
  18. uint32_t command,
  19. uint32_t commandArg)
  20. {
  21. client->prepare(radioConfig, deviceId, group);
  22. if (commandType == V6_PAIR) {
  23. client->pair();
  24. } else if (commandType == V6_UNPAIR) {
  25. client->unpair();
  26. } else if (commandType == V6_PRESET) {
  27. return this->handlePreset(client, command, commandArg);
  28. } else if (commandType == V6_COMMAND) {
  29. return this->handleCommand(client, command, commandArg);
  30. } else {
  31. return false;
  32. }
  33. return true;
  34. }
  35. bool V6CommandDemuxer::handleCommand(MiLightClient* client,
  36. uint16_t deviceId,
  37. uint8_t group,
  38. uint8_t commandType,
  39. uint32_t command,
  40. uint32_t commandArg)
  41. {
  42. for (size_t i = 0; i < numHandlers; i++) {
  43. if (((handlers[i]->commandId & command) == handlers[i]->commandId)
  44. && handlers[i]->handleCommand(client, deviceId, group, commandType, command, commandArg)) {
  45. return true;
  46. }
  47. }
  48. return false;
  49. }
  50. bool V6CommandDemuxer::handleCommand(MiLightClient* client,
  51. uint32_t commandLsb,
  52. uint32_t commandArg)
  53. {
  54. return false;
  55. }
  56. bool V6CommandDemuxer::handlePreset(MiLightClient* client,
  57. uint8_t commandLsb,
  58. uint32_t commandArg)
  59. {
  60. return false;
  61. }