Skip to content

Create clean UI flow enticing the user to plug in the power supply before proceeding. #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
bd05a99
Set-up power before running either custom or default menu.
aentinger Jan 12, 2022
248243d
Enable larger font with size 32px.
aentinger Jan 12, 2022
263d9db
Use LVGL instead of direct GFX calls for writing power message to TFT…
aentinger Jan 12, 2022
bdc99ca
Delete out-dated/out-commented code.
aentinger Jan 12, 2022
466ff98
Start display thread earlier. This allows to skip calling the display…
aentinger Jan 12, 2022
1a3af7c
mbed is the only platform we run this library on, hence we can drop t…
aentinger Jan 12, 2022
2db0bde
Since the Arduino GIF is white, we may just as well configure for whi…
aentinger Jan 12, 2022
c52923d
Prolonge showing of Arduino GIF.
aentinger Jan 12, 2022
cec317a
Replace 'while(1)' with 'for(;;)' which more expressively says 'infin…
aentinger Jan 12, 2022
6d1044c
Show empty battery symbol in order to entice user to connect power.
aentinger Jan 12, 2022
00b441c
Delete un-implemented function 'drawImage'.
aentinger Jan 13, 2022
254a01c
Delete un-implemented function 'hideMenu'.
aentinger Jan 13, 2022
5c8fbbf
Delete un-implemented function 'drawMenu'.
aentinger Jan 13, 2022
d73bcc2
Rename splashScreen to lvgl_splashScreen and remove default parameter.
aentinger Jan 13, 2022
59ab72c
Check for power while the splash screen is shown/only show empty batt…
aentinger Jan 13, 2022
1daccfd
Rewriting flow to entice user to attach power
aentinger Jan 13, 2022
90d6a15
Pack code for checking power into lambda in order to avoid code dupli…
aentinger Jan 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Braccio++.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ class BraccioClass
void digitalWrite(int pin, uint8_t value);

// default display APIs
void drawMenu();
void splashScreen(int duration = 1000);
void hideMenu();
void drawImage(char* image);
void lvgl_splashScreen(unsigned long const duration_ms, std::function<void()> check_power_func);
void lvgl_pleaseConnectPower();
void defaultMenu();

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

private:

RS485Class serial485;
SmartServoClass servos;
RS485Class serial485;
SmartServoClass servos;
PD_UFP_log_c PD_UFP;
TCA6424A expander;
Backlight bl;
rtos::Thread _display_thread;

speed_grade_t runTime; //ms

Expand All @@ -195,6 +194,7 @@ class BraccioClass
lv_color_t buf[240 * 240 / 10];
lv_group_t* p_objGroup;
lv_indev_t *kb_indev;
lv_style_t _lv_style;

bool _connected[8];

Expand Down
111 changes: 62 additions & 49 deletions src/Braccio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ BraccioClass::BraccioClass()
, PD_UFP{PD_LOG_LEVEL_VERBOSE}
, expander{TCA6424A_ADDRESS_ADDR_HIGH}
, bl{}
, _display_thread{}
, runTime{SLOW}
, _customMenu{nullptr}

