MiLightUdpServer.h 2.0 KB

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