-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayThread.cpp
139 lines (118 loc) · 3.27 KB
/
displayThread.cpp
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
#include "mbed.h"
#include "displayThread.h"
#ifdef TARGET_CY8CKIT_062_WIFI_BT
#include "GUI.h"
#endif
typedef enum {
CMD_temperature,
CMD_setPoint,
CMD_time,
CMD_mode,
} command_t;
typedef struct {
command_t cmd;
float value;
} msg_t;
static Queue<msg_t, 32> queue;
static MemoryPool<msg_t, 16> mpool;
void displaySendUpdateTemp(float temperature)
{
msg_t *message = mpool.alloc();
if(message)
{
message->cmd = CMD_temperature;
message->value = temperature;
queue.put(message);
}
}
void displaySendUpdateTime()
{
msg_t *message = mpool.alloc();
if(message)
{
message->cmd = CMD_time;
message->value = 0;
queue.put(message);
}
}
void displaySendUpdateSetPoint(float setPoint)
{
msg_t *message = mpool.alloc();
if(message)
{
message->cmd = CMD_setPoint;
message->value = setPoint;
queue.put(message);
}
}
void displaySendUpdateMode(float mode)
{
msg_t *message = mpool.alloc();
if(message)
{
message->cmd = CMD_mode;
message->value = mode;
queue.put(message);
}
}
static void displayAtXY(int x, int y,char *buffer)
{
#ifdef TARGET_CY8CKIT_062_WIFI_BT
GUI_SetTextAlign(GUI_TA_LEFT);
GUI_DispStringAt(buffer,(x-1)*8,(y-1)*16);
#endif
// row column
printf("\033[%d;%dH%s",y,x,buffer);
fflush(stdout);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
void displayThread()
{
char buffer[128];
printf("\033[2J\033[H"); // Clear Screen and go Home
printf("\033[?25l"); // Turn the cursor off
fflush(stdout);
#ifdef TARGET_CY8CKIT_062_WIFI_BT
GUI_Init();
GUI_SetColor(GUI_WHITE);
GUI_SetBkColor(GUI_BLACK);
GUI_SetFont(GUI_FONT_8X16_1);
#endif
while(1)
{
osEvent evt = queue.get();
if (evt.status == osEventMessage) {
msg_t *message = (msg_t*)evt.value.p;
switch(message->cmd)
{
case CMD_temperature:
sprintf(buffer,"Temperature = %2.1fF",message->value);
displayAtXY(1, 1, buffer);
break;
case CMD_setPoint:
sprintf(buffer,"Set Point = %2.1fF",message->value);
displayAtXY(1, 2, buffer);
break;
case CMD_time:
time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
rawtime = rawtime - (5*60*60); // UTC - 4hours ... serious hack which only works in winter
timeinfo = localtime (&rawtime);
strftime (buffer,sizeof(buffer),"%r",timeinfo);
displayAtXY(1,3, buffer);
break;
case CMD_mode:
if(message->value == 0.0)
sprintf(buffer,"Mode = Off ");
else if (message->value < 0.0)
sprintf(buffer,"Mode = Heat");
else
sprintf(buffer,"Mode = Cool");
displayAtXY(1, 4, buffer);
break;
}
mpool.free(message);
}
}
}