Skip to content

Commit b3a1a21

Browse files
authored
Merge pull request #19 from bcmi-labs/fix-stabilise-power-before-menu
Create clean UI flow enticing the user to plug in the power supply before proceeding.
2 parents 3b78f98 + 90d6a15 commit b3a1a21

File tree

3 files changed

+69
-56
lines changed

3 files changed

+69
-56
lines changed

src/Braccio++.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,8 @@ class BraccioClass
160160
void digitalWrite(int pin, uint8_t value);
161161

162162
// default display APIs
163-
void drawMenu();
164-
void splashScreen(int duration = 1000);
165-
void hideMenu();
166-
void drawImage(char* image);
163+
void lvgl_splashScreen(unsigned long const duration_ms, std::function<void()> check_power_func);
164+
void lvgl_pleaseConnectPower();
167165
void defaultMenu();
168166

169167
void setID(int id) {
@@ -172,11 +170,12 @@ class BraccioClass
172170

173171
private:
174172

175-
RS485Class serial485;
176-
SmartServoClass servos;
173+
RS485Class serial485;
174+
SmartServoClass servos;
177175
PD_UFP_log_c PD_UFP;
178176
TCA6424A expander;
179177
Backlight bl;
178+
rtos::Thread _display_thread;
180179

181180
speed_grade_t runTime; //ms
182181

@@ -195,6 +194,7 @@ class BraccioClass
195194
lv_color_t buf[240 * 240 / 10];
196195
lv_group_t* p_objGroup;
197196
lv_indev_t *kb_indev;
197+
lv_style_t _lv_style;
198198

199199
bool _connected[8];
200200

src/Braccio.cpp

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ BraccioClass::BraccioClass()
2121
, PD_UFP{PD_LOG_LEVEL_VERBOSE}
2222
, expander{TCA6424A_ADDRESS_ADDR_HIGH}
2323
, bl{}
24+
, _display_thread{}
2425
, runTime{SLOW}
2526
, _customMenu{nullptr}
26-
2727
{
2828

2929
}
@@ -112,50 +112,48 @@ bool BraccioClass::begin(voidFuncPtr customMenu) {
112112
indev_drv.read_cb = read_keypad;
113113
kb_indev = lv_indev_drv_register(&indev_drv);
114114

115+
lv_style_init(&_lv_style);
116+
115117
gfx.init();
116118
gfx.setRotation(4);
117-
gfx.fillScreen(TFT_BLACK);
119+
gfx.fillScreen(TFT_WHITE);
118120
gfx.setAddrWindow(0, 0, 240, 240);
119121
gfx.setFreeFont(&FreeSans18pt7b);
120122

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-
128123
p_objGroup = lv_group_create();
129124
lv_group_set_default(p_objGroup);
130125

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());
132150

133151
if (customMenu) {
134152
customMenu();
135153
} else {
136154
defaultMenu();
137155
}
138156

139-
if (!PD_UFP.is_PPS_ready()) {
140-
gfx.fillScreen(TFT_BLACK);
141-
gfx.println("\n\nPlease\nconnect\npower");
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-
159157
servos.begin();
160158
servos.setPositionMode(PositionMode::IMMEDIATE);
161159

@@ -198,43 +196,58 @@ void BraccioClass::pd_thread() {
198196
}
199197
}
200198

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+
{
211203
lv_task_handler();
212204
lv_tick_inc(LV_DISP_DEF_REFR_PERIOD);
213-
delay(30);
205+
delay(LV_DISP_DEF_REFR_PERIOD);
214206
}
215207
}
216208

217209
#include <extra/libs/gif/lv_gif.h>
218210

219-
void BraccioClass::splashScreen(int duration) {
211+
void BraccioClass::lvgl_splashScreen(unsigned long const duration_ms, std::function<void()> check_power_func)
212+
{
220213
LV_IMG_DECLARE(img_bulb_gif);
221214
lv_obj_t* img = lv_gif_create(lv_scr_act());
222215
lv_gif_set_src(img, &img_bulb_gif);
223216
lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
224217

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();
229225
}
226+
230227
lv_obj_del(img);
231-
lv_obj_clean(lv_scr_act());
232228
}
233229

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\nconnect\npower.");
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+
}
235240

241+
void BraccioClass::defaultMenu()
242+
{
236243
// 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);
238251
}
239252

240253
void BraccioClass::motors_connected_thread() {

src/lv_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
274274
#define LV_FONT_MONTSERRAT_26 0
275275
#define LV_FONT_MONTSERRAT_28 0
276276
#define LV_FONT_MONTSERRAT_30 0
277-
#define LV_FONT_MONTSERRAT_32 0
277+
#define LV_FONT_MONTSERRAT_32 1
278278
#define LV_FONT_MONTSERRAT_34 0
279279
#define LV_FONT_MONTSERRAT_36 0
280280
#define LV_FONT_MONTSERRAT_38 0

0 commit comments

Comments
 (0)