Skip to content

Commit

Permalink
finished new debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner committed Jan 17, 2024
1 parent b98ba56 commit 65add33
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 59 deletions.
8 changes: 8 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ build_flags =
-DMINIZ_NO_ARCHIVE_APIS=1
-DMINIZ_NO_ARCHIVE_WRITING_APIS=1
-DMINIZ_NO_ZLIB_COMPATIBLE_NAMES=1
-Os
build_unflags = -Og

[env:256x64]
framework = arduino
Expand All @@ -51,6 +53,8 @@ build_flags =
-DMINIZ_NO_ARCHIVE_APIS=1
-DMINIZ_NO_ARCHIVE_WRITING_APIS=1
-DMINIZ_NO_ZLIB_COMPATIBLE_NAMES=1
-Os
build_unflags = -Og

[env:128x32_wifi]
framework = arduino
Expand All @@ -72,6 +76,8 @@ build_flags =
-DMINIZ_NO_ARCHIVE_APIS=1
-DMINIZ_NO_ARCHIVE_WRITING_APIS=1
-DMINIZ_NO_ZLIB_COMPATIBLE_NAMES=1
-Os
build_unflags = -Og

[env:256x64_wifi]
framework = arduino
Expand All @@ -94,3 +100,5 @@ build_flags =
-DMINIZ_NO_ARCHIVE_APIS=1
-DMINIZ_NO_ARCHIVE_WRITING_APIS=1
-DMINIZ_NO_ZLIB_COMPATIBLE_NAMES=1
-Os
build_unflags = -Og
104 changes: 45 additions & 59 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ const uint8_t ordreRGB[3 * 6] = {0, 1, 2, 2, 0, 1, 1, 2, 0,
0, 2, 1, 1, 0, 2, 2, 1, 0};
uint8_t acordreRGB = 0;
bool debugMode = false;
// WTF removing this dummy variable kills the debug mode
bool debugWTF = false;
uint8_t c4;
int16_t transferBufferSize = 0;
int16_t receivedBytes = 0;
Expand Down Expand Up @@ -270,6 +272,29 @@ void DisplayLum(void) {
TOTAL_HEIGHT - 5, 255, 255, 255);
}

void DisplayDebugInfo(void) {
// WTF not comparing against true kills the debug mode
if (debugMode == true) {
DisplayText("Frames:", 0, 0, 255, 255, 255);
DisplayNumber(frameCount, 5, 7 * 4, 0, 0, 255, 0);
DisplayText("Transfer Buffer:", 0, 6, 255, 255, 255);
DisplayNumber(transferBufferSize, 5, 16 * 4, 6, 255, 255, 255);
DisplayText("Received Bytes: ", 0, 2 * 6, 255, 255, 255);
DisplayNumber(receivedBytes, 5, 16 * 4, 2 * 6, 255, 255, 255);
DisplayText("Miniz Status:", 0, 3 * 6, 255, 255, 255);
DisplayNumber(minizStatus, 6, 13 * 4, 3 * 6, 255, 255, 255);
DisplayText("Errors:", 0, 4 * 6, 255, 255, 255);
DisplayNumber(errorCount, 5, 7 * 4, 4 * 6, 255, 0, 0);

DisplayNumber(RomWidth, 3, TOTAL_WIDTH - 6 * 4, 0, 255, 255, 255);
DisplayText("x", TOTAL_WIDTH - 3 * 4, 0, 255, 255, 255);
DisplayNumber(RomHeight, 2, TOTAL_WIDTH - 2 * 4, 0, 255, 255, 255);
DisplayNumber(flowControlCounter, 2, TOTAL_WIDTH - 5 * 4, TOTAL_HEIGHT - 6,
0, 0, 255);
DisplayNumber(c4, 2, TOTAL_WIDTH - 2 * 4, TOTAL_HEIGHT - 6, 255, 255, 255);
}
}