{

}
Expand Down Expand Up @@ -112,50 +112,48 @@ bool BraccioClass::begin(voidFuncPtr customMenu) {
indev_drv.read_cb = read_keypad;
kb_indev = lv_indev_drv_register(&indev_drv);

lv_style_init(&_lv_style);

gfx.init();
gfx.setRotation(4);
gfx.fillScreen(TFT_BLACK);
gfx.fillScreen(TFT_WHITE);
gfx.setAddrWindow(0, 0, 240, 240);
gfx.setFreeFont(&FreeSans18pt7b);

/*
gfx.drawBitmap(44, 60, ArduinoLogo, 152, 72, 0x04B3);
gfx.drawBitmap(48, 145, ArduinoText, 144, 23, 0x04B3);
*/

//delay(2000);

p_objGroup = lv_group_create();
lv_group_set_default(p_objGroup);

splashScreen();
_display_thread.start(mbed::callback(this, &BraccioClass::display_thread));

auto check_power_func = [this]()
{
if (!PD_UFP.is_PPS_ready())
{
i2c_mutex.lock();
PD_UFP.print_status(Serial);
PD_UFP.set_PPS(PPS_V(7.2), PPS_A(2.0));
delay(10);
i2c_mutex.unlock();
}
};

lvgl_splashScreen(2000, check_power_func);
lv_obj_clean(lv_scr_act());

if (!PD_UFP.is_PPS_ready())
lvgl_pleaseConnectPower();

/* Loop forever, if no power is attached. */
while(!PD_UFP.is_PPS_ready())
check_power_func();
lv_obj_clean(lv_scr_act());

if (customMenu) {
customMenu();
} else {
defaultMenu();
}

if (!PD_UFP.is_PPS_ready()) {
gfx.fillScreen(TFT_BLACK);
gfx.println("\n\nPlease\nconnect\npower");
}

//PD_UFP.print_status(Serial);
while (!PD_UFP.is_PPS_ready()) {
i2c_mutex.lock();
PD_UFP.print_status(Serial);
//PD_UFP.print_status(Serial);
PD_UFP.set_PPS(PPS_V(7.2), PPS_A(2.0));
delay(10);
i2c_mutex.unlock();
}

#ifdef __MBED__
static rtos::Thread display_th;
display_th.start(mbed::callback(this, &BraccioClass::display_thread));
#endif

servos.begin();
servos.setPositionMode(PositionMode::IMMEDIATE);

Expand Down Expand Up @@ -198,43 +196,58 @@ void BraccioClass::pd_thread() {
}
}

void BraccioClass::display_thread() {
while (1) {
/*
if ((braccio::encoder.menu_running) && (braccio::encoder.menu_interrupt)) {
braccio::encoder.menu_interrupt = false;
braccio::nav.doInput();
braccio::nav.doOutput();
}
yield();
*/
void BraccioClass::display_thread()
{
for(;;)
{
lv_task_handler();
lv_tick_inc(LV_DISP_DEF_REFR_PERIOD);
delay(30);
delay(LV_DISP_DEF_REFR_PERIOD);
}
}

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

void BraccioClass::splashScreen(int duration) {
void BraccioClass::lvgl_splashScreen(unsigned long const duration_ms, std::function<void()> check_power_func)
{
LV_IMG_DECLARE(img_bulb_gif);
lv_obj_t* img = lv_gif_create(lv_scr_act());
lv_gif_set_src(img, &img_bulb_gif);
lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);

for (long start = millis(); millis() - start < duration;) {
lv_task_handler();
lv_tick_inc(LV_DISP_DEF_REFR_PERIOD);
delay(10);
/* Wait until the splash screen duration is over.
* Meanwhile use the wait time for checking the
* power.
*/
for (unsigned long const start = millis(); millis() - start < duration_ms;)
{
check_power_func();
}

lv_obj_del(img);
lv_obj_clean(lv_scr_act());
}

void BraccioClass::defaultMenu() {
void BraccioClass::lvgl_pleaseConnectPower()
{
lv_style_set_text_font(&_lv_style, &lv_font_montserrat_32);
lv_obj_t * label1 = lv_label_create(lv_scr_act());
lv_obj_add_style(label1, &_lv_style, 0);
lv_label_set_text(label1, "Please\nconnect\npower.");
lv_label_set_long_mode(label1, LV_LABEL_LONG_SCROLL);
lv_obj_set_align(label1, LV_ALIGN_CENTER);
lv_obj_set_pos(label1, 0, 0);
}

void BraccioClass::defaultMenu()
{
// TODO: create a meaningful default menu

lv_style_set_text_font(&_lv_style, &lv_font_montserrat_32);
lv_obj_t * label1 = lv_label_create(lv_scr_act());
lv_obj_add_style(label1, &_lv_style, 0);
lv_label_set_text(label1, "Braccio++");
lv_label_set_long_mode(label1, LV_LABEL_LONG_SCROLL);
lv_obj_set_align(label1, LV_ALIGN_CENTER);
lv_obj_set_pos(label1, 0, 0);
}

void BraccioClass::motors_connected_thread() {
Expand Down
2 changes: 1 addition & 1 deletion src/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
#define LV_FONT_MONTSERRAT_26 0
#define LV_FONT_MONTSERRAT_28 0
#define LV_FONT_MONTSERRAT_30 0
#define LV_FONT_MONTSERRAT_32 0
#define LV_FONT_MONTSERRAT_32 1
#define LV_FONT_MONTSERRAT_34 0
#define LV_FONT_MONTSERRAT_36 0
#define LV_FONT_MONTSERRAT_38 0
Expand Down