MiLightUdpServer.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. void begin();
  34. void handleClient();
  35. protected:
  36. WiFiUDP socket;
  37. MiLightClient*& client;
  38. uint16_t port;
  39. uint16_t deviceId;
  40. uint8_t lastGroup;
  41. char packetBuffer[MILIGHT_PACKET_BUFFER_SIZE];
  42. void handleCommand(uint8_t command, uint8_t commandArg);
  43. void pressButton(uint8_t group, MiLightButton button);
  44. };
  45. #endif