PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.6KB

  1. /*The MIT License (MIT)
  2. Copyright (c) 2014 Nathanaël Lécaudé
  3. https://github.com/natcl/Artnet, http://forum.pjrc.com/threads/24688-Artnet-to-OctoWS2811
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #ifndef ARTNET_H
  21. #define ARTNET_H
  22. #include <Arduino.h>
  23. #if defined(ARDUINO_SAMD_ZERO)
  24. #include <WiFi101.h>
  25. #include <WiFiUdp.h>
  26. #else
  27. #include <Ethernet.h>
  28. #include <EthernetUdp.h>
  29. #endif
  30. // UDP specific
  31. #define ART_NET_PORT 6454
  32. // Opcodes
  33. #define ART_POLL 0x2000
  34. #define ART_DMX 0x5000
  35. // Buffers
  36. #define MAX_BUFFER_ARTNET 530
  37. // Packet
  38. #define ART_NET_ID "Art-Net\0"
  39. #define ART_DMX_START 18
  40. class Artnet
  41. {
  42. public:
  43. Artnet();
  44. void begin(byte mac[], byte ip[]);
  45. void begin();
  46. uint16_t read();
  47. void printPacketHeader();
  48. void printPacketContent();
  49. // Return a pointer to the start of the DMX data
  50. inline uint8_t* getDmxFrame(void)
  51. {
  52. return artnetPacket + ART_DMX_START;
  53. }
  54. inline uint16_t getOpcode(void)
  55. {
  56. return opcode;
  57. }
  58. inline uint8_t getSequence(void)
  59. {
  60. return sequence;
  61. }
  62. inline uint16_t getUniverse(void)
  63. {
  64. return incomingUniverse;
  65. }
  66. inline uint16_t getLength(void)
  67. {
  68. return dmxDataLength;
  69. }
  70. inline void setArtDmxCallback(void (*fptr)(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data))
  71. {
  72. artDmxCallback = fptr;
  73. }
  74. private:
  75. #if defined(ARDUINO_SAMD_ZERO)
  76. WiFiUDP Udp;
  77. #else
  78. EthernetUDP Udp;
  79. #endif
  80. uint8_t artnetPacket[MAX_BUFFER_ARTNET];
  81. uint16_t packetSize;
  82. uint16_t opcode;
  83. uint8_t sequence;
  84. uint16_t incomingUniverse;
  85. uint16_t dmxDataLength;
  86. void (*artDmxCallback)(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data);
  87. };
  88. #endif