MiLightRemoteConfig.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. Serial.println(F("ERROR - tried to fetch remote config for unknown packet"));
  51. return NULL;
  52. }
  53. const MiLightRemoteConfig FUT096Config( //rgbw
  54. new RgbwPacketFormatter(),
  55. MiLightRadioConfig::ALL_CONFIGS[0],
  56. REMOTE_TYPE_RGBW,
  57. "rgbw",
  58. 4
  59. );
  60. const MiLightRemoteConfig FUT091Config( //cct
  61. new CctPacketFormatter(),
  62. MiLightRadioConfig::ALL_CONFIGS[1],
  63. REMOTE_TYPE_CCT,
  64. "cct",
  65. 4
  66. );
  67. const MiLightRemoteConfig FUT092Config( //rgb+cct
  68. new RgbCctPacketFormatter(),
  69. MiLightRadioConfig::ALL_CONFIGS[2],
  70. REMOTE_TYPE_RGB_CCT,
  71. "rgb_cct",
  72. 4
  73. );
  74. const MiLightRemoteConfig FUT089Config( //rgb+cct B8 / FUT089
  75. new FUT089PacketFormatter(),
  76. MiLightRadioConfig::ALL_CONFIGS[2],
  77. REMOTE_TYPE_FUT089,
  78. "fut089",
  79. 8
  80. );
  81. const MiLightRemoteConfig FUT098Config( //rgb
  82. new RgbPacketFormatter(),
  83. MiLightRadioConfig::ALL_CONFIGS[3],
  84. REMOTE_TYPE_RGB,
  85. "rgb",
  86. 0
  87. );