From 19082eeb4c7c2de6d4ffac2911d549be376cc876 Mon Sep 17 00:00:00 2001 From: henyxia Date: Tue, 3 Mar 2015 13:39:30 +0100 Subject: [PATCH] UI design not working anymore but some issues were fixed --- main.c | 13 ++++++------- printx.c | 8 ++++---- ui.c | 64 +++++++++++++++++++++++++++++++++++++++++++++------------------- 3 files changed, 55 insertions(+), 30 deletions(-) diff --git a/main.c b/main.c index f16df20..ce812df 100644 --- a/main.c +++ b/main.c @@ -7,11 +7,8 @@ int main(void) { - pthread_t tUI, tNFC, tHVC; - tNFC = 0; - tHVC = 0; - tHVC = tNFC; - tNFC = tHVC; + int ret; + pthread_t tUI;//, tNFC;//tHVC initUILog(); if(!initLog()) { @@ -21,8 +18,10 @@ int main(void) printx(INFO, "Tweekd starting\n"); printx(DEBUG, "Creating processes\n"); displayUI(); - close(1);// Black Magic Operating - pthread_create(&tUI, NULL, drawUI, NULL); + ret = pthread_create(&tUI, NULL, drawUI, NULL); + printx(DEBUG, "UI Started ID %08x ret %d\n", tUI, ret); + printx(INFO, "Initializing NFC"); + //pthread_create(&tNFC, NULL, pthread_join(tUI, NULL); closeLog(); return 0; diff --git a/printx.c b/printx.c index cdac53f..62cfb2c 100644 --- a/printx.c +++ b/printx.c @@ -50,13 +50,13 @@ void closeLog() void printx(severity s, char* str, ...) { - char buffer[MAX_BUFFER]; + char buffer1[MAX_BUFFER]; char buffer2[MAX_BUFFER]; va_list arglist; va_start(arglist, str); - vsprintf(buffer, str, arglist); - fprintf(logfile, buffer); - sprintf(buffer2, "%s%s%s", s_color[s], buffer, S_RESET); + vsprintf(buffer1, str, arglist); + fprintf(logfile, buffer1); + sprintf(buffer2, "%s%s%s", s_color[s], buffer1, S_RESET); removeCharFromString('\n', buffer2); addToLog(buffer2); va_end(arglist); diff --git a/ui.c b/ui.c index c19a265..d732182 100644 --- a/ui.c +++ b/ui.c @@ -11,9 +11,8 @@ #define LOG_LENGTH 69 #define IPS 20 #define SCREEN_TIME 1000000/IPS +#define SPACES " " -char tmpretheader[HEADER_TEXT_LENGTH+1]; -char tmpretlog[HEADER_TEXT_LENGTH+1]; char uilog[LOG_LINES][LOG_LENGTH]; char started[TIME_LENGTH]; char uid[HEADER_TEXT_LENGTH]; @@ -34,8 +33,6 @@ void* drawUI(void* we) void initUILog() { - tmpretheader[0]='\0'; - tmpretlog[0]='\0'; started[0]='\0'; mainPid = getpid(); uid[0]='\0'; @@ -44,13 +41,18 @@ void initUILog() uilog[i][0] = '\0'; } -char* fillHeaderWithSpaces(char* text) +char* fillHeaderWithSpaces(char* buf, char* text) { + char tmpretheader[HEADER_TEXT_LENGTH+1]; strcpy(tmpretheader, text); while(strlen(tmpretheader) < HEADER_TEXT_LENGTH) strcat(tmpretheader, " "); - return tmpretheader; + for(int i=0; i 0) while((strlen(tmpretlog)-12) < LOG_LENGTH) strcat(tmpretlog, " "); @@ -70,7 +74,25 @@ char* fillLogWithSpaces(char* text) while(strlen(tmpretlog) < LOG_LENGTH) strcat(tmpretlog, " "); - return tmpretlog; +// int j; +// printf("J val\n"); +// printf("%d\n", j); + for(int j=0; j 0) + while((strlen(buf)-12) < LOG_LENGTH) + strcat(buf, " "); + else + while(strlen(buf) < LOG_LENGTH) + strcat(buf, " "); + */ + //strncat(buf, SPACES, LOG_LENGTH-strlen(buf)); + + return buf; } @@ -81,21 +103,25 @@ void setStartTime(char* sT) void displayUI() { - char buffer[HEADER_TEXT_LENGTH]; + char buffer[LOG_LENGTH]; //header printf("\u250F\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\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\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\u2513\n"); - printf("\u2503 %s \u2503 T H E \u2503", fillHeaderWithSpaces("Started since")); - printf(" %s \u2503\n", fillHeaderWithSpaces("No Tag Detected")); - printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(started)); + printf("\u2503 %s \u2503 T H E \u2503", fillHeaderWithSpaces(buffer, "Started since")); + printf(" %s \u2503\n", fillHeaderWithSpaces(buffer, "No Tag Detected")); + printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(buffer, started)); sprintf(buffer, "%s", strlen(uidDate) > 0 ? uidDate : "Waiting for a tag"); - printf("%s \u2503\n", fillHeaderWithSpaces(buffer)); + printf("%s \u2503\n", fillHeaderWithSpaces(buffer, buffer)); sprintf(buffer, "PID %d", mainPid); - printf("\u2503 %s \u2503 P R O J E C T \u2503 ", fillHeaderWithSpaces(buffer)); + printf("\u2503 %s \u2503 P R O J E C T \u2503 ", fillHeaderWithSpaces(buffer, 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"); + printf("%s \u2503\n", fillHeaderWithSpaces(buffer, buffer)); + printf("\u2522\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