-
Notifications
You must be signed in to change notification settings - Fork 3
/
marlinui.cpp
561 lines (466 loc) · 14.1 KB
/
marlinui.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
#include "marlinui.h"
#include <lvgl>
#include "homescreen.h"
#include "menuscreen.h"
#include "splashscreen.h"
#include "menuscreen.h"
#include "printingscreen.h"
#include "temperaturescreen.h"
#include "motionscreen.h"
#include "extrudescreen.h"
#include "filescreen.h"
#include <langchinese.h>
#include <langenglish.h>
#include "themedark.h"
#include "resources.h"
#include "numberimputscreen.h"
#include "checkscreen.h"
//#include "themelight.h"
void marlinUiInit(void);
void marlinUiRun(void);
namespace ExtUI{
//实现Marlin事件函数
void onStartup ()
{
//初始化界面
marlinUiInit();
MarlinUi::getInstance()->getSignalStartup ().emit();
}
void onIdle ()
{
//运行界面
marlinUiRun();
MarlinUi::getInstance()->getSignalIdle ().emit();
}
void onMediaInserted ()
{
MarlinUi::getInstance()->getSignalMediaInserted ().emit();
}
void onMediaError ()
{
MarlinUi::getInstance()->getSignalMediaError ().emit();
}
void onMediaRemoved ()
{
MarlinUi::getInstance()->getSignalMediaRemoved ().emit();
}
void onPlayTone (const uint16_t frequency, const uint16_t duration)
{
static PlayToneParam param;
param.frequency = frequency;
param.duration = duration;
MarlinUi::getInstance()->getSignalPlayTone().emit(¶m);
}
void onPrinterKilled (PGM_P const msg)
{
static MesgParam param;
param.msg = msg;
MarlinUi::getInstance()->getSignalPrinterKilled ().emit(¶m);
}
void onPrintTimerStarted ()
{
MarlinUi::getInstance()->getSignalPrintTimerStarted ().emit();
}
void onPrintTimerPaused ()
{
MarlinUi::getInstance()->getSignalPrintTimerPaused ().emit();
}
void onPrintTimerStopped ()
{
MarlinUi::getInstance()->getSignalPrintTimerStopped ().emit();
}
void onFilamentRunout (const ExtUI::extruder_t extruder)
{
static FilamentRunoutParam param;
param.extruder = extruder;
MarlinUi::getInstance()->getSignalFilamentRunout ().emit(¶m);
}
void onUserConfirmRequired(const char * const msg)
{
static MesgParam param;
param.msg = msg;
MarlinUi::getInstance()->getSignalUserConfirmRequired().emit(¶m);
}
void onStatusChanged (const char * const msg)
{
static MesgParam param;
param.msg = msg;
MarlinUi::getInstance()->getSignalStatusChanged ().emit(¶m);
}
void onFactoryReset ()
{
MarlinUi::getInstance()->getSignalFactoryReset ().emit();
}
void onStoreSettings ()
{
MarlinUi::getInstance()->getSignalStoreSettings ().emit();
}
void onLoadSettings ()
{
MarlinUi::getInstance()->getSignalLoadSettings ().emit();
}
/////////////////////////////新添加API///////////////////////////
void onStoreSettings(char *buff) {
// This is called when saving to EEPROM (i.e. M500). If the ExtUI needs
// permanent data to be stored, it can write up to eeprom_data_size bytes
// into buff.
// Example:
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
// memcpy(buff, &myDataStruct, sizeof(myDataStruct));
}
void onLoadSettings(const char *buff) {
// This is called while loading settings from EEPROM. If the ExtUI
// needs to retrieve data, it should copy up to eeprom_data_size bytes
// from buff
// Example:
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
// memcpy(&myDataStruct, buff, sizeof(myDataStruct));
}
void onConfigurationStoreWritten(bool success) {
// This is called after the entire EEPROM has been written,
// whether successful or not.
}
void onConfigurationStoreRead(bool success) {
// This is called after the entire EEPROM has been read,
// whether successful or not.
}
}
MarlinUi * MarlinUi::s_instance = nullptr;
LVSignal & MarlinUi::getSignalStartup()
{
return m_signalStartup;
}
LVSignal & MarlinUi::getSignalIdle()
{
return m_signalIdle;
}
LVSignal & MarlinUi::getSignalMediaInserted()
{
return m_signalMediaInserted;
}
LVSignal & MarlinUi::getSignalMediaError()
{
return m_signalMediaError;
}
LVSignal & MarlinUi::getSignalMediaRemoved()
{
return m_signalMediaRemoved;
}
LVSignal & MarlinUi::getSignalPlayTone()
{
return m_signalPlayTone;
}
LVSignal & MarlinUi::getSignalPrinterKilled()
{
return m_signalPrinterKilled;
}
LVSignal & MarlinUi::getSignalPrintTimerStarted()
{
return m_signalPrintTimerStarted;
}
LVSignal & MarlinUi::getSignalPrintTimerPaused()
{
return m_signalPrintTimerPaused;
}
LVSignal & MarlinUi::getSignalPrintTimerStopped()
{
return m_signalPrintTimerStopped;
}
LVSignal & MarlinUi::getSignalFilamentRunout()
{
return m_signalFilamentRunout;
}
LVSignal & MarlinUi::getSignalUserConfirmRequired()
{
return m_signalUserConfirmRequired;
}
LVSignal & MarlinUi::getSignalStatusChanged()
{
return m_signalStatusChanged;
}
LVSignal & MarlinUi::getSignalFactoryReset()
{
return m_signalFactoryReset;
}
LVSignal & MarlinUi::getSignalStoreSettings()
{
return m_signalStoreSettings;
}
LVSignal & MarlinUi::getSignalLoadSettings()
{
return m_signalLoadSettings;
}
lv_font_t &MarlinUi::defaultFont() const
{
return m_defaultFont;
}
MessageScreen *MarlinUi::messageScreen() const
{
return m_messageScreen;
}
NumberImputScreen *MarlinUi::numberImputScreen() const
{
return m_numberImputScreen;
}
Screen *MarlinUi::defaultScreen(){ return m_defaultScreen; }
Screen *MarlinUi::currentScreen(){ return m_currentScreen; }
LVSignal &MarlinUi::getSignalRemotePrinting()
{
return m_signalRemotePrinting;
}
LVTask *MarlinUi::getRemotePrintingTask() const
{
return m_remotePrintingTask;
}
MarlinUi::MarlinUi(uint16_t width, uint16_t height, uint16_t dpi)
:m_width(width)
,m_height(height)
,m_dpi(dpi)
,m_defaultFont(*LV_FONT_DEFAULT)
{
}
MarlinUi * MarlinUi::getInstance(uint16_t width, uint16_t height,uint16_t dpi)
{
//static MarlinUi * s_instance = nullptr;
if(s_instance == nullptr)
{
s_instance = new MarlinUi(width,height,dpi);
}
return s_instance;
}
MarlinUi::~MarlinUi()
{
//TODO: 析构数据
DELETE_PTR(m_splashScreen );
DELETE_PTR(m_homeScreen );
DELETE_PTR(m_menuScreen );
DELETE_PTR(m_printingScreen );
DELETE_PTR(m_fileScreen );
DELETE_PTR(m_positionTask );
DELETE_PTR(m_temperatureTask );
DELETE_PTR(m_sdCardTask );
DELETE_PTR(m_endStopTask );
DELETE_PTR(m_errorTask );
}
void MarlinUi::showSplashScreen()
{
if(m_splashScreen)
m_splashScreen->show();
else
LV_LOG_INFO("m_splashScreen not init");
}
void MarlinUi::initMarlinUI()
{
initScreens();
initTasks();
}
void MarlinUi::showHomeScreen()
{
//加载主界面
if(m_homeScreen)
m_homeScreen->show();
else
LV_LOG_INFO("m_homeScreen not init");
}
void MarlinUi::showMenuScreen()
{
//加载菜单界面
if(m_menuScreen)
m_menuScreen->show();
else
LV_LOG_INFO("m_menuScreen not init");
}
void MarlinUi::showPrintingScreen()
{
//加载打印界面
if(m_printingScreen)
m_printingScreen->show();
else
LV_LOG_INFO("m_printingScreen not init");
}
void MarlinUi::showTemperatureScreen()
{
//加载温度界面
if(m_temperatureScreen)
m_temperatureScreen->show();
else
LV_LOG_INFO("m_temperatureScreen not init");
}
void MarlinUi::showMotionScreen()
{
//加载运动界面
if(m_motionScreen)
m_motionScreen->show();
else
LV_LOG_INFO("m_movementScreen not init");
}
void MarlinUi::showExtrudeScreen()
{
//加载挤出界面
if(m_extrudeScreen)
m_extrudeScreen->show();
else
LV_LOG_INFO("m_extrudeScreen not init");
}
void MarlinUi::showFileScreen()
{
//加载挤出界面
if(m_fileScreen)
m_fileScreen->show();
else
LV_LOG_INFO("m_fileScreen not init");
}
void MarlinUi::showMessageScreen()
{
//加载消息提示界面
if(m_messageScreen)
m_messageScreen->show();
else
LV_LOG_INFO("m_messageScreen not init");
}
void MarlinUi::showNumberInputScreen()
{
//加载消息提示界面
if(m_numberImputScreen)
m_numberImputScreen->show();
else
LV_LOG_INFO("m_numberImputScreen not init");
}
void MarlinUi::showCheckScreen()
{
//加载消息提示界面
if(m_checkScreen)
m_checkScreen->show();
else
LV_LOG_INFO("m_checkScreen not init");
}
uint16_t MarlinUi::width() const
{
//printf("Size %d %d",m_width,m_height);
return m_width;
}
void MarlinUi::setWidth(uint16_t width)
{
m_width = width;
}
uint16_t MarlinUi::height() const
{
return m_height;
}
void MarlinUi::setHeight(uint16_t height)
{
m_height = height;
}
uint16_t MarlinUi::dpi() const
{
return m_dpi;
}
void MarlinUi::setDpi(uint16_t dpi)
{
m_dpi = dpi;
}
SplashScreen *MarlinUi::splashScreen(){ return m_splashScreen; }
HomeScreen *MarlinUi::homeScreen(){ return m_homeScreen; }
TemperatureScreen *MarlinUi::temperatureScreen()
{
return m_temperatureScreen;
}
MenuScreen *MarlinUi::menuScreen(){ return m_menuScreen; }
PrintingScreen *MarlinUi::printingScreen(){ return m_printingScreen; }
FileScreen *MarlinUi::fileScreen(){ return m_fileScreen; }
void MarlinUi::initScreens()
{
//NOTE: 必须首先设置好字体
#if SCREEN_SIZE==28
lv_font_add(µsoft_yahei_chinese_16,µsoft_yahei_ascii_16);
lv_font_add(µsoft_yahei_symbol_16,µsoft_yahei_ascii_16);
#elif SCREEN_SIZE==35
lv_font_add(µsoft_yahei_chinese_20,µsoft_yahei_ascii_20);
lv_font_add(µsoft_yahei_symbol_20,µsoft_yahei_ascii_20);
#endif
//初始化界面语言
LangChinese::initLang();
LangEnglish::initLang();
//设置界面语言
MultiLang::langSet(LANG_ZH);
//初始化主题
ThemeDark::initTheme();
//激活黑色主题
Theme::activeTheme(Theme_Dark);
//TODO:实现UI初始化
m_splashScreen = new SplashScreen("");
m_homeScreen = new HomeScreen();
m_splashScreen->setNextScreen(m_homeScreen);
m_menuScreen = new MenuScreen();
m_printingScreen = new PrintingScreen();
m_temperatureScreen = new TemperatureScreen();
m_motionScreen = new MotionScreen();
m_extrudeScreen = new ExtrudeScreen();
m_fileScreen = new FileScreen();
m_checkScreen = new CheckScreen();
m_messageScreen = new MessageScreen();
m_numberImputScreen = new NumberImputScreen();
//初始化任务
m_remotePrintingTask = new LVTask(1000);
m_remotePrintingTask->setTaskFunc([this](){
//检测远程打印的类型
//BUG: 运动状态也会触发信号的产生 ExtUI::isPrinting()的判断不准确
//if(ExtUI::isPrinting() && !ExtUI::isPrintingFromMedia())
// m_signalRemotePrinting.emit();
});
m_remotePrintingTask->start();
//关联些信号槽
//关联事件提示气泡
//TODO:为气泡消息优化多语言
m_slotNotifyBubble.setSlotFunc([&](LVSignal* signal){
// if(signal == &m_signalStartup) {} else
// if(signal == &m_signalIdle) {} else
if(signal == &m_signalMediaInserted) { Screen::showBubble("Media Inserted"); } else
if(signal == &m_signalMediaError) { Screen::showBubble("Media Error"); } else
if(signal == &m_signalMediaRemoved) { Screen::showBubble("Media Removed"); } else
if(signal == &m_signalPlayTone) { /* TODO:添加蜂鸣器 */ } else
// if(signal == &m_signalPrinterKilled) {} else
if(signal == &m_signalPrintTimerStarted) { Screen::showBubble("Printing Started"); } else
if(signal == &m_signalPrintTimerPaused) { Screen::showBubble("Printing Paused"); } else
if(signal == &m_signalPrintTimerStopped) { Screen::showBubble("Printing Stopped"); } else
if(signal == &m_signalFilamentRunout) { Screen::showBubble("Filament Runout"); } else
// if(signal == &m_signalUserConfirmRequired) {} else
if(signal == &m_signalStatusChanged) { MesgParam * param = (MesgParam *)signal->param() ;
Screen::showBubble(param->msg); } else
if(signal == &m_signalFactoryReset) { Screen::showBubble("Factory Reset"); } else
if(signal == &m_signalStoreSettings) { Screen::showBubble("Store Settings"); } else
if(signal == &m_signalLoadSettings) { Screen::showBubble("Load Settings"); }
});
// connect(&m_signalStartup ,&m_slotNotifyBubble);
// connect(&m_signalIdle ,&m_slotNotifyBubble);
connect(&m_signalMediaInserted ,&m_slotNotifyBubble);
connect(&m_signalMediaError ,&m_slotNotifyBubble);
connect(&m_signalMediaRemoved ,&m_slotNotifyBubble);
connect(&m_signalPlayTone ,&m_slotNotifyBubble);
// connect(&m_signalPrinterKilled ,&m_slotNotifyBubble);
connect(&m_signalPrintTimerStarted ,&m_slotNotifyBubble);
connect(&m_signalPrintTimerPaused ,&m_slotNotifyBubble);
connect(&m_signalPrintTimerStopped ,&m_slotNotifyBubble);
connect(&m_signalFilamentRunout ,&m_slotNotifyBubble);
// connect(&m_signalUserConfirmRequired,&m_slotNotifyBubble);
connect(&m_signalStatusChanged ,&m_slotNotifyBubble);
connect(&m_signalFactoryReset ,&m_slotNotifyBubble);
connect(&m_signalStoreSettings ,&m_slotNotifyBubble);
connect(&m_signalLoadSettings ,&m_slotNotifyBubble);
}
void MarlinUi::initTasks()
{
//TODO:添加UI任务
}
//返回主界面
lv_res_t onButBackHomeClicked (struct _lv_obj_t * obj)
{
MarlinUi::getInstance()->showHomeScreen();
return LV_RES_OK;
}
//返回菜单界面
lv_res_t onButBackMenuClicked (struct _lv_obj_t * obj)
{
MarlinUi::getInstance()->showMenuScreen();
return LV_RES_OK;
}