Debug refactor
This commit is contained in:
parent
09674009cb
commit
9d3b956130
@ -35,13 +35,20 @@
|
||||
#ifndef __DEBUG_H
|
||||
#define __DEBUG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#if DEBUG
|
||||
#define Debug(__info,...) mvprintw(0, 0, "Debug: " __info,##__VA_ARGS__); refresh()
|
||||
#define Debug(__info, ...) do { \
|
||||
mvprintw(30, 0, "Debug:" __info, ##__VA_ARGS__); \
|
||||
refresh(); \
|
||||
} while (0)
|
||||
#define DebugLine(y, x, __info, ...) do { \
|
||||
mvprintw((y), (x), "Debug: " __info, ##__VA_ARGS__); \
|
||||
refresh(); \
|
||||
} while (0)
|
||||
#else
|
||||
#define Debug(__info,...)
|
||||
#define Debug(__info, ...)
|
||||
#define DebugLine(y, x, __info, ...)
|
||||
#endif
|
||||
|
||||
#endif
|
31
c/src/p2fa.c
31
c/src/p2fa.c
@ -13,20 +13,20 @@
|
||||
#include "../libs/e-Paper/EPD_2in13_V4.h"
|
||||
#include "../libs/GUI/GUI_Paint.h"
|
||||
#include "../libs/GUI/GUI_BMPfile.h"
|
||||
#include "../libs/Config/Debug.h"
|
||||
|
||||
void Handler(int sigNum) {
|
||||
printf("Caught signal %d\n", sigNum);
|
||||
DebugLine(28, 0, "Caught signal %d\n", sigNum);
|
||||
EPD_2in13_V4_Init();
|
||||
EPD_2in13_V4_Clear();
|
||||
|
||||
Debug("Goto Sleep...\r\n");
|
||||
DebugLine(29, 0, "Goto Sleep...\r\n");
|
||||
EPD_2in13_V4_Sleep();
|
||||
|
||||
DEV_Delay_ms(2000);//important, at least 2s
|
||||
Debug("close 5V, Module enters 0 power consumption ...\r\n");
|
||||
endwin();
|
||||
|
||||
DEV_Module_Exit();
|
||||
endwin();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ void code(UWORD *blackImage) {
|
||||
if (ch == 'q') {
|
||||
break;
|
||||
}
|
||||
Debug("Key Pressed: %c\n", ch);
|
||||
DebugLine(2, 0, "Key Pressed: %c\n", ch);
|
||||
|
||||
Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 90, WHITE);
|
||||
EPD_2in13_V4_Init();
|
||||
@ -54,7 +54,7 @@ void code(UWORD *blackImage) {
|
||||
const char *confName = "default";
|
||||
GoString confStr = {confName, strlen(confName)};
|
||||
const char *code = getCode(confStr);
|
||||
Debug("Code: %s\n", code);
|
||||
DebugLine(3, 0, "Code: %s\n", code);
|
||||
Paint_DrawString(5, 5, code, &Font36, WHITE, BLACK);
|
||||
|
||||
Paint_DrawRectangle(10, 112, 240, 92, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
|
||||
@ -70,27 +70,29 @@ void code(UWORD *blackImage) {
|
||||
int progBarEndIndex;
|
||||
int lastI = 30 * 1000;
|
||||
for (int i = getTimeRemainingMS(30);; i = getTimeRemainingMS(30)) {
|
||||
if (i > lastI) break;
|
||||
ch = getch();
|
||||
if (i > lastI || ch == 'q') break;
|
||||
startTime = clock();
|
||||
|
||||
Debug("Time Left: %d\n", i);
|
||||
DebugLine(4, 0, "Time Left: %d\n", i);
|
||||
double percentLeft = ((double) i / (double) (30 * 1000));
|
||||
Debug("Percent Left: %.3f\n", percentLeft);
|
||||
progBarEndIndex = 228 - ((int) (228 * percentLeft));
|
||||
Debug("Progress Bar Start: %d\nDebug: Progress Bar End: %d\n", progBarCurrentIndex, progBarEndIndex);
|
||||
Paint_ClearWindows(progBarCurrentIndex, 111, progBarEndIndex, 93, WHITE);
|
||||
int line = 15;
|
||||
while (progBarCurrentIndex < progBarEndIndex) {
|
||||
Debug("Line: %d,111 - %d,93\n", progBarCurrentIndex, progBarEndIndex);
|
||||
DebugLine(line, 0, "Line: %d,111 - %d,93\n", progBarCurrentIndex, progBarEndIndex);
|
||||
Paint_DrawLine(progBarCurrentIndex, 111, progBarCurrentIndex, 93, BLACK, DOT_PIXEL_1X1,
|
||||
LINE_STYLE_SOLID);
|
||||
++progBarCurrentIndex;
|
||||
++line;
|
||||
if (line == 21) line = 15;
|
||||
}
|
||||
EPD_2in13_V4_Display_Partial(blackImage);
|
||||
endTime = clock();
|
||||
elapsedTime = (int) ((endTime - startTime) / CLOCKS_PER_SEC);
|
||||
Debug("Elapsed Time %d\n", elapsedTime);
|
||||
DebugLine(5, 0, "Elapsed Time %d\n", elapsedTime);
|
||||
if (elapsedTime < 1000) {
|
||||
Debug("Delay for %dms\n", (1000 - (elapsedTime * 1000)));
|
||||
DebugLine(6, 0, "Delay for %dms\n", (1000 - (elapsedTime * 1000)));
|
||||
DEV_Delay_ms(1000 - (elapsedTime * 1000));
|
||||
}
|
||||
lastI = i;
|
||||
@ -108,7 +110,7 @@ int drawLoop() {
|
||||
UBYTE *blackImage;
|
||||
UWORD ImageSize = ((EPD_2in13_V4_WIDTH % 8 == 0) ? (EPD_2in13_V4_WIDTH / 8) : (EPD_2in13_V4_WIDTH / 8 + 1)) * EPD_2in13_V4_HEIGHT;
|
||||
if ((blackImage = (UBYTE *) malloc(ImageSize)) == NULL) {
|
||||
Debug("Failed to apply for black memory...\n");
|
||||
DebugLine(8, 0, "Failed to apply for black memory...\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -128,5 +130,6 @@ int main() {
|
||||
|
||||
drawLoop();
|
||||
|
||||
endwin();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user