Home Page
This commit is contained in:
parent
27ca83ad4f
commit
94843fa797
@ -19,6 +19,12 @@ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
|
||||
/* 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. */
|
||||
@ -74,8 +80,22 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
||||
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();
|
||||
extern __declspec(dllexport) GoSlice getConfigNames();
|
||||
|
||||
/* 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);
|
||||
|
24
c/src/p2fa.c
24
c/src/p2fa.c
@ -15,6 +15,9 @@
|
||||
#include "../libs/GUI/GUI_BMPfile.h"
|
||||
#include "../libs/Config/Debug.h"
|
||||
|
||||
extern char** getConfigNames(int* length);
|
||||
extern void freeCStringArray(char** cStrings, int length);
|
||||
|
||||
void Handler(int sigNum) {
|
||||
DebugLine(28, 0, "Caught signal %d\n", sigNum);
|
||||
EPD_2in13_V4_Init();
|
||||
@ -31,19 +34,35 @@ void Handler(int sigNum) {
|
||||
}
|
||||
|
||||
void home(UWORD *blackImage) {
|
||||
int length;
|
||||
char** configNames = getConfigNames(&length);
|
||||
|
||||
if (configNames == NULL || length == 0) {
|
||||
DebugLine(10, 0, "No configs 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);
|
||||
|
||||
for (int i = 0; i < length; ++i) {
|
||||
Paint_DrawString(5, 5 + (i * 20), configNames[i], &Font12, WHITE, BLACK);
|
||||
}
|
||||
EPD_2in13_V4_Display_Base(blackImage);
|
||||
|
||||
freeCStringArray(configNames, length);
|
||||
}
|
||||
|
||||
void code(UWORD *blackImage) {
|
||||
int ch;
|
||||
codeLoop:
|
||||
while(1) {
|
||||
ch = getch();
|
||||
if (ch != ERR) {
|
||||
if (ch == 'q') break;
|
||||
DebugLine(2, 0, "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);
|
||||
@ -72,7 +91,7 @@ void code(UWORD *blackImage) {
|
||||
for (int i = getTimeRemainingMS(30);; i = getTimeRemainingMS(30)) {
|
||||
ch = getch();
|
||||
if (ch != ERR) {
|
||||
if (ch == 'q') break;
|
||||
if (ch == 'q') return;
|
||||
}
|
||||
if (i > lastI) break;
|
||||
startTime = clock();
|
||||
@ -117,6 +136,7 @@ int drawLoop() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
home(blackImage);
|
||||
code(blackImage);
|
||||
|
||||
return 0;
|
||||
|
24
go/ctils.go
Normal file
24
go/ctils.go
Normal file
@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
//export prepareCStringArray
|
||||
func prepareCStringArray(goStrings []string) (**C.char, int) {
|
||||
cStrings := make([]*C.char, len(goStrings))
|
||||
for i, s := range goStrings {
|
||||
cStrings[i] = C.CString(s)
|
||||
}
|
||||
return (**C.char)(unsafe.Pointer(&cStrings[0])), len(goStrings)
|
||||
}
|
||||
|
||||
//export freeCStringArray
|
||||
func freeCStringArray(cStrings **C.char, length int) {
|
||||
array := (*[1 << 30]*C.char)(unsafe.Pointer(cStrings))[:length:length]
|
||||
for _, s := range array {
|
||||
C.free(unsafe.Pointer(s))
|
||||
}
|
||||
}
|
18
go/totp.go
18
go/totp.go
@ -10,10 +10,12 @@ import (
|
||||
"hash"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var token string
|
||||
@ -119,17 +121,25 @@ func loadConfigs() {
|
||||
Format: format,
|
||||
}
|
||||
|
||||
configs[fileEntry.Name()] = config
|
||||
fileName := fileEntry.Name()
|
||||
ext := filepath.Ext(fileName)
|
||||
|
||||
configs[strings.TrimSuffix(fileName, ext)] = config
|
||||
}
|
||||
}
|
||||
|
||||
//export getConfigNames
|
||||
func getConfigNames() []string {
|
||||
func getConfigNames() (**C.char, C.int) {
|
||||
names := make([]string, 0, len(configs))
|
||||
for name := range configs {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
cStrings := make([]*C.char, len(names))
|
||||
for i, name := range names {
|
||||
cStrings[i] = C.CString(name)
|
||||
}
|
||||
|
||||
return (**C.char)(unsafe.Pointer(&cStrings[0])), C.int(len(names))
|
||||
}
|
||||
|
||||
//export getCode
|
||||
@ -150,4 +160,4 @@ func getTimeRemainingMS(n int) uint64 {
|
||||
return (uint64(n) * 1000) - (uint64(time.Now().UnixNano()/1e6) % (uint64(n) * 1000))
|
||||
}
|
||||
|
||||
func main() {}
|
||||
//func main() {}
|
||||
|
Loading…
Reference in New Issue
Block a user