-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhomescreen.cpp
296 lines (246 loc) · 8.74 KB
/
homescreen.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#include "homescreen.h"
#include "marlinui.h"
#include <lvgl>
#include "theme.h"
#include <multilang.h>
#include <resources.h>
// 按键功能函数
/**
* @brief 工具按钮按下
*/
lv_res_t onToolButClocked(_lv_obj_t * obj)
{
MarlinUi::getInstance()->showMenuScreen();
return LV_RES_OK;
}
/**
* @brief 打印按钮按下
* @param obj
* @return
*/
lv_res_t onPrintButClocked(_lv_obj_t * obj)
{
MarlinUi::getInstance()->showFileScreen();
return LV_RES_OK;
}
/**
* @brief 打温度钮按下
* @param obj
* @return
*/
lv_res_t onTempButClocked(_lv_obj_t * obj)
{
MarlinUi::getInstance()->showTemperatureScreen();
return LV_RES_OK;
}
/**
* @brief onMoveButClocked
* @param obj
* @return
*/
lv_res_t onMoveButClocked(_lv_obj_t * obj)
{
MarlinUi::getInstance()->showMotionScreen();
return LV_RES_OK;
}
lv_res_t onExtrudeButClocked(_lv_obj_t * obj)
{
MarlinUi::getInstance()->showExtrudeScreen();
return LV_RES_OK;
}
HomeScreen::HomeScreen()
:Screen()
{
}
bool HomeScreen::initScreen()
{
/*
* 实现主界面
*
==============================================
= =
= 000000000000 11111111111 22222222222 =
= 000000000000 11111111111 22222222222 =
= 000000000000 11111111111 22222222222 =
= 000000000000 11111111111 22222222222 =
= 000000000000 11111111111 22222222222 =
= =
= 333333333333 4444444444444444444444444 =
= 333333333333 4444444444444444444444444 =
= 333333333333 4444444444444444444444444 =
= 333333333333 4444444444444444444444444 =
= 333333333333 4444444444444444444444444 =
= =
= ..........................5555..6666..7777 =
= ..........................5555..6666..7777 =
==============================================
*/
//构建主界面
int screenWidth = this->width();
int screenHeight = this->height();
int screenDpi = this->dpi();
//计算出各区域大小
#if SCREEN_SIZE == 28
int16_t safeMargin = 6;
int16_t spacing = 4;
int16_t barHeight = 26;
int16_t butAreaWidth = screenWidth;
int16_t butAreaHeight = screenHeight - barHeight;
int16_t butWidth = 100;
int16_t butHeight = 100;
int16_t fontSize = 16;
int16_t iconSize = 24;
#elif SCREEN_SIZE == 35
// scale 120%
int16_t safeMargin = 7;
int16_t spacing = 5;
int16_t barHeight = 32;
int16_t butAreaWidth = screenWidth;
int16_t butAreaHeight = screenHeight - barHeight;
int16_t butWidth = 152;
int16_t butHeight = 138;
int16_t fontSize = 20;
int16_t iconSize = 28;
#endif
//主界面按钮区域
{
LVObject * butArea = new LVObject(this,nullptr);
butArea->setPos(0,0);
butArea->setSize(butAreaWidth,butAreaHeight);
butArea->setStyle(THEME_STYLE_GET(Theme_screen_ButtonArea));
//移动按钮
LVButton * butMove = new LVButton(butArea,nullptr);
butMove->setSize(butWidth,butHeight);
butMove->alignOrigo(LV_ALIGN_IN_TOP_MID,0,safeMargin + butHeight / 2);
butMove->setStyle(LV_BTN_STYLE_PR,THEME_STYLE_GET(Theme_Screen_ButtonPr));
butMove->setStyle(LV_BTN_STYLE_REL,THEME_STYLE_GET(Theme_Screen_ButtonRel));
butMove->setAction(LV_BTN_ACTION_CLICK,onMoveButClocked);
//移动按钮图标
LVImage * imgMove = new LVImage(butMove,nullptr);
imgMove->setSize(iconSize,iconSize);
imgMove->align(LV_ALIGN_CENTER,0,0);
imgMove->setSrc(&move_24);
//移动按钮文本
labMove = new LVLabel(butMove,nullptr);
labMove->setText(Lang_HomeScreen_ButMove); //"Move"
//预热按钮
LVButton * butPreheat = new LVButton(butArea,butMove);
butPreheat->align(butMove,LV_ALIGN_OUT_LEFT_TOP,-spacing,0);
butPreheat->setAction(LV_BTN_ACTION_CLICK,onTempButClocked);
//预热按钮图标
LVImage * imgPreheat = new LVImage(butPreheat,nullptr);
imgPreheat->setSize(iconSize,iconSize);
imgPreheat->align(LV_ALIGN_CENTER,0,0);
imgPreheat->setSrc(&temp_24);
//预热按钮文本
labPreheat = new LVLabel(butPreheat,nullptr);
labPreheat->setText(Lang_HomeScreen_ButPreHeat);//"Preheat"
//挤出按钮
LVButton * butExtrude = new LVButton(butArea,butMove);
butExtrude->align(butMove,LV_ALIGN_OUT_RIGHT_TOP,spacing,0);
butExtrude->setAction(LV_BTN_ACTION_CLICK,onExtrudeButClocked);
//挤出按钮图标
LVImage * imgExtrude = new LVImage(butExtrude,nullptr);
imgExtrude->setSize(iconSize,iconSize);
imgExtrude->align(LV_ALIGN_CENTER,0,0);
imgExtrude->setSrc(&extrude_24);
//挤出按钮文本
labExtrude = new LVLabel(butExtrude,nullptr);
labExtrude->setText(Lang_HomeScreen_ButExtrude); //"Extrude"
//工具按钮
LVButton * butTool = new LVButton(butArea,butMove);
butTool->align(butPreheat,LV_ALIGN_OUT_BOTTOM_LEFT,0,spacing);
butTool->setAction(LV_BTN_ACTION_CLICK,onToolButClocked);
//工具按钮图标
LVImage * imgTool = new LVImage(butTool,nullptr);
imgTool->setSize(iconSize,iconSize);
imgTool->align(LV_ALIGN_CENTER,0,0);
imgTool->setSrc(&tool_24);
//工具按钮文本
labTool = new LVLabel(butTool,nullptr);
labTool->setText(Lang_HomeScreen_ButTool);//"Tool"
//打印按钮
LVButton * butPrint = new LVButton(butArea,butMove);
butPrint->setSize(butWidth*2 + spacing , butHeight);
butPrint->align(butTool,LV_ALIGN_OUT_RIGHT_TOP,spacing,0);
butPrint->setAction(LV_BTN_ACTION_CLICK,onPrintButClocked);
//打印按钮图标
LVImage * imgPrint = new LVImage(butPrint,nullptr);
imgPrint->setSize(iconSize,iconSize);
imgPrint->align(LV_ALIGN_CENTER,0,0);
imgPrint->setSrc(&print_24);
//打印按钮文本
labPrint = new LVLabel(butPrint,nullptr);
labPrint->setText(Lang_HomeScreen_ButPrint);//"Print"
}
//主界面消息区
{
//状态栏
LVObject * stateBar = new LVObject(this,nullptr);
stateBar->setSize(screenWidth,barHeight);
stateBar->align(LV_ALIGN_IN_BOTTOM_LEFT,0,0);
stateBar->setStyle(THEME_STYLE_GET(Theme_Screen_StateBar));
//状态栏信息
stateMesg = new LVLabel(stateBar,nullptr);
stateMesg->align(LV_ALIGN_IN_LEFT_MID,safeMargin,0);
stateMesg->setText(Lang_HomeScreen_MsgConnected); //"Connected!"
stateMesg->align(LV_ALIGN_IN_LEFT_MID,safeMargin,0);
//热床温度
labHeatbed = new LVLabel(stateBar,nullptr);
labHeatbed->setText("999");
labHeatbed->align(LV_ALIGN_IN_RIGHT_MID,-safeMargin,0);
labHeatbed->setValue((int16_t)ExtUI::getActualTemp_celsius(ExtUI::BED));
//热床温度图标
imgHeatbed = new LVImage(stateBar,nullptr);
imgHeatbed->setSrc(&heatbed_20_12);
imgHeatbed->align(labHeatbed,LV_ALIGN_OUT_LEFT_MID,-spacing,0);
//喷嘴温度
labHeatend = new LVLabel(stateBar,nullptr);
labHeatend->setText("999");
labHeatend->align(imgHeatbed,LV_ALIGN_OUT_LEFT_MID,-safeMargin*2,0);
labHeatend->setValue((int16_t)ExtUI::getActualTemp_celsius(ExtUI::E0));
//喷嘴温度图标
imgHeatend = new LVImage(stateBar,nullptr);
imgHeatend->setSrc(&heatend_20_12);
imgHeatend->align(labHeatend,LV_ALIGN_OUT_LEFT_MID,-spacing,0);
}
//温度查询任务
m_tempQueryTask = new ScreenTask(this);
m_tempQueryTask->setTaskFunc([&](){
//更新热床/喷嘴温度
labHeatbed->setValue((int16_t)ExtUI::getActualTemp_celsius(ExtUI::BED));
labHeatend->setValue((int16_t)ExtUI::getActualTemp_celsius(ExtUI::E0));
//更新图标状态颜色
if(ExtUI::getTargetTemp_celsius(ExtUI::BED) > 5)
imgHeatbed->setStyle(THEME_STYLE_GET(Theme_screen_Yellow));
else
imgHeatbed->setStyle(nullptr); //白色
if(ExtUI::getTargetTemp_celsius(ExtUI::E0) > 5)
imgHeatend->setStyle(THEME_STYLE_GET(Theme_screen_Red));
else
imgHeatend->setStyle(nullptr); //白色
});
m_tempQueryTask->startAndRun();
LV_LOG_INFO(__FUNCTION__);
return true;
}
void HomeScreen::onLangChanged()
{
//更新界面语言
}
void HomeScreen::onThemeChanged()
{
}
void HomeScreen::afterCleanScreen()
{
labMove = nullptr;
labPreheat = nullptr;
labExtrude = nullptr;
labTool = nullptr;
labPrint = nullptr;
stateMesg = nullptr;
labHeatbed = nullptr;
labHeatend = nullptr;
imgHeatbed = nullptr;
imgHeatend = nullptr;
}