@@ -21,9 +21,9 @@ BraccioClass::BraccioClass()
21
21
, PD_UFP{PD_LOG_LEVEL_VERBOSE}
22
22
, expander{TCA6424A_ADDRESS_ADDR_HIGH}
23
23
, bl{}
24
+ , _display_thread{}
24
25
, runTime{SLOW}
25
26
, _customMenu{nullptr }
26
-
27
27
{
28
28
29
29
}
@@ -112,50 +112,48 @@ bool BraccioClass::begin(voidFuncPtr customMenu) {
112
112
indev_drv.read_cb = read_keypad;
113
113
kb_indev = lv_indev_drv_register (&indev_drv);
114
114
115
+ lv_style_init (&_lv_style);
116
+
115
117
gfx.init ();
116
118
gfx.setRotation (4 );
117
- gfx.fillScreen (TFT_BLACK );
119
+ gfx.fillScreen (TFT_WHITE );
118
120
gfx.setAddrWindow (0 , 0 , 240 , 240 );
119
121
gfx.setFreeFont (&FreeSans18pt7b);
120
122
121
- /*
122
- gfx.drawBitmap(44, 60, ArduinoLogo, 152, 72, 0x04B3);
123
- gfx.drawBitmap(48, 145, ArduinoText, 144, 23, 0x04B3);
124
- */
125
-
126
- // delay(2000);
127
-
128
123
p_objGroup = lv_group_create ();
129
124
lv_group_set_default (p_objGroup);
130
125
131
- splashScreen ();
126
+ _display_thread.start (mbed::callback (this , &BraccioClass::display_thread));
127
+
128
+ auto check_power_func = [this ]()
129
+ {
130
+ if (!PD_UFP.is_PPS_ready ())
131
+ {
132
+ i2c_mutex.lock ();
133
+ PD_UFP.print_status (Serial);
134
+ PD_UFP.set_PPS (PPS_V (7.2 ), PPS_A (2.0 ));
135
+ delay (10 );
136
+ i2c_mutex.unlock ();
137
+ }
138
+ };
139
+
140
+ lvgl_splashScreen (2000 , check_power_func);
141
+ lv_obj_clean (lv_scr_act ());
142
+
143
+ if (!PD_UFP.is_PPS_ready ())
144
+ lvgl_pleaseConnectPower ();
145
+
146
+ /* Loop forever, if no power is attached. */
147
+ while (!PD_UFP.is_PPS_ready ())
148
+ check_power_func ();
149
+ lv_obj_clean (lv_scr_act ());
132
150
133
151
if (customMenu) {
134
152
customMenu ();
135
153
} else {
136
154
defaultMenu ();
137
155
}
138
156
139
- if (!PD_UFP.is_PPS_ready ()) {
140
- gfx.fillScreen (TFT_BLACK);
141
- gfx.println (" \n\n Please\n connect\n power" );
142
- }
143
-
144
- // PD_UFP.print_status(Serial);
145
- while (!PD_UFP.is_PPS_ready ()) {
146
- i2c_mutex.lock ();
147
- PD_UFP.print_status (Serial);
148
- // PD_UFP.print_status(Serial);
149
- PD_UFP.set_PPS (PPS_V (7.2 ), PPS_A (2.0 ));
150
- delay (10 );
151
- i2c_mutex.unlock ();
152
- }
153
-
154
- #ifdef __MBED__
155
- static rtos::Thread display_th;
156
- display_th.start (mbed::callback (this , &BraccioClass::display_thread));
157
- #endif
158
-
159
157
servos.begin ();
160
158
servos.setPositionMode (PositionMode::IMMEDIATE);
161
159
@@ -198,43 +196,58 @@ void BraccioClass::pd_thread() {
198
196
}
199
197
}
200
198
201
- void BraccioClass::display_thread () {
202
- while (1 ) {
203
- /*
204
- if ((braccio::encoder.menu_running) && (braccio::encoder.menu_interrupt)) {
205
- braccio::encoder.menu_interrupt = false;
206
- braccio::nav.doInput();
207
- braccio::nav.doOutput();
208
- }
209
- yield();
210
- */
199
+ void BraccioClass::display_thread ()
200
+ {
201
+ for (;;)
202
+ {
211
203
lv_task_handler ();
212
204
lv_tick_inc (LV_DISP_DEF_REFR_PERIOD);
213
- delay (30 );
205
+ delay (LV_DISP_DEF_REFR_PERIOD );
214
206
}
215
207
}
216
208
217
209
#include < extra/libs/gif/lv_gif.h>
218
210
219
- void BraccioClass::splashScreen (int duration) {
211
+ void BraccioClass::lvgl_splashScreen (unsigned long const duration_ms, std::function<void ()> check_power_func)
212
+ {
220
213
LV_IMG_DECLARE (img_bulb_gif);
221
214
lv_obj_t * img = lv_gif_create (lv_scr_act ());
222
215
lv_gif_set_src (img, &img_bulb_gif);
223
216
lv_obj_align (img, LV_ALIGN_CENTER, 0 , 0 );
224
217
225
- for (long start = millis (); millis () - start < duration;) {
226
- lv_task_handler ();
227
- lv_tick_inc (LV_DISP_DEF_REFR_PERIOD);
228
- delay (10 );
218
+ /* Wait until the splash screen duration is over.
219
+ * Meanwhile use the wait time for checking the
220
+ * power.
221
+ */
222
+ for (unsigned long const start = millis (); millis () - start < duration_ms;)
223
+ {
224
+ check_power_func ();
229
225
}
226
+
230
227
lv_obj_del (img);
231
- lv_obj_clean (lv_scr_act ());
232
228
}
233
229
234
- void BraccioClass::defaultMenu () {
230
+ void BraccioClass::lvgl_pleaseConnectPower ()
231
+ {
232
+ lv_style_set_text_font (&_lv_style, &lv_font_montserrat_32);
233
+ lv_obj_t * label1 = lv_label_create (lv_scr_act ());
234
+ lv_obj_add_style (label1, &_lv_style, 0 );
235
+ lv_label_set_text (label1, " Please\n connect\n power." );
236
+ lv_label_set_long_mode (label1, LV_LABEL_LONG_SCROLL);
237
+ lv_obj_set_align (label1, LV_ALIGN_CENTER);
238
+ lv_obj_set_pos (label1, 0 , 0 );
239
+ }
235
240
241
+ void BraccioClass::defaultMenu ()
242
+ {
236
243
// TODO: create a meaningful default menu
237
-
244
+ lv_style_set_text_font (&_lv_style, &lv_font_montserrat_32);
245
+ lv_obj_t * label1 = lv_label_create (lv_scr_act ());
246
+ lv_obj_add_style (label1, &_lv_style, 0 );
247
+ lv_label_set_text (label1, " Braccio++" );
248
+ lv_label_set_long_mode (label1, LV_LABEL_LONG_SCROLL);
249
+ lv_obj_set_align (label1, LV_ALIGN_CENTER);
250
+ lv_obj_set_pos (label1, 0 , 0 );
238
251
}
239
252
240
253
void BraccioClass::motors_connected_thread () {
0 commit comments