From be37a4a44478cb84382b162b4129c5c31cdd083b Mon Sep 17 00:00:00 2001 From: Jakob Krantz Date: Thu, 24 Oct 2024 22:38:05 +0200 Subject: [PATCH] Fitness App: Use latest steps and not latest stored steps as current steps. --- app/src/applications/fitness/fitness_app.c | 18 +++++++++--------- app/src/applications/fitness/fitness_ui.c | 9 ++++++++- app/src/applications/fitness/fitness_ui.h | 2 ++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/applications/fitness/fitness_app.c b/app/src/applications/fitness/fitness_app.c index 5fbe0652..80360719 100644 --- a/app/src/applications/fitness/fitness_app.c +++ b/app/src/applications/fitness/fitness_app.c @@ -13,7 +13,7 @@ #include "ui/zsw_ui.h" #include "zsw_clock.h" -LOG_MODULE_REGISTER(fitness_app, LOG_LEVEL_DBG); +LOG_MODULE_REGISTER(fitness_app, LOG_LEVEL_INF); #define STEP_RESET_COUNTER_INTERVAL_S 50 #define DAYS_IN_WEEK 7 @@ -98,7 +98,6 @@ static void step_sample_work(struct k_work *work) if (zsw_history_save(&fitness_history_context)) { LOG_ERR("Error during saving of step samples!"); } - LOG_DBG("______STEP HIST ADD________"); LOG_DBG("Step sample hist add: %d", sample.steps); LOG_DBG("Time: %d:%d:%d", sample.time.tm.tm_hour, sample.time.tm.tm_min, sample.time.tm.tm_sec); next_sample_seconds = 60 * (SAMPLE_INTERVAL_MIN - sample.time.tm.tm_min) - sample.time.tm.tm_sec; @@ -145,22 +144,29 @@ static void shift_char_array_n_left(char **arr, int n, int size) static void fitness_app_start(lv_obj_t *root, lv_group_t *group) { zsw_timeval_t time; + uint32_t steps; uint16_t step_weekdays[DAYS_IN_WEEK] = {0}; static char *weekday_names[] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"}; zsw_clock_get_time(&time); get_steps_per_day(step_weekdays); + // Data is in the order of the days of the week, starting from Sunday (index 0) // Rotate the array (left/counter-clockwise) so the last element is the current day + // As we want the last bar in the chart to be "Today". int shifts = time.tm.tm_wday + 1; shift_array_n_left(step_weekdays, shifts, DAYS_IN_WEEK); shift_char_array_n_left(weekday_names, shifts, DAYS_IN_WEEK); for (int i = 0; i < DAYS_IN_WEEK; i++) { - printk("%s %d: %d\n", weekday_names[i], i, step_weekdays[i]); + LOG_DBG("%s %d: %d\n", weekday_names[i], i, step_weekdays[i]); } fitness_ui_show(root, DAYS_IN_WEEK); fitness_ui_set_weekly_steps(step_weekdays, weekday_names, DAYS_IN_WEEK); + + if (zsw_imu_fetch_num_steps(&steps) == 0) { + fitness_ui_set_daily_steps(steps); + } } static void fitness_app_stop(void) @@ -170,11 +176,8 @@ static void fitness_app_stop(void) static int fitness_app_add(void) { - struct tm tm; - struct tm prev_tm; int num_hist_samples; zsw_timeval_t time; - zsw_step_sample_t sample; int next_sample_seconds = 0; zsw_app_manager_add_application(&app); @@ -205,9 +208,6 @@ static int fitness_app_add(void) zsw_imu_set_step_offset(samples[num_hist_samples - 1].steps); } - // Print curent minute and second - LOG_DBG("fitness_app_add time: %d:%d:%d", time.tm.tm_hour, time.tm.tm_min, time.tm.tm_sec); - // Try to sample about every full hour next_sample_seconds = 60 * (SAMPLE_INTERVAL_MIN - time.tm.tm_min) - time.tm.tm_sec; diff --git a/app/src/applications/fitness/fitness_ui.c b/app/src/applications/fitness/fitness_ui.c index 39e341e6..8a99b8c9 100644 --- a/app/src/applications/fitness/fitness_ui.c +++ b/app/src/applications/fitness/fitness_ui.c @@ -160,7 +160,7 @@ static void create_step_chart(lv_obj_t *ui_root_container, uint16_t max_samples) lv_obj_set_style_pad_bottom(ui_step_goal_arc, 0, LV_PART_INDICATOR | LV_STATE_DEFAULT); lv_obj_set_style_pad_row(ui_step_goal_arc, 0, LV_PART_INDICATOR | LV_STATE_DEFAULT); lv_obj_set_style_pad_column(ui_step_goal_arc, 0, LV_PART_INDICATOR | LV_STATE_DEFAULT); - lv_obj_set_style_arc_color(ui_step_goal_arc, lv_color_hex(0x00921A), LV_PART_INDICATOR | LV_STATE_DEFAULT); + lv_obj_set_style_arc_color(ui_step_goal_arc, lv_color_hex(0xffd147), LV_PART_INDICATOR | LV_STATE_DEFAULT); lv_obj_set_style_arc_opa(ui_step_goal_arc, 255, LV_PART_INDICATOR | LV_STATE_DEFAULT); lv_obj_set_style_arc_width(ui_step_goal_arc, 4, LV_PART_INDICATOR | LV_STATE_DEFAULT); @@ -208,6 +208,13 @@ void fitness_ui_set_weekly_steps(uint16_t *samples, char **weekday_names, uint16 lv_arc_set_value(ui_step_goal_arc, samples[num_samples - 1]); } +void fitness_ui_set_daily_steps(uint32_t steps) +{ + lv_label_set_text_fmt(ui_step_progress_label, "%d / %d", steps, 10000); + lv_obj_set_style_text_align(ui_step_progress_label, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_arc_set_value(ui_step_goal_arc, steps); +} + void fitness_ui_remove(void) { lv_obj_del(root_page); diff --git a/app/src/applications/fitness/fitness_ui.h b/app/src/applications/fitness/fitness_ui.h index 590e7148..2a917791 100644 --- a/app/src/applications/fitness/fitness_ui.h +++ b/app/src/applications/fitness/fitness_ui.h @@ -7,4 +7,6 @@ void fitness_ui_show(lv_obj_t *root, uint16_t max_samples); void fitness_ui_set_weekly_steps(uint16_t *samples, char **weekday_names, uint16_t num_samples); +void fitness_ui_set_daily_steps(uint32_t steps); + void fitness_ui_remove(void);