From ac55328a023270dc55e5e5a99c2bc9a3a1873885 Mon Sep 17 00:00:00 2001 From: henyxia Date: Wed, 22 Apr 2015 15:38:48 +0200 Subject: [PATCH] No more UI --- main.c | 3 ++- printx.c | 3 +-- ui.c | 140 ++++++++------------------------------------------------------------------------------------------------------------------------------------ ui.h | 2 -- 4 files changed, 11 insertions(+), 137 deletions(-) diff --git a/main.c b/main.c index 3ddd5aa..80e5428 100644 --- a/main.c +++ b/main.c @@ -23,7 +23,6 @@ int main(void) } printx(INFO, MAIN, "Tweekd starting\n"); printx(DEBUG, MAIN, "Creating processes\n"); - displayUI(); ret = pthread_create(&tUI, NULL, drawUI, NULL); printx(DEBUG, MAIN, "UI Started ID %08x ret %d\n", tUI, ret); printx(INFO, MAIN, "Initializing NFC"); @@ -45,6 +44,8 @@ int main(void) return 4; } pthread_create(&tHVC, NULL, processHVC, NULL); + //initProcessHeat(); + pthread_join(tUI, NULL); closeLog(); return 0; diff --git a/printx.c b/printx.c index 6f515fb..912cb3a 100644 --- a/printx.c +++ b/printx.c @@ -63,7 +63,6 @@ void printx(severity s, msgfrom from, char* str, ...) fprintf(logfile, "[%6f] : %s", (now - start)/CLOCKS_PER_SEC, buffer1); fflush(logfile); sprintf(buffer2, "[%s] %s%s%s", f_name[from], s_color[s], buffer1, S_RESET); - removeCharFromString('\n', buffer2); - addToLog(buffer2); + printf("%s", buffer2); va_end(arglist); } diff --git a/ui.c b/ui.c index d634e89..8029f41 100644 --- a/ui.c +++ b/ui.c @@ -15,8 +15,6 @@ #define IPS 20 #define SCREEN_TIME 1000000/IPS #define SPACES " " - -char uilog[LOG_LINES][LOG_LENGTH]; char started[TIME_LENGTH]; char uid[HEADER_TEXT_LENGTH]; char uidDate[HEADER_TEXT_LENGTH]; @@ -54,29 +52,24 @@ void setDebit(unsigned int d) debit = d; } +void processScreen() +{ + +} + void* drawUI(void* we) { while(!uiStop) { - printf("\x1b[2J\x1b[1;1H"); - displayUI(); + //printf("\x1b[2J\x1b[1;1H"); + //displayUI(); + processScreen(); usleep(SCREEN_TIME); } return NULL; } -void setDFG(void) -{ - if(tcgetattr(0, &old)<0) - perror("tcsetattr()"); - old.c_lflag&=~ICANON; - old.c_cc[VMIN]=1; - old.c_cc[VTIME]=0; - if(tcsetattr(0, TCSANOW, &old)<0) - perror("tcsetattr ICANON"); -} - void setTagName(char* tag) { time_t now = time(NULL); @@ -86,14 +79,11 @@ void setTagName(char* tag) void initUILog() { - setDFG(); cmd[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); -} - -char* fillLogWithSpaces(char* buf, char* text) -{ - strncpy(buf, text, LOG_LENGTH); - if(strlen(buf) > 0) - strncat(buf, SPACES, LOG_LENGTH-strlen(buf)-1); - else - strncat(buf, SPACES, LOG_LENGTH-strlen(buf)-1-12); - - return buf; -} - -char* fillStatusWithSpaces(char* buf, char* text) -{ - //TODO - //strncpy(buf, text, LOG_LENGTH); - //strncat(buf, SPACES, LOG_LENGTH-strlen(buf)-1-8); - - return buf; -} - void setStartTime(char* sT) { strcpy(started, sT); } - -char getch() -{ - char buf=0; - if(read(0,&buf,1)<0) - perror("read()"); - return buf; -} - -void displayUI() -{ - char buffer[LOG_LENGTH]; - struct timeval tv = {0, 5000}; - char bufferO[4] = {0, 0, 0, 0}; - fd_set rdfs; - FD_ZERO(&rdfs); - FD_SET(STDIN_FILENO, &rdfs); - select(1, &rdfs, NULL, NULL, &tv); - //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(buffer, "Started since")); - sprintf(buffer, "%s", strlen(uidDate) > 0 ? uidDate : "Waiting for a tag"); - printf(" %s \u2503\n", fillHeaderWithSpaces(buffer, buffer)); - printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(buffer, started)); - printf("%s \u2503\n", fillHeaderWithSpaces(buffer, " ")); - sprintf(buffer, "PID %d", mainPid); - 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, 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"); - sprintf(buffer, "\u2503 HEAT[%s] %02.1f\u2103 PUMP[%s] %04d", heat ? "ON " : "OFF", 25 + (((float)(80*temp)))/255, pump ? "ON " : "OFF", debit); - printf("%s \u2503\n", fillStatusWithSpaces(buffer, 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\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\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u252B\n"); - //body - int i=0; - while(i= 65 && bufferO[0] <= 90 && bufferO[1] == '\0') - { - sprintf(buffer, "%c", bufferO[0] + 32); - strcat(cmd, buffer); - } - else if(bufferO[0] >= 97 && bufferO[0] <= 122 && bufferO[1] == '\0') - { - sprintf(buffer, "%c", bufferO[0]); - strcat(cmd, buffer); - } - else if(bufferO[0] >= 48 && bufferO[0] <= 57) - { - sprintf(buffer, "%c", bufferO[0]); - strcat(cmd, buffer); - } - else if(bufferO[0] == 32) - { - sprintf(buffer, "%c", bufferO[0]); - strcat(cmd, buffer); - } - else if(bufferO[0] == 10) - { - sendToBus(cmd); - cmd[0]='\0'; - } - else if(bufferO[0] == 127) - { - if(strlen(cmd)>0) - cmd[strlen(cmd)-1]='\0'; - } - else - { - //sprintf(buffer, "Unrecognized %02x", bufferO[0]); - //strcat(cmd, buffer); - } - } - sprintf(buffer, "\u2503> %s", cmd); - printf("%s\u2503\n", fillStatusWithSpaces(buffer, buffer)); - printf("\u2517\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\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\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B\n"); - printf("\x1b[2A\x1b[%dC",(int)(strlen(cmd)) + 3); - fflush(stdout); -} diff --git a/ui.h b/ui.h index 773cd48..40822f7 100644 --- a/ui.h +++ b/ui.h @@ -5,8 +5,6 @@ void* drawUI(void*); void initUILog(); -void addToLog(char*); -void displayUI(); void setDebit(unsigned int); void setHeat(bool); void setPump(bool); -- libgit2 0.21.2