MiLightUdpServer.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <Arduino.h>
  2. #include <MiLightClient.h>
  3. #include <WiFiUdp.h>
  4. // This protocol is documented here:
  5. // http://www.limitlessled.com/dev/
  6. #define MILIGHT_PACKET_BUFFER_SIZE 10
  7. // Uncomment to enable Serial printing of packets
  8. //#define MILIGHT_UDP_DEBUG
  9. #ifndef _MILIGHT_UDP_SERVER
  10. #define _MILIGHT_UDP_SERVER
  11. enum MiLightUdpCommands {
  12. UDP_CCT_GROUP_1_ON = 0x38,
  13. UDP_CCT_GROUP_1_OFF = 0x3B,
  14. UDP_CCT_GROUP_2_ON = 0x3D,
  15. UDP_CCT_GROUP_2_OFF = 0x33,
  16. UDP_CCT_GROUP_3_ON = 0x37,
  17. UDP_CCT_GROUP_3_OFF = 0x3A,
  18. UDP_CCT_GROUP_4_ON = 0x32,
  19. UDP_CCT_GROUP_4_OFF = 0x36,
  20. UDP_CCT_TEMPERATURE_DOWN = 0x3F,
  21. UDP_CCT_TEMPERATURE_UP = 0x3E,
  22. UDP_CCT_BRIGHTNESS_DOWN = 0x34,
  23. UDP_CCT_BRIGHTNESS_UP = 0x3C,
  24. UDP_RGBW_ALL_ON = 0x41,
  25. UDP_RGBW_ALL_OFF = 0x42,
  26. UDP_RGBW_SPEED_UP = 0x43,
  27. UDP_RGBW_SPEED_DOWN = 0x44,
  28. UDP_RGBW_GROUP_1_ON = 0x45,
  29. UDP_RGBW_GROUP_1_OFF = 0x46,
  30. UDP_RGBW_GROUP_2_ON = 0x47,
  31. UDP_RGBW_GROUP_2_OFF = 0x48,
  32. UDP_RGBW_GROUP_3_ON = 0x49,
  33. UDP_RGBW_GROUP_3_OFF = 0x4A,
  34. UDP_RGBW_GROUP_4_ON = 0x4B,
  35. UDP_RGBW_GROUP_4_OFF = 0x4C,
  36. UDP_RGBW_DISCO_MODE = 0x4D,
  37. UDP_RGBW_GROUP_ALL_WHITE = 0xC2,
  38. UDP_RGBW_GROUP_1_WHITE = 0xC5,
  39. UDP_RGBW_GROUP_2_WHITE = 0xC7,
  40. UDP_RGBW_GROUP_3_WHITE = 0xC9,
  41. UDP_RGBW_GROUP_4_WHITE = 0xCB,
  42. UDP_RGBW_BRIGHTNESS = 0x4E,
  43. UDP_RGBW_COLOR = 0x40
  44. };
  45. class MiLightUdpServer {
  46. public:
  47. MiLightUdpServer(MiLightClient*& client, uint16_t port, uint16_t deviceId);
  48. ~MiLightUdpServer();
  49. void stop();
  50. void begin();
  51. void handleClient();
  52. protected:
  53. WiFiUDP socket;
  54. MiLightClient*& client;
  55. uint16_t port;
  56. uint16_t deviceId;
  57. uint8_t lastGroup;
  58. char packetBuffer[MILIGHT_PACKET_BUFFER_SIZE];
  59. void handleCommand(uint8_t command, uint8_t commandArg);
  60. void pressButton(uint8_t button);
  61. uint8_t cctCommandIdToGroup(uint8_t command);
  62. MiLightStatus cctCommandToStatus(uint8_t command);
  63. };
  64. #endif