Commit cdaa873f177705e6fb60f5272515ade56ea5419a

Authored by henyxia
1 parent 8fbf5343

Log fixed

UI is now threaded @ 20 IPS
Showing 4 changed files with 41 additions and 9 deletions   Show diff stats
1 CC=gcc 1 CC=gcc
2 -CC_FLAGS=-c -Wall -Werror -std=c99 -g  
3 -CC_LIBS= 2 +CC_FLAGS=-c -Wall -Werror -std=gnu99 -g
  3 +CC_LIBS=-pthread
4 INCLUDES= 4 INCLUDES=
5 5
6 SOURCES=main.c printx.c ui.c 6 SOURCES=main.c printx.c ui.c
1 #include <stdio.h> 1 #include <stdio.h>
  2 +#include <pthread.h>
2 #include "printx.h" 3 #include "printx.h"
3 #include "ui.h" 4 #include "ui.h"
4 5
  6 +#include <unistd.h>
  7 +
5 int main(void) 8 int main(void)
6 { 9 {
  10 + pthread_t tUI, tNFC, tHVC;
  11 + tNFC = 0;
  12 + tHVC = 0;
  13 + tHVC = tNFC;
  14 + tNFC = tHVC;
7 initUILog(); 15 initUILog();
8 if(!initLog()) 16 if(!initLog())
9 { 17 {
@@ -11,7 +19,11 @@ int main(void) @@ -11,7 +19,11 @@ int main(void)
11 return 1; 19 return 1;
12 } 20 }
13 printx(INFO, "Tweekd starting\n"); 21 printx(INFO, "Tweekd starting\n");
  22 + printx(DEBUG, "Creating processes\n");
14 displayUI(); 23 displayUI();
  24 + close(1);// Black Magic Operating
  25 + pthread_create(&tUI, NULL, drawUI, NULL);
  26 + pthread_join(tUI, NULL);
15 closeLog(); 27 closeLog();
16 return 0; 28 return 0;
17 } 29 }
@@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
9 #define HEADER_TEXT_LENGTH 24 9 #define HEADER_TEXT_LENGTH 24
10 #define LOG_LINES 25 10 #define LOG_LINES 25
11 #define LOG_LENGTH 69 11 #define LOG_LENGTH 69
  12 +#define IPS 20
  13 +#define SCREEN_TIME 1000000/IPS
12 14
13 char tmpretheader[HEADER_TEXT_LENGTH+1]; 15 char tmpretheader[HEADER_TEXT_LENGTH+1];
14 char tmpretlog[HEADER_TEXT_LENGTH+1]; 16 char tmpretlog[HEADER_TEXT_LENGTH+1];
@@ -16,9 +18,26 @@ char uilog[LOG_LINES][LOG_LENGTH]; @@ -16,9 +18,26 @@ char uilog[LOG_LINES][LOG_LENGTH];
16 char started[TIME_LENGTH]; 18 char started[TIME_LENGTH];
17 char uid[HEADER_TEXT_LENGTH]; 19 char uid[HEADER_TEXT_LENGTH];
18 char uidDate[HEADER_TEXT_LENGTH]; 20 char uidDate[HEADER_TEXT_LENGTH];
  21 +pid_t mainPid;
  22 +
  23 +void* drawUI(void* we)
  24 +{
  25 + while(1)
  26 + {
  27 + printf("\x1b[2J\x1b[1;1H");
  28 + displayUI();
  29 + usleep(SCREEN_TIME);
  30 + }
  31 +
  32 + return NULL;
  33 +}
19 34
20 void initUILog() 35 void initUILog()
21 { 36 {
  37 + tmpretheader[0]='\0';
  38 + tmpretlog[0]='\0';
  39 + started[0]='\0';
  40 + mainPid = getpid();
22 uid[0]='\0'; 41 uid[0]='\0';
23 uidDate[0]='\0'; 42 uidDate[0]='\0';
24 for(int i=0; i<LOG_LINES; i++) 43 for(int i=0; i<LOG_LINES; i++)
@@ -36,7 +55,7 @@ char* fillHeaderWithSpaces(char* text) @@ -36,7 +55,7 @@ char* fillHeaderWithSpaces(char* text)
36 55
37 void addToLog(char* newStr) 56 void addToLog(char* newStr)
38 { 57 {
39 - for(int i=0; i<(LOG_LINES-1); i++) 58 + for(int i=LOG_LINES-2; i>=0; i--)
40 strcpy(uilog[i+1], uilog[i]); 59 strcpy(uilog[i+1], uilog[i]);
41 strcpy(uilog[0], newStr); 60 strcpy(uilog[0], newStr);
42 } 61 }
@@ -70,13 +89,13 @@ void displayUI() @@ -70,13 +89,13 @@ void displayUI()
70 printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(started)); 89 printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(started));
71 sprintf(buffer, "%s", strlen(uidDate) > 0 ? uidDate : "Waiting for a tag"); 90 sprintf(buffer, "%s", strlen(uidDate) > 0 ? uidDate : "Waiting for a tag");
72 printf("%s \u2503\n", fillHeaderWithSpaces(buffer)); 91 printf("%s \u2503\n", fillHeaderWithSpaces(buffer));
73 - sprintf(buffer, "PID %d", getpid()); 92 + sprintf(buffer, "PID %d", mainPid);
74 printf("\u2503 %s \u2503 P R O J E C T \u2503 ", fillHeaderWithSpaces(buffer)); 93 printf("\u2503 %s \u2503 P R O J E C T \u2503 ", fillHeaderWithSpaces(buffer));
75 sprintf(buffer, "UID : %s", strlen(uid) > 0 ? uid : "Nope"); 94 sprintf(buffer, "UID : %s", strlen(uid) > 0 ? uid : "Nope");
76 printf("%s \u2503\n", fillHeaderWithSpaces(buffer)); 95 printf("%s \u2503\n", fillHeaderWithSpaces(buffer));
77 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"); 96 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");
78 //body 97 //body
79 for(int i=0; i<LOG_LINES; i++) 98 for(int i=0; i<LOG_LINES; i++)
80 - printf("\u2503 %s \u2503\n", fillLogWithSpaces(uilog[i])); 99 + printf("\u2503 %s \u2503\n", fillLogWithSpaces(uilog[LOG_LINES-i-1]));
81 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"); 100 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");
82 } 101 }
1 #ifndef __UI_H__ 1 #ifndef __UI_H__
2 #define __UI_H__ 2 #define __UI_H__
3 3
4 -void initUILog();  
5 -void addToLog(char*);  
6 -void displayUI();  
7 -void setStartTime(char*); 4 +void* drawUI(void*);
  5 +void initUILog();
  6 +void addToLog(char*);
  7 +void displayUI();
  8 +void setStartTime(char*);
8 9
9 #endif 10 #endif