MiLightUdpServer.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <Arduino.h>
  2. #include <MiLightClient.h>
  3. #include <WiFiUdp.h>
  4. #define MILIGHT_PACKET_BUFFER_SIZE 10
  5. #ifndef _MILIGHT_UDP_SERVER
  6. #define _MILIGHT_UDP_SERVER
  7. // These are mostly a remapping of MiLightButton
  8. enum MiLightUdpCommands {
  9. UDP_ALL_ON = 0x41,
  10. UDP_ALL_OFF = 0x42,
  11. UDP_SPEED_UP = 0x43,
  12. UDP_SPEED_DOWN = 0x44,
  13. UDP_GROUP_1_ON = 0x45,
  14. UDP_GROUP_1_OFF = 0x46,
  15. UDP_GROUP_2_ON = 0x47,
  16. UDP_GROUP_2_OFF = 0x48,
  17. UDP_GROUP_3_ON = 0x49,
  18. UDP_GROUP_3_OFF = 0x4A,
  19. UDP_GROUP_4_ON = 0x4B,
  20. UDP_GROUP_4_OFF = 0x4C,
  21. UDP_DISCO_MODE = 0x4D,
  22. UDP_GROUP_ALL_WHITE = 0xC2,
  23. UDP_GROUP_1_WHITE = 0xC5,
  24. UDP_GROUP_2_WHITE = 0xC7,
  25. UDP_GROUP_3_WHITE = 0xC9,
  26. UDP_GROUP_4_WHITE = 0xCB,
  27. UDP_BRIGHTNESS = 0x4E,
  28. UDP_COLOR = 0x40
  29. };
  30. class MiLightUdpServer {
  31. public:
  32. MiLightUdpServer(MiLightClient*& client, uint16_t port, uint16_t deviceId);
  33. ~MiLightUdpServer();
  34. void stop();
  35. void begin();
  36. void handleClient();
  37. protected:
  38. WiFiUDP socket;
  39. MiLightClient*& client;
  40. uint16_t port;
  41. uint16_t deviceId;
  42. uint8_t lastGroup;
  43. char packetBuffer[MILIGHT_PACKET_BUFFER_SIZE];
  44. void handleCommand(uint8_t command, uint8_t commandArg);
  45. void pressButton(uint8_t group, MiLightButton button);
  46. };
  47. #endif