-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathHMI.cpp
282 lines (239 loc) · 7.35 KB
/
HMI.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#include "HMI.h"
HMI::HMI(){
m_width=0;
m_height=0;
bufferPacket = "";
}
HMI::HMI(const HMI& orig){
}
HMI::~HMI(){
}
int HMI::setupHMI(){
//printf("Set up GPIO's..\n");
wiringPiSetup ();
pinMode(SW_1,INPUT);
pinMode(SW_2,INPUT);
pinMode(SW_3,INPUT);
pinMode(SW_4,INPUT);
pinMode(SW_4,INPUT);
pinMode(Power_Oled,OUTPUT);
//printf("Power OLED on..\n");
digitalWrite(Power_Oled,HIGH);
usleep(mTimout);
//Set up OLED display
//printf("Set up display..\n");
if ( !display.init(OLED_I2C_RESET,OLED_ADAFRUIT_I2C_128x64) ){
//printf("Error initialising display..\n");
return (1);
}
display.begin();
m_width=display.width();
m_height=display.height();
// init done
display.clearDisplay(); // clears the screen buffer
display.display(); // display it (clear display)
return 0;
}
//Gives back Number of Button
//pressed, if nothing is pressed then 0
int HMI::readButton(){
int iButton=0;
if(digitalRead(SW_1)){
usleep(mTimout);
//printf("SW_1 pressed..\n");
iButton=1;
}else if(digitalRead(SW_2)){
usleep(mTimout);
//printf("SW_2 pressed..\n");
iButton=2;
}else if(digitalRead(SW_3)){
usleep(mTimout);
//printf("SW_3 pressed..\n");
iButton=3;
}else if(digitalRead(SW_4)){
usleep(mTimout);
//printf("SW_4 pressed..\n");
iButton=4;
}else if(digitalRead(SW_5)){
usleep(mTimout);
//printf("SW_5 pressed..\n");
iButton=5;
}else{
iButton=0;
}
return iButton;
}
void HMI::drawMenue(const uint16_t x0, const uint16_t zeile_len,const char* sText){
drawMenue(x0,display.height()-10, zeile_len,sText);
}
void HMI::drawMenue(const uint16_t x0, const uint16_t y0, const uint16_t zeile_len,const char* sText){
display.fillRect(x0-2,y0-2, zeile_len, 20,WHITE);
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(x0,y0);
display.print(sText);
display.display();
}
void HMI::clearDisplay(){
display.clearDisplay(); // clears the screen buffer
display.display(); // display it (clear display)
}
void HMI::drawWelcome(){
display.fillRect(0,0, m_width, 50,WHITE);
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(5,5);
display.print(Welcome_Text_1);
display.setCursor(15,30);
display.print(Welcome_Text_2);
display.display();
}
void HMI::printGoodby(){
printMessage("Goodby","Hope, to see you again..");
usleep(3000000);
display.clearDisplay(); // clears the screen buffer
display.display(); // display it (clear display)
}
void HMI::printError(string Error){
printMessage("Error",Error);
}
void HMI::printInfo(string sMessage){
printMessage("Message", sMessage);
}
void HMI::printMenue(string sMessage){
printMessage("Menue", sMessage);
}
void HMI::printMessage(string sHeader,string Error){
int iThik = 5;
display.clearDisplay(); // clears the screen buffer
display.fillRect(0,0, m_width, m_height,WHITE);
display.fillRect(0,iThik*4, m_width, m_height,BLACK);
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(30,2);
display.print(sHeader.c_str());
//Calc how many Lines
int Lines=calcLine(Error);
//Split Text into Lines
if(Lines!=0){
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextWrap(true);
for(int i=0;i<Lines;i++){
if((i+1)*Max_Len_Line<=(int)Error.length()){
//printf("i = %d\n",i);
string sTemp=Error.substr(i*Max_Len_Line,Max_Len_Line);
//printf("%s\n",sTemp.c_str());
display.setCursor(5,iThik*5+5+i*10);
display.print(sTemp.c_str());
}else{
string sTemp=Error.substr(i*Max_Len_Line,Error.length()-i*Max_Len_Line);
//printf("%s\n",sTemp.c_str());
display.setCursor(5,iThik*5+5+i*10);
display.print(sTemp.c_str());
}
}
}
display.display();
}
void HMI::printPacket(string sPacket){
showPackets();
//Calc how many Lines
int Lines=calcLine(sPacket);
//Split Text into Lines
if(Lines!=0){
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextWrap(true);
for(int i=0;i<Lines;i++){
if((i+1)*Max_Len_Line<=(int)sPacket.length()){
//printf("i = %d\n",i);
string sTemp=sPacket.substr(i*Max_Len_Line,Max_Len_Line);
//printf("%s\n",sTemp.c_str());
display.setCursor(5,10+i*10);
display.print(sTemp.c_str());
}else{
string sTemp=sPacket.substr(i*Max_Len_Line,sPacket.length()-i*Max_Len_Line);
//printf("%s\n",sTemp.c_str());
display.setCursor(5,10+i*10);
display.print(sTemp.c_str());
}
}
}
display.display();
}
void HMI::setbufferPacket(string sPacket){
bufferPacket=sPacket.c_str();
}
void HMI::showbufferPacket(){
printPacket(bufferPacket.c_str());
}
void HMI::drawTriangle_down(){
const uint16_t x0 = display.width()-15;
const uint16_t y0 =display.height()-15;
display.fillTriangle(x0, y0, x0+10, y0, x0+5, y0+5, WHITE);
display.display();
}
void HMI::drawTriangle_up(){
const uint16_t x0 = display.width()-15;
const uint16_t y0 = 10;
display.fillTriangle(x0, y0, x0+10, y0, x0+5, y0-5, WHITE);
display.display();
}
void HMI::showConfig(){
int iThik = 5;
display.clearDisplay(); // clears the screen buffer
display.fillRect(0,0, m_width-20, m_height,WHITE);
display.fillRect(0,iThik*2, m_width, m_height,BLACK);
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(30,2);
display.print("Config");
display.display();
}
void HMI::showStatistic(){
int iThik = 5;
display.clearDisplay(); // clears the screen buffer
display.fillRect(0,0, m_width-20, m_height,WHITE);
display.fillRect(0,iThik*2, m_width, m_height,BLACK);
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(30,2);
display.print("Statistic");
display.display();
}
void HMI::showPackets(){
int iThik = 4;
display.clearDisplay(); // clears the screen buffer
display.fillRect(0,0, m_width-20, m_height,WHITE);
display.fillRect(0,iThik*2, m_width, m_height,BLACK);
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(30,2);
display.print("Packets");
drawMenue(68,28,"Back");
display.display();
}
void HMI::showLine(int Line, string Text){
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(5,Line*10+15);
display.print(Text.c_str());
display.display();
}
int HMI::calcLine(string sText){
int iLine =0;
int iLen=sText.length();
if(iLen!=0){
if(iLen<Max_Len_Line){
iLine=1;
}else{
iLine=iLen/Max_Len_Line;
int iRest=iLen%Max_Len_Line;
if(iRest)iLine++;
//printf("sText= %s | iLen %d | iRest= %d | iLine= %d \n",sText.c_str(),iLen,iRest,iLine);
}
}
if (iLine>Max_Line)iLine =Max_Line;
return iLine;
}