From 4cb6d560254eacd8ba0fcb19c83dc8621013c239 Mon Sep 17 00:00:00 2001 From: Jan Wiesemann Date: Sun, 18 Aug 2024 11:38:42 +0200 Subject: [PATCH 1/6] Added scroll support for the Desktop Lock Menu --- .../desktop/views/desktop_view_lock_menu.c | 68 ++++++++++++++----- .../desktop/views/desktop_view_lock_menu.h | 1 + 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/applications/services/desktop/views/desktop_view_lock_menu.c b/applications/services/desktop/views/desktop_view_lock_menu.c index 1b6bdab9c58..8df97a4d502 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.c +++ b/applications/services/desktop/views/desktop_view_lock_menu.c @@ -5,6 +5,10 @@ #include "../desktop_i.h" #include "desktop_view_lock_menu.h" +#define DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT 3 +#define DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR() \ + DesktopLockMenuIndexTotalCount - 1 > DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT + typedef enum { DesktopLockMenuIndexLock, DesktopLockMenuIndexStealth, @@ -53,31 +57,50 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) { canvas_draw_icon(canvas, 116, 0 + STATUS_BAR_Y_SHIFT, &I_DoorRight_70x55); canvas_set_font(canvas, FontSecondary); - for(size_t i = 0; i < DesktopLockMenuIndexTotalCount; ++i) { - const char* str = NULL; + for (size_t i = 0; i < DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT; ++i) { + + const char *str = NULL; + + const DesktopLockMenuIndex menu_index = m->first_item + i; + switch (menu_index) { + case DesktopLockMenuIndexLock: + str = "Lock"; + break; - if(i == DesktopLockMenuIndexLock) { - str = "Lock"; - } else if(i == DesktopLockMenuIndexStealth) { - if(m->stealth_mode) { - str = "Unmute"; - } else { - str = "Mute"; + case DesktopLockMenuIndexStealth: { + if (m->stealth_mode) { + str = "Unmute"; + } else { + str = "Mute"; + } + + break; } - } else if(i == DesktopLockMenuIndexDummy) { //-V547 - if(m->dummy_mode) { - str = "Default Mode"; - } else { - str = "Dummy Mode"; + + case DesktopLockMenuIndexDummy: { + if (m->dummy_mode) { + str = "Default Mode"; + } else { + str = "Dummy Mode"; + } + + break; } + + default: + break; } - if(str) //-V547 - canvas_draw_str_aligned( - canvas, 64, 9 + (i * 17) + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter, str); + if (str) + canvas_draw_str_aligned(canvas, 64, 9 + (i * 17) + STATUS_BAR_Y_SHIFT, + AlignCenter, AlignCenter, str); - if(m->idx == i) elements_frame(canvas, 15, 1 + (i * 17) + STATUS_BAR_Y_SHIFT, 98, 15); + if (m->idx == menu_index) + elements_frame(canvas, 15, 1 + (i * 17) + STATUS_BAR_Y_SHIFT, DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR() ? 95 : 98, 15); } + + if (DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR()) + elements_scrollbar_pos(canvas, 115, 1 + STATUS_BAR_Y_SHIFT, 50, m->idx, DesktopLockMenuIndexTotalCount); } View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu) { @@ -118,6 +141,15 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) { update = true; consumed = true; } + + if (DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR()) { + if (model->idx < 1) + model->first_item = 0; + else if (model->idx > DesktopLockMenuIndexTotalCount - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT + 1) + model->first_item = DesktopLockMenuIndexTotalCount - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT; + else + model->first_item = model->idx - 1; + } } idx = model->idx; dummy_mode = model->dummy_mode; diff --git a/applications/services/desktop/views/desktop_view_lock_menu.h b/applications/services/desktop/views/desktop_view_lock_menu.h index a44e6b13276..cf73b0e401c 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.h +++ b/applications/services/desktop/views/desktop_view_lock_menu.h @@ -19,6 +19,7 @@ typedef struct { uint8_t idx; bool dummy_mode; bool stealth_mode; + int8_t first_item; } DesktopLockMenuViewModel; void desktop_lock_menu_set_callback( From 0aea9b011e1d09a2983919cb578cc8ade65e87ce Mon Sep 17 00:00:00 2001 From: Jan Wiesemann Date: Tue, 20 Aug 2024 11:58:36 +0200 Subject: [PATCH 2/6] Moved notification settings descriptions to the notification service --- .../services/notification/notification_app.c | 7 +++++++ .../services/notification/notification_app.h | 4 ++++ .../notification_settings_app.c | 16 ---------------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 35d2fe675aa..7e22fe5e681 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -32,6 +32,13 @@ static uint8_t notification_settings_get_display_brightness(NotificationApp* app static uint8_t notification_settings_get_rgb_led_brightness(NotificationApp* app, uint8_t value); static uint32_t notification_settings_display_off_delay_ticks(NotificationApp* app); +const char * backlight_text[BACKLIGHT_COUNT] = { + "0%", "25%", "50%", "75%", "100%", +}; +float backlight_value[BACKLIGHT_COUNT] = { + 0.0f, 0.25f, 0.5f, 0.75f, 1.0f, +}; + void notification_message_save_settings(NotificationApp* app) { NotificationAppMessage m = { .type = SaveSettingsMessage, .back_event = furi_event_flag_alloc()}; diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index e1954657417..1d8f1bd6aeb 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -7,6 +7,10 @@ #define NOTIFICATION_LED_COUNT 3 #define NOTIFICATION_EVENT_COMPLETE 0x00000001U +#define BACKLIGHT_COUNT 5 +extern const char * backlight_text[BACKLIGHT_COUNT]; +extern float backlight_value[BACKLIGHT_COUNT]; + typedef enum { NotificationLayerMessage, InternalLayerMessage, diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index ada2bfdd42c..2d61770a775 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -48,22 +48,6 @@ const int32_t contrast_value[CONTRAST_COUNT] = { 5, }; -#define BACKLIGHT_COUNT 5 -const char* const backlight_text[BACKLIGHT_COUNT] = { - "0%", - "25%", - "50%", - "75%", - "100%", -}; -const float backlight_value[BACKLIGHT_COUNT] = { - 0.0f, - 0.25f, - 0.5f, - 0.75f, - 1.0f, -}; - #define VOLUME_COUNT 5 const char* const volume_text[VOLUME_COUNT] = { "0%", From 5c22122287f5eda3389de8f53a7bb9ca40000ae5 Mon Sep 17 00:00:00 2001 From: Jan Wiesemann Date: Tue, 20 Aug 2024 12:00:33 +0200 Subject: [PATCH 3/6] Replaced lock screen menu code with a array based system. This allows better a easier implementation for new lock menu items. --- .../desktop/views/desktop_view_lock_menu.c | 248 +++++++++++------- .../desktop/views/desktop_view_lock_menu.h | 2 +- 2 files changed, 161 insertions(+), 89 deletions(-) diff --git a/applications/services/desktop/views/desktop_view_lock_menu.c b/applications/services/desktop/views/desktop_view_lock_menu.c index 8df97a4d502..2d41958fa70 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.c +++ b/applications/services/desktop/views/desktop_view_lock_menu.c @@ -6,25 +6,131 @@ #include "desktop_view_lock_menu.h" #define DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT 3 -#define DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR() \ - DesktopLockMenuIndexTotalCount - 1 > DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT -typedef enum { - DesktopLockMenuIndexLock, - DesktopLockMenuIndexStealth, - DesktopLockMenuIndexDummy, +typedef struct DesktopLockMenuItem DesktopLockMenuItem; - DesktopLockMenuIndexTotalCount -} DesktopLockMenuIndex; +typedef FuriString* (*DesktopLockMenuItemGetTextCallback)(const DesktopLockMenuItem *item, DesktopLockMenuViewModel *model, bool is_selected); -void desktop_lock_menu_set_callback( - DesktopLockMenuView* lock_menu, - DesktopLockMenuViewCallback callback, - void* context) { - furi_assert(lock_menu); - furi_assert(callback); - lock_menu->callback = callback; - lock_menu->context = context; +typedef bool (*DesktopLockMenuItemOnInputCallback)(const DesktopLockMenuItem *item, const InputEvent* event, DesktopLockMenuView *view); + +struct DesktopLockMenuItem { + DesktopLockMenuItemGetTextCallback get_text; + DesktopLockMenuItemOnInputCallback on_input; +}; + +FuriString* desktop_lock_menu_lock_get_text(const DesktopLockMenuItem* item, DesktopLockMenuViewModel* model, bool is_selected) { + furi_assert(item); + furi_assert(model); + UNUSED(is_selected); + + return furi_string_alloc_set("Lock"); +} + +bool desktop_lock_menu_lock_on_input(const DesktopLockMenuItem* item, const InputEvent* event, DesktopLockMenuView* view) { + furi_assert(item); + furi_assert(event); + furi_assert(view); + + if(event->key == InputKeyOk) { + view->callback(DesktopLockMenuEventLock, view->context); + return true; + } else + return false; +} + +FuriString* desktop_lock_menu_stealth_get_text(const DesktopLockMenuItem* item, DesktopLockMenuViewModel* model, bool is_selected) { + furi_assert(item); + furi_assert(model); + UNUSED(is_selected); + + if (model->stealth_mode) + return furi_string_alloc_set("Unmute"); + else + return furi_string_alloc_set("Mute"); +} + +bool desktop_lock_menu_stealth_on_input(const DesktopLockMenuItem* item, const InputEvent* event, DesktopLockMenuView* view) { + furi_assert(item); + furi_assert(event); + furi_assert(view); + + if (event->key == InputKeyOk) { + DesktopEvent event_type = DesktopLockMenuEventStealthModeOff; + with_view_model( + view->view, DesktopLockMenuViewModel * model, + { + if (!model->stealth_mode) + event_type = DesktopLockMenuEventStealthModeOn; + }, + false) + + view->callback(event_type, view->context); + + return true; + } + else + return false; +} + +FuriString* desktop_lock_menu_dummy_mode_get_text(const DesktopLockMenuItem* item, DesktopLockMenuViewModel* model, bool is_selected) { + furi_assert(item); + furi_assert(model); + UNUSED(is_selected); + + if (model->dummy_mode) + return furi_string_alloc_set("Default Mode"); + else + return furi_string_alloc_set("Dummy Mode"); +} + +bool desktop_lock_menu_dummy_mode_on_input(const DesktopLockMenuItem* item, const InputEvent* event, DesktopLockMenuView* view) { + furi_assert(item); + furi_assert(event); + furi_assert(view); + + if (event->key == InputKeyOk) { + DesktopEvent event_type = DesktopLockMenuEventDummyModeOff; + with_view_model( + view->view, DesktopLockMenuViewModel * model, + { + if (!model->dummy_mode) + event_type = DesktopLockMenuEventDummyModeOn; + }, + false) + + view->callback(event_type, view->context); + + return true; + } + else + return false; +} + +const DesktopLockMenuItem menu_items[] = { + { + .get_text = desktop_lock_menu_lock_get_text, + .on_input = desktop_lock_menu_lock_on_input, + }, + { + .get_text = desktop_lock_menu_stealth_get_text, + .on_input = desktop_lock_menu_stealth_on_input, + }, + { + .get_text = desktop_lock_menu_dummy_mode_get_text, + .on_input = desktop_lock_menu_dummy_mode_on_input, + }, +}; +#define DESKTOP_LOCK_MENU_ITEM_COUNT \ + (uint8_t)(sizeof(menu_items) / sizeof(DesktopLockMenuItem)) + +#define DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR \ + DESKTOP_LOCK_MENU_ITEM_COUNT > DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT + +void desktop_lock_menu_set_callback(DesktopLockMenuView *lock_menu, DesktopLockMenuViewCallback callback, void *context) { + furi_assert(lock_menu); + furi_assert(callback); + lock_menu->callback = callback; + lock_menu->context = context; } void desktop_lock_menu_set_dummy_mode_state(DesktopLockMenuView* lock_menu, bool dummy_mode) { @@ -44,11 +150,24 @@ void desktop_lock_menu_set_stealth_mode_state(DesktopLockMenuView* lock_menu, bo } void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx) { - furi_assert(idx < DesktopLockMenuIndexTotalCount); + furi_assert(idx < DESKTOP_LOCK_MENU_ITEM_COUNT); with_view_model( lock_menu->view, DesktopLockMenuViewModel * model, { model->idx = idx; }, true); } +uint8_t desktop_lock_menu_get_first_visible_item(uint8_t idx){ + if (DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR) { + if (idx < 1) //first item is selected + return 0; + else if (idx > DESKTOP_LOCK_MENU_ITEM_COUNT - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT + 1) //last item is selected + return DESKTOP_LOCK_MENU_ITEM_COUNT - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT; + else //item is not the first or last item + return idx - 1; + } else { + return 0; + } +} + void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) { DesktopLockMenuViewModel* m = model; @@ -57,50 +176,29 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) { canvas_draw_icon(canvas, 116, 0 + STATUS_BAR_Y_SHIFT, &I_DoorRight_70x55); canvas_set_font(canvas, FontSecondary); - for (size_t i = 0; i < DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT; ++i) { - - const char *str = NULL; + const uint8_t first_visible_item = desktop_lock_menu_get_first_visible_item(m->idx); - const DesktopLockMenuIndex menu_index = m->first_item + i; - switch (menu_index) { - case DesktopLockMenuIndexLock: - str = "Lock"; - break; - - case DesktopLockMenuIndexStealth: { - if (m->stealth_mode) { - str = "Unmute"; - } else { - str = "Mute"; - } + for (size_t i = 0; i < DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT; ++i) { - break; - } + const uint32_t menu_item_index = first_visible_item + i; + const bool is_selected = m->idx == menu_item_index; + const DesktopLockMenuItem* menu_item = &menu_items[menu_item_index]; - case DesktopLockMenuIndexDummy: { - if (m->dummy_mode) { - str = "Default Mode"; - } else { - str = "Dummy Mode"; - } + FuriString *text = menu_item->get_text(menu_item, model, is_selected); - break; - } + if (text != NULL){ + canvas_draw_str_aligned(canvas, 64, 9 + (i * 17) + STATUS_BAR_Y_SHIFT, + AlignCenter, AlignCenter, furi_string_get_cstr(text)); - default: - break; + furi_string_free(text); } - if (str) - canvas_draw_str_aligned(canvas, 64, 9 + (i * 17) + STATUS_BAR_Y_SHIFT, - AlignCenter, AlignCenter, str); - - if (m->idx == menu_index) - elements_frame(canvas, 15, 1 + (i * 17) + STATUS_BAR_Y_SHIFT, DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR() ? 95 : 98, 15); + if (is_selected) + elements_frame(canvas, 15, 1 + (i * 17) + STATUS_BAR_Y_SHIFT, DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR ? 95 : 98, 15); } - if (DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR()) - elements_scrollbar_pos(canvas, 115, 1 + STATUS_BAR_Y_SHIFT, 50, m->idx, DesktopLockMenuIndexTotalCount); + if (DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR) + elements_scrollbar_pos(canvas, 115, 1 + STATUS_BAR_Y_SHIFT, 50, m->idx, DESKTOP_LOCK_MENU_ITEM_COUNT); } View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu) { @@ -115,8 +213,6 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) { DesktopLockMenuView* lock_menu = context; uint8_t idx = 0; bool consumed = false; - bool dummy_mode = false; - bool stealth_mode = false; bool update = false; with_view_model( @@ -126,56 +222,32 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) { if((event->type == InputTypeShort) || (event->type == InputTypeRepeat)) { if(event->key == InputKeyUp) { if(model->idx == 0) { - model->idx = DesktopLockMenuIndexTotalCount - 1; + model->idx = DESKTOP_LOCK_MENU_ITEM_COUNT - 1; } else { - model->idx = CLAMP(model->idx - 1, DesktopLockMenuIndexTotalCount - 1, 0); + model->idx = CLAMP(model->idx - 1, DESKTOP_LOCK_MENU_ITEM_COUNT - 1, 0); } update = true; consumed = true; } else if(event->key == InputKeyDown) { - if(model->idx == DesktopLockMenuIndexTotalCount - 1) { + if(model->idx == DESKTOP_LOCK_MENU_ITEM_COUNT - 1) { model->idx = 0; } else { - model->idx = CLAMP(model->idx + 1, DesktopLockMenuIndexTotalCount - 1, 0); + model->idx = CLAMP(model->idx + 1, DESKTOP_LOCK_MENU_ITEM_COUNT - 1, 0); } update = true; consumed = true; } - - if (DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR()) { - if (model->idx < 1) - model->first_item = 0; - else if (model->idx > DesktopLockMenuIndexTotalCount - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT + 1) - model->first_item = DesktopLockMenuIndexTotalCount - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT; - else - model->first_item = model->idx - 1; - } } idx = model->idx; - dummy_mode = model->dummy_mode; - stealth_mode = model->stealth_mode; }, update); - if(event->key == InputKeyOk) { - if(idx == DesktopLockMenuIndexLock) { - if(event->type == InputTypeShort) { - lock_menu->callback(DesktopLockMenuEventLock, lock_menu->context); - } - } else if(idx == DesktopLockMenuIndexStealth) { - if((stealth_mode == false) && (event->type == InputTypeShort)) { - lock_menu->callback(DesktopLockMenuEventStealthModeOn, lock_menu->context); - } else if((stealth_mode == true) && (event->type == InputTypeShort)) { - lock_menu->callback(DesktopLockMenuEventStealthModeOff, lock_menu->context); - } - } else if(idx == DesktopLockMenuIndexDummy) { - if((dummy_mode == false) && (event->type == InputTypeShort)) { - lock_menu->callback(DesktopLockMenuEventDummyModeOn, lock_menu->context); - } else if((dummy_mode == true) && (event->type == InputTypeShort)) { - lock_menu->callback(DesktopLockMenuEventDummyModeOff, lock_menu->context); - } - } - consumed = true; + if (event->key == InputKeyOk || event->key == InputKeyLeft || event->key == InputKeyRight) { + const DesktopLockMenuItem* menu_item = &menu_items[idx]; + if(menu_item->on_input) + consumed = menu_item->on_input(menu_item, event, lock_menu); + else + consumed = true; } return consumed; diff --git a/applications/services/desktop/views/desktop_view_lock_menu.h b/applications/services/desktop/views/desktop_view_lock_menu.h index cf73b0e401c..c06324df6a7 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.h +++ b/applications/services/desktop/views/desktop_view_lock_menu.h @@ -19,7 +19,7 @@ typedef struct { uint8_t idx; bool dummy_mode; bool stealth_mode; - int8_t first_item; + float display_brightness; } DesktopLockMenuViewModel; void desktop_lock_menu_set_callback( From 2a96a3b0330275fde818e3efdbc0340f42e85655 Mon Sep 17 00:00:00 2001 From: Jan Wiesemann Date: Wed, 21 Aug 2024 16:49:24 +0200 Subject: [PATCH 4/6] Added the ability to change the display brightness for the lock menu --- .../desktop/scenes/desktop_scene_lock_menu.c | 8 +- .../desktop/views/desktop_view_lock_menu.c | 106 ++++++++++++++++-- .../desktop/views/desktop_view_lock_menu.h | 8 +- 3 files changed, 113 insertions(+), 9 deletions(-) diff --git a/applications/services/desktop/scenes/desktop_scene_lock_menu.c b/applications/services/desktop/scenes/desktop_scene_lock_menu.c index 5ca95c4c590..db22f0814ee 100644 --- a/applications/services/desktop/scenes/desktop_scene_lock_menu.c +++ b/applications/services/desktop/scenes/desktop_scene_lock_menu.c @@ -26,6 +26,8 @@ void desktop_scene_lock_menu_on_enter(void* context) { desktop_lock_menu_set_stealth_mode_state( desktop->lock_menu, furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)); desktop_lock_menu_set_idx(desktop->lock_menu, 0); + desktop_lock_menu_set_notification_record(desktop->lock_menu, desktop->notification); + desktop_lock_menu_refresh_notification_values(desktop->lock_menu); view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdLockMenu); } @@ -77,5 +79,9 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) { } void desktop_scene_lock_menu_on_exit(void* context) { - UNUSED(context); + Desktop* desktop = (Desktop *)context; + + if(desktop_lock_menu_did_notification_settings_change(desktop->lock_menu)) { + notification_message_save_settings(desktop->notification); + } } diff --git a/applications/services/desktop/views/desktop_view_lock_menu.c b/applications/services/desktop/views/desktop_view_lock_menu.c index 2d41958fa70..41137ee2596 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.c +++ b/applications/services/desktop/views/desktop_view_lock_menu.c @@ -4,14 +4,15 @@ #include "../desktop_i.h" #include "desktop_view_lock_menu.h" +#include #define DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT 3 typedef struct DesktopLockMenuItem DesktopLockMenuItem; -typedef FuriString* (*DesktopLockMenuItemGetTextCallback)(const DesktopLockMenuItem *item, DesktopLockMenuViewModel *model, bool is_selected); +typedef FuriString* (*DesktopLockMenuItemGetTextCallback)(const DesktopLockMenuItem* item, DesktopLockMenuViewModel* model, bool is_selected); -typedef bool (*DesktopLockMenuItemOnInputCallback)(const DesktopLockMenuItem *item, const InputEvent* event, DesktopLockMenuView *view); +typedef bool (*DesktopLockMenuItemOnInputCallback)(const DesktopLockMenuItem* item, const InputEvent* event, DesktopLockMenuView* view); struct DesktopLockMenuItem { DesktopLockMenuItemGetTextCallback get_text; @@ -106,6 +107,65 @@ bool desktop_lock_menu_dummy_mode_on_input(const DesktopLockMenuItem* item, cons return false; } + +FuriString* desktop_lock_menu_display_brightness_get_text(const DesktopLockMenuItem* item, DesktopLockMenuViewModel* model, bool is_selected) { + furi_assert(item); + furi_assert(model); + + const char* value_string = backlight_text[model->display_brightness_index]; + FuriString* str = furi_string_alloc_set("Display "); + + if (is_selected) { + if (model->display_brightness_index > 0) + furi_string_cat(str, "< "); + + furi_string_cat(str, value_string); + + if (model->display_brightness_index < BACKLIGHT_COUNT - 1) + furi_string_cat(str, " >"); + } + else { + furi_string_cat(str, value_string); + } + + return str; +} + +bool desktop_lock_menu_display_brightness_on_input(const DesktopLockMenuItem* item, const InputEvent* event, DesktopLockMenuView* view) { + furi_assert(item); + furi_assert(event); + furi_assert(view); + + if (event->key == InputKeyLeft || event->key == InputKeyRight) { + bool update = false; + uint8_t index = 0; + with_view_model(view->view, DesktopLockMenuViewModel* model, { + if(event->key == InputKeyLeft && (int8_t)model->display_brightness_index - 1 >= 0) { + model->display_brightness_index--; + index = model->display_brightness_index; + update = true; + } else if(event->key == InputKeyRight && model->display_brightness_index + 1 < BACKLIGHT_COUNT) { + model->display_brightness_index++; + index = model->display_brightness_index; + update = true; + } + + if(update) { + model->notification_settings_changed = true; + } + }, update) + + if(update) { + view->notification_record->settings.display_brightness = backlight_value[index]; + notification_message(view->notification_record, &sequence_display_backlight_on); + } + + return true; + } + + return false; +} + const DesktopLockMenuItem menu_items[] = { { .get_text = desktop_lock_menu_lock_get_text, @@ -119,6 +179,10 @@ const DesktopLockMenuItem menu_items[] = { .get_text = desktop_lock_menu_dummy_mode_get_text, .on_input = desktop_lock_menu_dummy_mode_on_input, }, + { + .get_text = desktop_lock_menu_display_brightness_get_text, + .on_input = desktop_lock_menu_display_brightness_on_input, + }, }; #define DESKTOP_LOCK_MENU_ITEM_COUNT \ (uint8_t)(sizeof(menu_items) / sizeof(DesktopLockMenuItem)) @@ -126,7 +190,7 @@ const DesktopLockMenuItem menu_items[] = { #define DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR \ DESKTOP_LOCK_MENU_ITEM_COUNT > DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT -void desktop_lock_menu_set_callback(DesktopLockMenuView *lock_menu, DesktopLockMenuViewCallback callback, void *context) { +void desktop_lock_menu_set_callback(DesktopLockMenuView* lock_menu, DesktopLockMenuViewCallback callback, void* context) { furi_assert(lock_menu); furi_assert(callback); lock_menu->callback = callback; @@ -155,6 +219,34 @@ void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx) { lock_menu->view, DesktopLockMenuViewModel * model, { model->idx = idx; }, true); } +void desktop_lock_menu_set_notification_record(DesktopLockMenuView* lock_menu, NotificationApp* notification) { + furi_assert(lock_menu); + furi_assert(notification); + + lock_menu->notification_record = notification; + + desktop_lock_menu_refresh_notification_values(lock_menu); +} + +void desktop_lock_menu_refresh_notification_values(DesktopLockMenuView* lock_menu) { + furi_assert(lock_menu); + + uint8_t index = value_index_float(lock_menu->notification_record->settings.display_brightness, backlight_value , BACKLIGHT_COUNT); + with_view_model( + lock_menu->view, DesktopLockMenuViewModel * model, + { + model->display_brightness_index = index; + }, true); +} + +bool desktop_lock_menu_did_notification_settings_change(DesktopLockMenuView* lock_menu) { + furi_assert(lock_menu); + + bool ret = false; + with_view_model(lock_menu->view, DesktopLockMenuViewModel* model, ret = model->notification_settings_changed;, false); + return ret; +} + uint8_t desktop_lock_menu_get_first_visible_item(uint8_t idx){ if (DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR) { if (idx < 1) //first item is selected @@ -162,9 +254,9 @@ uint8_t desktop_lock_menu_get_first_visible_item(uint8_t idx){ else if (idx > DESKTOP_LOCK_MENU_ITEM_COUNT - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT + 1) //last item is selected return DESKTOP_LOCK_MENU_ITEM_COUNT - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT; else //item is not the first or last item - return idx - 1; + return idx - 1; } else { - return 0; + return 0; } } @@ -184,7 +276,7 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) { const bool is_selected = m->idx == menu_item_index; const DesktopLockMenuItem* menu_item = &menu_items[menu_item_index]; - FuriString *text = menu_item->get_text(menu_item, model, is_selected); + FuriString* text = menu_item->get_text(menu_item, model, is_selected); if (text != NULL){ canvas_draw_str_aligned(canvas, 64, 9 + (i * 17) + STATUS_BAR_Y_SHIFT, @@ -242,7 +334,7 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) { }, update); - if (event->key == InputKeyOk || event->key == InputKeyLeft || event->key == InputKeyRight) { + if ((event->type == InputTypeShort || event->type == InputTypeRepeat) && (event->key == InputKeyOk || event->key == InputKeyLeft || event->key == InputKeyRight)) { const DesktopLockMenuItem* menu_item = &menu_items[idx]; if(menu_item->on_input) consumed = menu_item->on_input(menu_item, event, lock_menu); diff --git a/applications/services/desktop/views/desktop_view_lock_menu.h b/applications/services/desktop/views/desktop_view_lock_menu.h index c06324df6a7..27ac00b20d3 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.h +++ b/applications/services/desktop/views/desktop_view_lock_menu.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "desktop_events.h" #define HINT_TIMEOUT 2 @@ -13,13 +14,15 @@ struct DesktopLockMenuView { View* view; DesktopLockMenuViewCallback callback; void* context; + NotificationApp* notification_record; }; typedef struct { uint8_t idx; bool dummy_mode; bool stealth_mode; - float display_brightness; + uint8_t display_brightness_index; + bool notification_settings_changed; } DesktopLockMenuViewModel; void desktop_lock_menu_set_callback( @@ -31,5 +34,8 @@ View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu); void desktop_lock_menu_set_dummy_mode_state(DesktopLockMenuView* lock_menu, bool dummy_mode); void desktop_lock_menu_set_stealth_mode_state(DesktopLockMenuView* lock_menu, bool stealth_mode); void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx); +void desktop_lock_menu_set_notification_record(DesktopLockMenuView* lock_menu, NotificationApp* notification); +bool desktop_lock_menu_did_notification_settings_change(DesktopLockMenuView* lock_menu); +void desktop_lock_menu_refresh_notification_values(DesktopLockMenuView* lock_menu); DesktopLockMenuView* desktop_lock_menu_alloc(void); void desktop_lock_menu_free(DesktopLockMenuView* lock_menu); From 2b5b8fe34774a5c376088f101af522b23f986d65 Mon Sep 17 00:00:00 2001 From: Jan Wiesemann Date: Sun, 25 Aug 2024 09:17:49 +0200 Subject: [PATCH 5/6] Fixed formatting --- .../desktop/scenes/desktop_scene_lock_menu.c | 2 +- .../desktop/views/desktop_view_lock_menu.c | 220 +++++++++++------- .../desktop/views/desktop_view_lock_menu.h | 4 +- .../services/notification/notification_app.c | 14 +- .../services/notification/notification_app.h | 2 +- 5 files changed, 153 insertions(+), 89 deletions(-) diff --git a/applications/services/desktop/scenes/desktop_scene_lock_menu.c b/applications/services/desktop/scenes/desktop_scene_lock_menu.c index db22f0814ee..d30365bf3ec 100644 --- a/applications/services/desktop/scenes/desktop_scene_lock_menu.c +++ b/applications/services/desktop/scenes/desktop_scene_lock_menu.c @@ -79,7 +79,7 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) { } void desktop_scene_lock_menu_on_exit(void* context) { - Desktop* desktop = (Desktop *)context; + Desktop* desktop = (Desktop*)context; if(desktop_lock_menu_did_notification_settings_change(desktop->lock_menu)) { notification_message_save_settings(desktop->notification); diff --git a/applications/services/desktop/views/desktop_view_lock_menu.c b/applications/services/desktop/views/desktop_view_lock_menu.c index 41137ee2596..806d6a94da5 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.c +++ b/applications/services/desktop/views/desktop_view_lock_menu.c @@ -10,16 +10,25 @@ typedef struct DesktopLockMenuItem DesktopLockMenuItem; -typedef FuriString* (*DesktopLockMenuItemGetTextCallback)(const DesktopLockMenuItem* item, DesktopLockMenuViewModel* model, bool is_selected); +typedef FuriString* (*DesktopLockMenuItemGetTextCallback)( + const DesktopLockMenuItem* item, + DesktopLockMenuViewModel* model, + bool is_selected); -typedef bool (*DesktopLockMenuItemOnInputCallback)(const DesktopLockMenuItem* item, const InputEvent* event, DesktopLockMenuView* view); +typedef bool (*DesktopLockMenuItemOnInputCallback)( + const DesktopLockMenuItem* item, + const InputEvent* event, + DesktopLockMenuView* view); struct DesktopLockMenuItem { - DesktopLockMenuItemGetTextCallback get_text; - DesktopLockMenuItemOnInputCallback on_input; + DesktopLockMenuItemGetTextCallback get_text; + DesktopLockMenuItemOnInputCallback on_input; }; -FuriString* desktop_lock_menu_lock_get_text(const DesktopLockMenuItem* item, DesktopLockMenuViewModel* model, bool is_selected) { +FuriString* desktop_lock_menu_lock_get_text( + const DesktopLockMenuItem* item, + DesktopLockMenuViewModel* model, + bool is_selected) { furi_assert(item); furi_assert(model); UNUSED(is_selected); @@ -27,7 +36,10 @@ FuriString* desktop_lock_menu_lock_get_text(const DesktopLockMenuItem* item, Des return furi_string_alloc_set("Lock"); } -bool desktop_lock_menu_lock_on_input(const DesktopLockMenuItem* item, const InputEvent* event, DesktopLockMenuView* view) { +bool desktop_lock_menu_lock_on_input( + const DesktopLockMenuItem* item, + const InputEvent* event, + DesktopLockMenuView* view) { furi_assert(item); furi_assert(event); furi_assert(view); @@ -39,123 +51,142 @@ bool desktop_lock_menu_lock_on_input(const DesktopLockMenuItem* item, const Inpu return false; } -FuriString* desktop_lock_menu_stealth_get_text(const DesktopLockMenuItem* item, DesktopLockMenuViewModel* model, bool is_selected) { +FuriString* desktop_lock_menu_stealth_get_text( + const DesktopLockMenuItem* item, + DesktopLockMenuViewModel* model, + bool is_selected) { furi_assert(item); furi_assert(model); UNUSED(is_selected); - if (model->stealth_mode) + if(model->stealth_mode) return furi_string_alloc_set("Unmute"); else return furi_string_alloc_set("Mute"); } -bool desktop_lock_menu_stealth_on_input(const DesktopLockMenuItem* item, const InputEvent* event, DesktopLockMenuView* view) { +bool desktop_lock_menu_stealth_on_input( + const DesktopLockMenuItem* item, + const InputEvent* event, + DesktopLockMenuView* view) { furi_assert(item); furi_assert(event); furi_assert(view); - if (event->key == InputKeyOk) { + if(event->key == InputKeyOk) { DesktopEvent event_type = DesktopLockMenuEventStealthModeOff; with_view_model( - view->view, DesktopLockMenuViewModel * model, + view->view, + DesktopLockMenuViewModel * model, { - if (!model->stealth_mode) - event_type = DesktopLockMenuEventStealthModeOn; + if(!model->stealth_mode) event_type = DesktopLockMenuEventStealthModeOn; }, false) - view->callback(event_type, view->context); + view->callback(event_type, view->context); return true; - } - else + } else return false; } -FuriString* desktop_lock_menu_dummy_mode_get_text(const DesktopLockMenuItem* item, DesktopLockMenuViewModel* model, bool is_selected) { +FuriString* desktop_lock_menu_dummy_mode_get_text( + const DesktopLockMenuItem* item, + DesktopLockMenuViewModel* model, + bool is_selected) { furi_assert(item); furi_assert(model); UNUSED(is_selected); - if (model->dummy_mode) + if(model->dummy_mode) return furi_string_alloc_set("Default Mode"); else return furi_string_alloc_set("Dummy Mode"); } -bool desktop_lock_menu_dummy_mode_on_input(const DesktopLockMenuItem* item, const InputEvent* event, DesktopLockMenuView* view) { +bool desktop_lock_menu_dummy_mode_on_input( + const DesktopLockMenuItem* item, + const InputEvent* event, + DesktopLockMenuView* view) { furi_assert(item); furi_assert(event); furi_assert(view); - if (event->key == InputKeyOk) { + if(event->key == InputKeyOk) { DesktopEvent event_type = DesktopLockMenuEventDummyModeOff; with_view_model( - view->view, DesktopLockMenuViewModel * model, + view->view, + DesktopLockMenuViewModel * model, { - if (!model->dummy_mode) - event_type = DesktopLockMenuEventDummyModeOn; + if(!model->dummy_mode) event_type = DesktopLockMenuEventDummyModeOn; }, false) - view->callback(event_type, view->context); + view->callback(event_type, view->context); return true; - } - else + } else return false; } - -FuriString* desktop_lock_menu_display_brightness_get_text(const DesktopLockMenuItem* item, DesktopLockMenuViewModel* model, bool is_selected) { +FuriString* desktop_lock_menu_display_brightness_get_text( + const DesktopLockMenuItem* item, + DesktopLockMenuViewModel* model, + bool is_selected) { furi_assert(item); furi_assert(model); const char* value_string = backlight_text[model->display_brightness_index]; FuriString* str = furi_string_alloc_set("Display "); - if (is_selected) { - if (model->display_brightness_index > 0) - furi_string_cat(str, "< "); + if(is_selected) { + if(model->display_brightness_index > 0) furi_string_cat(str, "< "); furi_string_cat(str, value_string); - if (model->display_brightness_index < BACKLIGHT_COUNT - 1) - furi_string_cat(str, " >"); - } - else { + if(model->display_brightness_index < BACKLIGHT_COUNT - 1) furi_string_cat(str, " >"); + } else { furi_string_cat(str, value_string); } return str; } -bool desktop_lock_menu_display_brightness_on_input(const DesktopLockMenuItem* item, const InputEvent* event, DesktopLockMenuView* view) { +bool desktop_lock_menu_display_brightness_on_input( + const DesktopLockMenuItem* item, + const InputEvent* event, + DesktopLockMenuView* view) { furi_assert(item); furi_assert(event); furi_assert(view); - if (event->key == InputKeyLeft || event->key == InputKeyRight) { + if(event->key == InputKeyLeft || event->key == InputKeyRight) { bool update = false; uint8_t index = 0; - with_view_model(view->view, DesktopLockMenuViewModel* model, { - if(event->key == InputKeyLeft && (int8_t)model->display_brightness_index - 1 >= 0) { - model->display_brightness_index--; - index = model->display_brightness_index; - update = true; - } else if(event->key == InputKeyRight && model->display_brightness_index + 1 < BACKLIGHT_COUNT) { - model->display_brightness_index++; - index = model->display_brightness_index; - update = true; - } + with_view_model( + view->view, + DesktopLockMenuViewModel * model, + { + if(event->key == InputKeyLeft && + (int8_t)model->display_brightness_index - 1 >= 0) { + model->display_brightness_index--; + index = model->display_brightness_index; + update = true; + } else if( + event->key == InputKeyRight && + model->display_brightness_index + 1 < BACKLIGHT_COUNT) { + model->display_brightness_index++; + index = model->display_brightness_index; + update = true; + } - if(update) { - model->notification_settings_changed = true; - } - }, update) + if(update) { + model->notification_settings_changed = true; + } + }, + update) - if(update) { + if(update) { view->notification_record->settings.display_brightness = backlight_value[index]; notification_message(view->notification_record, &sequence_display_backlight_on); } @@ -184,17 +215,19 @@ const DesktopLockMenuItem menu_items[] = { .on_input = desktop_lock_menu_display_brightness_on_input, }, }; -#define DESKTOP_LOCK_MENU_ITEM_COUNT \ - (uint8_t)(sizeof(menu_items) / sizeof(DesktopLockMenuItem)) +#define DESKTOP_LOCK_MENU_ITEM_COUNT (uint8_t)(sizeof(menu_items) / sizeof(DesktopLockMenuItem)) -#define DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR \ - DESKTOP_LOCK_MENU_ITEM_COUNT > DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT +#define DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR \ + DESKTOP_LOCK_MENU_ITEM_COUNT > DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT -void desktop_lock_menu_set_callback(DesktopLockMenuView* lock_menu, DesktopLockMenuViewCallback callback, void* context) { - furi_assert(lock_menu); - furi_assert(callback); - lock_menu->callback = callback; - lock_menu->context = context; +void desktop_lock_menu_set_callback( + DesktopLockMenuView* lock_menu, + DesktopLockMenuViewCallback callback, + void* context) { + furi_assert(lock_menu); + furi_assert(callback); + lock_menu->callback = callback; + lock_menu->context = context; } void desktop_lock_menu_set_dummy_mode_state(DesktopLockMenuView* lock_menu, bool dummy_mode) { @@ -219,7 +252,9 @@ void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx) { lock_menu->view, DesktopLockMenuViewModel * model, { model->idx = idx; }, true); } -void desktop_lock_menu_set_notification_record(DesktopLockMenuView* lock_menu, NotificationApp* notification) { +void desktop_lock_menu_set_notification_record( + DesktopLockMenuView* lock_menu, + NotificationApp* notification) { furi_assert(lock_menu); furi_assert(notification); @@ -231,32 +266,40 @@ void desktop_lock_menu_set_notification_record(DesktopLockMenuView* lock_menu, N void desktop_lock_menu_refresh_notification_values(DesktopLockMenuView* lock_menu) { furi_assert(lock_menu); - uint8_t index = value_index_float(lock_menu->notification_record->settings.display_brightness, backlight_value , BACKLIGHT_COUNT); + uint8_t index = value_index_float( + lock_menu->notification_record->settings.display_brightness, + backlight_value, + BACKLIGHT_COUNT); with_view_model( - lock_menu->view, DesktopLockMenuViewModel * model, - { - model->display_brightness_index = index; - }, true); + lock_menu->view, + DesktopLockMenuViewModel * model, + { model->display_brightness_index = index; }, + true); } bool desktop_lock_menu_did_notification_settings_change(DesktopLockMenuView* lock_menu) { furi_assert(lock_menu); bool ret = false; - with_view_model(lock_menu->view, DesktopLockMenuViewModel* model, ret = model->notification_settings_changed;, false); + with_view_model(lock_menu->view, + DesktopLockMenuViewModel * model, + ret = model->notification_settings_changed; + , false); return ret; } -uint8_t desktop_lock_menu_get_first_visible_item(uint8_t idx){ - if (DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR) { - if (idx < 1) //first item is selected +uint8_t desktop_lock_menu_get_first_visible_item(uint8_t idx) { + if(DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR) { + if(idx < 1) //first item is selected return 0; - else if (idx > DESKTOP_LOCK_MENU_ITEM_COUNT - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT + 1) //last item is selected + else if( + idx > DESKTOP_LOCK_MENU_ITEM_COUNT - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT + + 1) //last item is selected return DESKTOP_LOCK_MENU_ITEM_COUNT - DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT; else //item is not the first or last item return idx - 1; } else { - return 0; + return 0; } } @@ -270,27 +313,37 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) { const uint8_t first_visible_item = desktop_lock_menu_get_first_visible_item(m->idx); - for (size_t i = 0; i < DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT; ++i) { - + for(size_t i = 0; i < DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT; ++i) { const uint32_t menu_item_index = first_visible_item + i; const bool is_selected = m->idx == menu_item_index; const DesktopLockMenuItem* menu_item = &menu_items[menu_item_index]; FuriString* text = menu_item->get_text(menu_item, model, is_selected); - if (text != NULL){ - canvas_draw_str_aligned(canvas, 64, 9 + (i * 17) + STATUS_BAR_Y_SHIFT, - AlignCenter, AlignCenter, furi_string_get_cstr(text)); + if(text != NULL) { + canvas_draw_str_aligned( + canvas, + 64, + 9 + (i * 17) + STATUS_BAR_Y_SHIFT, + AlignCenter, + AlignCenter, + furi_string_get_cstr(text)); furi_string_free(text); } - if (is_selected) - elements_frame(canvas, 15, 1 + (i * 17) + STATUS_BAR_Y_SHIFT, DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR ? 95 : 98, 15); + if(is_selected) + elements_frame( + canvas, + 15, + 1 + (i * 17) + STATUS_BAR_Y_SHIFT, + DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR ? 95 : 98, + 15); } - if (DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR) - elements_scrollbar_pos(canvas, 115, 1 + STATUS_BAR_Y_SHIFT, 50, m->idx, DESKTOP_LOCK_MENU_ITEM_COUNT); + if(DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR) + elements_scrollbar_pos( + canvas, 115, 1 + STATUS_BAR_Y_SHIFT, 50, m->idx, DESKTOP_LOCK_MENU_ITEM_COUNT); } View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu) { @@ -334,7 +387,8 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) { }, update); - if ((event->type == InputTypeShort || event->type == InputTypeRepeat) && (event->key == InputKeyOk || event->key == InputKeyLeft || event->key == InputKeyRight)) { + if((event->type == InputTypeShort || event->type == InputTypeRepeat) && + (event->key == InputKeyOk || event->key == InputKeyLeft || event->key == InputKeyRight)) { const DesktopLockMenuItem* menu_item = &menu_items[idx]; if(menu_item->on_input) consumed = menu_item->on_input(menu_item, event, lock_menu); diff --git a/applications/services/desktop/views/desktop_view_lock_menu.h b/applications/services/desktop/views/desktop_view_lock_menu.h index 27ac00b20d3..a97f6144f47 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.h +++ b/applications/services/desktop/views/desktop_view_lock_menu.h @@ -34,7 +34,9 @@ View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu); void desktop_lock_menu_set_dummy_mode_state(DesktopLockMenuView* lock_menu, bool dummy_mode); void desktop_lock_menu_set_stealth_mode_state(DesktopLockMenuView* lock_menu, bool stealth_mode); void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx); -void desktop_lock_menu_set_notification_record(DesktopLockMenuView* lock_menu, NotificationApp* notification); +void desktop_lock_menu_set_notification_record( + DesktopLockMenuView* lock_menu, + NotificationApp* notification); bool desktop_lock_menu_did_notification_settings_change(DesktopLockMenuView* lock_menu); void desktop_lock_menu_refresh_notification_values(DesktopLockMenuView* lock_menu); DesktopLockMenuView* desktop_lock_menu_alloc(void); diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 7e22fe5e681..54576e5f8d2 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -32,11 +32,19 @@ static uint8_t notification_settings_get_display_brightness(NotificationApp* app static uint8_t notification_settings_get_rgb_led_brightness(NotificationApp* app, uint8_t value); static uint32_t notification_settings_display_off_delay_ticks(NotificationApp* app); -const char * backlight_text[BACKLIGHT_COUNT] = { - "0%", "25%", "50%", "75%", "100%", +const char* backlight_text[BACKLIGHT_COUNT] = { + "0%", + "25%", + "50%", + "75%", + "100%", }; float backlight_value[BACKLIGHT_COUNT] = { - 0.0f, 0.25f, 0.5f, 0.75f, 1.0f, + 0.0f, + 0.25f, + 0.5f, + 0.75f, + 1.0f, }; void notification_message_save_settings(NotificationApp* app) { diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index 1d8f1bd6aeb..a26dd381275 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -8,7 +8,7 @@ #define NOTIFICATION_EVENT_COMPLETE 0x00000001U #define BACKLIGHT_COUNT 5 -extern const char * backlight_text[BACKLIGHT_COUNT]; +extern const char* backlight_text[BACKLIGHT_COUNT]; extern float backlight_value[BACKLIGHT_COUNT]; typedef enum { From b15c868eb1917ecd9667c445513ef9a3a150cd3c Mon Sep 17 00:00:00 2001 From: Jan Wiesemann Date: Sat, 7 Sep 2024 21:38:30 +0200 Subject: [PATCH 6/6] Resolved a few minor issues --- .../desktop/views/desktop_view_lock_menu.c | 31 +++++++++++-------- .../services/notification/notification_app.c | 2 +- .../services/notification/notification_app.h | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/applications/services/desktop/views/desktop_view_lock_menu.c b/applications/services/desktop/views/desktop_view_lock_menu.c index 806d6a94da5..adfb47a271d 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.c +++ b/applications/services/desktop/views/desktop_view_lock_menu.c @@ -135,19 +135,22 @@ FuriString* desktop_lock_menu_display_brightness_get_text( bool is_selected) { furi_assert(item); furi_assert(model); + UNUSED(is_selected); const char* value_string = backlight_text[model->display_brightness_index]; FuriString* str = furi_string_alloc_set("Display "); - if(is_selected) { - if(model->display_brightness_index > 0) furi_string_cat(str, "< "); + if(model->display_brightness_index > 0) + furi_string_cat(str, "< "); + else + furi_string_cat(str, " "); - furi_string_cat(str, value_string); + furi_string_cat(str, value_string); - if(model->display_brightness_index < BACKLIGHT_COUNT - 1) furi_string_cat(str, " >"); - } else { - furi_string_cat(str, value_string); - } + if(model->display_brightness_index < BACKLIGHT_COUNT - 1) + furi_string_cat(str, " >"); + else + furi_string_cat(str, " "); return str; } @@ -184,9 +187,9 @@ bool desktop_lock_menu_display_brightness_on_input( model->notification_settings_changed = true; } }, - update) + update); - if(update) { + if(update) { view->notification_record->settings.display_brightness = backlight_value[index]; notification_message(view->notification_record, &sequence_display_backlight_on); } @@ -215,7 +218,7 @@ const DesktopLockMenuItem menu_items[] = { .on_input = desktop_lock_menu_display_brightness_on_input, }, }; -#define DESKTOP_LOCK_MENU_ITEM_COUNT (uint8_t)(sizeof(menu_items) / sizeof(DesktopLockMenuItem)) +#define DESKTOP_LOCK_MENU_ITEM_COUNT COUNT_OF(menu_items) #define DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR \ DESKTOP_LOCK_MENU_ITEM_COUNT > DESKTOP_LOCK_MENU_VISIBLE_ITEM_COUNT @@ -343,7 +346,7 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) { if(DESKTOP_LOCK_MENU_NEEDS_SCROLL_BAR) elements_scrollbar_pos( - canvas, 115, 1 + STATUS_BAR_Y_SHIFT, 50, m->idx, DESKTOP_LOCK_MENU_ITEM_COUNT); + canvas, 115, 1 + STATUS_BAR_Y_SHIFT, 51, m->idx, DESKTOP_LOCK_MENU_ITEM_COUNT); } View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu) { @@ -369,7 +372,8 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) { if(model->idx == 0) { model->idx = DESKTOP_LOCK_MENU_ITEM_COUNT - 1; } else { - model->idx = CLAMP(model->idx - 1, DESKTOP_LOCK_MENU_ITEM_COUNT - 1, 0); + model->idx = + CLAMP(model->idx - 1, (int8_t)DESKTOP_LOCK_MENU_ITEM_COUNT - 1, 0); } update = true; consumed = true; @@ -377,7 +381,8 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) { if(model->idx == DESKTOP_LOCK_MENU_ITEM_COUNT - 1) { model->idx = 0; } else { - model->idx = CLAMP(model->idx + 1, DESKTOP_LOCK_MENU_ITEM_COUNT - 1, 0); + model->idx = + CLAMP(model->idx + 1, (int8_t)DESKTOP_LOCK_MENU_ITEM_COUNT - 1, 0); } update = true; consumed = true; diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 54576e5f8d2..ccdd6761460 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -39,7 +39,7 @@ const char* backlight_text[BACKLIGHT_COUNT] = { "75%", "100%", }; -float backlight_value[BACKLIGHT_COUNT] = { +const float backlight_value[BACKLIGHT_COUNT] = { 0.0f, 0.25f, 0.5f, diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index a26dd381275..4fe3fea3a68 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -9,7 +9,7 @@ #define BACKLIGHT_COUNT 5 extern const char* backlight_text[BACKLIGHT_COUNT]; -extern float backlight_value[BACKLIGHT_COUNT]; +extern const float backlight_value[BACKLIGHT_COUNT]; typedef enum { NotificationLayerMessage,