Commit 19082eeb4c7c2de6d4ffac2911d549be376cc876

Authored by henyxia
1 parent cdaa873f

UI design not working anymore but some issues were fixed

Showing 3 changed files with 55 additions and 30 deletions   Show diff stats
... ... @@ -7,11 +7,8 @@
7 7  
8 8 int main(void)
9 9 {
10   - pthread_t tUI, tNFC, tHVC;
11   - tNFC = 0;
12   - tHVC = 0;
13   - tHVC = tNFC;
14   - tNFC = tHVC;
  10 + int ret;
  11 + pthread_t tUI;//, tNFC;//tHVC
15 12 initUILog();
16 13 if(!initLog())
17 14 {
... ... @@ -21,8 +18,10 @@ int main(void)
21 18 printx(INFO, "Tweekd starting\n");
22 19 printx(DEBUG, "Creating processes\n");
23 20 displayUI();
24   - close(1);// Black Magic Operating
25   - pthread_create(&tUI, NULL, drawUI, NULL);
  21 + ret = pthread_create(&tUI, NULL, drawUI, NULL);
  22 + printx(DEBUG, "UI Started ID %08x ret %d\n", tUI, ret);
  23 + printx(INFO, "Initializing NFC");
  24 + //pthread_create(&tNFC, NULL,
26 25 pthread_join(tUI, NULL);
27 26 closeLog();
28 27 return 0;
... ...
printx.c
... ... @@ -50,13 +50,13 @@ void closeLog()
50 50  
51 51 void printx(severity s, char* str, ...)
52 52 {
53   - char buffer[MAX_BUFFER];
  53 + char buffer1[MAX_BUFFER];
54 54 char buffer2[MAX_BUFFER];
55 55 va_list arglist;
56 56 va_start(arglist, str);
57   - vsprintf(buffer, str, arglist);
58   - fprintf(logfile, buffer);
59   - sprintf(buffer2, "%s%s%s", s_color[s], buffer, S_RESET);
  57 + vsprintf(buffer1, str, arglist);
  58 + fprintf(logfile, buffer1);
  59 + sprintf(buffer2, "%s%s%s", s_color[s], buffer1, S_RESET);
60 60 removeCharFromString('\n', buffer2);
61 61 addToLog(buffer2);
62 62 va_end(arglist);
... ...
... ... @@ -11,9 +11,8 @@
11 11 #define LOG_LENGTH 69
12 12 #define IPS 20
13 13 #define SCREEN_TIME 1000000/IPS
  14 +#define SPACES " "
14 15  
15   -char tmpretheader[HEADER_TEXT_LENGTH+1];
16   -char tmpretlog[HEADER_TEXT_LENGTH+1];
17 16 char uilog[LOG_LINES][LOG_LENGTH];
18 17 char started[TIME_LENGTH];
19 18 char uid[HEADER_TEXT_LENGTH];
... ... @@ -34,8 +33,6 @@ void* drawUI(void* we)
34 33  
35 34 void initUILog()
36 35 {
37   - tmpretheader[0]='\0';
38   - tmpretlog[0]='\0';
39 36 started[0]='\0';
40 37 mainPid = getpid();
41 38 uid[0]='\0';
... ... @@ -44,13 +41,18 @@ void initUILog()
44 41 uilog[i][0] = '\0';
45 42 }
46 43  
47   -char* fillHeaderWithSpaces(char* text)
  44 +char* fillHeaderWithSpaces(char* buf, char* text)
48 45 {
  46 + char tmpretheader[HEADER_TEXT_LENGTH+1];
49 47 strcpy(tmpretheader, text);
50 48 while(strlen(tmpretheader) < HEADER_TEXT_LENGTH)
51 49 strcat(tmpretheader, " ");
52 50  
53   - return tmpretheader;
  51 + for(int i=0; i<strlen(tmpretheader); i++)
  52 + buf[i] = tmpretheader[i];
  53 + buf[strlen(tmpretheader)] = '\0';
  54 +
  55 + return buf;
54 56 }
55 57  
56 58 void addToLog(char* newStr)
... ... @@ -60,9 +62,11 @@ void addToLog(char* newStr)
60 62 strcpy(uilog[0], newStr);
61 63 }
62 64  
63   -char* fillLogWithSpaces(char* text)
  65 +char* fillLogWithSpaces(char* buf, char* text)
64 66 {
65   - strcpy(tmpretlog, text);
  67 +/*
  68 + char tmpretlog[LOG_LENGTH];
  69 + strncpy(tmpretlog, text, LOG_LENGTH);
66 70 if(strlen(text) > 0)
67 71 while((strlen(tmpretlog)-12) < LOG_LENGTH)
68 72 strcat(tmpretlog, " ");
... ... @@ -70,7 +74,25 @@ char* fillLogWithSpaces(char* text)
70 74 while(strlen(tmpretlog) < LOG_LENGTH)
71 75 strcat(tmpretlog, " ");
72 76  
73   - return tmpretlog;
  77 +// int j;
  78 +// printf("J val\n");
  79 +// printf("%d\n", j);
  80 + for(int j=0; j<strlen(tmpretlog); j++)
  81 + buf[j] = tmpretlog[j];
  82 + buf[strlen(tmpretlog)] = '\0';
  83 +*/
  84 + strncpy(buf, text, LOG_LENGTH);
  85 + /*
  86 + if(strlen(buf) > 0)
  87 + while((strlen(buf)-12) < LOG_LENGTH)
  88 + strcat(buf, " ");
  89 + else
  90 + while(strlen(buf) < LOG_LENGTH)
  91 + strcat(buf, " ");
  92 + */
  93 + //strncat(buf, SPACES, LOG_LENGTH-strlen(buf));
  94 +
  95 + return buf;
74 96 }
75 97  
76 98  
... ... @@ -81,21 +103,25 @@ void setStartTime(char* sT)
81 103  
82 104 void displayUI()
83 105 {
84   - char buffer[HEADER_TEXT_LENGTH];
  106 + char buffer[LOG_LENGTH];
85 107 //header
86 108 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");
87   - printf("\u2503 %s \u2503 T H E \u2503", fillHeaderWithSpaces("Started since"));
88   - printf(" %s \u2503\n", fillHeaderWithSpaces("No Tag Detected"));
89   - printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(started));
  109 + printf("\u2503 %s \u2503 T H E \u2503", fillHeaderWithSpaces(buffer, "Started since"));
  110 + printf(" %s \u2503\n", fillHeaderWithSpaces(buffer, "No Tag Detected"));
  111 + printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(buffer, started));
90 112 sprintf(buffer, "%s", strlen(uidDate) > 0 ? uidDate : "Waiting for a tag");
91   - printf("%s \u2503\n", fillHeaderWithSpaces(buffer));
  113 + printf("%s \u2503\n", fillHeaderWithSpaces(buffer, buffer));
92 114 sprintf(buffer, "PID %d", mainPid);
93   - printf("\u2503 %s \u2503 P R O J E C T \u2503 ", fillHeaderWithSpaces(buffer));
  115 + printf("\u2503 %s \u2503 P R O J E C T \u2503 ", fillHeaderWithSpaces(buffer, buffer));
94 116 sprintf(buffer, "UID : %s", strlen(uid) > 0 ? uid : "Nope");
95   - printf("%s \u2503\n", fillHeaderWithSpaces(buffer));
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");
  117 + printf("%s \u2503\n", fillHeaderWithSpaces(buffer, buffer));
  118 + 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");
97 119 //body
98   - for(int i=0; i<LOG_LINES; i++)
99   - printf("\u2503 %s \u2503\n", fillLogWithSpaces(uilog[LOG_LINES-i-1]));
  120 + int i=0;
  121 + while(i<LOG_LINES)
  122 + {
  123 + printf("\u2503 %s \u2503\n", fillLogWithSpaces(buffer, uilog[LOG_LINES-i-1]));
  124 + i++;
  125 + }
100 126 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");
101 127 }
... ...