Some changes
This commit is contained in:
parent
44f73ed2d5
commit
d5b7facf36
@ -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
|
||||
|
85
c/libs/go_p2fa.h
Normal file
85
c/libs/go_p2fa.h
Normal file
@ -0,0 +1,85 @@
|
||||
/* 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. */
|
||||
|
||||
|
||||
|
||||
|
||||
/* 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
|
||||
|
||||
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
|
BIN
c/pic/100x100.bmp
Normal file
BIN
c/pic/100x100.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
c/pic/2in13_1.bmp
Normal file
BIN
c/pic/2in13_1.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
26
c/src/p2fa.c
26
c/src/p2fa.c
@ -7,6 +7,7 @@
|
||||
#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"
|
||||
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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=
|
||||
|
41
go/main.go
41
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() {}
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user