diff --git a/Makefile b/Makefile index 2078c3e..9ca760e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC=gcc -CC_FLAGS=-c -Wall -Werror -std=c99 -g -CC_LIBS= +CC_FLAGS=-c -Wall -Werror -std=gnu99 -g +CC_LIBS=-pthread INCLUDES= SOURCES=main.c printx.c ui.c diff --git a/main.c b/main.c index 78579ca..f16df20 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,17 @@ #include +#include #include "printx.h" #include "ui.h" +#include + int main(void) { + pthread_t tUI, tNFC, tHVC; + tNFC = 0; + tHVC = 0; + tHVC = tNFC; + tNFC = tHVC; initUILog(); if(!initLog()) { @@ -11,7 +19,11 @@ int main(void) return 1; } printx(INFO, "Tweekd starting\n"); + printx(DEBUG, "Creating processes\n"); displayUI(); + close(1);// Black Magic Operating + pthread_create(&tUI, NULL, drawUI, NULL); + pthread_join(tUI, NULL); closeLog(); return 0; } diff --git a/ui.c b/ui.c index 7775edc..c19a265 100644 --- a/ui.c +++ b/ui.c @@ -9,6 +9,8 @@ #define HEADER_TEXT_LENGTH 24 #define LOG_LINES 25 #define LOG_LENGTH 69 +#define IPS 20 +#define SCREEN_TIME 1000000/IPS char tmpretheader[HEADER_TEXT_LENGTH+1]; char tmpretlog[HEADER_TEXT_LENGTH+1]; @@ -16,9 +18,26 @@ char uilog[LOG_LINES][LOG_LENGTH]; char started[TIME_LENGTH]; char uid[HEADER_TEXT_LENGTH]; char uidDate[HEADER_TEXT_LENGTH]; +pid_t mainPid; + +void* drawUI(void* we) +{ + while(1) + { + printf("\x1b[2J\x1b[1;1H"); + displayUI(); + usleep(SCREEN_TIME); + } + + return NULL; +} void initUILog() { + tmpretheader[0]='\0'; + tmpretlog[0]='\0'; + started[0]='\0'; + mainPid = getpid(); uid[0]='\0'; uidDate[0]='\0'; for(int i=0; i=0; i--) strcpy(uilog[i+1], uilog[i]); strcpy(uilog[0], newStr); } @@ -70,13 +89,13 @@ void displayUI() printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(started)); sprintf(buffer, "%s", strlen(uidDate) > 0 ? uidDate : "Waiting for a tag"); printf("%s \u2503\n", fillHeaderWithSpaces(buffer)); - sprintf(buffer, "PID %d", getpid()); + sprintf(buffer, "PID %d", mainPid); printf("\u2503 %s \u2503 P R O J E C T \u2503 ", fillHeaderWithSpaces(buffer)); sprintf(buffer, "UID : %s", strlen(uid) > 0 ? uid : "Nope"); printf("%s \u2503\n", fillHeaderWithSpaces(buffer)); printf("\u2523\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u252B\n"); //body for(int i=0; i