MiLightRemoteConfig.cpp 2.4 KB

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