MiLightRemoteConfig.cpp 3.1 KB

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