MiLightRemoteConfig.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include <MiLightRemoteConfig.h>
  2. #include <MiLightRemoteType.h>
  3. /**
  4. * IMPORTANT NOTE: These should be in the same order as MiLightRemoteType.
  5. */
  6. const MiLightRemoteConfig* MiLightRemoteConfig::ALL_REMOTES[] = {
  7. &FUT096Config, // rgbw
  8. &FUT007Config, // cct
  9. &FUT092Config, // rgb+cct
  10. &FUT098Config, // rgb
  11. &FUT089Config, // 8-group rgb+cct (b8, fut089)
  12. &FUT091Config,
  13. &FUT020Config
  14. };
  15. const size_t MiLightRemoteConfig::NUM_REMOTES = size(ALL_REMOTES);
  16. const MiLightRemoteConfig* MiLightRemoteConfig::fromType(const String& type) {
  17. return fromType(MiLightRemoteTypeHelpers::remoteTypeFromString(type));
  18. }
  19. const MiLightRemoteConfig* MiLightRemoteConfig::fromType(MiLightRemoteType type) {
  20. if (type == REMOTE_TYPE_UNKNOWN || type >= size(ALL_REMOTES)) {
  21. Serial.print(F("MiLightRemoteConfig::fromType: ERROR - tried to fetch remote config for unknown type: "));
  22. Serial.println(type);
  23. return NULL;
  24. }
  25. return ALL_REMOTES[type];
  26. }
  27. const MiLightRemoteConfig* MiLightRemoteConfig::fromReceivedPacket(
  28. const MiLightRadioConfig& radioConfig,
  29. const uint8_t* packet,
  30. const size_t len
  31. ) {
  32. for (size_t i = 0; i < MiLightRemoteConfig::NUM_REMOTES; i++) {
  33. const MiLightRemoteConfig* config = MiLightRemoteConfig::ALL_REMOTES[i];
  34. if (&config->radioConfig == &radioConfig
  35. && config->packetFormatter->canHandle(packet, len)) {
  36. return config;
  37. }
  38. }
  39. // This can happen under normal circumstances, so not an error condition
  40. #ifdef DEBUG_PRINTF
  41. Serial.println(F("MiLightRemoteConfig::fromReceivedPacket: ERROR - tried to fetch remote config for unknown packet"));
  42. #endif
  43. return NULL;
  44. }
  45. const MiLightRemoteConfig FUT096Config( //rgbw
  46. new RgbwPacketFormatter(),
  47. MiLightRadioConfig::ALL_CONFIGS[0],
  48. REMOTE_TYPE_RGBW,
  49. "rgbw",
  50. 4
  51. );
  52. const MiLightRemoteConfig FUT007Config( //cct
  53. new CctPacketFormatter(),
  54. MiLightRadioConfig::ALL_CONFIGS[1],
  55. REMOTE_TYPE_CCT,
  56. "cct",
  57. 4
  58. );
  59. const MiLightRemoteConfig FUT091Config( //v2 cct
  60. new FUT091PacketFormatter(),
  61. MiLightRadioConfig::ALL_CONFIGS[2],
  62. REMOTE_TYPE_FUT091,
  63. "fut091",
  64. 4
  65. );
  66. const MiLightRemoteConfig FUT092Config( //rgb+cct
  67. new RgbCctPacketFormatter(),
  68. MiLightRadioConfig::ALL_CONFIGS[2],
  69. REMOTE_TYPE_RGB_CCT,
  70. "rgb_cct",
  71. 4
  72. );
  73. const MiLightRemoteConfig FUT089Config( //rgb+cct B8 / FUT089
  74. new FUT089PacketFormatter(),
  75. MiLightRadioConfig::ALL_CONFIGS[2],
  76. REMOTE_TYPE_FUT089,
  77. "fut089",
  78. 8
  79. );
  80. const MiLightRemoteConfig FUT098Config( //rgb
  81. new RgbPacketFormatter(),
  82. MiLightRadioConfig::ALL_CONFIGS[3],
  83. REMOTE_TYPE_RGB,
  84. "rgb",
  85. 0
  86. );
  87. const MiLightRemoteConfig FUT020Config(
  88. new FUT020PacketFormatter(),
  89. MiLightRadioConfig::ALL_CONFIGS[4],
  90. REMOTE_TYPE_FUT020,
  91. "fut020",
  92. 0
  93. );