Skip to content

Commit

Permalink
Add basic flashligh app, started from watchface quick menu/dropdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkra committed May 15, 2024
1 parent a5ed8d3 commit 6f354a4
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 21 deletions.
2 changes: 2 additions & 0 deletions app/src/applications/flashlight/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FILE(GLOB app_sources *.c)
target_sources(app PRIVATE ${app_sources})
38 changes: 38 additions & 0 deletions app/src/applications/flashlight/flashlight_app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <zephyr/kernel.h>
#include <zephyr/init.h>
#include "flashlight_ui.h"
#include "managers/zsw_app_manager.h"
#include "drivers/zsw_display_control.h"

static void flashlight_app_start(lv_obj_t *root, lv_group_t *group);
static void flashlight_app_stop(void);

static application_t app = {
.name = "Flashlight",
.start_func = flashlight_app_start,
.stop_func = flashlight_app_stop,
.hidden = true,
};

static uint8_t original_brightness;

static void flashlight_app_start(lv_obj_t *root, lv_group_t *group)
{
original_brightness = zsw_display_control_get_brightness();
flashlight_ui_show(root);
}

static void flashlight_app_stop(void)
{
flashlight_ui_remove();
zsw_display_control_set_brightness(original_brightness);
}

static int flashlight_app_add(void)
{
zsw_app_manager_add_application(&app);

return 0;
}

SYS_INIT(flashlight_app_add, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
41 changes: 41 additions & 0 deletions app/src/applications/flashlight/flashlight_ui.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "flashlight_ui.h"
#include "ui/zsw_ui.h"

static lv_obj_t *root_page = NULL;
static bool on;

static void on_click(lv_event_t *e)
{
on = !on;
if (on) {
lv_obj_set_style_bg_color(root_page, lv_color_white(), LV_PART_MAIN);
} else {
lv_obj_set_style_bg_color(root_page, lv_color_black(), LV_PART_MAIN);
}
}

void flashlight_ui_show(lv_obj_t *root)
{
assert(root_page == NULL);

root_page = lv_obj_create(root);
lv_obj_set_style_border_width(root_page, 0, LV_PART_MAIN);
lv_obj_set_size(root_page, LV_PCT(100), LV_PCT(100));

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);

lv_obj_add_event_cb(root_page, on_click, LV_EVENT_CLICKED, NULL);

on = true;
}

void flashlight_ui_remove(void)
{
lv_obj_del(root_page);
root_page = NULL;
}
8 changes: 8 additions & 0 deletions app/src/applications/flashlight/flashlight_ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <inttypes.h>
#include <lvgl.h>

void flashlight_ui_show(lv_obj_t *root);

void flashlight_ui_remove(void);
3 changes: 2 additions & 1 deletion app/src/applications/watchface/watchface_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ typedef enum watchface_app_evt_open_app_t {
WATCHFACE_APP_EVT_CLICK_STEP,
WATCHFACE_APP_EVT_CLICK_WEATHER,
WATCHFACE_APP_EVT_CLICK_MUSIC,
WATCHFACE_APP_EVT_CLICK_SETTINGS
WATCHFACE_APP_EVT_CLICK_SETTINGS,
WATCHFACE_APP_EVT_CLICK_FLASHLIGHT
} watchface_app_evt_open_app_t;

