correct packages (length) must be read into memory

This commit is contained in:
Ollo 2023-05-17 21:14:54 +02:00
parent 1993e4818f
commit 7cb172f101
2 changed files with 25 additions and 23 deletions

View File

@ -61,7 +61,7 @@ void receiveUDP() {
Serial.print(", port "); Serial.print(", port ");
Serial.print(Udp.remotePort()); Serial.print(Udp.remotePort());
someOneIsConnected = true; someOneIsConnected = true;
if (packetSize < ((int) PACKET_LENGTH) ) { if (packetSize <= ((int) PACKET_LENGTH) ) {
// read the packet into packetBufffer // read the packet into packetBufffer
Udp.read(packetBuffer, packetSize); Udp.read(packetBuffer, packetSize);
} }
@ -69,36 +69,35 @@ void receiveUDP() {
if (packetSize == PACKET_LENGTH) { if (packetSize == PACKET_LENGTH) {
/* first byte describe the brightness */ /* first byte describe the brightness */
auto brightness = packetBuffer[0]; uint8_t brightness = packetBuffer[0];
//TODO OCR5A = brightness; OCR5A = brightness;
image.clear_pixels(); image.clear_pixels();
int offset = 0; int offset = 0;
/* second byte has the first LEDs*/ /* second byte has the first LEDs*/
for(int i = 1; i < packetSize; i++){ for(int i = 1; i < packetSize; i++){
uint8_t value = packetBuffer[i]; uint8_t value = packetBuffer[i];
uint8_t a = (value & 0x1) ? 1 : 0;
uint8_t a = (value & 0x1) > 0 ? 1 : 0;
image.set_pixel_offset(offset, a); image.set_pixel_offset(offset, a);
offset++; offset++;
uint8_t b = ((value & 0x2) > 0) ? 1 : 0; uint8_t b = (value & 0x2) ? 1 : 0;
image.set_pixel_offset(offset, b); image.set_pixel_offset(offset, b);
offset++; offset++;
uint8_t c = ((value & 0x4) > 0) ? 1 : 0; uint8_t c = (value & 0x4) ? 1 : 0;
image.set_pixel_offset(offset, c); image.set_pixel_offset(offset, c);
offset++; offset++;
uint8_t d = ((value & 0x8) > 0) ? 1 : 0; uint8_t d = (value & 0x8) ? 1 : 0;
image.set_pixel_offset(offset, d); image.set_pixel_offset(offset, d);
offset++; offset++;
uint8_t e = ((value & 0x10) > 0) ? 1 : 0; uint8_t e = (value & 0x10) ? 1 : 0;
image.set_pixel_offset(offset, e); image.set_pixel_offset(offset, e);
offset++; offset++;
uint8_t f = ((value & 0x20) > 0) ? 1 : 0; uint8_t f = (value & 0x20) ? 1 : 0;
image.set_pixel_offset(offset, f); image.set_pixel_offset(offset, f);
offset++; offset++;
uint8_t g = ((value & 0x40) > 0) ? 1 : 0; uint8_t g = (value & 0x40) ? 1 : 0;
image.set_pixel_offset(offset, g); image.set_pixel_offset(offset, g);
offset++; offset++;
uint8_t h = ((value & 0x80) > 0) ? 1 : 0; uint8_t h = (value & 0x80) ? 1 : 0;
image.set_pixel_offset(offset, h); image.set_pixel_offset(offset, h);
offset++; offset++;
} }
@ -120,7 +119,7 @@ void setup() {
//digitalWrite(46,1); //digitalWrite(46,1);
TCCR5A |= (1 << COM5A1);//pwm mode 8 bit TCCR5A |= (1 << COM5A1);//pwm mode 8 bit
OCR5A = 255; OCR5A = 40;
TCCR5B = TCCR5B & B11111000 | B00000001; TCCR5B = TCCR5B & B11111000 | B00000001;
panel1.init(); panel1.init();
@ -128,8 +127,8 @@ void setup() {
panel3.init(); panel3.init();
panel4.init(); panel4.init();
panel5.init(); panel5.init();
Serial.print(F("Activate all LEDs\r\n")); Serial.print(F("Activate first LEDs\r\n"));
for (int x = 0; x < IMAGE_WIDTH; x++) { for (int x = 0; x < PANEL_WIDTH; x++) {
for (int y = 0; y < IMAGE_HEIGHT; y++) { for (int y = 0; y < IMAGE_HEIGHT; y++) {
image.set_pixel(x, y, 1); image.set_pixel(x, y, 1);
} }
@ -155,6 +154,17 @@ void setup() {
delay(1); delay(1);
} }
} }
Serial.print(F("Activate second LED panel\r\n"));
for (int x = PANEL_WIDTH; x < PANEL_WIDTH*2; x++) {
for (int y = 0; y < IMAGE_HEIGHT; y++) {
image.set_pixel(x, y, 1);
}
}
panel1.send_image(&image);
panel2.send_image(&image);
panel3.send_image(&image);
panel4.send_image(&image);
panel5.send_image(&image);
Serial.print(F("My IP address: ")); Serial.print(F("My IP address: "));
Serial.println(Ethernet.localIP()); Serial.println(Ethernet.localIP());

View File

@ -43,14 +43,6 @@ void Image::set_pixel_offset(int offset, byte value) {
Serial.print("\r\n"); Serial.print("\r\n");
return; return;
} }
if (value > 0) {
Serial.print(F("ON : "));
Serial.print(x);
Serial.print("x");
Serial.print(y);
Serial.print("\r\n");
return;
}
data[offset] = value; data[offset] = value;
} }