-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathemWinDemo.ino
303 lines (273 loc) · 8.41 KB
/
emWinDemo.ino
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
emWinDemo
created 04 Dec 2023
by Leonardo Cavagnis
*/
#include "DIALOG.h" /* emWin library includes Arduino_H7_Video and Arduino_GigaDisplayTouch library */
/*
* Main window handler: It creates 4 window childs.
* Source: https://wiki.segger.com/WM_child_windows_(Sample)
*/
static void _cbWin(WM_MESSAGE * pMsg) {
switch (pMsg->MsgId) {
case WM_CREATE:
/* [0, 0] - Image */
WM_CreateWindowAsChild(20, 20, 370, 210, pMsg->hWin, WM_CF_SHOW, _cbChildWinImg, 0);
/* [1, 0] - Slider */
WM_CreateWindowAsChild(20, 210+20*2, 370, 210, pMsg->hWin, WM_CF_SHOW, _cbChildWinSlider, 0);
/* [0, 1] - Checkbox, button and labels */
WM_CreateWindowAsChild(370+20*2, 20, 370, 210, pMsg->hWin, WM_CF_SHOW, _cbChildWinChkBtn, 0);
/* [1, 1] - Progress bar */
WM_CreateWindowAsChild(370+20*2, 210+20*2, 370, 210, pMsg->hWin, WM_CF_SHOW, _cbChildWinPgrBar, 0);
break;
case WM_PAINT:
GUI_SetBkColor(0x03989e); /* Background color set to: R(0x03),G(0x98),B(0x9E) */
GUI_Clear();
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*
* Image window handler
* To convert image use "Bitmap Converter for emWin"
* https://www.segger.com/products/user-interface/emwin/tools/tools-overview/
*/
extern GUI_CONST_STORAGE GUI_BITMAP bmarduinologo; /* Image bitmap structure (see img_arduinologo_emwin.c in attach) */
static void _cbChildWinImg(WM_MESSAGE * pMsg) {
switch (pMsg->MsgId) {
case WM_CREATE:
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
/* Draw image */
GUI_DrawBitmap(&bmarduinologo, 85, 35);
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*
* Slider window handler
* Source: https://wiki.segger.com/SLIDER_-_Usage_(Sample)
*/
static void _cbChildWinSlider(WM_MESSAGE * pMsg) {
static WM_HWIN hSlider;
int NCode, Id;
int Value;
char acBuffer[32];
switch(pMsg->MsgId) {
case WM_CREATE:
/* Create horizonzal slider */
hSlider = SLIDER_CreateEx(110, 90, 150, 30, pMsg->hWin, WM_CF_SHOW, SLIDER_CF_HORIZONTAL, GUI_ID_SLIDER0);
/* Set range of slider */
SLIDER_SetRange(hSlider, 0, 100);
/* Set number of tick marks */
SLIDER_SetNumTicks(hSlider, 10);
/* Set value of slider */
SLIDER_SetValue(hSlider, 20);
/* Set width of thumb */
SLIDER_SetWidth(hSlider, 20);
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
GUI_SetFont(&GUI_Font13B_1);
GUI_SetColor(GUI_BLACK);
/* Display slider value */
Value = SLIDER_GetValue(hSlider);
sprintf(acBuffer, "Value: %d", Value);
GUI_DispStringAt(acBuffer, 110, 120);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case GUI_ID_SLIDER0:
switch(NCode) {
case WM_NOTIFICATION_VALUE_CHANGED:
/* Redraw the window when a value has changed so the displayed value will be updated */
WM_InvalidateWindow(pMsg->hWin);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
/*
* Checkbox&Button window handler
* Source:
* https://wiki.segger.com/CHECKBOX_-_Usage_(Sample)
* https://wiki.segger.com/BUTTON_-_Usage_(Sample)
*/
#define ID_BUTTON 1
static void _cbChildWinChkBtn(WM_MESSAGE * pMsg) {
static WM_HWIN hBox;
BUTTON_Handle hButton;
int NCode, Id;
char acBuffer[32];
int State;
static int Clicked, Released;
switch(pMsg->MsgId) {
case WM_CREATE:
/* Create CHECKBOX widget */
hBox = CHECKBOX_CreateEx(10, 30, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_CHECK0);
/* Edit widget properties */
CHECKBOX_SetText(hBox, "Check");
CHECKBOX_SetTextColor(hBox, GUI_BLACK);
CHECKBOX_SetFont(hBox, &GUI_Font16_1);
/* Set number of possible states to 3 (if needed). The minimum number of states is 2 and the maximum is 3 */
CHECKBOX_SetNumStates(hBox, 3);
/* Manually set the state */
CHECKBOX_SetState(hBox, 1);
/* Create a button */
hButton = BUTTON_CreateEx(10, 100, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, ID_BUTTON);
BUTTON_SetText(hButton, "Click me");
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
GUI_SetFont(&GUI_Font16_1);
GUI_SetColor(GUI_BLACK);
/* Display current CHECKBOX state */
State = CHECKBOX_GetState(hBox);
sprintf(acBuffer, "State of checkbox: %d", State);
GUI_DispStringAt(acBuffer, 10, 60);
/* Check button state and print info on labels */
if(Clicked) {
sprintf(acBuffer, "Button was clicked at: %d.", Clicked);
GUI_DispStringAt(acBuffer, 10, 130);
}
if(Released) {
sprintf(acBuffer, "Button was released at: %d.", Released);
GUI_DispStringAt(acBuffer, 10, 150);
}
break;
case WM_NOTIFY_PARENT:
/* Get Id of sender window and notification code */
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (Id) {
case GUI_ID_CHECK0:
switch(NCode) {
case WM_NOTIFICATION_VALUE_CHANGED:
/* When the value of the checkbox changed, redraw parent window to update the display of the state */
WM_InvalidateWindow(pMsg->hWin);
break;
}
break;
case ID_BUTTON:
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
Clicked = GUI_GetTime();
WM_InvalidateWindow(pMsg->hWin);
break;
case WM_NOTIFICATION_RELEASED:
Released = GUI_GetTime();
WM_InvalidateWindow(pMsg->hWin);
break;
}
break;
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
/*
* Progress bar window handler
* Source: https://wiki.segger.com/PROGBAR_-_Custom_(Sample)
*/
PROGBAR_Handle hProg;
static void _cbChildWinPgrBar(WM_MESSAGE * pMsg) {
GUI_RECT Rect;
float ValueF;
int Value;
char acBuffer[16];
switch (pMsg->MsgId) {
case WM_CREATE:
hProg = PROGBAR_CreateEx(85, 90, 200, 30, pMsg->hWin, WM_CF_SHOW, PROGBAR_CF_HORIZONTAL, GUI_ID_PROGBAR0);
WM_SetCallback(hProg, _cbProgbar);
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*
* Progress bar widget handler
* Source: https://wiki.segger.com/PROGBAR_-_Custom_(Sample)
*/
static void _cbProgbar(WM_MESSAGE * pMsg) {
GUI_RECT Rect;
float ValueF;
int Value;
char acBuffer[16];
switch (pMsg->MsgId) {
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
/* Draw progress bar */
WM_GetClientRect(&Rect);
GUI_SetColor(GUI_BLACK);
GUI_AA_DrawRoundedRectEx(&Rect, 3);
Value = PROGBAR_GetValue(pMsg->hWin);
ValueF = Value / 100.0F;
sprintf(acBuffer, "Progress: %d%%", Value);
Rect.x0 += 2;
Rect.y0 += 2;
Rect.x1 -= 2;
Rect.y1 -= 2;
Rect.x1 = Rect.x1 * (ValueF);
GUI_SetColor(GUI_GRAY_9A);
GUI_AA_FillRoundedRectEx(&Rect, 1);
WM_GetClientRect(&Rect);
Rect.x0 += 2;
Rect.y0 += 2;
Rect.x1 -= 2;
Rect.y1 -= 2;
GUI_SetColor(GUI_BLACK);
GUI_SetTextMode(GUI_TM_TRANS);
GUI_SetFont(&GUI_Font16B_1);
GUI_DispStringInRect(acBuffer, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
break;
default:
PROGBAR_Callback(pMsg);
break;
}
}
int progbarCnt = 0;
unsigned long previousMillis = 0;
void setup() {
/* Init SEGGER emWin library. It also init display and touch controller */
GUI_Init();
LCD_ROTATE_SetSel(1); /* Set landscape mode */
WM_MULTIBUF_Enable(1); /* Enable multi buffering mode for Windows manager */
/* Create the main window. It will include all the sub-windows */
WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);
}
void loop() {
/* Update progress bar value */
if (millis() - previousMillis >= 100) {
previousMillis = millis();
progbarCnt++;
if (progbarCnt > 100) {
progbarCnt = 0;
}
PROGBAR_SetValue(hProg, progbarCnt);
WM_InvalidateWindow(hProg); /* Make sure the entire PROGBAR gets redrawn */
}
/* Keep emWin alive, handle touch and other stuff */
GUI_Exec();
}