Skip to content

Commit

Permalink
UI improvements
Browse files Browse the repository at this point in the history
7: Further improvements for distance handling

Task-Url: #7
  • Loading branch information
euphi committed Feb 26, 2024
1 parent b777973 commit 15d228d
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 55 deletions.
2 changes: 1 addition & 1 deletion SquareLine/Prj_BC_ScreenMainNoFL/BC_noFL_Main.sll

Large diffs are not rendered by default.

78 changes: 54 additions & 24 deletions SquareLine/Prj_BC_ScreenMainNoFL/BC_noFL_Main.spj
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,27 @@
},
{
"part": "lv.PART.MAIN",
"childs": [],
"childs": [
{
"nid": 603924104,
"strtype": "_style/StyleState",
"strval": "DEFAULT",
"childs": [
{
"nid": 1124367577,
"strtype": "_style/Image_reColor",
"intarray": [
0,
255,
128,
255
],
"InheritedType": 7
}
],
"InheritedType": 1
}
],
"nid": -1238569088,
"strtype": "IMAGE/Style_main",
"strval": "lv.PART.MAIN, Rectangle, Image",
Expand Down Expand Up @@ -2759,7 +2779,6 @@
},
{
"nid": -1093591655,
"flags": 1048576,
"strtype": "OBJECT/Flags",
"InheritedType": 1
},
Expand Down Expand Up @@ -3363,7 +3382,7 @@
{
"disabled": false,
"nid": -1107602054,
"strtype": "BAR/EventHandler",
"strtype": "_event/EventHandler",
"strval": "LONG_PRESSED",
"childs": [
{
Expand All @@ -3385,39 +3404,50 @@
"InheritedType": 10
},
{
"nid": 2059399822,
"strtype": "_custom/action",
"strval": "CALL FUNCTION",
"nid": -1990359932,
"strtype": "_event/action",
"strval": "CHANGE SCREEN",
"childs": [
{
"nid": 1332783641,
"strtype": "CALL FUNCTION/Name",
"strval": "CALL FUNCTION",
"nid": 5215819,
"strtype": "CHANGE SCREEN/Name",
"strval": "CHANGE SCREEN",
"InheritedType": 10
},
{
"nid": 1817510223,
"strtype": "CALL FUNCTION/Call",
"strval": "<{Function_name}>( event_struct )",
"nid": 1921040003,
"strtype": "CHANGE SCREEN/Call",
"strval": "ChangeScreen( <{Screen_to}>, lv.SCR_LOAD_ANIM.<{Fade_mode}>, <{Speed}>, <{Delay}>)",
"InheritedType": 10
},
{
"nid": 497649743,
"strtype": "CALL FUNCTION/CallC",
"strval": "<{Function_name}>( e );",
"nid": -1943115893,
"strtype": "CHANGE SCREEN/CallC",
"strval": "_ui_screen_change( &<{Screen_to}>, LV_SCR_LOAD_ANIM_<{Fade_mode}>, <{Speed}>, <{Delay}>, &<{Screen_to}>_screen_init);",
"InheritedType": 10
},
{
"nid": 327416136,
"strtype": "CALL FUNCTION/Function_name",
"strval": "EvShowChart",
"InheritedType": 10
"nid": 1787548846,
"strtype": "CHANGE SCREEN/Screen_to",
"strval": "GUID7263531-768085S8942168",
"InheritedType": 9
},
{
"nid": -647089206,
"strtype": "CALL FUNCTION/Dont_export_function",
"strval": "False",
"InheritedType": 2
"nid": 1618416246,
"strtype": "CHANGE SCREEN/Fade_mode",
"strval": "OVER_TOP",
"InheritedType": 3
},
{
"nid": 2117332731,
"strtype": "CHANGE SCREEN/Speed",
"integer": 500,
"InheritedType": 6
},
{
"nid": 597170260,
"strtype": "CHANGE SCREEN/Delay",
"InheritedType": 6
}
],
"InheritedType": 10
Expand Down Expand Up @@ -8569,7 +8599,7 @@
"theme_color2": 0,
"uiExportFolderPath": "/home/ian/Coding/Bike/TRGB-BikeComputer/SquareLine/exported_files/SMainNoFl",
"projectExportFolderPath": "",
"backup_cnt": 43,
"backup_cnt": 48,
"autosave_cnt": 0,
"lvgl_version": "8.3.4",
"callfuncsexport": "CPP_FILE",
Expand Down
4 changes: 4 additions & 0 deletions SquareLine/Prj_BC_ScreenMainNoFL/BC_noFL_Main_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ def stateIconClicked(event_struct):
def driveStateUpdate(event_struct):
return


def EvShowChart(event_struct):
return

24 changes: 12 additions & 12 deletions include/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@

/*Montserrat fonts with ASCII range and some symbols using bpp = 4
*https://fonts.google.com/specimen/Montserrat*/
#define LV_FONT_MONTSERRAT_8 1
#define LV_FONT_MONTSERRAT_8 0
#define LV_FONT_MONTSERRAT_10 0
#define LV_FONT_MONTSERRAT_12 1
#define LV_FONT_MONTSERRAT_12 0
#define LV_FONT_MONTSERRAT_14 1
#define LV_FONT_MONTSERRAT_16 0
#define LV_FONT_MONTSERRAT_18 1
Expand Down Expand Up @@ -511,9 +511,9 @@
*----------*/
#define LV_USE_ANIMIMG 1

#define LV_USE_CALENDAR 1
#define LV_USE_CALENDAR 0
#if LV_USE_CALENDAR
#define LV_CALENDAR_WEEK_STARTS_MONDAY 0
#define LV_CALENDAR_WEEK_STARTS_MONDAY 1
#if LV_CALENDAR_WEEK_STARTS_MONDAY
#define LV_CALENDAR_DEFAULT_DAY_NAMES {"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"}
#else
Expand All @@ -527,13 +527,13 @@

#define LV_USE_CHART 1

#define LV_USE_COLORWHEEL 1
#define LV_USE_COLORWHEEL 0

#define LV_USE_IMGBTN 1

#define LV_USE_KEYBOARD 1

#define LV_USE_LED 1
#define LV_USE_LED 0

#define LV_USE_LIST 1

Expand All @@ -553,11 +553,11 @@

#define LV_USE_SPINNER 1

#define LV_USE_TABVIEW 1
#define LV_USE_TABVIEW 0

#define LV_USE_TILEVIEW 1
#define LV_USE_TILEVIEW 0

#define LV_USE_WIN 1
#define LV_USE_WIN 0

/*-----------
* Themes
Expand Down Expand Up @@ -726,7 +726,7 @@
====================*/

/*Show some widget. It might be required to increase `LV_MEM_SIZE` */
#define LV_USE_DEMO_WIDGETS 1
#define LV_USE_DEMO_WIDGETS 0
#if LV_USE_DEMO_WIDGETS
#define LV_DEMO_WIDGETS_SLIDESHOW 0
#endif
Expand All @@ -735,7 +735,7 @@
#define LV_USE_DEMO_KEYPAD_AND_ENCODER 0

/*Benchmark your system*/
#define LV_USE_DEMO_BENCHMARK 1
#define LV_USE_DEMO_BENCHMARK 0
#if LV_USE_DEMO_BENCHMARK
/*Use RGB565A8 images with 16 bit color depth instead of ARGB8565*/
#define LV_DEMO_BENCHMARK_RGB565A8 0
Expand All @@ -745,7 +745,7 @@
#define LV_USE_DEMO_STRESS 0

/*Music player demo*/
#define LV_USE_DEMO_MUSIC 1
#define LV_USE_DEMO_MUSIC 0
#if LV_USE_DEMO_MUSIC
#define LV_DEMO_MUSIC_SQUARE 0
#define LV_DEMO_MUSIC_LANDSCAPE 0
Expand Down
3 changes: 2 additions & 1 deletion src/Stats/Distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ bool Distance::updateWheelCirc(const float circ_in_m) {

void Distance::resetDistToZero(Statistics::ESummaryType eSummaryType) {
if (eSummaryType < Statistics::SUM_ESP_TOTAL || eSummaryType > Statistics::SUM_ESP_START) {
bclog.logf(BCLogger::Log_Error, BCLogger::TAG_STAT, "Try to reset invalid Sum-Type 0x%04x", eSummaryType);
bool expected = (eSummaryType == Statistics::SUM_ESP_TOTAL) || (eSummaryType == Statistics::SUM_ESP_START); // if user presses reset in TOTAL or START
bclog.logf(expected ? BCLogger::Log_Debug : BCLogger::Log_Error, BCLogger::TAG_STAT, "Try to reset invalid Sum-Type 0x%04x", eSummaryType);
return;
}
curTotalDistance[eSummaryType] = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Stats/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ void Statistics::calculateGradient(float newDist) {

float gradient_new = NAN; // division by 0 should not lead not +Inf or -Inf, because delta_height is also close to zero. Ideally it would be zero, so 0/0 --> NAN.
if (delta_dist > 0.2) {
gradient = delta_height / (delta_dist) * 100.0; // simplified gradient calculation. Accurate enough for smaller gradients.
gradient_new = delta_height / (delta_dist) * 100.0; // simplified gradient calculation. Accurate enough for smaller gradients.
}
bclog.logf(BCLogger::Log_Info, BCLogger::TAG_STAT, "Gradient: %.2f", gradient);
bclog.logf(BCLogger::Log_Info, BCLogger::TAG_STAT, "Gradient: %.2f", gradient_new);
addGradientHeight(gradient_new, height_new);
}
#endif
Expand Down
22 changes: 18 additions & 4 deletions src/ui/Screens/MainNoFL/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lv_obj_t * ui_ArcSpeed;
lv_obj_t * ui_ArcAvg;
lv_obj_t * ui_ArcCad;
lv_obj_t * ui_LabelSpeed;
void ui_event_BarHR(lv_event_t * e);
lv_obj_t * ui_BarHR;
lv_obj_t * ui_LabelHR;
lv_obj_t * ui_LabelDist;
Expand Down Expand Up @@ -64,28 +65,41 @@ void ui_event_PanelNav(lv_event_t * e)
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_CLICKED) {
_ui_screen_change(ui_SNavi, LV_SCR_LOAD_ANIM_MOVE_TOP, 500, 0);
_ui_screen_change(ui_SChart, LV_SCR_LOAD_ANIM_MOVE_TOP, 500, 0);
}
}
void ui_event_BarHR(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_LONG_PRESSED) {
_ui_screen_change(ui_SChart, LV_SCR_LOAD_ANIM_OVER_TOP, 500, 0);
}
}
void ui_event_PanelClock(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);

if(event_code == LV_EVENT_LONG_PRESSED) {
resetStats(e);
lv_indev_wait_release(lv_indev_get_act());
resetStats();
}
if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_TOP) {
lv_indev_wait_release(lv_indev_get_act());
statsTimeMode(true);
}
if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_BOTTOM) {
lv_indev_wait_release(lv_indev_get_act());
statsTimeMode(false);
}

