MiLightRemoteConfig.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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("rgb") || 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. return NULL;
  23. }
  24. const MiLightRemoteConfig* MiLightRemoteConfig::fromType(MiLightRemoteType type) {
  25. switch (type) {
  26. case REMOTE_TYPE_RGB:
  27. return &FUT096Config;
  28. case REMOTE_TYPE_CCT:
  29. return &FUT091Config;
  30. case REMOTE_TYPE_RGB_CCT:
  31. return &FUT092Config;
  32. case REMOTE_TYPE_FUT089:
  33. return &FUT089Config;
  34. default:
  35. return NULL;
  36. }
  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. return NULL;
  51. }