Blame view

ui.c 1.84 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>
ea1218f1   henyxia   UI finished
8
  #include "ui.h"
d4d5bb6d   henyxia   Bus working
9
  #include "bus.h"
ea1218f1   henyxia   UI finished
10
11
12
  
  #define	TIME_LENGTH			24
  #define	HEADER_TEXT_LENGTH	24
3bdc9daf   henyxia   NFC Added
13
  #define	LOG_LINES			35
297a72df   henyxia   Added sender
14
  #define	LOG_LENGTH			82
cdaa873f   henyxia   Log fixed
15
16
  #define	IPS					20
  #define	SCREEN_TIME			1000000/IPS
19082eeb   henyxia   UI design not wor...
17
  #define	SPACES				"                                                                                                                                                                                                                                                                  "
ea1218f1   henyxia   UI finished
18
19
20
  char	started[TIME_LENGTH];
  char	uid[HEADER_TEXT_LENGTH];
  char	uidDate[HEADER_TEXT_LENGTH];
d4d5bb6d   henyxia   Bus working
21
  char	cmd[LOG_LENGTH];
cdaa873f   henyxia   Log fixed
22
  pid_t	mainPid;
d4d5bb6d   henyxia   Bus working
23
24
25
26
27
28
29
30
31
32
33
  bool	heat = false;
  bool	pump = false;
  unsigned int	temp = 1;
  unsigned int	debit = 1;
  struct	termios old={0};
  bool uiStop = false;
  
  void stopUI()
  {
  	uiStop = true;
  }
cdaa873f   henyxia   Log fixed
34
  
9e9f365e   henyxia   Added HVC interface
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  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;
  }
  
ac55328a   henyxia   No more UI
55
56
57
58
59
  void processScreen()
  {
  	
  }
  
cdaa873f   henyxia   Log fixed
60
61
  void* drawUI(void* we)
  {
d4d5bb6d   henyxia   Bus working
62
  	while(!uiStop)
cdaa873f   henyxia   Log fixed
63
  	{
ac55328a   henyxia   No more UI
64
65
66
  		//printf("\x1b[2J\x1b[1;1H");
  		//displayUI();
  		processScreen();
cdaa873f   henyxia   Log fixed
67
68
69
70
71
  		usleep(SCREEN_TIME);
  	}
  
  	return NULL;
  }
ea1218f1   henyxia   UI finished
72
  
3bdc9daf   henyxia   NFC Added
73
74
75
76
77
78
79
  void setTagName(char* tag)
  {
  	time_t now = time(NULL);
  	strcpy(uid, tag);
  	strftime(uidDate, HEADER_TEXT_LENGTH, "%F-%T:%d", localtime(&now));
  }
  
ea1218f1   henyxia   UI finished
80
81
  void initUILog()
  {
d4d5bb6d   henyxia   Bus working
82
  	cmd[0]='\0';
cdaa873f   henyxia   Log fixed
83
84
  	started[0]='\0';
  	mainPid = getpid();
ea1218f1   henyxia   UI finished
85
86
  	uid[0]='\0';
  	uidDate[0]='\0';
ea1218f1   henyxia   UI finished
87
88
  }
  
19082eeb   henyxia   UI design not wor...
89
  char* fillHeaderWithSpaces(char* buf, char* text)
ea1218f1   henyxia   UI finished
90
  {
19082eeb   henyxia   UI design not wor...
91
  	char tmpretheader[HEADER_TEXT_LENGTH+1];
ea1218f1   henyxia   UI finished
92
93
94
95
  	strcpy(tmpretheader, text);
  	while(strlen(tmpretheader) < HEADER_TEXT_LENGTH)
  		strcat(tmpretheader, " ");
  
19082eeb   henyxia   UI design not wor...
96
97
98
99
100
  	for(int i=0; i<strlen(tmpretheader); i++)
  		buf[i] = tmpretheader[i];
  	buf[strlen(tmpretheader)] = '\0';
  
  	return buf;
ea1218f1   henyxia   UI finished
101
102
  }
  
ea1218f1   henyxia   UI finished
103
104
105
106
  void setStartTime(char* sT)
  {
  	strcpy(started, sT);
  }