Blame view

ui.c 1.97 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  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:
  			strcat(filename, "map/main.map");
  			break;
  		default:
  			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
86
87
  void processScreen()
  {
8b194ee7   henyxia   Getting touch inf...
88
89
  	int x = -1;
  	int y = -1;
fbc5816b   henyxia   UI should be upda...
90
91
  	if(actScreen == SC_HOME)
  	{
bc20374b   henyxia   Low IPS
92
  		if(uid[0] == '\0')
fbc5816b   henyxia   UI should be upda...
93
94
95
96
  			return;
  		else
  		{
  			actScreen = SC_MAIN;
5a135e77   henyxia   MAP Files generated
97
  			displayPicture("img/main.rgb");
fbc5816b   henyxia   UI should be upda...
98
99
  		}
  	}
8b194ee7   henyxia   Getting touch inf...
100
101
102
  	else if(actScreen == SC_MAIN)
  	{
  		if(screenTouched(&x, &y))
5a135e77   henyxia   MAP Files generated
103
  			actScreen = calculateInteraction(actScreen, x, y);
8b194ee7   henyxia   Getting touch inf...
104
  	}
ac55328a   henyxia   No more UI
105
106
  }
  
cdaa873f   henyxia   Log fixed
107
108
  void* drawUI(void* we)
  {
d4d5bb6d   henyxia   Bus working
109
  	while(!uiStop)
cdaa873f   henyxia   Log fixed
110
  	{
bc20374b   henyxia   Low IPS
111
  		processScreen();
cdaa873f   henyxia   Log fixed
112
113
114
115
116
  		usleep(SCREEN_TIME);
  	}
  
  	return NULL;
  }
ea1218f1   henyxia   UI finished
117
  
3bdc9daf   henyxia   NFC Added
118
119
  void setTagName(char* tag)
  {
fbc5816b   henyxia   UI should be upda...
120
  	//time_t now = time(NULL);
3bdc9daf   henyxia   NFC Added
121
  	strcpy(uid, tag);
fbc5816b   henyxia   UI should be upda...
122
  	//strftime(uidDate, HEADER_TEXT_LENGTH, "%F-%T:%d", localtime(&now));
3bdc9daf   henyxia   NFC Added
123
124
  }
  
ea1218f1   henyxia   UI finished
125
126
  void initUILog()
  {
d4d5bb6d   henyxia   Bus working
127
  	cmd[0]='\0';
cdaa873f   henyxia   Log fixed
128
129
  	started[0]='\0';
  	mainPid = getpid();
ea1218f1   henyxia   UI finished
130
  	uid[0]='\0';
fbc5816b   henyxia   UI should be upda...
131
  	initUSB();
ea1218f1   henyxia   UI finished
132
133
  }
  
ea1218f1   henyxia   UI finished
134
135
136
137
  void setStartTime(char* sT)
  {
  	strcpy(started, sT);
  }