108 lines
3.3 KiB
C
108 lines
3.3 KiB
C
//
|
|
// Created by steven on 11/14/2024.
|
|
//
|
|
|
|
#include <time.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <signal.h>
|
|
|
|
#include "../libs/go_p2fa.h"
|
|
#include "images.h"
|
|
#include "../libs/e-Paper/EPD_2in13_V4.h"
|
|
#include "../libs/GUI/GUI_Paint.h"
|
|
#include "../libs/GUI/GUI_BMPfile.h"
|
|
|
|
void Handler(int sigNum) {
|
|
printf("Caught signal %d\n", sigNum);
|
|
EPD_2in13_V4_Init();
|
|
EPD_2in13_V4_Clear();
|
|
|
|
Debug("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");
|
|
|
|
DEV_Module_Exit();
|
|
exit(0);
|
|
}
|
|
|
|
int draw() {
|
|
if (DEV_Module_Init() != 0) {
|
|
return -1;
|
|
}
|
|
EPD_2in13_V4_Init();
|
|
EPD_2in13_V4_Clear();
|
|
|
|
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");
|
|
return -1;
|
|
}
|
|
|
|
while(1) {
|
|
|
|
|
|
Paint_NewImage(BlackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 90, WHITE);
|
|
EPD_2in13_V4_Init();
|
|
Paint_SelectImage(BlackImage);
|
|
Paint_Clear(WHITE);
|
|
|
|
const char *confName = "default";
|
|
GoString confStr = {confName, strlen(confName)};
|
|
const char *code = getCode(confStr);
|
|
Debug("Code: %s\n", code);
|
|
Paint_DrawString(5, 5, code, &Font48, WHITE, BLACK);
|
|
|
|
Paint_DrawRectangle(10, 112, 240, 92, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
|
|
EPD_2in13_V4_Display_Base(BlackImage);
|
|
|
|
Paint_NewImage(BlackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 90, WHITE);
|
|
Paint_SelectImage(BlackImage);
|
|
|
|
clock_t startTime;
|
|
clock_t endTime;
|
|
int elapsedTime;
|
|
int progBarCurrentIndex = 11;
|
|
int progBarEndIndex;
|
|
int lastI = 30 * 1000;
|
|
for (int i = getTimeRemainingMS(30);; i = getTimeRemainingMS(30)) {
|
|
if (i > lastI) break;
|
|
startTime = clock();
|
|
|
|
Debug("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);
|
|
while (progBarCurrentIndex < progBarEndIndex) {
|
|
Debug("Line: %d,111 - %d,93\n", progBarCurrentIndex, progBarEndIndex);
|
|
Paint_DrawLine(progBarCurrentIndex, 111, progBarCurrentIndex, 93, BLACK, DOT_PIXEL_1X1,
|
|
LINE_STYLE_SOLID);
|
|
++progBarCurrentIndex;
|
|
}
|
|
EPD_2in13_V4_Display_Partial(BlackImage);
|
|
endTime = clock();
|
|
elapsedTime = (int) ((endTime - startTime) / CLOCKS_PER_SEC);
|
|
Debug("Elapsed Time %d\n", elapsedTime);
|
|
if (elapsedTime < 1000) {
|
|
Debug("Delay for %dms\n", (1000 - (elapsedTime * 1000)));
|
|
DEV_Delay_ms(1000 - (elapsedTime * 1000));
|
|
}
|
|
lastI = i;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
signal(SIGINT, Handler);
|
|
|
|
loadConfigs();
|
|
|
|
draw();
|
|
|
|
return 0;
|
|
} |