MiLightRemoteConfig.cpp 2.8 KB

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