MiLightRemoteConfig.cpp 2.6 KB

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