MiLightRemoteConfig.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. return NULL;
  26. }
  27. const MiLightRemoteConfig* MiLightRemoteConfig::fromType(MiLightRemoteType type) {
  28. switch (type) {
  29. case REMOTE_TYPE_RGB:
  30. return &FUT096Config;
  31. case REMOTE_TYPE_CCT:
  32. return &FUT091Config;
  33. case REMOTE_TYPE_RGB_CCT:
  34. return &FUT092Config;
  35. case REMOTE_TYPE_FUT089:
  36. return &FUT089Config;
  37. default:
  38. return NULL;
  39. }
  40. }
  41. const MiLightRemoteConfig* MiLightRemoteConfig::fromReceivedPacket(
  42. const MiLightRadioConfig& radioConfig,
  43. const uint8_t* packet,
  44. const size_t len
  45. ) {
  46. for (size_t i = 0; i < MiLightRemoteConfig::NUM_REMOTES; i++) {
  47. const MiLightRemoteConfig* config = MiLightRemoteConfig::ALL_REMOTES[i];
  48. if (&config->radioConfig == &radioConfig
  49. && config->packetFormatter->canHandle(packet, len)) {
  50. return config;
  51. }
  52. }
  53. return NULL;
  54. }
  55. const MiLightRemoteConfig FUT096Config( //rgbw
  56. new RgbwPacketFormatter(),
  57. MiLightRadioConfig::ALL_CONFIGS[0],
  58. REMOTE_TYPE_RGBW,
  59. "rgbw"
  60. );
  61. const MiLightRemoteConfig FUT091Config( //cct
  62. new CctPacketFormatter(),
  63. MiLightRadioConfig::ALL_CONFIGS[1],
  64. REMOTE_TYPE_CCT,
  65. "cct"
  66. );
  67. const MiLightRemoteConfig FUT092Config( //rgb+cct
  68. new RgbCctPacketFormatter(),
  69. MiLightRadioConfig::ALL_CONFIGS[2],
  70. REMOTE_TYPE_RGB_CCT,
  71. "rgb_cct"
  72. );
  73. const MiLightRemoteConfig FUT089Config( //rgb+cct B8 / FUT089
  74. new FUT089PacketFormatter(),
  75. MiLightRadioConfig::ALL_CONFIGS[2],
  76. REMOTE_TYPE_FUT089,
  77. "fut089"
  78. );
  79. const MiLightRemoteConfig FUT098Config( //rgb
  80. new RgbPacketFormatter(),
  81. MiLightRadioConfig::ALL_CONFIGS[3],
  82. REMOTE_TYPE_RGB,
  83. "rgb"
  84. );