V6ComamndHandler.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(),
  9. new V6RgbwCommandHandler(),
  10. new V6RgbCommandHandler(),
  11. new V6CctCommandHandler(),
  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_COMMAND) {
  27. return this->handleCommand(client, deviceId, group, command, commandArg);
  28. } else {
  29. return false;
  30. }
  31. return true;
  32. }
  33. bool V6CommandDemuxer::handleCommand(MiLightClient* client,
  34. uint16_t deviceId,
  35. uint8_t group,
  36. uint8_t commandType,
  37. uint32_t command,
  38. uint32_t commandArg)
  39. {
  40. for (size_t i = 0; i < numHandlers; i++) {
  41. if (((handlers[i]->commandId & command) == handlers[i]->commandId)
  42. && handlers[i]->handleCommand(client, deviceId, group, commandType, command, commandArg)) {
  43. return true;
  44. }
  45. }
  46. return false;
  47. }
  48. bool V6CommandDemuxer::handleCommand(MiLightClient* client,
  49. uint16_t deviceId,
  50. uint8_t group,
  51. uint32_t command,
  52. uint32_t commandArg)
  53. {
  54. return false;
  55. }