V6CommandHandler.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <MiLightClient.h>
  2. #include <MiLightRadioConfig.h>
  3. #ifndef _V6_COMMAND_HANDLER_H
  4. #define _V6_COMMAND_HANDLER_H
  5. enum V6CommandTypes {
  6. V6_PAIR = 0x3D,
  7. V6_UNPAIR = 0x3E,
  8. V6_PRESET = 0x3F,
  9. V6_COMMAND = 0x31
  10. };
  11. class V6CommandHandler {
  12. public:
  13. static V6CommandHandler* ALL_HANDLERS[];
  14. static const size_t NUM_HANDLERS;
  15. V6CommandHandler(uint16_t commandId, const MiLightRemoteConfig& remoteConfig)
  16. : commandId(commandId),
  17. remoteConfig(remoteConfig)
  18. { }
  19. virtual bool handleCommand(
  20. MiLightClient* client,
  21. uint16_t deviceId,
  22. uint8_t group,
  23. uint8_t commandType,
  24. uint32_t command,
  25. uint32_t commandArg
  26. );
  27. const uint16_t commandId;
  28. const MiLightRemoteConfig& remoteConfig;
  29. protected:
  30. virtual bool handleCommand(
  31. MiLightClient* client,
  32. uint32_t command,
  33. uint32_t commandArg
  34. ) = 0;
  35. virtual bool handlePreset(
  36. MiLightClient* client,
  37. uint8_t commandLsb,
  38. uint32_t commandArg
  39. ) = 0;
  40. };
  41. class V6CommandDemuxer : public V6CommandHandler {
  42. public:
  43. V6CommandDemuxer(V6CommandHandler* handlers[], size_t numHandlers)
  44. : V6CommandHandler(0, FUT096Config),
  45. handlers(handlers),
  46. numHandlers(numHandlers)
  47. { }
  48. virtual bool handleCommand(
  49. MiLightClient* client,
  50. uint16_t deviceId,
  51. uint8_t group,
  52. uint8_t commandType,
  53. uint32_t command,
  54. uint32_t commandArg
  55. );
  56. protected:
  57. V6CommandHandler** handlers;
  58. size_t numHandlers;
  59. virtual bool handleCommand(
  60. MiLightClient* client,
  61. uint32_t command,
  62. uint32_t commandArg
  63. );
  64. virtual bool handlePreset(
  65. MiLightClient* client,
  66. uint8_t commandLsb,
  67. uint32_t commandArg
  68. );
  69. };
  70. #endif