Commit ac55328a023270dc55e5e5a99c2bc9a3a1873885

Authored by henyxia
1 parent bb8c2799

No more UI

Showing 4 changed files with 11 additions and 137 deletions   Show diff stats
... ... @@ -23,7 +23,6 @@ int main(void)
23 23 }
24 24 printx(INFO, MAIN, "Tweekd starting\n");
25 25 printx(DEBUG, MAIN, "Creating processes\n");
26   - displayUI();
27 26 ret = pthread_create(&tUI, NULL, drawUI, NULL);
28 27 printx(DEBUG, MAIN, "UI Started ID %08x ret %d\n", tUI, ret);
29 28 printx(INFO, MAIN, "Initializing NFC");
... ... @@ -45,6 +44,8 @@ int main(void)
45 44 return 4;
46 45 }
47 46 pthread_create(&tHVC, NULL, processHVC, NULL);
  47 + //initProcessHeat();
  48 +
48 49 pthread_join(tUI, NULL);
49 50 closeLog();
50 51 return 0;
... ...
printx.c
... ... @@ -63,7 +63,6 @@ void printx(severity s, msgfrom from, char* str, ...)
63 63 fprintf(logfile, "[%6f] : %s", (now - start)/CLOCKS_PER_SEC, buffer1);
64 64 fflush(logfile);
65 65 sprintf(buffer2, "[%s] %s%s%s", f_name[from], s_color[s], buffer1, S_RESET);
66   - removeCharFromString('\n', buffer2);
67   - addToLog(buffer2);
  66 + printf("%s", buffer2);
68 67 va_end(arglist);
69 68 }
... ...
... ... @@ -15,8 +15,6 @@
15 15 #define IPS 20
16 16 #define SCREEN_TIME 1000000/IPS
17 17 #define SPACES " "
18   -
19   -char uilog[LOG_LINES][LOG_LENGTH];
20 18 char started[TIME_LENGTH];
21 19 char uid[HEADER_TEXT_LENGTH];
22 20 char uidDate[HEADER_TEXT_LENGTH];
... ... @@ -54,29 +52,24 @@ void setDebit(unsigned int d)
54 52 debit = d;
55 53 }
56 54  
  55 +void processScreen()
  56 +{
  57 +
  58 +}
  59 +