if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_RIGHT) {
lv_indev_wait_release(lv_indev_get_act());
statModeNext(true);
}
if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_LEFT) {
lv_indev_wait_release(lv_indev_get_act());
statModeNext(false);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/Screens/MainNoFL/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern lv_obj_t * ui_ArcSpeed;
extern lv_obj_t * ui_ArcAvg;
extern lv_obj_t * ui_ArcCad;
extern lv_obj_t * ui_LabelSpeed;
void ui_event_BarHR(lv_event_t * e);
extern lv_obj_t * ui_BarHR;
extern lv_obj_t * ui_LabelHR;
extern lv_obj_t * ui_LabelDist;
Expand Down
13 changes: 5 additions & 8 deletions src/ui/Screens/MainNoFL/ui_MainNoFL_CustFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void ui_SMainNoFLUpdateSpeed(float speed) {

}
void ui_SMainNoFLUpdateCadence(int16_t cadence) {
lv_label_set_text_fmt(ui_LabelCad, (cadence >= 0) ? "%d rpm" : "-/-", cadence);
lv_label_set_text_fmt(ui_LabelCad, (cadence >= 0) ? "%drpm" : "-/-", cadence);
lv_arc_set_value(ui_ArcCad, cadence);
}

Expand All @@ -27,12 +27,10 @@ void ui_SMainNoFLUpdateHR(int16_t hr) {
}

void ui_SMainNoFLUpdateGrad(float grad, float height) {
lv_label_set_text_fmt(ui_LabelGradient, "%.1f", grad);
lv_label_set_text_fmt(ui_LabelHeight, "%.1f", height);
lv_label_set_text_fmt(ui_LabelGradient, "%.1f%%", grad);
lv_label_set_text_fmt(ui_LabelHeight, "%.1fm", height);
}



void ui_SMainNoFLUpdateNavDist(uint32_t dist) {
if (dist < 1500) {
lv_label_set_text_fmt(ui_LabelNavDist, "%dm", dist);
Expand Down Expand Up @@ -84,9 +82,8 @@ void ui_SMainNoFLUpdateStats(const char* modeStr, const char* avgStr, float avgS
lv_arc_set_value(ui_ArcAvg, (int16_t)(avgSpd * 10));
lv_label_set_text_fmt(ui_LabelDist, "%.1fkm", dist/1000.0);
lv_label_set_text_fmt(ui_LabelClock, "%02d:%02d:%02d", timeInS / 3600, (timeInS / 60) % 60, timeInS % 60);
lv_label_set_text_fmt(ui_LabelTemp, "%.1f", temperature);
lv_label_set_text_fmt(ui_LabelHeight, "%.1f", height);

lv_label_set_text_fmt(ui_LabelTemp, "%.1f°C", temperature);
lv_label_set_text_fmt(ui_LabelHeight, "%.1fm", height);
}

void ui_SMainNoFLUpdateStateIcon(const lv_img_dsc_t * pStateIcon, lv_color_t color) {
Expand Down
3 changes: 2 additions & 1 deletion src/ui/Screens/MainNoFL/ui_SMainNoFL.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void ui_SMainNoFL_screen_init(void)
lv_obj_set_x(ui_ImgNav, -8);
lv_obj_set_y(ui_ImgNav, -10);
lv_obj_set_style_img_recolor(ui_ImgNav, lv_color_hex(0x0000FF), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_img_opa(ui_ImgNav, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_align(ui_ImgNav, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_ImgNav, LV_OBJ_FLAG_ADV_HITTEST | LV_OBJ_FLAG_EVENT_BUBBLE); /// Flags
lv_obj_clear_flag(ui_ImgNav, LV_OBJ_FLAG_SCROLLABLE); /// Flags
Expand Down Expand Up @@ -316,5 +317,5 @@ void ui_SMainNoFL_screen_init(void)
lv_obj_add_event_cb(ui_ImgWifi, ui_event_ImgWifi, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_ImgSettings, ui_event_ImgSettings, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_ImgState, ui_event_ImgState, LV_EVENT_ALL, NULL);

lv_obj_add_event_cb(ui_BarHR, ui_event_BarHR, LV_EVENT_ALL, NULL);
}
2 changes: 1 addition & 1 deletion src/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void chart_dn(lv_event_t * e);
void statModeChanged(uint8_t mode);
void statModeNext(bool dir);

void resetStats(lv_event_t * e);
void resetStats();
void statsTimeMode(bool dir);

typedef enum {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/ui_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void statModeNext(bool dir) {
ui.setStatMode(dir);
}

void resetStats(lv_event_t * e)
void resetStats()
{
// Serial.println("UI Event: Reset stats");
stats.getDistHandler().resetDistToZero(ui.getStatMode());
Expand Down

0 comments on commit 15d228d

Please sign in to comment.