From 23d2bed66a4f96463a8bbf5c0f1b300cad6dac64 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 25 Mar 2025 15:52:38 +0700 Subject: [PATCH 1/8] Remove Rainbow timer bug (after last code cleanup) --- applications/services/rgb_backlight/rgb_backlight.c | 4 +++- .../notification_settings/notification_settings_app.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index 053654ec2..9dc60a5ec 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -154,7 +154,9 @@ void rainbow_timer_start(RGBBacklightApp* app) { // stop furi timer for rainbow void rainbow_timer_stop(RGBBacklightApp* app) { - furi_timer_stop(app->rainbow_timer); + if (furi_timer_is_running (app->rainbow_timer)){ + furi_timer_stop(app->rainbow_timer); + } } // if rgb_backlight_installed then apply rainbow colors to backlight and start/restart/stop rainbow_timer diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index dd2206dc2..2408d4e05 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -355,7 +355,6 @@ static void rgb_backlight_rainbow_changed(VariableItem* item) { variable_item_set_current_value_text(item, rgb_backlight_rainbow_mode_text[index]); app->notification->rgb_srv->settings->rainbow_mode = rgb_backlight_rainbow_mode_value[index]; - rainbow_timer_starter(app->notification->rgb_srv); rgb_backlight_settings_save(app->notification->rgb_srv->settings); // restore saved rgb backlight settings if we switch_off rainbow mode @@ -367,6 +366,9 @@ static void rgb_backlight_rainbow_changed(VariableItem* item) { rgb_backlight_set_led_static_color( 0, app->notification->rgb_srv->settings->led_0_color_index); rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + rainbow_timer_stop (app->notification->rgb_srv); + } else { + rainbow_timer_starter(app->notification->rgb_srv); } } From ca2765a3fb1af0aa79410b163b1827ca1755c27b Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 25 Mar 2025 18:23:18 +0700 Subject: [PATCH 2/8] Small rgb_backlight settings menu changes --- .../rgb_backlight/rgb_backlight_settings.c | 4 +- .../rgb_backlight/rgb_backlight_settings.h | 1 + .../notification_settings_app.c | 68 +++++++++++++++++-- 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index 681197284..60361923f 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -9,8 +9,8 @@ #define RGB_BACKLIGHT_SETTINGS_PATH INT_PATH(RGB_BACKLIGHT_SETTINGS_FILE_NAME) #define RGB_BACKLIGHT_SETTINGS_MAGIC (0x30) -#define RGB_BACKLIGHT_SETTINGS_VER_PREV (2) // Previous version number -#define RGB_BACKLIGHT_SETTINGS_VER (3) // Current version number +#define RGB_BACKLIGHT_SETTINGS_VER_PREV (3) // Previous version number +#define RGB_BACKLIGHT_SETTINGS_VER (4) // Current version number //pervious settings must be copyed from previous rgb_backlight_settings.h file typedef struct { diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.h b/applications/services/rgb_backlight/rgb_backlight_settings.h index 3f3af005f..5136a16ca 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.h +++ b/applications/services/rgb_backlight/rgb_backlight_settings.h @@ -10,6 +10,7 @@ typedef struct { float brightness; // static gradient mode settings + bool individual_led; uint8_t led_2_color_index; uint8_t led_1_color_index; uint8_t led_0_color_index; diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 2408d4e05..9a123e014 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -175,6 +175,16 @@ const uint32_t rgb_backlight_rainbow_wide_value[RGB_BACKLIGHT_RAINBOW_WIDE_COUNT 50, }; +#define RGB_BACKLIGHT_INDIVIDUAL_LED_COUNT 2 +const char* const rgb_backlight_individual_led_text[RGB_BACKLIGHT_INDIVIDUAL_LED_COUNT] = { + "OFF", + "ON", +}; +const bool rgb_backlight_individual_value[RGB_BACKLIGHT_INDIVIDUAL_LED_COUNT] = { + false, + true, +}; + typedef enum { MainViewId, RGBViewId, @@ -291,7 +301,7 @@ static void rgb_backlight_installed_changed(VariableItem* item) { if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { slide = 1; } - for(int i = slide; i < (slide + 8); i++) { + for(int i = slide; i < (slide + 9); i++) { VariableItem* t_item = variable_item_list_get(app->variable_item_list_rgb, i); if(index == 0) { variable_item_set_locked(t_item, true, "RGB\nOFF!"); @@ -301,6 +311,32 @@ static void rgb_backlight_installed_changed(VariableItem* item) { } } +static void individual_led_changed (VariableItem* item){ + NotificationAppSettings* app = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text (item,rgb_backlight_individual_led_text[index]); + app->notification->rgb_srv->settings->individual_led = index; + + // if individual led OFF - set led0 and led1 colors indexes as led2 index + if (index == 0) { + app->notification->rgb_srv->settings->led_1_color_index = app->notification->rgb_srv->settings->led_2_color_index; + app->notification->rgb_srv->settings->led_0_color_index = app->notification->rgb_srv->settings->led_2_color_index; + } + + // enable/disable led0 and led1 color settings + for(int i = 2; i < 4; i++) { + VariableItem* t_item = variable_item_list_get(app->variable_item_list_rgb, i); + if(index == 0) { + variable_item_set_locked(t_item, true, "Individual\nleds OFF!"); + } else { + variable_item_set_locked(t_item, false, "Individual\nleds OFF!"); + } + } + rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + //rgb_backlight_settings_save(app->notification->rgb_srv->settings); +} + static void led_2_color_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -550,6 +586,22 @@ static NotificationAppSettings* alloc_settings(void) { } // We (humans) are numbering LEDs from left to right as 1..3, but hardware have another order from right to left 2..0 + + // Individual led color switch + item = variable_item_list_add( + app->variable_item_list_rgb, + "Individual leds colors", + RGB_BACKLIGHT_INDIVIDUAL_LED_COUNT, + individual_led_changed, + app); + value_index = app->notification->rgb_srv->settings->individual_led; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_individual_led_text[value_index]); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + // led_1 color item = variable_item_list_add( app->variable_item_list_rgb, @@ -579,6 +631,10 @@ static NotificationAppSettings* alloc_settings(void) { item, (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), "RGB MOD \nOFF!"); + variable_item_set_locked( + item, + (!app->notification->rgb_srv->settings->individual_led), + "Individual\nleds OFF!"); // led 3 color item = variable_item_list_add( @@ -594,11 +650,15 @@ static NotificationAppSettings* alloc_settings(void) { item, (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), "RGB MOD \nOFF!"); + variable_item_set_locked( + item, + (!app->notification->rgb_srv->settings->individual_led), + "Individual\nleds OFF!"); // Rainbow mode item = variable_item_list_add( app->variable_item_list_rgb, - "Rainbow mode", + "Dynamic colors mode", RGB_BACKLIGHT_RAINBOW_MODE_COUNT, rgb_backlight_rainbow_changed, app); @@ -615,7 +675,7 @@ static NotificationAppSettings* alloc_settings(void) { item = variable_item_list_add( app->variable_item_list_rgb, - "Rainbow speed", + "Mode speed", RGB_BACKLIGHT_RAINBOW_SPEED_COUNT, rgb_backlight_rainbow_speed_changed, app); @@ -632,7 +692,7 @@ static NotificationAppSettings* alloc_settings(void) { item = variable_item_list_add( app->variable_item_list_rgb, - "Rainbow step", + "Colors step", RGB_BACKLIGHT_RAINBOW_STEP_COUNT, rgb_backlight_rainbow_step_changed, app); From 8df48988f54b49dad7213e2e910835adc5a8ab31 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 25 Mar 2025 22:34:03 +0700 Subject: [PATCH 3/8] Revert "Small rgb_backlight settings menu changes" This reverts commit ca2765a3fb1af0aa79410b163b1827ca1755c27b. --- .../rgb_backlight/rgb_backlight_settings.c | 4 +- .../rgb_backlight/rgb_backlight_settings.h | 1 - .../notification_settings_app.c | 68 ++----------------- 3 files changed, 6 insertions(+), 67 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index 60361923f..681197284 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -9,8 +9,8 @@ #define RGB_BACKLIGHT_SETTINGS_PATH INT_PATH(RGB_BACKLIGHT_SETTINGS_FILE_NAME) #define RGB_BACKLIGHT_SETTINGS_MAGIC (0x30) -#define RGB_BACKLIGHT_SETTINGS_VER_PREV (3) // Previous version number -#define RGB_BACKLIGHT_SETTINGS_VER (4) // Current version number +#define RGB_BACKLIGHT_SETTINGS_VER_PREV (2) // Previous version number +#define RGB_BACKLIGHT_SETTINGS_VER (3) // Current version number //pervious settings must be copyed from previous rgb_backlight_settings.h file typedef struct { diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.h b/applications/services/rgb_backlight/rgb_backlight_settings.h index 5136a16ca..3f3af005f 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.h +++ b/applications/services/rgb_backlight/rgb_backlight_settings.h @@ -10,7 +10,6 @@ typedef struct { float brightness; // static gradient mode settings - bool individual_led; uint8_t led_2_color_index; uint8_t led_1_color_index; uint8_t led_0_color_index; diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 9a123e014..2408d4e05 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -175,16 +175,6 @@ const uint32_t rgb_backlight_rainbow_wide_value[RGB_BACKLIGHT_RAINBOW_WIDE_COUNT 50, }; -#define RGB_BACKLIGHT_INDIVIDUAL_LED_COUNT 2 -const char* const rgb_backlight_individual_led_text[RGB_BACKLIGHT_INDIVIDUAL_LED_COUNT] = { - "OFF", - "ON", -}; -const bool rgb_backlight_individual_value[RGB_BACKLIGHT_INDIVIDUAL_LED_COUNT] = { - false, - true, -}; - typedef enum { MainViewId, RGBViewId, @@ -301,7 +291,7 @@ static void rgb_backlight_installed_changed(VariableItem* item) { if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { slide = 1; } - for(int i = slide; i < (slide + 9); i++) { + for(int i = slide; i < (slide + 8); i++) { VariableItem* t_item = variable_item_list_get(app->variable_item_list_rgb, i); if(index == 0) { variable_item_set_locked(t_item, true, "RGB\nOFF!"); @@ -311,32 +301,6 @@ static void rgb_backlight_installed_changed(VariableItem* item) { } } -static void individual_led_changed (VariableItem* item){ - NotificationAppSettings* app = variable_item_get_context(item); - uint8_t index = variable_item_get_current_value_index(item); - - variable_item_set_current_value_text (item,rgb_backlight_individual_led_text[index]); - app->notification->rgb_srv->settings->individual_led = index; - - // if individual led OFF - set led0 and led1 colors indexes as led2 index - if (index == 0) { - app->notification->rgb_srv->settings->led_1_color_index = app->notification->rgb_srv->settings->led_2_color_index; - app->notification->rgb_srv->settings->led_0_color_index = app->notification->rgb_srv->settings->led_2_color_index; - } - - // enable/disable led0 and led1 color settings - for(int i = 2; i < 4; i++) { - VariableItem* t_item = variable_item_list_get(app->variable_item_list_rgb, i); - if(index == 0) { - variable_item_set_locked(t_item, true, "Individual\nleds OFF!"); - } else { - variable_item_set_locked(t_item, false, "Individual\nleds OFF!"); - } - } - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); - //rgb_backlight_settings_save(app->notification->rgb_srv->settings); -} - static void led_2_color_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -586,22 +550,6 @@ static NotificationAppSettings* alloc_settings(void) { } // We (humans) are numbering LEDs from left to right as 1..3, but hardware have another order from right to left 2..0 - - // Individual led color switch - item = variable_item_list_add( - app->variable_item_list_rgb, - "Individual leds colors", - RGB_BACKLIGHT_INDIVIDUAL_LED_COUNT, - individual_led_changed, - app); - value_index = app->notification->rgb_srv->settings->individual_led; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_individual_led_text[value_index]); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - // led_1 color item = variable_item_list_add( app->variable_item_list_rgb, @@ -631,10 +579,6 @@ static NotificationAppSettings* alloc_settings(void) { item, (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), "RGB MOD \nOFF!"); - variable_item_set_locked( - item, - (!app->notification->rgb_srv->settings->individual_led), - "Individual\nleds OFF!"); // led 3 color item = variable_item_list_add( @@ -650,15 +594,11 @@ static NotificationAppSettings* alloc_settings(void) { item, (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), "RGB MOD \nOFF!"); - variable_item_set_locked( - item, - (!app->notification->rgb_srv->settings->individual_led), - "Individual\nleds OFF!"); // Rainbow mode item = variable_item_list_add( app->variable_item_list_rgb, - "Dynamic colors mode", + "Rainbow mode", RGB_BACKLIGHT_RAINBOW_MODE_COUNT, rgb_backlight_rainbow_changed, app); @@ -675,7 +615,7 @@ static NotificationAppSettings* alloc_settings(void) { item = variable_item_list_add( app->variable_item_list_rgb, - "Mode speed", + "Rainbow speed", RGB_BACKLIGHT_RAINBOW_SPEED_COUNT, rgb_backlight_rainbow_speed_changed, app); @@ -692,7 +632,7 @@ static NotificationAppSettings* alloc_settings(void) { item = variable_item_list_add( app->variable_item_list_rgb, - "Colors step", + "Rainbow step", RGB_BACKLIGHT_RAINBOW_STEP_COUNT, rgb_backlight_rainbow_step_changed, app); From a9288da9ba7ffa0dadc025ccf5ac4778e66dd692 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 26 Mar 2025 08:11:52 +0700 Subject: [PATCH 4/8] RGB backlight bags and code cleanup --- .../notification_settings_app.c | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 2408d4e05..4e14d2012 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -261,16 +261,19 @@ static void rgb_backlight_installed_changed(VariableItem* item) { variable_item_set_current_value_text(item, rgb_backlight_installed_text[index]); app->notification->rgb_srv->settings->rgb_backlight_installed = rgb_backlight_installed_value[index]; - rgb_backlight_settings_save(app->notification->rgb_srv->settings); + + app->notification->rgb_srv->settings->brightness = + app->notification->settings.display_brightness; // In case of user playing with rgb_backlight_installed swith: // if user swith_off rgb_backlight_installed (but may be he have mod installed) - // then force set default orange color - defence from stupid. + // then force set default orange color and stop rainbow timer if(index == 0) { rgb_backlight_set_led_static_color(2, 0); rgb_backlight_set_led_static_color(1, 0); rgb_backlight_set_led_static_color(0, 0); SK6805_update(); + rainbow_timer_stop(app->notification->rgb_srv); // start rainbow (if its Enabled) or set saved static colors if user swith_on rgb_backlight_installed switch } else { if(app->notification->rgb_srv->settings->rainbow_mode > 0) { @@ -299,6 +302,8 @@ static void rgb_backlight_installed_changed(VariableItem* item) { variable_item_set_locked(t_item, false, "RGB\nOFF!"); } } + + rgb_backlight_settings_save(app->notification->rgb_srv->settings); } static void led_2_color_changed(VariableItem* item) { @@ -313,6 +318,7 @@ static void led_2_color_changed(VariableItem* item) { rgb_backlight_set_led_static_color(2, index); rgb_backlight_update(app->notification->rgb_srv->settings->brightness); } + rgb_backlight_settings_save(app->notification->rgb_srv->settings); } @@ -355,10 +361,8 @@ static void rgb_backlight_rainbow_changed(VariableItem* item) { variable_item_set_current_value_text(item, rgb_backlight_rainbow_mode_text[index]); app->notification->rgb_srv->settings->rainbow_mode = rgb_backlight_rainbow_mode_value[index]; - rgb_backlight_settings_save(app->notification->rgb_srv->settings); - - // restore saved rgb backlight settings if we switch_off rainbow mode - if(app->notification->rgb_srv->settings->rainbow_mode == 0) { + // restore saved rgb backlight settings if we switch_off effects + if(index == 0) { rgb_backlight_set_led_static_color( 2, app->notification->rgb_srv->settings->led_2_color_index); rgb_backlight_set_led_static_color( @@ -366,10 +370,12 @@ static void rgb_backlight_rainbow_changed(VariableItem* item) { rgb_backlight_set_led_static_color( 0, app->notification->rgb_srv->settings->led_0_color_index); rgb_backlight_update(app->notification->rgb_srv->settings->brightness); - rainbow_timer_stop (app->notification->rgb_srv); + rainbow_timer_stop(app->notification->rgb_srv); } else { rainbow_timer_starter(app->notification->rgb_srv); } + + rgb_backlight_settings_save(app->notification->rgb_srv->settings); } static void rgb_backlight_rainbow_speed_changed(VariableItem* item) { @@ -381,8 +387,8 @@ static void rgb_backlight_rainbow_speed_changed(VariableItem* item) { rgb_backlight_rainbow_speed_value[index]; // save settings and restart timer with new speed value - rgb_backlight_settings_save(app->notification->rgb_srv->settings); rainbow_timer_starter(app->notification->rgb_srv); + rgb_backlight_settings_save(app->notification->rgb_srv->settings); } static void rgb_backlight_rainbow_step_changed(VariableItem* item) { @@ -404,6 +410,7 @@ static void rgb_backlight_rainbow_saturation_changed(VariableItem* item) { snprintf(valtext, sizeof(valtext), "%d", index); variable_item_set_current_value_text(item, valtext); app->notification->rgb_srv->settings->rainbow_saturation = index; + rgb_backlight_settings_save(app->notification->rgb_srv->settings); } @@ -414,9 +421,7 @@ static void rgb_backlight_rainbow_wide_changed(VariableItem* item) { variable_item_set_current_value_text(item, rgb_backlight_rainbow_wide_text[index]); app->notification->rgb_srv->settings->rainbow_wide = rgb_backlight_rainbow_wide_value[index]; - // save settings and restart timer with new speed value rgb_backlight_settings_save(app->notification->rgb_srv->settings); - rainbow_timer_starter(app->notification->rgb_srv); } // open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_backlight_installed is true) @@ -553,7 +558,7 @@ static NotificationAppSettings* alloc_settings(void) { // led_1 color item = variable_item_list_add( app->variable_item_list_rgb, - "LED 1 Color", + "Led 1 Color", rgb_backlight_get_color_count(), led_2_color_changed, app); @@ -568,7 +573,7 @@ static NotificationAppSettings* alloc_settings(void) { // led_2 color item = variable_item_list_add( app->variable_item_list_rgb, - "LED 2 Color", + "Led 2 Color", rgb_backlight_get_color_count(), led_1_color_changed, app); @@ -583,7 +588,7 @@ static NotificationAppSettings* alloc_settings(void) { // led 3 color item = variable_item_list_add( app->variable_item_list_rgb, - "LED 3 Color", + "Led 3 Color", rgb_backlight_get_color_count(), led_0_color_changed, app); @@ -595,10 +600,10 @@ static NotificationAppSettings* alloc_settings(void) { (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), "RGB MOD \nOFF!"); - // Rainbow mode + // Efects item = variable_item_list_add( app->variable_item_list_rgb, - "Rainbow mode", + "Effects", RGB_BACKLIGHT_RAINBOW_MODE_COUNT, rgb_backlight_rainbow_changed, app); @@ -615,7 +620,7 @@ static NotificationAppSettings* alloc_settings(void) { item = variable_item_list_add( app->variable_item_list_rgb, - "Rainbow speed", + " . Speed", RGB_BACKLIGHT_RAINBOW_SPEED_COUNT, rgb_backlight_rainbow_speed_changed, app); @@ -632,7 +637,7 @@ static NotificationAppSettings* alloc_settings(void) { item = variable_item_list_add( app->variable_item_list_rgb, - "Rainbow step", + " . Color step", RGB_BACKLIGHT_RAINBOW_STEP_COUNT, rgb_backlight_rainbow_step_changed, app); @@ -649,7 +654,7 @@ static NotificationAppSettings* alloc_settings(void) { item = variable_item_list_add( app->variable_item_list_rgb, - "Saturation", + " . Saturation", 255, rgb_backlight_rainbow_saturation_changed, app); @@ -665,7 +670,7 @@ static NotificationAppSettings* alloc_settings(void) { item = variable_item_list_add( app->variable_item_list_rgb, - "Wave wide", + " . Wave wide", RGB_BACKLIGHT_RAINBOW_WIDE_COUNT, rgb_backlight_rainbow_wide_changed, app); From c86b6e4b56e9af8a3975f2fc1856caa306745929 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 26 Mar 2025 10:43:45 +0700 Subject: [PATCH 5/8] Bump settings for new auto recreation after update --- applications/services/rgb_backlight/rgb_backlight_settings.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index 681197284..b76c6598a 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -9,8 +9,8 @@ #define RGB_BACKLIGHT_SETTINGS_PATH INT_PATH(RGB_BACKLIGHT_SETTINGS_FILE_NAME) #define RGB_BACKLIGHT_SETTINGS_MAGIC (0x30) -#define RGB_BACKLIGHT_SETTINGS_VER_PREV (2) // Previous version number -#define RGB_BACKLIGHT_SETTINGS_VER (3) // Current version number +#define RGB_BACKLIGHT_SETTINGS_VER_PREV (4) // Previous version number +#define RGB_BACKLIGHT_SETTINGS_VER (5) // Current version number //pervious settings must be copyed from previous rgb_backlight_settings.h file typedef struct { From 77865586e13b2bd2d6c2352e2062949ef341d3cf Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 26 Mar 2025 18:51:36 +0700 Subject: [PATCH 6/8] Start working with "Night Shift" option --- .../services/notification/notification_app.h | 3 + .../notification_settings_app.c | 90 +++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index 798b01ab6..7ee421b31 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -45,6 +45,9 @@ typedef struct { uint32_t display_off_delay_ms; int8_t contrast; bool vibro_on; + float night_shift; + uint32_t night_shift_start; + uint32_t night_shift_end; } NotificationSettings; struct NotificationApp { diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 4e14d2012..435a0087c 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -182,6 +182,66 @@ typedef enum { // --- RGB BACKLIGHT END --- + // --- NIGHT SHIFT --- + #define NIGHT_SHIFT_COUNT 7 + const char* const night_shift_text[NIGHT_SHIFT_COUNT] = { + "OFF", + "5%", + "10%" + "15%", + "20%", + "25%", + "30%" + + }; + const float night_shift_value[NIGHT_SHIFT_COUNT] = { + 0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, + }; + + #define NIGHT_SHIFT_START_COUNT 14 + const char* const night_shift_start_text[NIGHT_SHIFT_START_COUNT] = { + "17:00", + "17:30", + "18:00" + "18:30", + "19:00", + "19:30", + "20:00", + "20:30", + "21:00", + "21:30", + "22:00", + "22:30", + "23:00", + "23:30", + }; + const uint32_t night_shift_start_value[NIGHT_SHIFT_START_COUNT] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; + + #define NIGHT_SHIFT_END_COUNT 14 + const char* const night_shift_end_text[NIGHT_SHIFT_END_COUNT] = { + "05:00", + "05:30", + "06:00" + "06:30", + "07:00", + "07:30", + "08:00", + "08:30", + "09:00", + "09:30", + "10:00", + "10:30", + "11:00", + "11:30", + }; + const uint32_t night_shift_end_value[NIGHT_SHIFT_END_COUNT] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; + + // --- NIGHT SHIFT END --- + static void contrast_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -443,6 +503,11 @@ static uint32_t notification_app_rgb_settings_exit(void* context) { } //--- RGB BACKLIGHT END --- +// --- NIGHT SHIFT --- + + +// --- NIGHT SHIFT END --- + static uint32_t notification_app_settings_exit(void* context) { UNUSED(context); return VIEW_NONE; @@ -495,6 +560,31 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, delay_text[value_index]); + // --- NIGHT SHIFT --- + item = variable_item_list_add( + app->variable_item_list, "Night Shift", NIGHT_SHIFT_COUNT, night_shift_changed, app); + value_index = value_index_float( + app->notification->settings.night_shift, night_shift_value, NIGHT_SHIFT_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, night_shift_text[value_index]); + + item = variable_item_list_add( + app->variable_item_list, " . Start", NIGHT_SHIFT_START_COUNT, night_shift_start_changed, app); + value_index = value_index_uint32( + app->notification->settings.night_shift_start, night_shift_start_value, NIGHT_SHIFT_START_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, night_shift_start_text[value_index]); + + item = variable_item_list_add( + app->variable_item_list, " . End", NIGHT_SHIFT_END_COUNT, night_shift_end_changed, app); + value_index = value_index_uint32( + app->notification->settings.night_shift_end, night_shift_end_value, NIGHT_SHIFT_END_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, night_shift_end_text[value_index]); + + // --- NIGHT SHIFT END--- + + item = variable_item_list_add( app->variable_item_list, "LED Brightness", BACKLIGHT_COUNT, led_changed, app); value_index = value_index_float( From cd28f7d23223e8dfe675190c0cc09c7e5b5f7f82 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Fri, 28 Mar 2025 01:14:57 +0700 Subject: [PATCH 7/8] current working, need find and remove 1 bug --- .../services/notification/notification_app.c | 85 ++++++- .../services/notification/notification_app.h | 7 +- .../services/rgb_backlight/rgb_backlight.c | 13 +- .../services/rgb_backlight/rgb_backlight.h | 3 + .../rgb_backlight/rgb_backlight_settings.c | 1 + .../rgb_backlight/rgb_backlight_settings.h | 2 +- .../notification_settings_app.c | 233 +++++++++++++----- 7 files changed, 264 insertions(+), 80 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index cf03d4389..3eca2fd2d 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -33,6 +33,51 @@ 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); +// --- NIGHT SHIFT --- + +void night_shift_timer_start(NotificationApp* app) { + if(app->settings.night_shift != 1) { + furi_timer_start(app->night_shift_timer, furi_ms_to_ticks(2000)); + } +} + +void night_shift_timer_stop(NotificationApp* app) { + if(furi_timer_is_running(app->night_shift_timer)) { + furi_timer_stop(app->night_shift_timer); + } +} + +// every callback time we check current time and current night_shift_settings value +void night_shift_timer_callback(void* context) { + furi_assert(context); + NotificationApp* app = context; + DateTime current_date_time; + + // save current night_shift; + // float old_night_shift = app->current_night_shift; + + // take system time and convert to minutes + furi_hal_rtc_get_datetime(¤t_date_time); + uint32_t time = current_date_time.hour * 60 + current_date_time.minute; + + // if current time not in night_shift range then current_night_shift = 1 else = settings value; + // set values to stock and rgb backlights + if((time > app->settings.night_shift_end) && (time < app->settings.night_shift_start)) { + app->current_night_shift = 1.0f; + app->rgb_srv->current_night_shift = 1.0f; + } else { + app->current_night_shift = app->settings.night_shift; + app->rgb_srv->current_night_shift = app->settings.night_shift; + } + + // // if night shift was changed then update stock and rgb backlight to new value + // if(old_night_shift != app->current_night_shift) { + // notification_message(app, &sequence_display_backlight_on); + // } +} + +// --- NIGHT SHIFT END --- + void notification_message_save_settings(NotificationApp* app) { NotificationAppMessage m = { .type = SaveSettingsMessage, .back_event = furi_event_flag_alloc()}; @@ -129,7 +174,11 @@ static void notification_reset_notification_layer( } if(reset_mask & reset_display_mask) { if(!float_is_equal(display_brightness_set, app->settings.display_brightness)) { - furi_hal_light_set(LightBacklight, app->settings.display_brightness * 0xFF); + // --- NIGHT SHIFT --- + furi_hal_light_set( + LightBacklight, + app->settings.display_brightness * 0xFF * app->current_night_shift); + // --- NIGHT SHIFT END--- } furi_timer_start(app->display_timer, notification_settings_display_off_delay_ticks(app)); } @@ -214,15 +263,17 @@ static void notification_process_notification_message( // if on - switch on and start timer // if off - switch off and stop timer // on timer - switch off + // --- NIGHT SHIFT --- if(notification_message->data.led.value > 0x00) { notification_apply_notification_led_layer( &app->display, - notification_message->data.led.value * display_brightness_setting); + notification_message->data.led.value * display_brightness_setting * + app->current_night_shift); reset_mask |= reset_display_mask; //start rgb_mod_rainbow_timer when display backlight is ON and all corresponding settings is ON too rainbow_timer_starter(app->rgb_srv); - + // --- NIGHT SHIFT END --- } else { reset_mask &= ~reset_display_mask; notification_reset_notification_led_layer(&app->display); @@ -238,10 +289,12 @@ static void notification_process_notification_message( case NotificationMessageTypeLedDisplayBacklightEnforceOn: furi_check(app->display_led_lock < UINT8_MAX); app->display_led_lock++; + // --- NIGHT SHIFT --- if(app->display_led_lock == 1) { notification_apply_internal_led_layer( &app->display, - notification_message->data.led.value * display_brightness_setting); + notification_message->data.led.value * display_brightness_setting * + app->current_night_shift); } break; case NotificationMessageTypeLedDisplayBacklightEnforceAuto: @@ -250,8 +303,10 @@ static void notification_process_notification_message( if(app->display_led_lock == 0) { notification_apply_internal_led_layer( &app->display, - notification_message->data.led.value * display_brightness_setting); + notification_message->data.led.value * display_brightness_setting * + app->current_night_shift); } + // --- NIGHT SHIFT END --- } else { FURI_LOG_E(TAG, "Incorrect BacklightEnforce use"); } @@ -559,6 +614,17 @@ static NotificationApp* notification_app_alloc(void) { furi_pubsub_subscribe(app->event_record, input_event_callback, app); notification_message(app, &sequence_display_backlight_on); + // --- NIGHT SHIFT --- + app->rgb_srv = furi_record_open(RECORD_RGB_BACKLIGHT); + app->rgb_srv->current_night_shift = 1.0f; + app->current_night_shift = 1.0f; + app->settings.night_shift = 1.0f; + app->settings.night_shift_start = 1020; + app->settings.night_shift_end = 300; + app->night_shift_timer = + furi_timer_alloc(night_shift_timer_callback, FuriTimerTypePeriodic, app); + // --- NIGHT SHIFT END --- + return app; } @@ -582,6 +648,13 @@ static void notification_apply_settings(NotificationApp* app) { } notification_apply_lcd_contrast(app); + + // --- NIGHT SHIFT --- + // if night_shift_enabled start timer for controlling current_night_shift multiplicator value depent from current time + if(app->settings.night_shift != 1) { + night_shift_timer_start(app); + } + // --- NIGHT SHIFT END --- } static void notification_init_settings(NotificationApp* app) { @@ -600,7 +673,7 @@ static void notification_init_settings(NotificationApp* app) { int32_t notification_srv(void* p) { UNUSED(p); NotificationApp* app = notification_app_alloc(); - app->rgb_srv = furi_record_open(RECORD_RGB_BACKLIGHT); + notification_init_settings(app); notification_vibro_off(); diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index 7ee421b31..0d4404fa5 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -34,7 +34,7 @@ typedef struct { Light light; } NotificationLedLayer; -#define NOTIFICATION_SETTINGS_VERSION 0x02 +#define NOTIFICATION_SETTINGS_VERSION 0x03 #define NOTIFICATION_SETTINGS_PATH INT_PATH(NOTIFICATION_SETTINGS_FILE_NAME) typedef struct { @@ -61,6 +61,11 @@ struct NotificationApp { NotificationSettings settings; RGBBacklightApp* rgb_srv; + + FuriTimer* night_shift_timer; + float current_night_shift; }; void notification_message_save_settings(NotificationApp* app); +void night_shift_timer_start(NotificationApp* app); +void night_shift_timer_stop(NotificationApp* app); diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index 9dc60a5ec..8862ac154 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -137,9 +137,9 @@ void rgb_backlight_update(float brightness) { if(app->settings->rgb_backlight_installed) { for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - uint8_t r = current_led[i].red * (brightness * 1.0f); - uint8_t g = current_led[i].green * (brightness * 1.0f); - uint8_t b = current_led[i].blue * (brightness * 1.0f); + uint8_t r = current_led[i].red * brightness; + uint8_t g = current_led[i].green * brightness; + uint8_t b = current_led[i].blue * brightness; SK6805_set_led_color(i, r, g, b); } SK6805_update(); @@ -154,7 +154,7 @@ void rainbow_timer_start(RGBBacklightApp* app) { // stop furi timer for rainbow void rainbow_timer_stop(RGBBacklightApp* app) { - if (furi_timer_is_running (app->rainbow_timer)){ + if(furi_timer_is_running(app->rainbow_timer)) { furi_timer_stop(app->rainbow_timer); } } @@ -214,7 +214,7 @@ static void rainbow_timer_callback(void* context) { break; } - rgb_backlight_update(app->settings->brightness); + rgb_backlight_update(app->settings->brightness * app->current_night_shift); } } @@ -233,6 +233,7 @@ int32_t rgb_backlight_srv(void* p) { rgb_backlight_settings_load(app->settings); app->rainbow_hue = 1; + app->current_night_shift = 1.0f; furi_record_create(RECORD_RGB_BACKLIGHT, app); @@ -244,7 +245,7 @@ int32_t rgb_backlight_srv(void* p) { rgb_backlight_set_led_static_color(2, app->settings->led_2_color_index); rgb_backlight_set_led_static_color(1, app->settings->led_1_color_index); rgb_backlight_set_led_static_color(0, app->settings->led_0_color_index); - rgb_backlight_update(app->settings->brightness); + rgb_backlight_update(app->settings->brightness * app->current_night_shift); } // if rgb_backlight not installed then set default static orange color(index=0) to all leds (0-2) and force light on } else { diff --git a/applications/services/rgb_backlight/rgb_backlight.h b/applications/services/rgb_backlight/rgb_backlight.h index d6f8b5fce..1be252dc1 100644 --- a/applications/services/rgb_backlight/rgb_backlight.h +++ b/applications/services/rgb_backlight/rgb_backlight.h @@ -33,6 +33,9 @@ typedef struct { uint8_t rainbow_green; uint8_t rainbow_blue; RGBBacklightSettings* settings; + // night_shift multiplicator for leds brightnes coming from Notificatoin app. + float current_night_shift; + } RGBBacklightApp; #define RECORD_RGB_BACKLIGHT "rgb_backlight" diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index b76c6598a..17f6bb271 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -30,6 +30,7 @@ typedef struct { uint16_t rainbow_step; uint8_t rainbow_saturation; uint8_t rainbow_wide; + } RGBBacklightSettingsPrevious; void rgb_backlight_settings_load(RGBBacklightSettings* settings) { diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.h b/applications/services/rgb_backlight/rgb_backlight_settings.h index 3f3af005f..b1e4a4a01 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.h +++ b/applications/services/rgb_backlight/rgb_backlight_settings.h @@ -20,7 +20,7 @@ typedef struct { uint16_t rainbow_step; uint8_t rainbow_saturation; uint8_t rainbow_wide; - + } RGBBacklightSettings; #ifdef __cplusplus diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 435a0087c..86176c8e5 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -182,65 +182,93 @@ typedef enum { // --- RGB BACKLIGHT END --- - // --- NIGHT SHIFT --- - #define NIGHT_SHIFT_COUNT 7 - const char* const night_shift_text[NIGHT_SHIFT_COUNT] = { - "OFF", - "5%", - "10%" - "15%", - "20%", - "25%", - "30%" +// --- NIGHT SHIFT --- +#define NIGHT_SHIFT_COUNT 7 +const char* const night_shift_text[NIGHT_SHIFT_COUNT] = + {"OFF", "-10%", "-20%", "-30%", "-40%", "-50%", "-60%" - }; - const float night_shift_value[NIGHT_SHIFT_COUNT] = { - 0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, - }; +}; +const float night_shift_value[NIGHT_SHIFT_COUNT] = { + 1.0f, + 0.9f, + 0.8f, + 0.7f, + 0.6f, + 0.5f, + 0.4f, +}; - #define NIGHT_SHIFT_START_COUNT 14 - const char* const night_shift_start_text[NIGHT_SHIFT_START_COUNT] = { - "17:00", - "17:30", - "18:00" - "18:30", - "19:00", - "19:30", - "20:00", - "20:30", - "21:00", - "21:30", - "22:00", - "22:30", - "23:00", - "23:30", - }; - const uint32_t night_shift_start_value[NIGHT_SHIFT_START_COUNT] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - }; +#define NIGHT_SHIFT_START_COUNT 14 +const char* const night_shift_start_text[NIGHT_SHIFT_START_COUNT] = { + "17:00", + "17:30", + "18:00", + "18:30", + "19:00", + "19:30", + "20:00", + "20:30", + "21:00", + "21:30", + "22:00", + "22:30", + "23:00", + "23:30", +}; +// values in minutes like 23:30 = 23*60+30=1410 +const uint32_t night_shift_start_value[NIGHT_SHIFT_START_COUNT] = { + 1020, + 1050, + 1080, + 1110, + 1140, + 1170, + 1200, + 1230, + 1260, + 1290, + 1320, + 1350, + 1380, + 1410, +}; - #define NIGHT_SHIFT_END_COUNT 14 - const char* const night_shift_end_text[NIGHT_SHIFT_END_COUNT] = { - "05:00", - "05:30", - "06:00" - "06:30", - "07:00", - "07:30", - "08:00", - "08:30", - "09:00", - "09:30", - "10:00", - "10:30", - "11:00", - "11:30", - }; - const uint32_t night_shift_end_value[NIGHT_SHIFT_END_COUNT] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - }; +#define NIGHT_SHIFT_END_COUNT 14 +const char* const night_shift_end_text[NIGHT_SHIFT_END_COUNT] = { + "05:00", + "05:30", + "06:00", + "06:30", + "07:00", + "07:30", + "08:00", + "08:30", + "09:00", + "09:30", + "10:00", + "10:30", + "11:00", + "11:30", +}; +// values in minutes like 6:30 = 6*60+30=390 +const uint32_t night_shift_end_value[NIGHT_SHIFT_END_COUNT] = { + 300, + 330, + 360, + 390, + 410, + 440, + 470, + 500, + 530, + 560, + 590, + 620, + 650, + 680, +}; - // --- NIGHT SHIFT END --- +// --- NIGHT SHIFT END --- static void contrast_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); @@ -345,7 +373,9 @@ static void rgb_backlight_installed_changed(VariableItem* item) { 1, app->notification->rgb_srv->settings->led_1_color_index); rgb_backlight_set_led_static_color( 0, app->notification->rgb_srv->settings->led_0_color_index); - rgb_backlight_update(app->notification->settings.display_brightness); + rgb_backlight_update( + app->notification->settings.display_brightness * + app->notification->current_night_shift); } } @@ -376,7 +406,9 @@ static void led_2_color_changed(VariableItem* item) { // dont update screen color if rainbow timer working if(!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) { rgb_backlight_set_led_static_color(2, index); - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + rgb_backlight_update( + app->notification->rgb_srv->settings->brightness * + app->notification->current_night_shift); } rgb_backlight_settings_save(app->notification->rgb_srv->settings); @@ -392,7 +424,9 @@ static void led_1_color_changed(VariableItem* item) { // dont update screen color if rainbow timer working if(!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) { rgb_backlight_set_led_static_color(1, index); - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + rgb_backlight_update( + app->notification->rgb_srv->settings->brightness * + app->notification->current_night_shift); } rgb_backlight_settings_save(app->notification->rgb_srv->settings); @@ -408,7 +442,9 @@ static void led_0_color_changed(VariableItem* item) { // dont update screen color if rainbow timer working if(!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) { rgb_backlight_set_led_static_color(0, index); - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + rgb_backlight_update( + app->notification->rgb_srv->settings->brightness * + app->notification->current_night_shift); } rgb_backlight_settings_save(app->notification->rgb_srv->settings); @@ -429,7 +465,9 @@ static void rgb_backlight_rainbow_changed(VariableItem* item) { 1, app->notification->rgb_srv->settings->led_1_color_index); rgb_backlight_set_led_static_color( 0, app->notification->rgb_srv->settings->led_0_color_index); - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + rgb_backlight_update( + app->notification->rgb_srv->settings->brightness * + app->notification->current_night_shift); rainbow_timer_stop(app->notification->rgb_srv); } else { rainbow_timer_starter(app->notification->rgb_srv); @@ -505,6 +543,60 @@ static uint32_t notification_app_rgb_settings_exit(void* context) { // --- NIGHT SHIFT --- +static void night_shift_changed(VariableItem* item) { + NotificationAppSettings* app = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text(item, night_shift_text[index]); + app->notification->settings.night_shift = night_shift_value[index]; + app->notification->current_night_shift = night_shift_value[index]; + app->notification->rgb_srv->current_night_shift = night_shift_value[index]; + + // force demo night_shift brightness ot rgb backlight and stock backlight + notification_message(app->notification, &sequence_display_backlight_on); + + int slide = 0; + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) || + (app->notification->rgb_srv->settings->rgb_backlight_installed)) { + slide = 1; + } + for(int i = 4 + slide; i < (6 + slide); i++) { + VariableItem* t_item = variable_item_list_get(app->variable_item_list, i); + if(index == 0) { + variable_item_set_locked(t_item, true, "Night shift\nOFF!"); + } else { + variable_item_set_locked(t_item, false, "Night shift\nOFF!"); + } + } + + if(night_shift_value[index] != 1) { + night_shift_timer_start(app->notification); + } else { + night_shift_timer_stop(app->notification); + } + + notification_message_save_settings(app->notification); +} + +static void night_shift_start_changed(VariableItem* item) { + NotificationAppSettings* app = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text(item, night_shift_start_text[index]); + app->notification->settings.night_shift_start = night_shift_start_value[index]; + + notification_message_save_settings(app->notification); +} + +static void night_shift_end_changed(VariableItem* item) { + NotificationAppSettings* app = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text(item, night_shift_end_text[index]); + app->notification->settings.night_shift_end = night_shift_end_value[index]; + + notification_message_save_settings(app->notification); +} // --- NIGHT SHIFT END --- @@ -562,28 +654,37 @@ static NotificationAppSettings* alloc_settings(void) { // --- NIGHT SHIFT --- item = variable_item_list_add( - app->variable_item_list, "Night Shift", NIGHT_SHIFT_COUNT, night_shift_changed, app); + app->variable_item_list, "Night shift", NIGHT_SHIFT_COUNT, night_shift_changed, app); value_index = value_index_float( app->notification->settings.night_shift, night_shift_value, NIGHT_SHIFT_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, night_shift_text[value_index]); item = variable_item_list_add( - app->variable_item_list, " . Start", NIGHT_SHIFT_START_COUNT, night_shift_start_changed, app); + app->variable_item_list, + " . Start", + NIGHT_SHIFT_START_COUNT, + night_shift_start_changed, + app); value_index = value_index_uint32( - app->notification->settings.night_shift_start, night_shift_start_value, NIGHT_SHIFT_START_COUNT); + app->notification->settings.night_shift_start, + night_shift_start_value, + NIGHT_SHIFT_START_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, night_shift_start_text[value_index]); - + variable_item_set_locked( + item, (app->notification->settings.night_shift == 1), "Night shift \nOFF!"); + item = variable_item_list_add( app->variable_item_list, " . End", NIGHT_SHIFT_END_COUNT, night_shift_end_changed, app); value_index = value_index_uint32( app->notification->settings.night_shift_end, night_shift_end_value, NIGHT_SHIFT_END_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, night_shift_end_text[value_index]); - - // --- NIGHT SHIFT END--- + variable_item_set_locked( + item, (app->notification->settings.night_shift == 1), "Night shift \nOFF!"); + // --- NIGHT SHIFT END--- item = variable_item_list_add( app->variable_item_list, "LED Brightness", BACKLIGHT_COUNT, led_changed, app); From 31b7c4a34fd22c1cedc9c2ed9f98235eb6f3b49c Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Fri, 28 Mar 2025 13:48:32 +0700 Subject: [PATCH 8/8] Night shift done. --- .../services/notification/notification_app.c | 12 +++++++----- applications/services/rgb_backlight/rgb_backlight.c | 6 +++--- .../services/rgb_backlight/rgb_backlight_settings.c | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 3eca2fd2d..b5a95b4a3 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -53,7 +53,8 @@ void night_shift_timer_callback(void* context) { NotificationApp* app = context; DateTime current_date_time; - // save current night_shift; + // IN DEVELOPMENT + // // save current night_shift; // float old_night_shift = app->current_night_shift; // take system time and convert to minutes @@ -70,6 +71,7 @@ void night_shift_timer_callback(void* context) { app->rgb_srv->current_night_shift = app->settings.night_shift; } + // IN DEVELOPMENT // // if night shift was changed then update stock and rgb backlight to new value // if(old_night_shift != app->current_night_shift) { // notification_message(app, &sequence_display_backlight_on); @@ -177,7 +179,7 @@ static void notification_reset_notification_layer( // --- NIGHT SHIFT --- furi_hal_light_set( LightBacklight, - app->settings.display_brightness * 0xFF * app->current_night_shift); + app->settings.display_brightness * 0xFF * app->current_night_shift * 1.0f); // --- NIGHT SHIFT END--- } furi_timer_start(app->display_timer, notification_settings_display_off_delay_ticks(app)); @@ -268,7 +270,7 @@ static void notification_process_notification_message( notification_apply_notification_led_layer( &app->display, notification_message->data.led.value * display_brightness_setting * - app->current_night_shift); + app->current_night_shift * 1.0f); reset_mask |= reset_display_mask; //start rgb_mod_rainbow_timer when display backlight is ON and all corresponding settings is ON too @@ -294,7 +296,7 @@ static void notification_process_notification_message( notification_apply_internal_led_layer( &app->display, notification_message->data.led.value * display_brightness_setting * - app->current_night_shift); + app->current_night_shift * 1.0f); } break; case NotificationMessageTypeLedDisplayBacklightEnforceAuto: @@ -304,7 +306,7 @@ static void notification_process_notification_message( notification_apply_internal_led_layer( &app->display, notification_message->data.led.value * display_brightness_setting * - app->current_night_shift); + app->current_night_shift * 1.0f); } // --- NIGHT SHIFT END --- } else { diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index 8862ac154..916357b89 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -137,9 +137,9 @@ void rgb_backlight_update(float brightness) { if(app->settings->rgb_backlight_installed) { for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - uint8_t r = current_led[i].red * brightness; - uint8_t g = current_led[i].green * brightness; - uint8_t b = current_led[i].blue * brightness; + uint8_t r = current_led[i].red * brightness * 1.0f; + uint8_t g = current_led[i].green * brightness * 1.0f; + uint8_t b = current_led[i].blue * brightness * 1.0f; SK6805_set_led_color(i, r, g, b); } SK6805_update(); diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index 17f6bb271..baa573a77 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -30,7 +30,7 @@ typedef struct { uint16_t rainbow_step; uint8_t rainbow_saturation; uint8_t rainbow_wide; - + } RGBBacklightSettingsPrevious; void rgb_backlight_settings_load(RGBBacklightSettings* settings) {