Skip to content

Commit

Permalink
watchface dropdown: Add swipe down on any watchface opens a dropdown …
Browse files Browse the repository at this point in the history
…with quick actions etc.
  • Loading branch information
jakkra committed May 15, 2024
1 parent 1d7dc1a commit a5ed8d3
Show file tree
Hide file tree
Showing 19 changed files with 1,279 additions and 61 deletions.
2 changes: 2 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ target_sources(app PRIVATE src/ui/notification/zsw_popup_notifcation.c)
target_sources(app PRIVATE src/ui/popup/zsw_popup_window.c)
target_sources(app PRIVATE src/ui/utils/zsw_ui_utils.c)

target_sources(app PRIVATE src/ui/watchfaces/zsw_watchface_dropdown_ui.c)

target_sources_ifdef(CONFIG_SPI_FLASH_LOADER app PRIVATE src/filesystem/zsw_rtt_flash_loader.c)
target_sources_ifdef(CONFIG_FILE_SYSTEM_LITTLEFS app PRIVATE src/filesystem/zsw_filesystem.c)
target_sources_ifdef(CONFIG_FILE_SYSTEM_LITTLEFS app PRIVATE src/filesystem/zsw_lvgl_spi_decoder.c)
Expand Down
33 changes: 27 additions & 6 deletions app/src/applications/watchface/watchface_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "sensors/zsw_environment_sensor.h"
#include "sensors/zsw_pressure_sensor.h"
#include "managers/zsw_notification_manager.h"
#include "ui/watchfaces/zsw_watchface_dropdown_ui.h"

LOG_MODULE_REGISTER(watcface_app, LOG_LEVEL_WRN);

Expand Down Expand Up @@ -106,11 +107,13 @@ static struct k_work_sync canel_work_sync;
static K_WORK_DEFINE(update_ui_work, update_ui_from_event);
static ble_comm_cb_data_t last_data_update;
static ble_comm_weather_t last_weather_data;
static ble_comm_music_info_t last_music_info;
static struct battery_sample_event last_batt_evt = {.percent = 100, .mV = 4300};

static bool running;
static bool is_connected;
static bool is_suspended;
static lv_obj_t *watchface_root_screen;

static watchface_ui_api_t *watchfaces[MAX_WATCHFACES];
static uint8_t num_watchfaces;
Expand All @@ -137,13 +140,19 @@ void watchface_app_register_ui(watchface_ui_api_t *ui_api)
num_watchfaces++;
}

void watchface_app_start(lv_group_t *group, watchface_app_evt_listener evt_cb)
void watchface_app_start(lv_obj_t *root_screen, lv_group_t *group, watchface_app_evt_listener evt_cb)
{
__ASSERT(num_watchfaces > 0, "Must enable at least one watchface.");
int err = settings_load_subtree_direct(ZSW_SETTINGS_WATCHFACE, settings_load_handler, &watchface_settings);
if (err != 0) {
LOG_ERR("Failed loading watchface settings");
}

if (watchface_settings.watchface_index >= num_watchfaces) {
watchface_settings.watchface_index = 0;
}

watchface_root_screen = root_screen;
watchface_evt_cb = evt_cb;
general_work_item.type = OPEN_WATCHFACE;
__ASSERT(0 <= k_work_schedule(&general_work_item.work, K_MSEC(100)), "FAIL schedule");
Expand All @@ -157,6 +166,7 @@ void watchface_app_stop(void)
k_work_cancel_delayable_sync(&date_work.work, &canel_work_sync);
k_work_cancel_delayable_sync(&general_work_item.work, &canel_work_sync);
watchfaces[watchface_settings.watchface_index]->remove();
zsw_watchface_dropdown_ui_remove();
}

void watchface_change(int index)
Expand Down Expand Up @@ -238,11 +248,13 @@ static void general_work(struct k_work *item)
case OPEN_WATCHFACE: {
running = true;
is_suspended = false;
if (watchface_settings.watchface_index >= num_watchfaces) {
watchface_settings.watchface_index = 0;
}
watchfaces[watchface_settings.watchface_index]->show(watchface_evt_cb, &watchface_settings);
// 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);
}

__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 @@ -341,6 +353,9 @@ static void update_ui_from_event(struct k_work *item)
last_data_update.data.weather.weather_code);
} else if (last_data_update.type == BLE_COMM_DATA_TYPE_SET_TIME) {
k_work_reschedule(&date_work.work, K_NO_WAIT);
} else if (last_data_update.type == BLE_COMM_DATA_TYPE_MUSIC_INFO) {
zsw_watchface_dropdown_ui_set_music_info(last_data_update.data.music_info.track_name,
last_data_update.data.music_info.artist);
}
return;
}
Expand All @@ -352,7 +367,13 @@ static void zbus_ble_comm_data_callback(const struct zbus_channel *chan)
// TODO getting this callback again before workqueue has ran will
// cause previous to be lost.
memcpy(&last_data_update, &event->data, sizeof(ble_comm_cb_data_t));
memcpy(&last_weather_data, &last_data_update.data.weather, sizeof(last_data_update.data.weather));
if (event->data.type == BLE_COMM_DATA_TYPE_WEATHER) {
memcpy(&last_weather_data, &last_data_update.data.weather, sizeof(last_data_update.data.weather));
}
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 Down
23 changes: 20 additions & 3 deletions app/src/applications/watchface/watchface_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,33 @@
// UI need to be initialized after watchface_app
#define WATCHFACE_UI_INIT_PRIO 99

typedef enum watchface_app_evt_t {
typedef enum watchface_app_evt_type_t {
WATCHFACE_APP_EVENT_OPEN_APP,
WATCHFACE_APP_EVENT_SET_BRIGHTNESS,
WATCHFACE_APP_EVENT_RESTART,
WATCHFACE_APP_EVENT_SHUTDOWN,
} watchface_app_evt_type_t;

typedef enum watchface_app_evt_open_app_t {
WATCHFACE_APP_EVT_CLICK_BATT,
WATCHFACE_APP_EVT_CLICK_STEP,
WATCHFACE_APP_EVT_CLICK_WEATHER,
WATCHFACE_APP_EVT_CLICK_MUSIC,
WATCHFACE_APP_EVT_CLICK_SETTINGS
} watchface_app_evt_open_app_t;

typedef struct watchface_app_evt_t {
watchface_app_evt_type_t type;
union watchface_app_evt_data_t {
watchface_app_evt_open_app_t app;
uint16_t brightness;
} data;
} watchface_app_evt_t;

typedef void(*watchface_app_evt_listener)(watchface_app_evt_t);

typedef struct watchface_ui_api_t {
void (*show)(watchface_app_evt_listener, zsw_settings_watchface_t *settings);
void (*show)(lv_obj_t *root_screen, watchface_app_evt_listener, zsw_settings_watchface_t *settings);
void (*remove)(void);
void (*set_battery_percent)(int32_t percent, int32_t battery);
void (*set_hrm)(int32_t bpm, int32_t oxygen);
Expand All @@ -49,7 +66,7 @@ typedef struct watchface_ui_api_t {
const char *name;
} watchface_ui_api_t;

void watchface_app_start(lv_group_t *group, watchface_app_evt_listener evt_cb);
void watchface_app_start(lv_obj_t *root_screen, lv_group_t *group, watchface_app_evt_listener evt_cb);
void watchface_app_stop(void);
void watchface_change(int index);
int watchface_app_get_current_face(void);
Expand Down
Loading

0 comments on commit a5ed8d3

Please sign in to comment.