ea1218f1
henyxia
UI finished
|
1
2
3
4
5
6
7
8
9
10
11
|
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include "ui.h"
#define TIME_LENGTH 24
#define HEADER_TEXT_LENGTH 24
#define LOG_LINES 25
#define LOG_LENGTH 69
|
cdaa873f
henyxia
Log fixed
|
12
13
|
#define IPS 20
#define SCREEN_TIME 1000000/IPS
|
19082eeb
henyxia
UI design not wor...
|
14
|
#define SPACES " "
|
ea1218f1
henyxia
UI finished
|
15
|
|
ea1218f1
henyxia
UI finished
|
16
17
18
19
|
char uilog[LOG_LINES][LOG_LENGTH];
char started[TIME_LENGTH];
char uid[HEADER_TEXT_LENGTH];
char uidDate[HEADER_TEXT_LENGTH];
|
cdaa873f
henyxia
Log fixed
|
20
21
22
23
24
25
26
27
28
29
30
31
32
|
pid_t mainPid;
void* drawUI(void* we)
{
while(1)
{
printf("\x1b[2J\x1b[1;1H");
displayUI();
usleep(SCREEN_TIME);
}
return NULL;
}
|
ea1218f1
henyxia
UI finished
|
33
34
35
|
void initUILog()
{
|
cdaa873f
henyxia
Log fixed
|
36
37
|
started[0]='\0';
mainPid = getpid();
|
ea1218f1
henyxia
UI finished
|
38
39
40
41
42
43
|
uid[0]='\0';
uidDate[0]='\0';
for(int i=0; i<LOG_LINES; i++)
uilog[i][0] = '\0';
}
|
19082eeb
henyxia
UI design not wor...
|
44
|
char* fillHeaderWithSpaces(char* buf, char* text)
|
ea1218f1
henyxia
UI finished
|
45
|
{
|
19082eeb
henyxia
UI design not wor...
|
46
|
char tmpretheader[HEADER_TEXT_LENGTH+1];
|
ea1218f1
henyxia
UI finished
|
47
48
49
50
|
strcpy(tmpretheader, text);
while(strlen(tmpretheader) < HEADER_TEXT_LENGTH)
strcat(tmpretheader, " ");
|
19082eeb
henyxia
UI design not wor...
|
51
52
53
54
55
|
for(int i=0; i<strlen(tmpretheader); i++)
buf[i] = tmpretheader[i];
buf[strlen(tmpretheader)] = '\0';
return buf;
|
ea1218f1
henyxia
UI finished
|
56
57
58
59
|
}
void addToLog(char* newStr)
{
|
cdaa873f
henyxia
Log fixed
|
60
|
for(int i=LOG_LINES-2; i>=0; i--)
|
ea1218f1
henyxia
UI finished
|
61
62
63
64
|
strcpy(uilog[i+1], uilog[i]);
strcpy(uilog[0], newStr);
}
|
19082eeb
henyxia
UI design not wor...
|
65
|
char* fillLogWithSpaces(char* buf, char* text)
|
ea1218f1
henyxia
UI finished
|
66
|
{
|
19082eeb
henyxia
UI design not wor...
|
67
68
69
|
/*
char tmpretlog[LOG_LENGTH];
strncpy(tmpretlog, text, LOG_LENGTH);
|
ea1218f1
henyxia
UI finished
|
70
71
72
73
74
75
76
|
if(strlen(text) > 0)
while((strlen(tmpretlog)-12) < LOG_LENGTH)
strcat(tmpretlog, " ");
else
while(strlen(tmpretlog) < LOG_LENGTH)
strcat(tmpretlog, " ");
|
19082eeb
henyxia
UI design not wor...
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// int j;
// printf("J val\n");
// printf("%d\n", j);
for(int j=0; j<strlen(tmpretlog); j++)
buf[j] = tmpretlog[j];
buf[strlen(tmpretlog)] = '\0';
*/
strncpy(buf, text, LOG_LENGTH);
/*
if(strlen(buf) > 0)
while((strlen(buf)-12) < LOG_LENGTH)
strcat(buf, " ");
else
while(strlen(buf) < LOG_LENGTH)
strcat(buf, " ");
*/
//strncat(buf, SPACES, LOG_LENGTH-strlen(buf));
return buf;
|
ea1218f1
henyxia
UI finished
|
96
97
98
99
100
101
102
103
104
105
|
}
void setStartTime(char* sT)
{
strcpy(started, sT);
}
void displayUI()
{
|
19082eeb
henyxia
UI design not wor...
|
106
|
char buffer[LOG_LENGTH];
|
ea1218f1
henyxia
UI finished
|
107
108
|
//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");
|
19082eeb
henyxia
UI design not wor...
|
109
110
111
|
printf("\u2503 %s \u2503 T H E \u2503", fillHeaderWithSpaces(buffer, "Started since"));
printf(" %s \u2503\n", fillHeaderWithSpaces(buffer, "No Tag Detected"));
printf("\u2503 %s \u2503 T W E E K \u2503 ", fillHeaderWithSpaces(buffer, started));
|
ea1218f1
henyxia
UI finished
|
112
|
sprintf(buffer, "%s", strlen(uidDate) > 0 ? uidDate : "Waiting for a tag");
|
19082eeb
henyxia
UI design not wor...
|
113
|
printf("%s \u2503\n", fillHeaderWithSpaces(buffer, buffer));
|
cdaa873f
henyxia
Log fixed
|
114
|
sprintf(buffer, "PID %d", mainPid);
|
19082eeb
henyxia
UI design not wor...
|
115
|
printf("\u2503 %s \u2503 P R O J E C T \u2503 ", fillHeaderWithSpaces(buffer, buffer));
|
ea1218f1
henyxia
UI finished
|
116
|
sprintf(buffer, "UID : %s", strlen(uid) > 0 ? uid : "Nope");
|
19082eeb
henyxia
UI design not wor...
|
117
118
|
printf("%s \u2503\n", fillHeaderWithSpaces(buffer, buffer));
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");
|
ea1218f1
henyxia
UI finished
|
119
|
//body
|
19082eeb
henyxia
UI design not wor...
|
120
121
122
123
124
125
|
int i=0;
while(i<LOG_LINES)
{
printf("\u2503 %s \u2503\n", fillLogWithSpaces(buffer, uilog[LOG_LINES-i-1]));
i++;
}
|
ea1218f1
henyxia
UI finished
|
126
127
|
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");
}
|