diff --git a/README.md b/README.md index 56fc9ec..5cc4c55 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,6 @@ Hardware 2FA Manager -https://www.adafruit.com/product/4282 -https://github.com/waveshareteam/e-Paper/tree/master -https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT_Manual#C + - https://www.adafruit.com/product/4282 + - https://github.com/waveshareteam/e-Paper/tree/master + - https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT_Manual#C diff --git a/c/libs/go_p2fa.h b/c/libs/go_p2fa.h new file mode 100644 index 0000000..cdac00b --- /dev/null +++ b/c/libs/go_p2fa.h @@ -0,0 +1,85 @@ +/* Code generated by cmd/cgo; DO NOT EDIT. */ + +/* package P2FA */ + + +#line 1 "cgo-builtin-export-prolog" + +#include + +#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. */ + + + + +/* 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 +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 + +extern __declspec(dllexport) void loadConfigs(); +extern __declspec(dllexport) GoSlice getConfigNames(); +extern __declspec(dllexport) GoString getCode(GoString configName); +extern __declspec(dllexport) GoUint64 getTimeRemaining(GoInt n); +extern __declspec(dllexport) GoUint64 getTimeRemainingMS(GoInt n); + +#ifdef __cplusplus +} +#endif diff --git a/c/pic/100x100.bmp b/c/pic/100x100.bmp new file mode 100644 index 0000000..70f4584 Binary files /dev/null and b/c/pic/100x100.bmp differ diff --git a/c/pic/2in13_1.bmp b/c/pic/2in13_1.bmp new file mode 100644 index 0000000..84e6497 Binary files /dev/null and b/c/pic/2in13_1.bmp differ diff --git a/c/src/p2fa.c b/c/src/p2fa.c index 4d7825d..b79cd29 100644 --- a/c/src/p2fa.c +++ b/c/src/p2fa.c @@ -7,6 +7,7 @@ #include #include +#include "../libs/go_p2fa.h" #include "images.h" #include "../libs/e-Paper/EPD_2in13_V4.h" #include "../libs/GUI/GUI_Paint.h" @@ -19,6 +20,31 @@ void Handler(int sigNum) { } int draw() { + if (DEV_Module_Init() != 0) { + return -1; + } + EPD_2in13_V4_Init(); + + Paint_Clear(WHITE); + const char *confName = "default"; + Paint_DrawString(5, 5, getCode(GoString{confName, strlen(confName)}).p, &Font24, WHITE, BLACK); + + DEV_Delay_ms(5000); + + Debug("Clear...\r\n"); + 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 + // close 5V + Debug("close 5V, Module enters 0 power consumption ...\r\n"); + DEV_Module_Exit(); + return 0; +} + +int drawOld() { Debug("EPD_2in13_V4_test Demo\r\n"); if(DEV_Module_Init()!=0){ return -1; diff --git a/go/go.mod b/go/go.mod index 6cee1ea..040ad0c 100644 --- a/go/go.mod +++ b/go/go.mod @@ -3,3 +3,5 @@ module P2FA go 1.23.2 require github.com/creachadair/otp v0.5.0 + +require github.com/creachadair/wirepb v0.0.0-20240525191938-8530265c0822 // indirect diff --git a/go/go.sum b/go/go.sum index 4957390..492bad3 100644 --- a/go/go.sum +++ b/go/go.sum @@ -2,3 +2,7 @@ github.com/creachadair/mds v0.21.3 h1:RRgEAPIb52cU0q7UxGyN+13QlCVTZIL4slRr0cYYQf github.com/creachadair/mds v0.21.3/go.mod h1:1ltMWZd9yXhaHEoZwBialMaviWVUpRPvMwVP7saFAzM= github.com/creachadair/otp v0.5.0 h1:q3Th7CXm2zlmCdBjw5tEPFOj4oWJMnVL5HXlq0sNKS0= github.com/creachadair/otp v0.5.0/go.mod h1:0kceI87EnYFNYSTL121goJVAnk3eJhaed9H0nMuJUkA= +github.com/creachadair/wirepb v0.0.0-20240525191938-8530265c0822 h1:qMXKIQdq1vG9AQjejDZ6GEab9DNWb72O/dvxEpJF/yA= +github.com/creachadair/wirepb v0.0.0-20240525191938-8530265c0822/go.mod h1:N3X4c2/WeOpnFyf5lL46Pc3VXFrfqdwCR+JIHNCHaGU= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= diff --git a/go/main.go b/go/main.go index 14285f0..2edd6cf 100644 --- a/go/main.go +++ b/go/main.go @@ -1,6 +1,7 @@ package main import ( + "C" "crypto/hmac" "crypto/sha1" "crypto/sha256" @@ -21,6 +22,7 @@ var configs map[string]otp.Config func getSha1() func() hash.Hash { return sha1.New } +//export loadConfigs func loadConfigs() { var homeDir string @@ -121,31 +123,28 @@ func loadConfigs() { } } -func refreshTokenVar() { - token, _ = otp.DefaultTOTP("alksjdfhalksjdbf") +//export getConfigNames +func getConfigNames() []string { + names := make([]string, 0, len(configs)) + for name := range configs { + names = append(names, name) + } + return names } +//export getCode +func getCode(configName string) string { + return configs[configName].TOTP() +} + +//export getTimeRemaining func getTimeRemaining(n int) uint64 { return uint64(n) - (uint64(time.Now().Unix()) % uint64(n)) } -func main() { - //loadConfigs() - - startUI() - - //refreshTokenVar() - // - //getTimeRemaining(30) - // - //for i := 0; i < 5; i++ { - // refreshTokenVar() - // fmt.Printf("TOTP: %s\n", token) - // for getTimeRemaining(30) > 1 { - // time.Sleep(1 * time.Second) - // fmt.Printf("\rTime Remaining: %ds", getTimeRemaining(30)) - // } - // time.Sleep(1 * time.Second) - // fmt.Print("\n") - //} +//export getTimeRemainingMS +func getTimeRemainingMS(n int) uint64 { + return (uint64(n) * 1000) - (uint64(time.Now().UnixNano()/1e6) % (uint64(n) * 1000)) } + +func main() {} diff --git a/go/ui.go b/go/ui.go.old similarity index 81% rename from go/ui.go rename to go/ui.go.old index 60d8039..7bd1eac 100644 --- a/go/ui.go +++ b/go/ui.go.old @@ -2,10 +2,9 @@ package main /* #cgo CFLAGS: -I. -#cgo LDFLAGS: -L. -llibp2fa -lSDL2 -lSDL2main +#cgo LDFLAGS: -L. -llibp2fa -#include "../c/libs/include/SDL2/SDL.h" -#include "../c/p2fa.h" +#include "../c/src/p2fa.h" */ import "C"