Skip to content

Commit

Permalink
watchface dropdown: Add battery icon reflecting charge, time to empty…
Browse files Browse the repository at this point in the history
…, percent.

Also adjust the UI, making buttons round and changing the brightness slider icon.
  • Loading branch information
jakkra committed May 16, 2024
1 parent 6f354a4 commit d76f995
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 897 deletions.
14 changes: 3 additions & 11 deletions app/src/applications/battery/battery_ui.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <battery/battery_ui.h>
#include "battery_ui.h"
#include "ui/utils/zsw_ui_utils.h"
#include <lvgl.h>

// Common
Expand Down Expand Up @@ -129,27 +130,18 @@ void battery_ui_add_measurement(int percent, int voltage)
}
}

static void seconds_to_day_hour_min(int seconds, int *days, int *hours, int *minutes)
{
*days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
*hours = seconds / 3600;
seconds = seconds % 3600;
*minutes = seconds / 60;
}

void battery_ui_update(int ttf, int tte, int status, int error, int charging)
{
int days, hours, minutes;

if (root_page && pmic_ui_enabled) {
seconds_to_day_hour_min(ttf, &days, &hours, &minutes);
zsw_ui_utils_seconds_to_day_hour_min(ttf, &days, &hours, &minutes);
if (ttf == 0) {
lv_label_set_text(ui_charging_label_ttf, "-");
} else {
lv_label_set_text_fmt(ui_charging_label_ttf, "%dd %dh %dm", days, hours, minutes);
}
seconds_to_day_hour_min(tte, &days, &hours, &minutes);
zsw_ui_utils_seconds_to_day_hour_min(tte, &days, &hours, &minutes);
if (tte == 0) {
lv_label_set_text(ui_charging_label_tte, "-");
} else {
Expand Down
1 change: 0 additions & 1 deletion app/src/applications/flashlight/flashlight_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void flashlight_ui_show(lv_obj_t *root)
lv_obj_set_width(root_page, lv_pct(100));
lv_obj_set_height(root_page, lv_pct(100));
lv_obj_set_align(root_page, LV_ALIGN_CENTER);
//lv_obj_clear_flag(root_page, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_bg_color(root_page, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_bg_opa(root_page, LV_OPA_COVER, LV_PART_MAIN | LV_STATE_DEFAULT);

Expand Down
12 changes: 7 additions & 5 deletions app/src/applications/watchface/watchface_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ static void refresh_ui(void)
uint32_t steps;
watchfaces[watchface_settings.watchface_index]->set_ble_connected(is_connected);
watchfaces[watchface_settings.watchface_index]->set_battery_percent(last_batt_evt.percent, last_batt_evt.mV);
zsw_watchface_dropdown_ui_set_battery_info(last_batt_evt.percent, last_batt_evt.is_charging, last_batt_evt.tte,
last_batt_evt.ttf);
if (strlen(last_weather_data.report_text) > 0) {
watchfaces[watchface_settings.watchface_index]->set_weather(last_weather_data.temperature_c,
last_weather_data.weather_code);
Expand All @@ -235,6 +237,9 @@ static void refresh_ui(void)
// TODO: Add calculation for distance and kcal
watchfaces[watchface_settings.watchface_index]->set_step(steps, 0, 0);
}
if (strlen(last_music_info.track_name) > 0) {
zsw_watchface_dropdown_ui_set_music_info(last_music_info.track_name, last_music_info.artist);
}
}

static void general_work(struct k_work *item)
Expand All @@ -250,11 +255,8 @@ static void general_work(struct k_work *item)
is_suspended = false;
// Dropdown
watchfaces[watchface_settings.watchface_index]->show(watchface_root_screen, watchface_evt_cb, &watchface_settings);
refresh_ui();
zsw_watchface_dropdown_ui_add(watchface_root_screen, watchface_evt_cb);
if (strlen(last_music_info.track_name) > 0) {
zsw_watchface_dropdown_ui_set_music_info(last_music_info.track_name, last_music_info.artist);
}
refresh_ui();

__ASSERT(0 <= k_work_schedule(&clock_work.work, K_NO_WAIT), "FAIL clock_work");
__ASSERT(0 <= k_work_schedule(&update_work.work, K_SECONDS(1)), "FAIL update_work");
Expand Down Expand Up @@ -372,7 +374,6 @@ static void zbus_ble_comm_data_callback(const struct zbus_channel *chan)
}
if (event->data.type == BLE_COMM_DATA_TYPE_MUSIC_INFO) {
memcpy(&last_music_info, &last_data_update.data.music_info, sizeof(last_data_update.data.music_info));
printk("Got music info: %s %s\n", last_music_info.track_name, last_music_info.artist);
}
if (running && !is_suspended) {
k_work_submit(&update_ui_work);
Expand All @@ -397,6 +398,7 @@ static void zbus_battery_sample_data_callback(const struct zbus_channel *chan)

if (running && !is_suspended) {
watchfaces[watchface_settings.watchface_index]->set_battery_percent(event->percent, event->mV);
zsw_watchface_dropdown_ui_set_battery_info(last_batt_evt.percent, event->is_charging, event->tte, event->ttf);
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/events/battery_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ struct battery_sample_event {
int status;
int error;
bool is_charging;
bool pmic_data_valid;
};
1 change: 1 addition & 0 deletions app/src/fuel_gauge/zsw_pmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ int zsw_pmic_get_full_state(struct battery_sample_event *sample)
sample->status = status;
sample->error = error;
sample->is_charging = is_charging_from_status(status);
sample->pmic_data_valid = true;

return ret;
}
Expand Down

0 comments on commit d76f995

Please sign in to comment.