void ClearScreen() {
dma_display->clearScreen();
dma_display->setBrightness8(lumval[lumstep]);
Expand Down Expand Up @@ -866,10 +891,9 @@ void setup() {
if (minizStatus != MZ_OK ||
uncompressedBufferSize !=
(ZONE_SIZE * numZones + numZones)) {
if (debugMode) {
DisplayText("Miniz Status:", 0, 3 * 6, 255, 255, 255);
DisplayNumber(minizStatus, 6, 13 * 4, 3 * 6, 255, 255, 255);
}

DisplayDebugInfo();

return;
}
} else {
Expand Down Expand Up @@ -910,10 +934,7 @@ bool SerialReadBuffer(uint8_t *pBuffer, uint16_t BufferSize,
transferBuffer = pBuffer;
}

if (debugMode) {
DisplayText("Transfer Buffer:", 0, 6, 255, 255, 255);
DisplayNumber(transferBufferSize, 5, 16 * 4, 6, 255, 255, 255);
}
DisplayDebugInfo();

// We always receive chunks of "serialTransferChunkSize" bytes (maximum).
// At this point, the control chars and the one byte command have been read
Expand All @@ -927,17 +948,11 @@ bool SerialReadBuffer(uint8_t *pBuffer, uint16_t BufferSize,
transferBuffer + transferBufferSize - remainingBytes,
(remainingBytes > chunkSize) ? chunkSize : remainingBytes);

if (debugMode) {
DisplayText("Received Bytes: ", 0, 2 * 6, 255, 255, 255);
DisplayNumber(receivedBytes, 5, 16 * 4, 2 * 6, 255, 255, 255);
}
DisplayDebugInfo();

if (receivedBytes != remainingBytes && receivedBytes != chunkSize) {
errorCount++;
if (debugMode) {
DisplayText("Errors:", 0, 4 * 6, 255, 255, 255);
DisplayNumber(errorCount, 5, 7 * 4, 4 * 6, 255, 0, 0);
}
DisplayDebugInfo();
// Send an (E)rror signal to tell the client that no more chunks should be
// send or to repeat the entire frame from the beginning.
Serial.write('E');
Expand All @@ -962,10 +977,7 @@ bool SerialReadBuffer(uint8_t *pBuffer, uint16_t BufferSize,
(mz_ulong *)&transferBufferSize);
free(transferBuffer);

if (debugMode) {
DisplayText("Miniz Status:", 0, 3 * 6, 255, 255, 255);
DisplayNumber(minizStatus, 6, 13 * 4, 3 * 6, 255, 255, 255);
}
DisplayDebugInfo();

if ((MZ_OK == minizStatus) &&
(!fixedSize || (fixedSize && uncompressed_buffer_size == BufferSize))) {
Expand All @@ -974,14 +986,11 @@ bool SerialReadBuffer(uint8_t *pBuffer, uint16_t BufferSize,

if (debugMode && (MZ_OK == minizStatus)) {
// uncrompessed data isn't of expected size
DisplayNumber(99, 6, 13 * 4, 3 * 6, 255, 255, 255);
minizStatus = 99;
}

errorCount++;
if (debugMode) {
DisplayText("Errors:", 0, 4 * 6, 255, 255, 255);
DisplayNumber(errorCount, 5, 7 * 4, 4 * 6, 255, 0, 0);
}
DisplayDebugInfo();

Serial.write('E');
return false;
Expand Down Expand Up @@ -1027,10 +1036,9 @@ bool wait_for_ctrl_chars(void) {
if (Serial.available()) {
if (Serial.read() != CtrlCharacters[nCtrlCharFound++]) {
nCtrlCharFound = 0;
if (debugMode) {
// There's garbage on the line.
DisplayText("Miniz Status:____99", 0, 3 * 6, 255, 255, 255);
}
// There's garbage on the line.
minizStatus = 666;
DisplayDebugInfo();
}
}

Expand Down Expand Up @@ -1122,10 +1130,7 @@ void loop() {
;
c4 = Serial.read();

if (debugMode) {
DisplayNumber(c4, 2, TOTAL_WIDTH - 3 * 4, TOTAL_HEIGHT - 8, 200, 200,
200);
}
DisplayDebugInfo();

if (displayStatus != 1) {
// Exit screen saver.
Expand Down Expand Up @@ -1154,10 +1159,7 @@ void loop() {
RomWidth = (int)(tbuf[0]) + (int)(tbuf[1] << 8);
RomHeight = (int)(tbuf[2]) + (int)(tbuf[3] << 8);
RomWidthPlane = RomWidth >> 3;
if (debugMode) {
DisplayNumber(RomWidth, 3, TOTAL_WIDTH - 7 * 4, 4, 200, 200, 200);
DisplayNumber(RomHeight, 2, TOTAL_WIDTH - 3 * 4, 4, 200, 200, 200);
}
DisplayDebugInfo();
}
break;
}
Expand Down Expand Up @@ -1357,7 +1359,8 @@ void loop() {
case 99: // enable debug mode
{
debugMode = true;

// WTF removing this dummy variable kills the debug mode
debugWTF = true;
Serial.write('A');
break;
}
Expand Down Expand Up @@ -1729,34 +1732,17 @@ void loop() {
}
#endif
default: {
if (debugMode) {
DisplayText("Unsupported render mode!", 4, 6, 255, 0, 0);
}

Serial.write('E');
DisplayText("Unsupported render mode:", 0, 0, 255, 0, 0);
DisplayNumber(c4, 3, 24 * 4, 0, 255, 0, 0);
delay(5000);
}
}

// An overflow of the unsigned int counters should not be an issue, they
// just reset to 0.
frameCount++;
}

if (debugMode) {
DisplayNumber(RomWidth, 3, TOTAL_WIDTH - 7 * 4, 4, 200, 200, 200);
DisplayNumber(RomHeight, 2, TOTAL_WIDTH - 3 * 4, 4, 200, 200, 200);
DisplayNumber(flowControlCounter, 2, TOTAL_WIDTH - 6 * 4, TOTAL_HEIGHT - 8,
200, 200, 200);
DisplayNumber(c4, 2, TOTAL_WIDTH - 3 * 4, TOTAL_HEIGHT - 8, 200, 200, 200);
DisplayText("Frames:", 0, 0, 255, 255, 255);
DisplayNumber(frameCount, 5, 7 * 4, 0, 0, 255, 0);
DisplayText("Transfer Buffer:", 0, 6, 255, 255, 255);
DisplayNumber(transferBufferSize, 5, 16 * 4, 6, 255, 255, 255);
DisplayText("Received Bytes: ", 0, 2 * 6, 255, 255, 255);
DisplayNumber(receivedBytes, 5, 16 * 4, 2 * 6, 255, 255, 255);
DisplayText("Miniz Status:", 0, 3 * 6, 255, 255, 255);
DisplayNumber(minizStatus, 6, 13 * 4, 3 * 6, 255, 255, 255);
DisplayText("Errors:", 0, 4 * 6, 255, 255, 255);
DisplayNumber(errorCount, 5, 7 * 4, 4 * 6, 255, 0, 0);
DisplayDebugInfo();
}
}

0 comments on commit 65add33

Please sign in to comment.