57 60 void* drawUI(void* we)
58 61 {
59 62 while(!uiStop)
60 63 {
61   - printf("\x1b[2J\x1b[1;1H");
62   - displayUI();
  64 + //printf("\x1b[2J\x1b[1;1H");
  65 + //displayUI();
  66 + processScreen();
63 67 usleep(SCREEN_TIME);
64 68 }
65 69  
66 70 return NULL;
67 71 }
68 72  
69   -void setDFG(void)
70   -{
71   - if(tcgetattr(0, &old)<0)
72   - perror("tcsetattr()");
73   - old.c_lflag&=~ICANON;
74   - old.c_cc[VMIN]=1;
75   - old.c_cc[VTIME]=0;
76   - if(tcsetattr(0, TCSANOW, &old)<0)
77   - perror("tcsetattr ICANON");
78   -}
79   -
80 73 void setTagName(char* tag)
81 74 {
82 75 time_t now = time(NULL);
... ... @@ -86,14 +79,11 @@ void setTagName(char* tag)
86 79  
87 80 void initUILog()
88 81 {
89   - setDFG();
90 82 cmd[0]='\0';
91 83 started[0]='\0';
92 84 mainPid = getpid();
93 85 uid[0]='\0';
94 86 uidDate[0]='\0';
95   - for(int i=0; i<LOG_LINES; i++)
96   - uilog[i][0] = '\0';
97 87 }
98 88  
99 89 char* fillHeaderWithSpaces(char* buf, char* text)
... ... @@ -110,121 +100,7 @@ char* fillHeaderWithSpaces(char* buf, char* text)
110 100 return buf;
111 101 }
112 102  
113   -void addToLog(char* newStr)
114   -{
115   - for(int i=LOG_LINES-3; i>=0; i--)
116   - strcpy(uilog[i+1], uilog[i]);
117   - strcpy(uilog[0], newStr);
118   -}
119   -
120   -char* fillLogWithSpaces(char* buf, char* text)
121   -{
122   - strncpy(buf, text, LOG_LENGTH);
123   - if(strlen(buf) > 0)
124   - strncat(buf, SPACES, LOG_LENGTH-strlen(buf)-1);
125   - else
126   - strncat(buf, SPACES, LOG_LENGTH-strlen(buf)-1-12);
127   -
128   - return buf;
129   -}
130   -
131   -char* fillStatusWithSpaces(char* buf, char* text)
132   -{
133   - //TODO
134   - //strncpy(buf, text, LOG_LENGTH);
135   - //strncat(buf, SPACES, LOG_LENGTH-strlen(buf)-1-8);
136   -
137   - return buf;
138   -}
139   -
140 103 void setStartTime(char* sT)
141 104 {
142 105 strcpy(started, sT);
143 106 }
144   -
145   -char getch()
146   -{
147   - char buf=0;
148   - if(read(0,&buf,1)<0)
149   - perror("read()");
150   - return buf;
151   -}
152   -
153   -void displayUI()
154   -{
155   - char buffer[LOG_LENGTH];
156   - struct timeval tv = {0, 5000};
157   - char bufferO[4] = {0, 0, 0, 0};
158   - fd_set rdfs;
159   - FD_ZERO(&rdfs);
160   - FD_SET(STDIN_FILENO, &rdfs);
161   - select(1, &rdfs, NULL, NULL, &tv);
162   - //header
163   - 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");
164   - printf("\u2503 %s \u2503 T H E \u2503", fillHeaderWithSpaces(buffer, "Started since"));
165   - sprintf(buffer, "%s", strlen(uidDate) > 0 ? uidDate : "Waiting for a tag");
166   - printf(" %s \u2503\n", fillHeaderWithSpaces(buffer, buffer));
167   - printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(buffer, started));
168   - printf("%s \u2503\n", fillHeaderWithSpaces(buffer, " "));
169   - sprintf(buffer, "PID %d", mainPid);
170   - printf("\u2503 %s \u2503 P R O J E C T \u2503 ", fillHeaderWithSpaces(buffer, buffer));
171   - sprintf(buffer, "UID : %s", strlen(uid) > 0 ? uid : "Nope");
172   - printf("%s \u2503\n", fillHeaderWithSpaces(buffer, buffer));
173   - 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");
174   - sprintf(buffer, "\u2503 HEAT[%s] %02.1f\u2103 PUMP[%s] %04d", heat ? "ON " : "OFF", 25 + (((float)(80*temp)))/255, pump ? "ON " : "OFF", debit);
175   - printf("%s \u2503\n", fillStatusWithSpaces(buffer, buffer));
176   - 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");
177   - //body
178   - int i=0;
179   - while(i<LOG_LINES)
180   - {
181   - printf("\u2503 %s \u2503\n", fillLogWithSpaces(buffer, uilog[LOG_LINES-i-1]));
182   - i++;
183   - }
184   - 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");
185   - //cmd
186   - if(FD_ISSET(STDIN_FILENO, &rdfs))
187   - {
188   - bufferO[0] = getch();
189   - if(bufferO[0] >= 65 && bufferO[0] <= 90 && bufferO[1] == '\0')
190   - {
191   - sprintf(buffer, "%c", bufferO[0] + 32);
192   - strcat(cmd, buffer);
193   - }
194   - else if(bufferO[0] >= 97 && bufferO[0] <= 122 && bufferO[1] == '\0')
195   - {
196   - sprintf(buffer, "%c", bufferO[0]);
197   - strcat(cmd, buffer);
198   - }
199   - else if(bufferO[0] >= 48 && bufferO[0] <= 57)
200   - {
201   - sprintf(buffer, "%c", bufferO[0]);
202   - strcat(cmd, buffer);
203   - }
204   - else if(bufferO[0] == 32)
205   - {
206   - sprintf(buffer, "%c", bufferO[0]);
207   - strcat(cmd, buffer);
208   - }
209   - else if(bufferO[0] == 10)
210   - {
211   - sendToBus(cmd);
212   - cmd[0]='\0';
213   - }
214   - else if(bufferO[0] == 127)
215   - {
216   - if(strlen(cmd)>0)
217   - cmd[strlen(cmd)-1]='\0';
218   - }
219   - else
220   - {
221   - //sprintf(buffer, "Unrecognized %02x", bufferO[0]);
222   - //strcat(cmd, buffer);
223   - }
224   - }
225   - sprintf(buffer, "\u2503> %s", cmd);
226   - printf("%s\u2503\n", fillStatusWithSpaces(buffer, buffer));
227   - 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");
228   - printf("\x1b[2A\x1b[%dC",(int)(strlen(cmd)) + 3);
229   - fflush(stdout);
230   -}
... ...
... ... @@ -5,8 +5,6 @@
5 5  
6 6 void* drawUI(void*);
7 7 void initUILog();
8   -void addToLog(char*);
9   -void displayUI();
10 8 void setDebit(unsigned int);
11 9 void setHeat(bool);
12 10 void setPump(bool);
... ...