From b790dc3013fd822649d1f311140dcafc73cccc5e Mon Sep 17 00:00:00 2001 From: Steven Tracey Date: Thu, 21 Nov 2024 18:27:46 -0500 Subject: [PATCH] Here goes nothing --- c/src/p2fa.c | 36 +++++++++++++++++++++++++++++++++--- go/totp.go | 8 ++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/c/src/p2fa.c b/c/src/p2fa.c index c72c4cc..fd43cd5 100644 --- a/c/src/p2fa.c +++ b/c/src/p2fa.c @@ -60,12 +60,42 @@ void home(UWORD *blackImage) { } EPD_2in13_V4_Display_Base(blackImage); + + Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 0, WHITE); + Paint_SelectImage(blackImage); + + int i = 0; + int ch; + while (1) { + ch = getch(); + if (ch != ERR) { + switch(ch) { + case KEY_UP: + if (i > 0) i--; + break; + case KEY_DOWN: + if (i < length - 1) i++; + break; + case '\n': + getCode(configNames[i]); + break; + case 'q': + return; + } + } + + Paint_ClearWindows(110, 5 + (i * 20), 117, 17 + (i * 20), WHITE); + Paint_DrawString(115, 5 + (i * 20), "<", &Font12, WHITE, BLACK); + + } + Paint_ClearWindows(); + freeCStringArray(configNames, length); DEV_Delay_ms(2000); } -void code(UWORD *blackImage) { +void code(UWORD *blackImage, char* confName) { int ch; codeLoop: while(1) { @@ -80,13 +110,13 @@ void code(UWORD *blackImage) { Paint_SelectImage(blackImage); Paint_Clear(WHITE); - const char *confName = "default"; GoString confStr = {confName, strlen(confName)}; const char *code = getCode(confStr); DebugLine(3, 0, "Code: %s\n", code); Paint_DrawString(5, 5, code, &Font36, WHITE, BLACK); + Paint_DrawString(5, 100, confName, &Font12, WHITE, BLACK); - Paint_DrawRectangle(10, 112, 240, 92, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY); + Paint_DrawRectangle(10, 112, 240, 92, BLACK, 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); diff --git a/go/totp.go b/go/totp.go index 3227f5c..7c1f720 100644 --- a/go/totp.go +++ b/go/totp.go @@ -151,6 +151,14 @@ func getCode(configName string) *C.char { return cCode } +//export getCodeFromI +func getCodeFromI(index int) *C.char { + code := configs[index].TOTP() + cCode := C.CString(code) + runtime.KeepAlive(code) + return cCode +} + //export getTimeRemaining func getTimeRemaining(n int) uint64 { return uint64(n) - (uint64(time.Now().Unix()) % uint64(n))