This repository has been archived by the owner on Jul 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.c
158 lines (137 loc) · 2.29 KB
/
ui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <stdbool.h>
#include <termios.h>
#include "printx.h"
#include "ui.h"
#include "bus.h"
#include "usb.h"
#include "pump.h"
#define TIME_LENGTH 24
#define HEADER_TEXT_LENGTH 24
#define LOG_LINES 35
#define LOG_LENGTH 82
#define IPS 2
#define SCREEN_TIME 1000000/IPS
#define MAX_FILENAME_LENGTH 30
#define SC_HOME 0
#define SC_MAIN 1
char started[TIME_LENGTH];
char uid[HEADER_TEXT_LENGTH];
char cmd[LOG_LENGTH];
pid_t mainPid;
bool heat = false;
bool pump = false;
unsigned int temp = 1;
unsigned int debit = 1;
struct termios old={0};
bool uiStop = false;
int actScreen = SC_HOME;
void stopUI()
{
uiStop = true;
}
void setHeat(bool s)
{
heat = s;
}
void setPump(bool s)
{
pump = s;
}
void setTemp(unsigned int t)
{
temp = t;
}
void setDebit(unsigned int d)
{
debit = d;
}
int calculateInteraction(int act, int x, int y)
{
char filename[MAX_FILENAME_LENGTH];
FILE* f = NULL;
unsigned char ret;
switch(act)
{
case SC_HOME:
return act;
case SC_MAIN:
strcpy(filename, "map/main.map");
break;
default:
printx(ERROR, UI, "Unrecognized state %d\n", act);
return act;
}
f = fopen(filename, "r");
if(f == NULL)
{
printx(ERROR, UI, "The selected map is unopenable\n");
return act;
}
fseek(f, x + y*320, SEEK_SET);
ret = fgetc(f);
printx(DEBUG, UI, "Ret is %02X\n", ret);
if(ret == 1)
{
setVolWanted(1);
setCoffeeWanted();
}
else if(ret == 2)
{
setVolWanted(2);
setCoffeeWanted();
}
fclose(f);
return act;
}
void processScreen()
{
int x = -1;
int y = -1;
if(actScreen == SC_HOME)
{
if(uid[0] == '\0')
return;
else
{
actScreen = SC_MAIN;
displayPicture("img/main.rgb");
}
}
else if(actScreen == SC_MAIN)
{
if(screenTouched(&x, &y))
actScreen = calculateInteraction(actScreen, x, y);
}
}
void* drawUI(void* we)
{
while(!uiStop)
{
processScreen();
usleep(SCREEN_TIME);
}
return NULL;
}
void setTagName(char* tag)
{
//time_t now = time(NULL);
strcpy(uid, tag);
//strftime(uidDate, HEADER_TEXT_LENGTH, "%F-%T:%d", localtime(&now));
}
void initUILog()
{
cmd[0]='\0';
started[0]='\0';
mainPid = getpid();
uid[0]='\0';
initUSB();
}
void setStartTime(char* sT)
{
strcpy(started, sT);
}