Add view config page
This commit is contained in:
105
c/libs/go_p2fa.h
105
c/libs/go_p2fa.h
@@ -1,105 +0,0 @@
|
||||
/* Code generated by cmd/cgo; DO NOT EDIT. */
|
||||
|
||||
/* package P2FA */
|
||||
|
||||
|
||||
#line 1 "cgo-builtin-export-prolog"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef GO_CGO_EXPORT_PROLOGUE_H
|
||||
#define GO_CGO_EXPORT_PROLOGUE_H
|
||||
|
||||
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
||||
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Start of preamble from import "C" comments. */
|
||||
|
||||
|
||||
#line 3 "ctils.go"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#line 1 "cgo-generated-wrapper"
|
||||
|
||||
|
||||
|
||||
/* End of preamble from import "C" comments. */
|
||||
|
||||
|
||||
/* Start of boilerplate cgo prologue. */
|
||||
#line 1 "cgo-gcc-export-header-prolog"
|
||||
|
||||
#ifndef GO_CGO_PROLOGUE_H
|
||||
#define GO_CGO_PROLOGUE_H
|
||||
|
||||
typedef signed char GoInt8;
|
||||
typedef unsigned char GoUint8;
|
||||
typedef short GoInt16;
|
||||
typedef unsigned short GoUint16;
|
||||
typedef int GoInt32;
|
||||
typedef unsigned int GoUint32;
|
||||
typedef long long GoInt64;
|
||||
typedef unsigned long long GoUint64;
|
||||
typedef GoInt64 GoInt;
|
||||
typedef GoUint64 GoUint;
|
||||
typedef size_t GoUintptr;
|
||||
typedef float GoFloat32;
|
||||
typedef double GoFloat64;
|
||||
#ifdef _MSC_VER
|
||||
#include <complex.h>
|
||||
typedef _Fcomplex GoComplex64;
|
||||
typedef _Dcomplex GoComplex128;
|
||||
#else
|
||||
typedef float _Complex GoComplex64;
|
||||
typedef double _Complex GoComplex128;
|
||||
#endif
|
||||
|
||||
/*
|
||||
static assertion to make sure the file is being used on architecture
|
||||
at least with matching size of GoInt.
|
||||
*/
|
||||
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
|
||||
|
||||
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
||||
typedef _GoString_ GoString;
|
||||
#endif
|
||||
typedef void *GoMap;
|
||||
typedef void *GoChan;
|
||||
typedef struct { void *t; void *v; } GoInterface;
|
||||
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
||||
|
||||
#endif
|
||||
|
||||
/* End of boilerplate cgo prologue. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Return type for prepareCStringArray */
|
||||
struct prepareCStringArray_return {
|
||||
char** r0;
|
||||
GoInt r1;
|
||||
};
|
||||
extern __declspec(dllexport) struct prepareCStringArray_return prepareCStringArray(GoSlice goStrings);
|
||||
extern __declspec(dllexport) void freeCStringArray(char** cStrings, GoInt length);
|
||||
extern __declspec(dllexport) void loadConfigs();
|
||||
|
||||
/* Return type for getConfigNames */
|
||||
struct getConfigNames_return {
|
||||
char** r0;
|
||||
int r1;
|
||||
};
|
||||
extern __declspec(dllexport) struct getConfigNames_return getConfigNames();
|
||||
extern __declspec(dllexport) char* getCode(GoString configName);
|
||||
extern __declspec(dllexport) GoUint64 getTimeRemaining(GoInt n);
|
||||
extern __declspec(dllexport) GoUint64 getTimeRemainingMS(GoInt n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
76
c/src/p2fa.c
76
c/src/p2fa.c
@@ -40,7 +40,6 @@ int computeWidth(char* text, sFONT *font) {
|
||||
//TODO Put display to sleep after
|
||||
void code(UWORD *blackImage, char* confName) {
|
||||
int ch;
|
||||
codeLoop:
|
||||
while(1) {
|
||||
ch = getch();
|
||||
if (ch != ERR) {
|
||||
@@ -105,7 +104,42 @@ void code(UWORD *blackImage, char* confName) {
|
||||
}
|
||||
}
|
||||
|
||||
void home(UWORD *blackImage) {
|
||||
void config(UWORD *blackImage, char* configName) {
|
||||
GoString goConfName = { configName, strlen(configName) };
|
||||
struct getConfig_return getConfigReturn = getConfig(goConfName);
|
||||
if (getConfigReturn.r1 == -1) {
|
||||
DebugLine(10, 0, "Config not found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 0, WHITE);
|
||||
EPD_2in13_V4_Init();
|
||||
Paint_SelectImage(blackImage);
|
||||
Paint_Clear(WHITE);
|
||||
|
||||
Paint_DrawString(5, 5, getConfigReturn.r0, &Font12, WHITE, BLACK);
|
||||
EPD_2in13_V4_Display(blackImage);
|
||||
|
||||
int ch = getch();
|
||||
if (ch == 'q') return;
|
||||
}
|
||||
|
||||
void drawTotpHome(UWORD *blackImage, char** configNames) {
|
||||
Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 0, WHITE);
|
||||
Paint_SelectImage(blackImage);
|
||||
Paint_Clear(WHITE);
|
||||
for (int j = 0; j < length; j++) {
|
||||
if (configNames[j] == NULL) {
|
||||
DebugLine(13, 0, "Null Config: %d\n", j);
|
||||
}
|
||||
Paint_DrawString(5, 5 + j * 20, configNames[j], &Font12, WHITE, BLACK);
|
||||
}
|
||||
EPD_2in13_V4_Display_Base(blackImage);
|
||||
Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 0, WHITE);
|
||||
Paint_SelectImage(blackImage);
|
||||
}
|
||||
|
||||
void totpHome(UWORD *blackImage) {
|
||||
struct getConfigNames_return configNamesReturn = getConfigNames();
|
||||
int length = configNamesReturn.r1;
|
||||
char** configNames = configNamesReturn.r0;
|
||||
@@ -117,21 +151,7 @@ void home(UWORD *blackImage) {
|
||||
return;
|
||||
}
|
||||
|
||||
Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 0, WHITE);
|
||||
EPD_2in13_V4_Init();
|
||||
Paint_SelectImage(blackImage);
|
||||
Paint_Clear(WHITE);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (configNames[i] == NULL) {
|
||||
DebugLine(13, 0, "Null Config: %d\n", i);
|
||||
}
|
||||
Paint_DrawString(5, 5 + (i * 20), configNames[i], &Font12, WHITE, BLACK);
|
||||
}
|
||||
EPD_2in13_V4_Display_Base(blackImage);
|
||||
|
||||
Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 0, WHITE);
|
||||
Paint_SelectImage(blackImage);
|
||||
drawTotpHome(blackImage, configNames);
|
||||
|
||||
int i = 0;
|
||||
Paint_DrawString(115, 5 + (i * 20), "<", &Font12, WHITE, BLACK);
|
||||
@@ -154,20 +174,11 @@ void home(UWORD *blackImage) {
|
||||
case '\n':
|
||||
timeout(0);
|
||||
code(blackImage, configNames[i]);
|
||||
|
||||
Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 0, WHITE);
|
||||
Paint_SelectImage(blackImage);
|
||||
Paint_Clear(WHITE);
|
||||
for (int j = 0; j < length; j++) {
|
||||
if (configNames[j] == NULL) {
|
||||
DebugLine(13, 0, "Null Config: %d\n", j);
|
||||
}
|
||||
Paint_DrawString(5, 5 + j * 20, configNames[j], &Font12, WHITE, BLACK);
|
||||
}
|
||||
EPD_2in13_V4_Display_Base(blackImage);
|
||||
Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 0, WHITE);
|
||||
Paint_SelectImage(blackImage);
|
||||
|
||||
drawTotpHome(blackImage, configNames);
|
||||
break;
|
||||
case 'c':
|
||||
config(blackImage, configNames[i]);
|
||||
drawTotpHome(blackImage, configNames);
|
||||
break;
|
||||
case 'q':
|
||||
return;
|
||||
@@ -198,13 +209,14 @@ int drawLoop() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
home(blackImage);
|
||||
totpHome(blackImage);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
signal(SIGINT, Handler);
|
||||
signal(SIGTERM, Handler)
|
||||
|
||||
initscr();
|
||||
cbreak();
|
||||
|
||||
Reference in New Issue
Block a user