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
Makefile
1 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 4 INCLUDES=
5 5  
6 6 SOURCES=main.c printx.c ui.c
... ...
1 1 #include <stdio.h>
  2 +#include <pthread.h>
2 3 #include "printx.h"
3 4 #include "ui.h"
4 5  
  6 +#include <unistd.h>
  7 +
5 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 15 initUILog();
8 16 if(!initLog())
9 17 {
... ... @@ -11,7 +19,11 @@ int main(void)
11 19 return 1;
12 20 }
13 21 printx(INFO, "Tweekd starting\n");
  22 + printx(DEBUG, "Creating processes\n");
14 23 displayUI();
  24 + close(1);// Black Magic Operating
  25 + pthread_create(&tUI, NULL, drawUI, NULL);
  26 + pthread_join(tUI, NULL);
15 27 closeLog();
16 28 return 0;
17 29 }
... ...
... ... @@ -9,6 +9,8 @@
9 9 #define HEADER_TEXT_LENGTH 24
10 10 #define LOG_LINES 25
11 11 #define LOG_LENGTH 69
  12 +#define IPS 20
  13 +#define SCREEN_TIME 1000000/IPS
12 14  
13 15 char tmpretheader[HEADER_TEXT_LENGTH+1];
14 16 char tmpretlog[HEADER_TEXT_LENGTH+1];
... ... @@ -16,9 +18,26 @@ char uilog[LOG_LINES][LOG_LENGTH];
16 18 char started[TIME_LENGTH];
17 19 char uid[HEADER_TEXT_LENGTH];
18 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 35 void initUILog()
21 36 {
  37 + tmpretheader[0]='\0';
  38 + tmpretlog[0]='\0';
  39 + started[0]='\0';
  40 + mainPid = getpid();
22 41 uid[0]='\0';
23 42 uidDate[0]='\0';
24 43 for(int i=0; i<LOG_LINES; i++)
... ... @@ -36,7 +55,7 @@ char* fillHeaderWithSpaces(char* text)
36 55  
37 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 59 strcpy(uilog[i+1], uilog[i]);
41 60 strcpy(uilog[0], newStr);
42 61 }
... ... @@ -70,13 +89,13 @@ void displayUI()
70 89 printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(started));
71 90 sprintf(buffer, "%s", strlen(uidDate) > 0 ? uidDate : "Waiting for a tag");
72 91 printf("%s \u2503\n", fillHeaderWithSpaces(buffer));
73   - sprintf(buffer, "PID %d", getpid());
  92 + sprintf(buffer, "PID %d", mainPid);
74 93 printf("\u2503 %s \u2503 P R O J E C T \u2503 ", fillHeaderWithSpaces(buffer));
75 94 sprintf(buffer, "UID : %s", strlen(uid) > 0 ? uid : "Nope");
76 95 printf("%s \u2503\n", fillHeaderWithSpaces(buffer));
77 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 97 //body
79 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 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 1 #ifndef __UI_H__
2 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 10 #endif
... ...