MiLightRemoteConfig.cpp 2.6 KB

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