Blame view

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