typedef struct watchface_app_evt_t {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ static void on_watchface_app_event_callback(watchface_app_evt_t evt)
case WATCHFACE_APP_EVT_CLICK_SETTINGS:
open_application_manager_page("Settings");
break;
case WATCHFACE_APP_EVT_CLICK_FLASHLIGHT:
open_application_manager_page("Flashlight");
break;
default:
break;
}
Expand Down
40 changes: 20 additions & 20 deletions app/src/ui/watchfaces/zsw_watchface_dropdown_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ static lv_obj_t *ui_up_bg_Panel;
static lv_obj_t *ui_music_info_label;
static lv_obj_t *ui_music_button;
static lv_obj_t *ui_music_label;
static lv_obj_t *ui_restart_button;
static lv_obj_t *ui_restart_label;
static lv_obj_t *ui_flashlight_button;
static lv_obj_t *ui_flashlight_label;
static lv_obj_t *ui_shutdown_button;
static lv_obj_t *ui_shutdown_label;
static lv_obj_t *ui_settings_button;
Expand Down Expand Up @@ -71,9 +71,9 @@ void ui_event_button(lv_event_t *e)
{
lv_obj_t *button = e->current_target;
if (e->code == LV_EVENT_CLICKED) {
if (button == ui_restart_button)
if (button == ui_flashlight_button)
evt_cb((watchface_app_evt_t) {
WATCHFACE_APP_EVENT_RESTART
WATCHFACE_APP_EVENT_OPEN_APP, .data.app = WATCHFACE_APP_EVT_CLICK_FLASHLIGHT
});
else if (button == ui_music_button) {
evt_cb((watchface_app_evt_t) {
Expand Down Expand Up @@ -171,21 +171,21 @@ void zsw_watchface_dropdown_ui_add(lv_obj_t *root_page,
lv_obj_set_style_text_opa(ui_music_label, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_font(ui_music_label, &lv_font_montserrat_18, LV_PART_MAIN | LV_STATE_DEFAULT);

ui_restart_button = lv_btn_create(ui_down_bg_panel);
lv_obj_set_width(ui_restart_button, 50);
lv_obj_set_height(ui_restart_button, 50);
lv_obj_set_x(ui_restart_button, 20);
lv_obj_set_y(ui_restart_button, 95);
lv_obj_clear_flag(ui_restart_button, LV_OBJ_FLAG_SCROLLABLE); /// Flags

ui_restart_label = lv_label_create(ui_restart_button);
lv_obj_set_width(ui_restart_label, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_restart_label, LV_SIZE_CONTENT); /// 1
lv_obj_set_align(ui_restart_label, LV_ALIGN_CENTER);
lv_label_set_text(ui_restart_label, LV_SYMBOL_REFRESH);
lv_obj_set_style_text_color(ui_restart_label, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_opa(ui_restart_label, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_font(ui_restart_label, &lv_font_montserrat_18, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_flashlight_button = lv_btn_create(ui_down_bg_panel);
lv_obj_set_width(ui_flashlight_button, 50);
lv_obj_set_height(ui_flashlight_button, 50);
lv_obj_set_x(ui_flashlight_button, 20);
lv_obj_set_y(ui_flashlight_button, 95);
lv_obj_clear_flag(ui_flashlight_button, LV_OBJ_FLAG_SCROLLABLE); /// Flags

ui_flashlight_label = lv_label_create(ui_flashlight_button);
lv_obj_set_width(ui_flashlight_label, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_flashlight_label, LV_SIZE_CONTENT); /// 1
lv_obj_set_align(ui_flashlight_label, LV_ALIGN_CENTER);
lv_label_set_text(ui_flashlight_label, LV_SYMBOL_CHARGE);
lv_obj_set_style_text_color(ui_flashlight_label, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_opa(ui_flashlight_label, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_font(ui_flashlight_label, &lv_font_montserrat_18, LV_PART_MAIN | LV_STATE_DEFAULT);

ui_shutdown_button = lv_btn_create(ui_down_bg_panel);
lv_obj_set_width(ui_shutdown_button, 50);
Expand Down Expand Up @@ -267,7 +267,7 @@ void zsw_watchface_dropdown_ui_add(lv_obj_t *root_page,
lv_obj_set_style_border_opa(ui_dropdown_bg_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

lv_obj_add_event_cb(ui_music_button, ui_event_button, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_restart_button, ui_event_button, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_flashlight_button, ui_event_button, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_shutdown_button, ui_event_button, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_settings_button, ui_event_button, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_bri_slider, ui_event_light_slider, LV_EVENT_ALL, NULL);
Expand Down

0 comments on commit 6f354a4

Please sign in to comment.