Last active
December 11, 2023 14:50
-
-
Save drvkmr/6ade8bcb5b8476f05910dea27ecd88f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <matrix.h> | |
#include <ESPAsyncE131.h> | |
uint8_t wsRawData[VPANEL_W * VPANEL_H * 3]; | |
class E131 { | |
private: | |
// With 512 channels per universe, you need 24 universes to send all the data | |
const uint8_t NUM_UNIVERSES = 24; | |
const uint16_t CHANNELS_PER_UNIVERSE = 512; | |
ESPAsyncE131 _e131; | |
uint8_t colorToSet[3]; | |
void onNewPacketReceived(void* packet, protocol_t protocol, void* userInfo) { | |
if (protocol == PROTOCOL_E131) { | |
e131_packet_t* e131Packet = reinterpret_cast<e131_packet_t*>(packet); | |
uint16_t offset = (htons(e131Packet->universe) - 1) * CHANNELS_PER_UNIVERSE; | |
memcpy(wsRawData+offset, e131Packet->property_values + 1, CHANNELS_PER_UNIVERSE); // +1 to skip the start code | |
lastPacketReceived = millis(); | |
} | |
} | |
public: | |
E131() { | |
// Register the member function callback | |
_e131.registerCallback([this](void* packet, protocol_t protocol, void* userInfo) { | |
this->onNewPacketReceived(packet, protocol, userInfo); | |
}); | |
} | |
void begin() { // Listen via Unicast | |
if (_e131.begin(E131_MULTICAST, 1, NUM_UNIVERSES, PROTOCOL_E131)) { | |
Serial.println(F("Listening for data...")); | |
} else { | |
Serial.println(F("*** e131.begin failed ***")); | |
} | |
} | |
// Call from the main loop depending on the frame-rate you want to achieve. | |
void show() { | |
int k = 0; | |
for (int i = posY; i < sizeY + posY; i++) { | |
for (int j = posX; j < sizeX + posX; j++) { | |
if (sprite[k] != 0 || sprite[k + 1] != 0 || sprite[k + 2] != 0) { | |
virtualDisp->drawPixelRGB888(j, i, sprite[k], sprite[k + 1], sprite[k + 2]); | |
} | |
k += 3; | |
} | |
} | |
// only needed for double-buffer | |
virtualDisp->flipDMABuffer(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment