From 0847c52728cc28dab2609e80b0d9c95c5243cf49 Mon Sep 17 00:00:00 2001 From: Krad Date: Tue, 7 Dec 2021 15:15:05 +0800 Subject: [PATCH] Add ShimLib.c --- .gitignore | 1 - src/ShimLib/ShimLib.c | 115 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/ShimLib/ShimLib.c diff --git a/.gitignore b/.gitignore index 439fef0..cd14e6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ /cmake-build-debug/ /.idea/* /.idea/ -/src/ShimLib/ShimLib.c /project/ /src/styles/ /cmake-build-release/ diff --git a/src/ShimLib/ShimLib.c b/src/ShimLib/ShimLib.c new file mode 100644 index 0000000..15652be --- /dev/null +++ b/src/ShimLib/ShimLib.c @@ -0,0 +1,115 @@ +#include +#include +#include "ShimLib.h" +typedef void(*error_cb)(const char * msg); + +int statusCountFlag = 0; +error_cb innerCallback = NULL; + + +int InitLib(error_cb cb ){ + innerCallback = cb; + return 0; +} + +int ScanControl(ScanAction actionType){ + switch (actionType) { + case SCAN: + printf("Do Scan!\r\n"); + statusCountFlag = 2; + break; + case PREVIEW_SCAN: + statusCountFlag = 1; + printf("Do preview!\r\n"); + break; + case STOP: + statusCountFlag = 0; + printf("Stop everything!\r\n"); + break; + } + return 0; +} + +StatusInfo GetStatus(){ + StatusInfo inf; + switch(statusCountFlag) + { + case 0: + inf.status = READY; + break; + case 1: + inf.status = SCANNING; + inf.progress = 0.0f; + break; + case 2: + inf.status = SCANNING; + inf.progress = 0.3f; + statusCountFlag++; + break; + case 3: + inf.status = SCANNING; + inf.progress = 0.6f; + statusCountFlag++; + break; + case 4: + inf.status = SCANNING; + inf.progress = 0.9f; + statusCountFlag++; + break; + case 5: + inf.status = SCANNING; + inf.progress = 1.0f; + statusCountFlag=0; + break; + case 6: +// case 7: +// inf.status = BUSY; +// statusCountFlag++; +// break; +// case 8: + inf.status = BUSY; + statusCountFlag=0; + break; + default: + inf.status = BUSY; + statusCountFlag=0; + } + return inf; +} + +//result, 0 success, other false +int SetScanInfo(const char * jsonString, int empty){ + return 0; +} + +int preivew_change_flag = 0; + +const size_t Row = 140; +const size_t Col = 140; + +#define BUFFER_SIZE Row * Col + +const char * FRAME_FILE_PATH_1 = "./img1_v2.bin"; +const char * FRAME_FILE_PATH_2 = "./pre_image.bin"; +const char * GetPreviewData(){ + FILE *file; + preivew_change_flag++; + preivew_change_flag = preivew_change_flag%2; +// _sleep(2000); + if(file = fopen(preivew_change_flag?FRAME_FILE_PATH_1:FRAME_FILE_PATH_2,"rb")){ + unsigned char * buffer = malloc(sizeof(unsigned char)*BUFFER_SIZE); + fread(buffer, sizeof(unsigned char),BUFFER_SIZE, file); + fclose(file); + return buffer; + } + + return NULL; +} + +const char * GetDeviceInfo(DeviceInfo infoType){ + switch (infoType) { + case MEAN_TEMPERATURE: + return "28"; + } + return ""; +}