diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index a6f4539..56fc9ec 100644
--- a/README.md
+++ b/README.md
@@ -2,4 +2,6 @@
Hardware 2FA Manager
-https://www.adafruit.com/product/4282
\ No newline at end of file
+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/CMakeLists.txt b/c/CMakeLists.txt
index f02c6ca..1cf3d31 100644
--- a/c/CMakeLists.txt
+++ b/c/CMakeLists.txt
@@ -4,8 +4,12 @@ project(P2FA)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
-add_library(p2fa SHARED p2fa.c
- p2fa.h)
+include_directories(${CMAKE_SOURCE_DIR}/libs/include)
+link_directories(${CMAKE_SOURCE_DIR}/libs)
+
+add_library(p2fa SHARED p2fa.c)
+
+target_link_libraries(p2fa SDL2 SDL2main)
set_target_properties(p2fa PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build"
diff --git a/c/p2fa.c b/c/p2fa.c
index f4231d5..7227cf9 100644
--- a/c/p2fa.c
+++ b/c/p2fa.c
@@ -2,154 +2,55 @@
// Created by steven on 11/14/2024.
//
-#include
-#include
-#include "libs/EPD_2in13_V4.h"
-#include "libs/GUI/GUI_Paint.h"
-#include "libs/GUI/GUI_BMPfile.h"
+//#include
+//#include
+#include "libs/include/SDL2/SDL.h"
+#include
+//#include "libs/EPD_2in13_V4.h"
+//#include "libs/GUI/GUI_Paint.h"
+//#include "libs/GUI/GUI_BMPfile.h"
-__declspec(dllexport) int draw() {
- srand(time(NULL));
- return rand();
+__declspec(dllexport) SDL_Window* createWindow() {
+ SDL_Window *win = SDL_CreateWindow("Hello SDL",
+ SDL_WINDOWPOS_CENTERED,
+ SDL_WINDOWPOS_CENTERED,
+ 250, 122, SDL_WINDOW_SHOWN);
+ if (!win) {
+ printf("SDL_CreateWindow Error: %s\n", SDL_GetError());
+ SDL_Quit();
+ return NULL;
+ }
+ return win;
}
-
-int EPD_2in13_V4_test(void) {
-
- Debug("EPD_2in13_V4_test Demo\r\n");
- if(DEV_Module_Init()!=0){
- return -1;
+__declspec(dllexport) SDL_Renderer* createRenderer(SDL_Window *win) {
+ SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
+ if (!ren) {
+ SDL_DestroyWindow(win);
+ printf("SDL_CreateRenderer Error: %s\n", SDL_GetError());
+ SDL_Quit();
+ return NULL;
}
+ return ren;
+}
- Debug("e-Paper Init and Clear...\r\n");
- EPD_2in13_V4_Init();
+__declspec(dllexport) int draw(SDL_Renderer *ren) {
+ SDL_SetRenderDrawColor(ren, 255, 255, 255, 255);
+ SDL_RenderClear(ren);
+ SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
+ SDL_RenderDrawLine(ren, 10, 10, 240, 112);
+ SDL_RenderDrawLine(ren, 240, 10, 10, 112);
+ SDL_RenderPresent(ren);
- struct timespec start={0,0}, finish={0,0};
- clock_gettime(CLOCK_REALTIME,&start);
- EPD_2in13_V4_Clear();
- clock_gettime(CLOCK_REALTIME,&finish);
- Debug("%ld S\r\n",finish.tv_sec-start.tv_sec);
-
- //Create a new image cache
- UBYTE *BlackImage;
- UWORD Imagesize = ((EPD_2in13_V4_WIDTH % 8 == 0)? (EPD_2in13_V4_WIDTH / 8 ): (EPD_2in13_V4_WIDTH / 8 + 1)) * EPD_2in13_V4_HEIGHT;
- if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
- Debug("Failed to apply for black memory...\r\n");
- return -1;
- }
- Debug("Paint_NewImage\r\n");
- Paint_NewImage(BlackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 90, WHITE);
- Paint_Clear(WHITE);
-
-#if 1 // show bmp
- Paint_NewImage(BlackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 90, WHITE);
- Debug("show window BMP-----------------\r\n");
- Paint_SelectImage(BlackImage);
- GUI_ReadBmp("./pic/100x100.bmp", 10, 10);
- EPD_2in13_V4_Display(BlackImage);
- DEV_Delay_ms(3000);
-
- Debug("show bmp------------------------\r\n");
- Paint_SelectImage(BlackImage);
- GUI_ReadBmp("./pic/2in13_1.bmp", 0, 0);
- EPD_2in13_V4_Display(BlackImage);
- DEV_Delay_ms(3000);
-#endif
-
-#if 1 //show image for array
- Debug("show image for array\r\n");
- EPD_2in13_V4_Init_Fast();
- Paint_SelectImage(BlackImage);
- Paint_Clear(WHITE);
- Paint_DrawBitMap(gImage_2in13_2);
-
- EPD_2in13_V4_Display_Fast(BlackImage);
- DEV_Delay_ms(2000);
-#endif
-
-#if 1 // Drawing on the image
- Paint_NewImage(BlackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 90, WHITE);
- Debug("Drawing\r\n");
- //1.Select Image
- EPD_2in13_V4_Init();
- Paint_SelectImage(BlackImage);
- Paint_Clear(WHITE);
-
- // 2.Drawing on the image
- Paint_DrawPoint(5, 10, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
- Paint_DrawPoint(5, 25, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
- Paint_DrawPoint(5, 40, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
- Paint_DrawPoint(5, 55, BLACK, DOT_PIXEL_4X4, DOT_STYLE_DFT);
-
- Paint_DrawLine(20, 10, 70, 60, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
- Paint_DrawLine(70, 10, 20, 60, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
- Paint_DrawRectangle(20, 10, 70, 60, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
- Paint_DrawRectangle(85, 10, 135, 60, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
-
- Paint_DrawLine(45, 15, 45, 55, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
- Paint_DrawLine(25, 35, 70, 35, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
- Paint_DrawCircle(45, 35, 20, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
- Paint_DrawCircle(110, 35, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
-
- Paint_DrawString_EN(140, 15, "waveshare", &Font16, BLACK, WHITE);
- Paint_DrawNum(140, 40, 123456789, &Font16, BLACK, WHITE);
-
- Paint_DrawString_CN(140, 60, "ÄãºÃabc", &Font12CN, BLACK, WHITE);
- Paint_DrawString_CN(5, 65, "΢ѩµç×Ó", &Font24CN, WHITE, BLACK);
-
- EPD_2in13_V4_Display_Base(BlackImage);
- DEV_Delay_ms(3000);
-#endif
-
-#if 1 //Partial refresh, example shows time
- Paint_NewImage(BlackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 90, WHITE);
- Debug("Partial refresh\r\n");
- Paint_SelectImage(BlackImage);
-
- PAINT_TIME sPaint_time;
- sPaint_time.Hour = 12;
- sPaint_time.Min = 34;
- sPaint_time.Sec = 56;
- UBYTE num = 10;
- for (;;) {
- sPaint_time.Sec = sPaint_time.Sec + 1;
- if (sPaint_time.Sec == 60) {
- sPaint_time.Min = sPaint_time.Min + 1;
- sPaint_time.Sec = 0;
- if (sPaint_time.Min == 60) {
- sPaint_time.Hour = sPaint_time.Hour + 1;
- sPaint_time.Min = 0;
- if (sPaint_time.Hour == 24) {
- sPaint_time.Hour = 0;
- sPaint_time.Min = 0;
- sPaint_time.Sec = 0;
- }
- }
- }
- Paint_ClearWindows(150, 80, 150 + Font20.Width * 7, 80 + Font20.Height, WHITE);
- Paint_DrawTime(150, 80, &sPaint_time, &Font20, WHITE, BLACK);
-
- num = num - 1;
- if(num == 0) {
- break;
- }
- EPD_2in13_V4_Display_Partial(BlackImage);
- DEV_Delay_ms(500);//Analog clock 1s
- }
-#endif
-
- Debug("Clear...\r\n");
- EPD_2in13_V4_Init();
- EPD_2in13_V4_Clear();
-
- Debug("Goto Sleep...\r\n");
- EPD_2in13_V4_Sleep();
- free(BlackImage);
- BlackImage = NULL;
- 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;
-}
\ No newline at end of file
+}
+
+__declspec(dllexport) int destroy(SDL_Renderer *ren, SDL_Window *win) {
+ if (!ren) {
+ SDL_DestroyRenderer(ren);
+ }
+ if (!win) {
+ SDL_DestroyWindow(win);
+ }
+}
diff --git a/c/p2fa.h b/c/p2fa.h
index 1eea40a..ccb9e87 100644
--- a/c/p2fa.h
+++ b/c/p2fa.h
@@ -2,9 +2,17 @@
// Created by steven on 11/14/2024.
//
+#include "libs/include/SDL2/SDL.h"
+
#ifndef P2FA_P2FA_H
#define P2FA_P2FA_H
#endif //P2FA_P2FA_H
-__declspec(dllexport) int draw();
\ No newline at end of file
+__declspec(dllexport) SDL_Window* createWindow();
+
+__declspec(dllexport) SDL_Renderer* createRenderer(SDL_Window*);
+
+__declspec(dllexport) int draw(SDL_Renderer*);
+
+__declspec(dllexport) int destroy(SDL_Renderer*, SDL_Window*);
\ No newline at end of file
diff --git a/go.mod b/go/go.mod
similarity index 100%
rename from go.mod
rename to go/go.mod
diff --git a/go.sum b/go/go.sum
similarity index 100%
rename from go.sum
rename to go/go.sum
diff --git a/main.go b/go/main.go
similarity index 94%
rename from main.go
rename to go/main.go
index 5e5ff46..14285f0 100644
--- a/main.go
+++ b/go/main.go
@@ -1,19 +1,10 @@
package main
-/*
-#cgo CFLAGS: -I.
-#cgo LDFLAGS: -L. -llibp2fa
-
-#include "p2fa.h"
-*/
-import "C"
-
import (
"crypto/hmac"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
- "fmt"
"github.com/creachadair/otp"
"hash"
"log"
@@ -139,11 +130,9 @@ func getTimeRemaining(n int) uint64 {
}
func main() {
- loadConfigs()
+ //loadConfigs()
- var rand C.int = C.draw()
-
- fmt.Printf("Rand: %d\n", int(rand))
+ startUI()
//refreshTokenVar()
//
diff --git a/go/ui.go b/go/ui.go
new file mode 100644
index 0000000..60d8039
--- /dev/null
+++ b/go/ui.go
@@ -0,0 +1,36 @@
+package main
+
+/*
+#cgo CFLAGS: -I.
+#cgo LDFLAGS: -L. -llibp2fa -lSDL2 -lSDL2main
+
+#include "../c/libs/include/SDL2/SDL.h"
+#include "../c/p2fa.h"
+*/
+import "C"
+
+import (
+ "time"
+ "unsafe"
+)
+
+func startUI() {
+ if C.SDL_Init(C.SDL_INIT_VIDEO) != 0 {
+ panic("Failed to initialize SDL")
+ }
+ defer C.SDL_Quit()
+
+ window := C.createWindow()
+ if window == nil {
+ panic("Error creating window")
+ }
+
+ renderer := C.createRenderer((*C.SDL_Window)(unsafe.Pointer(window)))
+ if renderer == nil {
+ panic("Error creating renderer")
+ }
+ C.draw(renderer)
+
+ time.Sleep(10 * time.Second)
+ C.destroy(renderer, window)
+}
diff --git a/p2fa.h b/p2fa.h
deleted file mode 100644
index 1eea40a..0000000
--- a/p2fa.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//
-// Created by steven on 11/14/2024.
-//
-
-#ifndef P2FA_P2FA_H
-#define P2FA_P2FA_H
-
-#endif //P2FA_P2FA_H
-
-__declspec(dllexport) int draw();
\ No newline at end of file