Blame view

ui.c 2.29 KB
ea1218f1   henyxia   UI finished
1
2
3
4
5
  #include <stdio.h>
  #include <sys/types.h>
  #include <unistd.h>
  #include <string.h>
  #include <time.h>
d4d5bb6d   henyxia   Bus working
6
7
  #include <stdbool.h>
  #include <termios.h>
5a135e77   henyxia   MAP Files generated
8
  #include "printx.h"
ea1218f1   henyxia   UI finished
9
  #include "ui.h"
d4d5bb6d   henyxia   Bus working
10
  #include "bus.h"
9c066355   henyxia   USB Initialized
11
  #include "usb.h"
1afa113c   henyxia   Coffee is now ord...
12
  #include "pump.h"
ea1218f1   henyxia   UI finished
13
14
15
  
  #define	TIME_LENGTH			24
  #define	HEADER_TEXT_LENGTH	24
3bdc9daf   henyxia   NFC Added
16
  #define	LOG_LINES			35
297a72df   henyxia   Added sender
17
  #define	LOG_LENGTH			82
bc20374b   henyxia   Low IPS
18
  #define	IPS					2
cdaa873f   henyxia   Log fixed
19
  #define	SCREEN_TIME			1000000/IPS
5a135e77   henyxia   MAP Files generated
20
  #define	MAX_FILENAME_LENGTH	30
fbc5816b   henyxia   UI should be upda...
21
  #define	SC_HOME				0
bc20374b   henyxia   Low IPS
22
  #define	SC_MAIN				1
5a135e77   henyxia   MAP Files generated
23
24
  
  
fbc5816b   henyxia   UI should be upda...
25
26
27
28
29
30
  char			started[TIME_LENGTH];
  char			uid[HEADER_TEXT_LENGTH];
  char			cmd[LOG_LENGTH];
  pid_t			mainPid;
  bool			heat = false;
  bool			pump = false;
d4d5bb6d   henyxia   Bus working
31
32
  unsigned int	temp = 1;
  unsigned int	debit = 1;
fbc5816b   henyxia   UI should be upda...
33
34
35
  struct			termios old={0};
  bool			uiStop = false;
  int				actScreen = SC_HOME;
d4d5bb6d   henyxia   Bus working
36
37
38
39
40
  
  void stopUI()
  {
  	uiStop = true;
  }
cdaa873f   henyxia   Log fixed
41
  
9e9f365e   henyxia   Added HVC interface
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  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;
  }
  
5a135e77   henyxia   MAP Files generated
62
63
  int calculateInteraction(int act, int x, int y)
  {
1afa113c   henyxia   Coffee is now ord...
64
65
66
  	char			filename[MAX_FILENAME_LENGTH];
  	FILE*			f = NULL;
  	unsigned char	ret;
5a135e77   henyxia   MAP Files generated
67
68
69
70
71
  	switch(act)
  	{
  		case SC_HOME:
  			return act;
  		case SC_MAIN:
fc49d661   henyxia   Fixed call
72
  			strcpy(filename, "map/main.map");
5a135e77   henyxia   MAP Files generated
73
74
  			break;
  		default:
fc49d661   henyxia   Fixed call
75
  			printx(ERROR, UI, "Unrecognized state %d\n", act);
5a135e77   henyxia   MAP Files generated
76
77
78
79
80
81
82
83
84
  			return act;
  	}
  
  	f = fopen(filename, "r");
  	if(f == NULL)
  	{
  		printx(ERROR, UI, "The selected map is unopenable\n");
  		return act;
  	}
c95bd3c4   henyxia   Retrieving data f...
85
86
87
  
  	fseek(f, x + y*320, SEEK_SET);
  
1afa113c   henyxia   Coffee is now ord...
88
89
90
91
92
93
94
95
96
97
98
99
100
  	ret = fgetc(f);
  	printx(DEBUG, UI, "Ret is %02X\n", ret);
  
  	if(ret == 1)
  	{
  		setVolWanted(1);
  		setCoffeeWanted();
  	}
  	else if(ret == 2)
  	{
  		setVolWanted(2);
  		setCoffeeWanted();
  	}
c95bd3c4   henyxia   Retrieving data f...
101
102
  
  	fclose(f);
5a135e77   henyxia   MAP Files generated
103
104
105
106
  	
  	return act;
  }
  
ac55328a   henyxia   No more UI
107
108
  void processScreen()
  {
8b194ee7   henyxia   Getting touch inf...
109
110
  	int x = -1;
  	int y = -1;
fbc5816b   henyxia   UI should be upda...
111
112
  	if(actScreen == SC_HOME)
  	{
bc20374b   henyxia   Low IPS
113
  		if(uid[0] == '\0')
fbc5816b   henyxia   UI should be upda...
114
115
116
117
  			return;
  		else
  		{
  			actScreen = SC_MAIN;
5a135e77   henyxia   MAP Files generated
118
  			displayPicture("img/main.rgb");
fbc5816b   henyxia   UI should be upda...
119
120
  		}
  	}
8b194ee7   henyxia   Getting touch inf...
121
122
123
  	else if(actScreen == SC_MAIN)
  	{
  		if(screenTouched(&x, &y))
5a135e77   henyxia   MAP Files generated
124
  			actScreen = calculateInteraction(actScreen, x, y);
8b194ee7   henyxia   Getting touch inf...
125
  	}
ac55328a   henyxia   No more UI
126
127
  }
  
cdaa873f   henyxia   Log fixed
128
129
  void* drawUI(void* we)
  {
d4d5bb6d   henyxia   Bus working
130
  	while(!uiStop)
cdaa873f   henyxia   Log fixed
131
  	{
bc20374b   henyxia   Low IPS
132
  		processScreen();
cdaa873f   henyxia   Log fixed
133
134
135
136
137
  		usleep(SCREEN_TIME);
  	}
  
  	return NULL;
  }
ea1218f1   henyxia   UI finished
138
  
3bdc9daf   henyxia   NFC Added
139
140
  void setTagName(char* tag)
  {
fbc5816b   henyxia   UI should be upda...
141
  	//time_t now = time(NULL);
3bdc9daf   henyxia   NFC Added
142
  	strcpy(uid, tag);
fbc5816b   henyxia   UI should be upda...
143
  	//strftime(uidDate, HEADER_TEXT_LENGTH, "%F-%T:%d", localtime(&now));
3bdc9daf   henyxia   NFC Added
144
145
  }
  
ea1218f1   henyxia   UI finished
146
147
  void initUILog()
  {
d4d5bb6d   henyxia   Bus working
148
  	cmd[0]='\0';
cdaa873f   henyxia   Log fixed
149
150
  	started[0]='\0';
  	mainPid = getpid();
ea1218f1   henyxia   UI finished
151
  	uid[0]='\0';
fbc5816b   henyxia   UI should be upda...
152
  	initUSB();
ea1218f1   henyxia   UI finished
153
154
  }
  
ea1218f1   henyxia   UI finished
155
156
157
158
  void setStartTime(char* sT)
  {
  	strcpy(started, sT);
  }