Skip to content

Commit

Permalink
Fitness App: Use latest steps and not latest stored steps as current …
Browse files Browse the repository at this point in the history
…steps.
  • Loading branch information
jakkra committed Oct 24, 2024
1 parent 9ff076f commit be37a4a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
18 changes: 9 additions & 9 deletions app/src/applications/fitness/fitness_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
9 changes: 8 additions & 1 deletion app/src/applications/fitness/fitness_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions app/src/applications/fitness/fitness_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit be37a4a

Please sign in to comment.