From 05423d5cb357876b5b89dc519bc5d28c2e5da994 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Sun, 16 Mar 2025 22:42:22 +0700 Subject: [PATCH 1/8] Start rgb backlight settings refactoring and adding new options; --- .../services/rgb_backlight/rgb_backlight.c | 36 +-- .../rgb_backlight/rgb_backlight_settings.c | 22 +- .../rgb_backlight/rgb_backlight_settings.h | 14 +- .../notification_settings_app.c | 266 ++++++++++++------ 4 files changed, 226 insertions(+), 112 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index 03f8f9af0..9b25ded5b 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -42,7 +42,7 @@ static const RGBBacklightColor colors[] = { {"Pink", 255, 0, 127}, {"Red", 255, 0, 0}, {"White", 254, 210, 200}, - {"Custom", 0, 0, 0}, + {"Custom", 255, 255, 255}, }; uint8_t rgb_backlight_get_color_count(void) { @@ -82,7 +82,7 @@ void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue) { // use RECORD for acces to rgb service instance, use current_* colors and update backlight void rgb_backlight_update(float brightness) { RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); - if(app->settings->rgb_mod_installed) { + if(app->settings->rgb_backlight_mode > 0) { for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { uint8_t r = app->current_red * (brightness / 1.0f); uint8_t g = app->current_green * (brightness / 1.0f); @@ -104,9 +104,9 @@ void rainbow_timer_stop(RGBBacklightApp* app) { furi_timer_stop(app->rainbow_timer); } -// if rgb_mod_installed then apply rainbow colors to backlight and start/restart/stop rainbow_timer +// if rgb_backlight_installed then apply rainbow colors to backlight and start/restart/stop rainbow_timer void rainbow_timer_starter(RGBBacklightApp* app) { - if((app->settings->rainbow_mode > 0) && (app->settings->rgb_mod_installed)) { + if((app->settings->rainbow_mode > 0) && (app->settings->rgb_backlight_installed)) { rainbow_timer_start(app); } else { if(furi_timer_is_running(app->rainbow_timer)) { @@ -200,22 +200,22 @@ int32_t rgb_backlight_srv(void* p) { furi_record_create(RECORD_RGB_BACKLIGHT, app); // if rgb mod installed - start rainbow or set static color from settings (default index = 0) - if(app->settings->rgb_mod_installed) { - if(app->settings->rainbow_mode > 0) { - rainbow_timer_starter(app); - } else { - rgb_backlight_set_static_color(app->settings->static_color_index); - rgb_backlight_update(app->settings->brightness); - } - // if rgb mod not installed - set default static orange color (index=0) + // + // TODO запуск сохраненного режима + if(app->settings->rgb_backlight_mode > 0) { + // if(app->settings->rainbow_mode > 0) { + // rainbow_timer_starter(app); + // } else { + // rgb_backlight_set_static_color(app->settings->static_color_index); + // rgb_backlight_update(app->settings->brightness); + // } + // if rgb mode = 0 (rgb_backlight not installed) then set default static orange color (index=0) and light on default color } else { - //rgb_backlight_set_static_color(0); - //rgb_backlight_update(app->settings->brightness); rgb_backlight_set_static_color(0); for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - uint8_t r = app->current_red * (1.0f / 1.0f); - uint8_t g = app->current_green * (1.0f / 1.0f); - uint8_t b = app->current_blue * (1.0f / 1.0f); + uint8_t r = app->current_red * 1.0f; + uint8_t g = app->current_green * 1.0f; + uint8_t b = app->current_blue * 1.0f; SK6805_set_led_color(i, r, g, b); } SK6805_update(); @@ -224,7 +224,7 @@ int32_t rgb_backlight_srv(void* p) { while(1) { // place for message queue and other future options furi_delay_ms(5000); - if(app->settings->rgb_mod_installed) { + if(app->settings->rgb_backlight_mode > 0) { FURI_LOG_D(TAG, "Mod is enabled - serivce is running"); } else { FURI_LOG_D(TAG, "Mod is DISABLED - serivce is running"); diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index 7e69eb0dc..7c73ddf19 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -10,18 +10,27 @@ #define RGB_BACKLIGHT_SETTINGS_MAGIC (0x30) #define RGB_BACKLIGHT_SETTINGS_VER_PREV (0) // Previous version number -#define RGB_BACKLIGHT_SETTINGS_VER (1) // New version number +#define RGB_BACKLIGHT_SETTINGS_VER (1) // Current version number //pervious settings must be copyed from previous rgb_backlight_settings.h file typedef struct { + //Common settings uint8_t version; - bool rgb_mod_installed; + uint8_t rgb_backlight_mode; + float brightness; + //static and custom colors mode settings uint8_t static_color_index; - uint8_t custom_r; - uint8_t custom_g; - uint8_t custom_b; + uint8_t custom_red; + uint8_t custom_green; + uint8_t custom_blue; + // static gradient mode settings + uint8_t static_vd1_index; + uint8_t static_vd2_index; + uint8_t static_vd3_index; + + // rainbow mode setings uint32_t rainbow_mode; uint32_t rainbow_speed_ms; uint16_t rainbow_step; @@ -79,6 +88,9 @@ void rgb_backlight_settings_load(RGBBacklightSettings* settings) { settings->brightness = 1.0f; settings->rainbow_speed_ms = 100; settings->rainbow_step = 1; + settings->custom_red=255; + settings->custom_green = 255; + settings->custom_blue=255; rgb_backlight_settings_save(settings); } } diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.h b/applications/services/rgb_backlight/rgb_backlight_settings.h index 48b0c43b9..478048039 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.h +++ b/applications/services/rgb_backlight/rgb_backlight_settings.h @@ -4,15 +4,23 @@ #include typedef struct { + //Common settings uint8_t version; - bool rgb_mod_installed; + uint8_t rgb_backlight_mode; + float brightness; + //static and custom colors mode settings uint8_t static_color_index; uint8_t custom_red; uint8_t custom_green; uint8_t custom_blue; - float brightness; - + + // static gradient mode settings + uint8_t static_vd1_index; + uint8_t static_vd2_index; + uint8_t static_vd3_index; + + // rainbow mode setings uint32_t rainbow_mode; uint32_t rainbow_speed_ms; uint16_t rainbow_step; diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index ff90e96e7..cc316e6aa 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -110,30 +110,40 @@ const char* const vibro_text[VIBRO_COUNT] = { const bool vibro_value[VIBRO_COUNT] = {false, true}; // --- RGB BACKLIGHT --- -#define RGB_MOD_INSTALLED_COUNT 2 -const char* const rgb_mod_installed_text[RGB_MOD_INSTALLED_COUNT] = { - "OFF", - "ON", -}; -const bool rgb_mod_installed_value[RGB_MOD_INSTALLED_COUNT] = {false, true}; -#define RGB_MOD_RAINBOW_MODE_COUNT 2 -const char* const rgb_mod_rainbow_mode_text[RGB_MOD_RAINBOW_MODE_COUNT] = { - "OFF", +// #define RGB_BACKLIGHT_INSTALLED_COUNT 2 +// const char* const rgb_backlight_installed_text[RGB_BACKLIGHT_INSTALLED_COUNT] = { +// "OFF", +// "ON", +// }; +// const bool rgb_backlight_installed_value[RGB_BACKLIGHT_INSTALLED_COUNT] = {false, true}; + +#define RGB_BACKLIGHT_MODE_COUNT 4 +const char* const rgb_backlight_mode_text[RGB_BACKLIGHT_MODE_COUNT] = { + "OFF" + "OneColor", + 'Gradient', "Rainbow", }; -const uint32_t rgb_mod_rainbow_mode_value[RGB_MOD_RAINBOW_MODE_COUNT] = {0, 1}; +const uint32_t rgb_backlight_mode_value[RGB_BACKLIGHT_MODE_COUNT] = {0, 1, 3, 4}; -#define RGB_MOD_RAINBOW_SPEED_COUNT 20 -const char* const rgb_mod_rainbow_speed_text[RGB_MOD_RAINBOW_SPEED_COUNT] = { +#define RGB_BACKLIGHT_RAINBOW_MODE_COUNT 2 +const char* const rgb_backlight_rainbow_mode_text[RGB_BACKLIGHT_RAINBOW_MODE_COUNT] = { + "Rainbow", + "Wave", +}; +const uint32_t rgb_backlight_rainbow_mode_value[RGB_BACKLIGHT_RAINBOW_MODE_COUNT] = {1, 2}; + +#define RGB_BACKLIGHT_RAINBOW_SPEED_COUNT 20 +const char* const rgb_backlight_rainbow_speed_text[RGB_BACKLIGHT_RAINBOW_SPEED_COUNT] = { "0.1s", "0.2s", "0.3s", "0.4s", "0.5s", "0.6s", "0.7", "0.8", "0.9", "1s", "1.1s", "1.2s", "1.3s", "1.4s", "1.5s", "1.6s", "1.7s", "1.8s", "1.9s", "2s"}; -const uint32_t rgb_mod_rainbow_speed_value[RGB_MOD_RAINBOW_SPEED_COUNT] = { +const uint32_t rgb_backlight_rainbow_speed_value[RGB_BACKLIGHT_RAINBOW_SPEED_COUNT] = { 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000}; -#define RGB_MOD_RAINBOW_STEP_COUNT 10 -const char* const rgb_mod_rainbow_step_text[RGB_MOD_RAINBOW_SPEED_COUNT] = { +#define RGB_BACKLIGHT_RAINBOW_STEP_COUNT 10 +const char* const rgb_backlight_rainbow_step_text[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] = { "1", "2", "3", @@ -145,7 +155,7 @@ const char* const rgb_mod_rainbow_step_text[RGB_MOD_RAINBOW_SPEED_COUNT] = { "9", "10", }; -const uint32_t rgb_mod_rainbow_step_value[RGB_MOD_RAINBOW_STEP_COUNT] = +const uint32_t rgb_backlight_rainbow_step_value[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; typedef enum { @@ -228,33 +238,76 @@ static void vibro_changed(VariableItem* item) { //--- RGB BACKLIGHT --- -static void rgb_mod_installed_changed(VariableItem* item) { +// static void rgb_backlight_installed_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_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); +// // Lock/Unlock all rgb settings depent from rgb_backlight_installed switch +// int slide = 0; +// if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { +// slide = 1; +// } +// for(int i = slide; i < (slide + 7); 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!"); +// } else { +// variable_item_set_locked(t_item, false, "RGB\nOFF!"); +// } +// } + +//TODO по умолчанию все пункты ВЫКЛ, когда включаем РГБ установлен, то разблокируем только +// переключатель режима РГБ и в зависимости от его значения остальные пункты +// когда переключталь РГБ выключен, то выключаем все пункты меню. +// } + +static void rgb_backlight_mode_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_mod_installed_text[index]); - app->notification->rgb_srv->settings->rgb_mod_installed = rgb_mod_installed_value[index]; + variable_item_set_current_value_text(item, rgb_backlight_mode_text[index]); + app->notification->rgb_srv->settings->rgb_backlight_mode = rgb_backlight_mode_value[index]; rgb_backlight_settings_save(app->notification->rgb_srv->settings); - // Lock/Unlock rgb settings depent from rgb_mod_installed switch + + // Lock/Unlock rgb settings depent from selected mode int slide = 0; if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { slide = 1; } - for(int i = slide; i < (slide + 7); 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 MOD\nOFF!"); - } else { - variable_item_set_locked(t_item, false, "RGB MOD\nOFF!"); - } + + VariableItem* t_item = variable_item_list_get(app->variable_item_list_rgb, i); + + switch(index) { + // OneColor + case 0: + break; + // Gradient + case 1: + break; + // Rainbow + case 2: + break; + default: + break; } + + // for(int i = slide; i < (slide + 7); 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 MOD\nOFF!"); + // } else { + // variable_item_set_locked(t_item, false, "RGB MOD\nOFF!"); + // } + // } } -static void rgb_mod_rainbow_changed(VariableItem* item) { +static void rgb_backlight_rainbow_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_mod_rainbow_mode_text[index]); - app->notification->rgb_srv->settings->rainbow_mode = rgb_mod_rainbow_mode_value[index]; + 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); @@ -280,24 +333,25 @@ static void rgb_mod_rainbow_changed(VariableItem* item) { } } -static void rgb_mod_rainbow_speed_changed(VariableItem* item) { +static void rgb_backlight_rainbow_speed_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_mod_rainbow_speed_text[index]); - app->notification->rgb_srv->settings->rainbow_speed_ms = rgb_mod_rainbow_speed_value[index]; + variable_item_set_current_value_text(item, rgb_backlight_rainbow_speed_text[index]); + app->notification->rgb_srv->settings->rainbow_speed_ms = + 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); } -static void rgb_mod_rainbow_step_changed(VariableItem* item) { +static void rgb_backlight_rainbow_step_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_mod_rainbow_step_text[index]); - app->notification->rgb_srv->settings->rainbow_step = rgb_mod_rainbow_step_value[index]; + variable_item_set_current_value_text(item, rgb_backlight_rainbow_step_text[index]); + app->notification->rgb_srv->settings->rainbow_step = rgb_backlight_rainbow_step_value[index]; rgb_backlight_settings_save(app->notification->rgb_srv->settings); } @@ -320,9 +374,12 @@ static void color_set_custom_red(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - //Set custom red to settings and current color - app->notification->rgb_srv->settings->custom_red = index; + // Update all current colors with selected customs and save changed custom color to settings app->notification->rgb_srv->current_red = index; + app->notification->rgb_srv->current_green = app->notification->rgb_srv->settings->custom_green; + app->notification->rgb_srv->current_blue = app->notification->rgb_srv->settings->custom_blue; + + app->notification->rgb_srv->settings->custom_red = index; app->notification->rgb_srv->settings->static_color_index = 13; char valtext[4] = {}; @@ -340,9 +397,12 @@ static void color_set_custom_green(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - //Set custom green to settings and current color - app->notification->rgb_srv->settings->custom_green = index; + // Update all current colors with selected customs and save changed custom color to settings + app->notification->rgb_srv->current_red = app->notification->rgb_srv->settings->custom_red; app->notification->rgb_srv->current_green = index; + app->notification->rgb_srv->current_blue = app->notification->rgb_srv->settings->custom_blue; + + app->notification->rgb_srv->settings->custom_green = index; app->notification->rgb_srv->settings->static_color_index = 13; char valtext[4] = {}; @@ -360,9 +420,12 @@ static void color_set_custom_blue(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - //Set custom blue to settings and current color - app->notification->rgb_srv->settings->custom_blue = index; + // Update all current colors with selected customs and save changed custom color to settings + app->notification->rgb_srv->current_red = app->notification->rgb_srv->settings->custom_red; + app->notification->rgb_srv->current_green = app->notification->rgb_srv->settings->custom_green; app->notification->rgb_srv->current_blue = index; + + app->notification->rgb_srv->settings->custom_blue = index; app->notification->rgb_srv->settings->static_color_index = 13; char valtext[4] = {}; @@ -377,12 +440,12 @@ static void color_set_custom_blue(VariableItem* item) { rgb_backlight_settings_save(app->notification->rgb_srv->settings); } -// open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_mod_install is true) +// open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_backlight_installed is true) void variable_item_list_enter_callback(void* context, uint32_t index) { UNUSED(context); NotificationAppSettings* app = context; - if(((app->notification->rgb_srv->settings->rgb_mod_installed) || + if(((app->notification->rgb_srv->settings->rgb_backlight_installed) || (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) && (index == 0)) { view_dispatcher_switch_to_view(app->view_dispatcher, RGBViewId); @@ -420,10 +483,10 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_list_set_enter_callback( app->variable_item_list, variable_item_list_enter_callback, app); - //Show RGB settings only when debug_mode or rgb_mod_installed is active - if((app->notification->rgb_srv->settings->rgb_mod_installed) || + //Show RGB settings only when debug_mode or rgb_backlight_installed is active + if((app->notification->rgb_srv->settings->rgb_backlight_installed) || (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) { - item = variable_item_list_add(app->variable_item_list, "RGB mod settings", 0, NULL, app); + item = variable_item_list_add(app->variable_item_list, "RGB settings", 0, NULL, app); } //--- RGB BACKLIGHT END --- @@ -490,22 +553,39 @@ static NotificationAppSettings* alloc_settings(void) { // set callback for OK pressed in rgb_settings_menu view_set_previous_callback(view_rgb, notification_app_rgb_settings_exit); - // Show RGB_MOD_Installed_Swith only in Debug mode - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { - item = variable_item_list_add( - app->variable_item_list_rgb, - "RGB MOD Installed", - RGB_MOD_INSTALLED_COUNT, - rgb_mod_installed_changed, - app); - value_index = value_index_bool( - app->notification->rgb_srv->settings->rgb_mod_installed, - rgb_mod_installed_value, - RGB_MOD_INSTALLED_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_mod_installed_text[value_index]); - } + // // Show rgb_backlight_Installed_Swith only in Debug mode + // if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { + // item = variable_item_list_add( + // app->variable_item_list_rgb, + // "RGB mod installed", + // RGB_BACKLIGHT_INSTALLED_COUNT, + // rgb_backlight_installed_changed, + // app); + // value_index = value_index_bool( + // app->notification->rgb_srv->settings->rgb_backlight_installed, + // rgb_backlight_installed_value, + // RGB_BACKLIGHT_INSTALLED_COUNT); + // variable_item_set_current_value_index(item, value_index); + // variable_item_set_current_value_text(item, rgb_backlight_installed_text[value_index]); + // } + // Show rgb_backlight_mode_swith only in Debug mode or when rgb_mode is not OFF. + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) || + (app->notification->rgb_srv->settings->rgb_backlight_mode > 0)) { + item = variable_item_list_add( + app->variable_item_list_rgb, + "RGB MODE", + RGB_BACKLIGHT_MODE_COUNT, + rgb_backlight_mode_changed, + app); + value_index = value_index_uint32( + app->notification->rgb_srv->settings->rgb_backlight_mode, + rgb_backlight_mode_value, + RGB_BACKLIGHT_MODE_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_mode_text[value_index]); + } + // Static Colors settings item = variable_item_list_add( app->variable_item_list_rgb, @@ -519,7 +599,9 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_locked( item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rgb_mod_installed == 0), "RGB MOD \nOFF!"); + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); temp_item = item; @@ -534,7 +616,9 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_locked( item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rgb_mod_installed == 0), "RGB MOD \nOFF!"); + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); item = variable_item_list_add( app->variable_item_list_rgb, "Custom Green", 255, color_set_custom_green, app); @@ -545,7 +629,9 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_locked( item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rgb_mod_installed == 0), "RGB MOD \nOFF!"); + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); item = variable_item_list_add( app->variable_item_list_rgb, "Custom Blue", 255, color_set_custom_blue, app); @@ -556,53 +642,61 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_locked( item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rgb_mod_installed == 0), "RGB MOD \nOFF!"); + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); // Rainbow (based on Willy-JL idea) settings item = variable_item_list_add( app->variable_item_list_rgb, "Rainbow mode", - RGB_MOD_RAINBOW_MODE_COUNT, - rgb_mod_rainbow_changed, + RGB_BACKLIGHT_RAINBOW_MODE_COUNT, + rgb_backlight_rainbow_changed, app); value_index = value_index_uint32( app->notification->rgb_srv->settings->rainbow_mode, - rgb_mod_rainbow_mode_value, - RGB_MOD_RAINBOW_MODE_COUNT); + rgb_backlight_rainbow_mode_value, + RGB_BACKLIGHT_RAINBOW_MODE_COUNT); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_mod_rainbow_mode_text[value_index]); + variable_item_set_current_value_text(item, rgb_backlight_rainbow_mode_text[value_index]); variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rgb_mod_installed == 0), "RGB MOD \nOFF!"); + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); item = variable_item_list_add( app->variable_item_list_rgb, "Rainbow speed", - RGB_MOD_RAINBOW_SPEED_COUNT, - rgb_mod_rainbow_speed_changed, + RGB_BACKLIGHT_RAINBOW_SPEED_COUNT, + rgb_backlight_rainbow_speed_changed, app); value_index = value_index_uint32( app->notification->rgb_srv->settings->rainbow_speed_ms, - rgb_mod_rainbow_speed_value, - RGB_MOD_RAINBOW_SPEED_COUNT); + rgb_backlight_rainbow_speed_value, + RGB_BACKLIGHT_RAINBOW_SPEED_COUNT); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_mod_rainbow_speed_text[value_index]); + variable_item_set_current_value_text(item, rgb_backlight_rainbow_speed_text[value_index]); variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rgb_mod_installed == 0), "RGB MOD \nOFF!"); + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); item = variable_item_list_add( app->variable_item_list_rgb, "Rainbow step", - RGB_MOD_RAINBOW_STEP_COUNT, - rgb_mod_rainbow_step_changed, + RGB_BACKLIGHT_RAINBOW_STEP_COUNT, + rgb_backlight_rainbow_step_changed, app); value_index = value_index_uint32( app->notification->rgb_srv->settings->rainbow_step, - rgb_mod_rainbow_step_value, - RGB_MOD_RAINBOW_SPEED_COUNT); + rgb_backlight_rainbow_step_value, + RGB_BACKLIGHT_RAINBOW_SPEED_COUNT); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_mod_rainbow_step_text[value_index]); + variable_item_set_current_value_text(item, rgb_backlight_rainbow_step_text[value_index]); variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rgb_mod_installed == 0), "RGB MOD \nOFF!"); + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); //--- RGB BACKLIGHT END --- @@ -632,8 +726,8 @@ int32_t notification_settings_app(void* p) { view_dispatcher_run(app->view_dispatcher); notification_message_save_settings(app->notification); - // Automaticaly switch_off debug_mode when user exit from settings with enabled rgb_mod_installed - // if(app->notification->settings.rgb_mod_installed) { + // Automaticaly switch_off debug_mode when user exit from settings with enabled rgb_backlight_installed + // if(app->notification->settings.rgb_backlight_installed) { // furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug); // } From c66b332a7dd369b90e42cb66aaee7f0857749830 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Mon, 17 Mar 2025 23:56:39 +0700 Subject: [PATCH 2/8] refactor rgb_backlight --- .../services/rgb_backlight/rgb_backlight.c | 30 +- .../rgb_backlight/rgb_backlight_settings.c | 2 +- .../rgb_backlight/rgb_backlight_settings.h | 8 +- .../notification_settings_app.c | 287 ++++-------------- 4 files changed, 87 insertions(+), 240 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index 9b25ded5b..f3d3cfb35 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -42,7 +42,7 @@ static const RGBBacklightColor colors[] = { {"Pink", 255, 0, 127}, {"Red", 255, 0, 0}, {"White", 254, 210, 200}, - {"Custom", 255, 255, 255}, + {"White1", 255, 255, 255}, }; uint8_t rgb_backlight_get_color_count(void) { @@ -54,19 +54,27 @@ const char* rgb_backlight_get_color_text(uint8_t index) { } // use RECORD for acces to rgb service instance and update current colors by static -void rgb_backlight_set_static_color(uint8_t index) { +void rgb_backlight_set_static_color(uint8_t index, uint8_t vd) { RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); - //if user select "custom" value then set current colors by custom values - if(index == 13) { - app->current_red = app->settings->custom_red; - app->current_green = app->settings->custom_green; - app->current_blue = app->settings->custom_blue; - } else { - app->current_red = colors[index].red; - app->current_green = colors[index].green; - app->current_blue = colors[index].blue; + if(vd < SK6805_get_led_count()) { + uint8_t r = colors[index].red; + uint8_t g = colors[index].green; + uint8_t b = colors[index].blue; + SK6805_set_led_color(vd, r, g, b); + SK6805_update(); } + + //if user select "custom" value then set current colors by custom values + if(index == 13) { + app->current_red = app->settings->custom_red; + app->current_green = app->settings->custom_green; + app->current_blue = app->settings->custom_blue; + } else { + app->current_red = colors[index].red; + app->current_green = colors[index].green; + app->current_blue = colors[index].blue; + } furi_record_close(RECORD_RGB_BACKLIGHT); } diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index 7c73ddf19..e2a2e5df7 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -16,7 +16,7 @@ typedef struct { //Common settings uint8_t version; - uint8_t rgb_backlight_mode; + bool rgb_backlight_installed; float brightness; //static and custom colors mode settings diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.h b/applications/services/rgb_backlight/rgb_backlight_settings.h index 478048039..694161c2b 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.h +++ b/applications/services/rgb_backlight/rgb_backlight_settings.h @@ -6,14 +6,8 @@ typedef struct { //Common settings uint8_t version; - uint8_t rgb_backlight_mode; + uint8_t rgb_backlight_installed; float brightness; - - //static and custom colors mode settings - uint8_t static_color_index; - uint8_t custom_red; - uint8_t custom_green; - uint8_t custom_blue; // static gradient mode settings uint8_t static_vd1_index; diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index cc316e6aa..1a738b492 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -111,28 +111,20 @@ const bool vibro_value[VIBRO_COUNT] = {false, true}; // --- RGB BACKLIGHT --- -// #define RGB_BACKLIGHT_INSTALLED_COUNT 2 -// const char* const rgb_backlight_installed_text[RGB_BACKLIGHT_INSTALLED_COUNT] = { -// "OFF", -// "ON", -// }; -// const bool rgb_backlight_installed_value[RGB_BACKLIGHT_INSTALLED_COUNT] = {false, true}; - -#define RGB_BACKLIGHT_MODE_COUNT 4 -const char* const rgb_backlight_mode_text[RGB_BACKLIGHT_MODE_COUNT] = { - "OFF" - "OneColor", - 'Gradient', - "Rainbow", +#define RGB_BACKLIGHT_INSTALLED_COUNT 2 +const char* const rgb_backlight_installed_text[RGB_BACKLIGHT_INSTALLED_COUNT] = { + "OFF", + "ON", }; -const uint32_t rgb_backlight_mode_value[RGB_BACKLIGHT_MODE_COUNT] = {0, 1, 3, 4}; +const bool rgb_backlight_installed_value[RGB_BACKLIGHT_INSTALLED_COUNT] = {false, true}; -#define RGB_BACKLIGHT_RAINBOW_MODE_COUNT 2 +#define RGB_BACKLIGHT_RAINBOW_MODE_COUNT 3 const char* const rgb_backlight_rainbow_mode_text[RGB_BACKLIGHT_RAINBOW_MODE_COUNT] = { + "OFF", "Rainbow", "Wave", }; -const uint32_t rgb_backlight_rainbow_mode_value[RGB_BACKLIGHT_RAINBOW_MODE_COUNT] = {1, 2}; +const uint32_t rgb_backlight_rainbow_mode_value[RGB_BACKLIGHT_RAINBOW_MODE_COUNT] = {0, 1, 2}; #define RGB_BACKLIGHT_RAINBOW_SPEED_COUNT 20 const char* const rgb_backlight_rainbow_speed_text[RGB_BACKLIGHT_RAINBOW_SPEED_COUNT] = { @@ -238,68 +230,25 @@ static void vibro_changed(VariableItem* item) { //--- RGB BACKLIGHT --- -// static void rgb_backlight_installed_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_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); -// // Lock/Unlock all rgb settings depent from rgb_backlight_installed switch -// int slide = 0; -// if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { -// slide = 1; -// } -// for(int i = slide; i < (slide + 7); 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!"); -// } else { -// variable_item_set_locked(t_item, false, "RGB\nOFF!"); -// } -// } - -//TODO по умолчанию все пункты ВЫКЛ, когда включаем РГБ установлен, то разблокируем только -// переключатель режима РГБ и в зависимости от его значения остальные пункты -// когда переключталь РГБ выключен, то выключаем все пункты меню. -// } - -static void rgb_backlight_mode_changed(VariableItem* item) { +static void rgb_backlight_installed_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_mode_text[index]); - app->notification->rgb_srv->settings->rgb_backlight_mode = rgb_backlight_mode_value[index]; + 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); - - // Lock/Unlock rgb settings depent from selected mode + // Lock/Unlock all rgb settings depent from rgb_backlight_installed switch int slide = 0; if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { slide = 1; } - - VariableItem* t_item = variable_item_list_get(app->variable_item_list_rgb, i); - - switch(index) { - // OneColor - case 0: - break; - // Gradient - case 1: - break; - // Rainbow - case 2: - break; - default: - break; + for(int i = slide; i < (slide + 7); 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!"); + } else { + variable_item_set_locked(t_item, false, "RGB\nOFF!"); + } } - - // for(int i = slide; i < (slide + 7); 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 MOD\nOFF!"); - // } else { - // variable_item_set_locked(t_item, false, "RGB MOD\nOFF!"); - // } - // } } static void rgb_backlight_rainbow_changed(VariableItem* item) { @@ -312,20 +261,6 @@ static void rgb_backlight_rainbow_changed(VariableItem* item) { rainbow_timer_starter(app->notification->rgb_srv); rgb_backlight_settings_save(app->notification->rgb_srv->settings); - // Lock/Unlock color settings if rainbow mode Enabled/Disabled (0-3 index if debug off and 1-4 index if debug on) - int slide = 0; - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { - slide = 1; - } - for(int i = slide; i < (slide + 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, "Rainbow mode\nenabled!"); - } else { - variable_item_set_locked(t_item, false, "Rainbow mode\nenabled!"); - } - } - // restore saved rgb backlight settings if we switch_off rainbow mode if(app->notification->rgb_srv->settings->rainbow_mode == 0) { rgb_backlight_set_static_color(app->notification->rgb_srv->settings->static_color_index); @@ -356,9 +291,8 @@ static void rgb_backlight_rainbow_step_changed(VariableItem* item) { rgb_backlight_settings_save(app->notification->rgb_srv->settings); } -// Set rgb_backlight colors static and custom -static void color_changed(VariableItem* item) { +static void vd1_color_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -370,72 +304,26 @@ static void color_changed(VariableItem* item) { rgb_backlight_settings_save(app->notification->rgb_srv->settings); } -static void color_set_custom_red(VariableItem* item) { +static void vd2_color_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - // Update all current colors with selected customs and save changed custom color to settings - app->notification->rgb_srv->current_red = index; - app->notification->rgb_srv->current_green = app->notification->rgb_srv->settings->custom_green; - app->notification->rgb_srv->current_blue = app->notification->rgb_srv->settings->custom_blue; - - app->notification->rgb_srv->settings->custom_red = index; - app->notification->rgb_srv->settings->static_color_index = 13; - - char valtext[4] = {}; - snprintf(valtext, sizeof(valtext), "%d", index); - variable_item_set_current_value_text(item, valtext); - - // Set to custom color explicitly - variable_item_set_current_value_index(temp_item, 13); - variable_item_set_current_value_text(temp_item, rgb_backlight_get_color_text(13)); + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); + app->notification->rgb_srv->settings->static_color_index = index; + rgb_backlight_set_static_color(index); rgb_backlight_update(app->notification->rgb_srv->settings->brightness); rgb_backlight_settings_save(app->notification->rgb_srv->settings); } -static void color_set_custom_green(VariableItem* item) { + +static void vd3_color_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - // Update all current colors with selected customs and save changed custom color to settings - app->notification->rgb_srv->current_red = app->notification->rgb_srv->settings->custom_red; - app->notification->rgb_srv->current_green = index; - app->notification->rgb_srv->current_blue = app->notification->rgb_srv->settings->custom_blue; - - app->notification->rgb_srv->settings->custom_green = index; - app->notification->rgb_srv->settings->static_color_index = 13; - - char valtext[4] = {}; - snprintf(valtext, sizeof(valtext), "%d", index); - variable_item_set_current_value_text(item, valtext); - - // Set to custom color explicitly - variable_item_set_current_value_index(temp_item, 13); - variable_item_set_current_value_text(temp_item, rgb_backlight_get_color_text(13)); - - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); - rgb_backlight_settings_save(app->notification->rgb_srv->settings); -} -static void color_set_custom_blue(VariableItem* item) { - NotificationAppSettings* app = variable_item_get_context(item); - uint8_t index = variable_item_get_current_value_index(item); - - // Update all current colors with selected customs and save changed custom color to settings - app->notification->rgb_srv->current_red = app->notification->rgb_srv->settings->custom_red; - app->notification->rgb_srv->current_green = app->notification->rgb_srv->settings->custom_green; - app->notification->rgb_srv->current_blue = index; - - app->notification->rgb_srv->settings->custom_blue = index; - app->notification->rgb_srv->settings->static_color_index = 13; - - char valtext[4] = {}; - snprintf(valtext, sizeof(valtext), "%d", index); - variable_item_set_current_value_text(item, valtext); - - // Set to custom color explicitly - variable_item_set_current_value_index(temp_item, 13); - variable_item_set_current_value_text(temp_item, rgb_backlight_get_color_text(13)); + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); + app->notification->rgb_srv->settings->static_color_index = index; + rgb_backlight_set_static_color(index); rgb_backlight_update(app->notification->rgb_srv->settings->brightness); rgb_backlight_settings_save(app->notification->rgb_srv->settings); } @@ -547,106 +435,63 @@ static NotificationAppSettings* alloc_settings(void) { } //--- RGB BACKLIGHT --- + app->variable_item_list_rgb = variable_item_list_alloc(); View* view_rgb = variable_item_list_get_view(app->variable_item_list_rgb); - // set callback for OK pressed in rgb_settings_menu + // set callback for exit from rgb_settings_menu view_set_previous_callback(view_rgb, notification_app_rgb_settings_exit); // // Show rgb_backlight_Installed_Swith only in Debug mode - // if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { - // item = variable_item_list_add( - // app->variable_item_list_rgb, - // "RGB mod installed", - // RGB_BACKLIGHT_INSTALLED_COUNT, - // rgb_backlight_installed_changed, - // app); - // value_index = value_index_bool( - // app->notification->rgb_srv->settings->rgb_backlight_installed, - // rgb_backlight_installed_value, - // RGB_BACKLIGHT_INSTALLED_COUNT); - // variable_item_set_current_value_index(item, value_index); - // variable_item_set_current_value_text(item, rgb_backlight_installed_text[value_index]); - // } - - // Show rgb_backlight_mode_swith only in Debug mode or when rgb_mode is not OFF. - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) || - (app->notification->rgb_srv->settings->rgb_backlight_mode > 0)) { - item = variable_item_list_add( - app->variable_item_list_rgb, - "RGB MODE", - RGB_BACKLIGHT_MODE_COUNT, - rgb_backlight_mode_changed, - app); - value_index = value_index_uint32( - app->notification->rgb_srv->settings->rgb_backlight_mode, - rgb_backlight_mode_value, - RGB_BACKLIGHT_MODE_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_mode_text[value_index]); + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { + item = variable_item_list_add( + app->variable_item_list_rgb, + "RGB backlight installed", + RGB_BACKLIGHT_INSTALLED_COUNT, + rgb_backlight_installed_changed, + app); + value_index = value_index_bool( + app->notification->rgb_srv->settings->rgb_backlight_installed, + rgb_backlight_installed_value, + RGB_BACKLIGHT_INSTALLED_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_installed_text[value_index]); } - // Static Colors settings + // vd1 color item = variable_item_list_add( app->variable_item_list_rgb, - "LCD Color", + "VD1 Color", rgb_backlight_get_color_count(), - color_changed, + vd1_color_changed, app); value_index = app->notification->rgb_srv->settings->static_color_index; variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); - variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - temp_item = item; - - // Custom Color - REFACTOR THIS + // vd2 color item = variable_item_list_add( - app->variable_item_list_rgb, "Custom Red", 255, color_set_custom_red, app); - value_index = app->notification->rgb_srv->settings->custom_red; + app->variable_item_list_rgb, + "VD2 Color", + rgb_backlight_get_color_count(), + vd2_color_changed, + app); + value_index = app->notification->rgb_srv->settings->static_color_index; variable_item_set_current_value_index(item, value_index); - char valtext[4] = {}; - snprintf(valtext, sizeof(valtext), "%d", value_index); - variable_item_set_current_value_text(item, valtext); - variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + + // vd 3 color item = variable_item_list_add( - app->variable_item_list_rgb, "Custom Green", 255, color_set_custom_green, app); - value_index = app->notification->rgb_srv->settings->custom_green; + app->variable_item_list_rgb, + "VD3 Color", + rgb_backlight_get_color_count(), + vd3_color_changed, + app); + value_index = app->notification->rgb_srv->settings->static_color_index; variable_item_set_current_value_index(item, value_index); - snprintf(valtext, sizeof(valtext), "%d", value_index); - variable_item_set_current_value_text(item, valtext); - variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - item = variable_item_list_add( - app->variable_item_list_rgb, "Custom Blue", 255, color_set_custom_blue, app); - value_index = app->notification->rgb_srv->settings->custom_blue; - variable_item_set_current_value_index(item, value_index); - snprintf(valtext, sizeof(valtext), "%d", value_index); - variable_item_set_current_value_text(item, valtext); - variable_item_set_locked( - item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - // Rainbow (based on Willy-JL idea) settings + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + + // Rainbow mode item = variable_item_list_add( app->variable_item_list_rgb, "Rainbow mode", From a4d0c467f91e8e2bdbc3278ef6f8997bbe224a46 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 18 Mar 2025 18:41:50 +0700 Subject: [PATCH 3/8] End of static colors settings, next rainbow --- .../services/rgb_backlight/rgb_backlight.c | 173 +++++++----------- .../services/rgb_backlight/rgb_backlight.h | 18 +- .../rgb_backlight/rgb_backlight_settings.c | 21 +-- .../rgb_backlight/rgb_backlight_settings.h | 6 +- .../notification_settings_app.c | 149 +++++++++------ targets/f7/api_symbols.csv | 5 +- 6 files changed, 180 insertions(+), 192 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index f3d3cfb35..323cc5d48 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -28,6 +28,20 @@ #define TAG "RGB_BACKLIGHT_SRV" +typedef struct { + char* name; + uint8_t red; + uint8_t green; + uint8_t blue; +} RGBBacklightColor; + +//use one type RGBBacklightColor for current_leds_settings and for static colors definition +static RGBBacklightColor current_led [] = { + {"LED0",255,60,0}, + {"LED1",255,60,0}, + {"LED2",255,60,0}, +}; + static const RGBBacklightColor colors[] = { {"Orange", 255, 60, 0}, {"Yellow", 255, 144, 0}, @@ -42,7 +56,7 @@ static const RGBBacklightColor colors[] = { {"Pink", 255, 0, 127}, {"Red", 255, 0, 0}, {"White", 254, 210, 200}, - {"White1", 255, 255, 255}, + {"OFF", 0, 0, 0}, }; uint8_t rgb_backlight_get_color_count(void) { @@ -54,47 +68,43 @@ const char* rgb_backlight_get_color_text(uint8_t index) { } // use RECORD for acces to rgb service instance and update current colors by static -void rgb_backlight_set_static_color(uint8_t index, uint8_t vd) { - RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); +void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index) { + // RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); + // float brightness = app->settings->brightness; - if(vd < SK6805_get_led_count()) { + if(led < SK6805_get_led_count()) { uint8_t r = colors[index].red; uint8_t g = colors[index].green; uint8_t b = colors[index].blue; - SK6805_set_led_color(vd, r, g, b); - SK6805_update(); + + current_led[led].red = r; + current_led[led].green =g; + current_led[led].blue = b; + + SK6805_set_led_color(led, r, g, b); } - //if user select "custom" value then set current colors by custom values - if(index == 13) { - app->current_red = app->settings->custom_red; - app->current_green = app->settings->custom_green; - app->current_blue = app->settings->custom_blue; - } else { - app->current_red = colors[index].red; - app->current_green = colors[index].green; - app->current_blue = colors[index].blue; - } - furi_record_close(RECORD_RGB_BACKLIGHT); + // furi_record_close(RECORD_RGB_BACKLIGHT); } // use RECORD for acces to rgb service instance and update current colors by custom -void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue) { - RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); - app->current_red = red; - app->current_green = green; - app->current_blue = blue; - furi_record_close(RECORD_RGB_BACKLIGHT); -} +// void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue) { +// RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); +// app->current_red = red; +// app->current_green = green; +// app->current_blue = blue; +// furi_record_close(RECORD_RGB_BACKLIGHT); +// } // use RECORD for acces to rgb service instance, use current_* colors and update backlight void rgb_backlight_update(float brightness) { RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); - if(app->settings->rgb_backlight_mode > 0) { + + if(app->settings->rgb_backlight_installed) { for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - uint8_t r = app->current_red * (brightness / 1.0f); - uint8_t g = app->current_green * (brightness / 1.0f); - uint8_t b = app->current_blue * (brightness / 1.0f); + 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(); @@ -126,59 +136,14 @@ static void rainbow_timer_callback(void* context) { furi_assert(context); RGBBacklightApp* app = context; - // if rainbow_mode is rainbow do rainbow effect - if(app->settings->rainbow_mode == 1) { - switch(app->rainbow_stage) { - // from red to yellow (255,0,0) - (255,255,0) - case 1: - app->current_green += app->settings->rainbow_step; - if(app->current_green >= 255) { - app->current_green = 255; - app->rainbow_stage++; - } - break; - // yellow to green (255,255,0) - (0,255,0) - case 2: - app->current_red -= app->settings->rainbow_step; - if(app->current_red <= 0) { - app->current_red = 0; - app->rainbow_stage++; - } - break; - // from green to light blue (0,255,0) - (0,255,255) - case 3: - app->current_blue += app->settings->rainbow_step; - if(app->current_blue >= 255) { - app->current_blue = 255; - app->rainbow_stage++; - } - break; - //from light blue to blue (0,255,255) - (0,0,255) - case 4: - app->current_green -= app->settings->rainbow_step; - if(app->current_green <= 0) { - app->current_green = 0; - app->rainbow_stage++; - } - break; - //from blue to violet (0,0,255) - (255,0,255) - case 5: - app->current_red += app->settings->rainbow_step; - if(app->current_red >= 255) { - app->current_red = 255; - app->rainbow_stage++; - } - break; - //from violet to red (255,0,255) - (255,0,0) - case 6: - app->current_blue -= app->settings->rainbow_step; - if(app->current_blue <= 0) { - app->current_blue = 0; - app->rainbow_stage = 1; - } - break; - default: - break; + if (app->settings->rgb_backlight_installed) { + switch(app->settings->rainbow_mode) { + case 1: + break; + case 2: + break; + default: + break; } rgb_backlight_update(app->settings->brightness); } @@ -186,6 +151,7 @@ static void rainbow_timer_callback(void* context) { // if rainbow_mode is ..... do another effect // if(app->settings.rainbow_mode == ...) { // } + } int32_t rgb_backlight_srv(void* p) { @@ -194,7 +160,7 @@ int32_t rgb_backlight_srv(void* p) { // Define object app (full app with settings and running variables), // allocate memory and create RECORD for access to app structure from outside RGBBacklightApp* app = malloc(sizeof(RGBBacklightApp)); - + //define rainbow_timer and they callback app->rainbow_timer = furi_timer_alloc(rainbow_timer_callback, FuriTimerTypePeriodic, app); @@ -202,40 +168,33 @@ int32_t rgb_backlight_srv(void* p) { app->settings = malloc(sizeof(RGBBacklightSettings)); rgb_backlight_settings_load(app->settings); - // Init app variables - app->rainbow_stage = 1; - furi_record_create(RECORD_RGB_BACKLIGHT, app); - // if rgb mod installed - start rainbow or set static color from settings (default index = 0) - // - // TODO запуск сохраненного режима - if(app->settings->rgb_backlight_mode > 0) { - // if(app->settings->rainbow_mode > 0) { - // rainbow_timer_starter(app); - // } else { - // rgb_backlight_set_static_color(app->settings->static_color_index); - // rgb_backlight_update(app->settings->brightness); - // } - // if rgb mode = 0 (rgb_backlight not installed) then set default static orange color (index=0) and light on default color - } else { - rgb_backlight_set_static_color(0); - for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - uint8_t r = app->current_red * 1.0f; - uint8_t g = app->current_green * 1.0f; - uint8_t b = app->current_blue * 1.0f; - SK6805_set_led_color(i, r, g, b); + //if rgb_backlight_installed then start rainbow or set leds colors from saved settings (default index = 0) + if(app->settings->rgb_backlight_installed) { + if(app->settings->rainbow_mode > 0) { + // rainbow_timer_starter(app); + } else { + 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); } + // if rgb_backlight not installed then set default static orange color(index=0) to all leds (0-2) and force light on + } else { + 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(); } while(1) { // place for message queue and other future options - furi_delay_ms(5000); - if(app->settings->rgb_backlight_mode > 0) { - FURI_LOG_D(TAG, "Mod is enabled - serivce is running"); + furi_delay_ms (5000); + if(app->settings->rgb_backlight_installed) { + FURI_LOG_D(TAG, "RGB backlight enabled - serivce is running"); } else { - FURI_LOG_D(TAG, "Mod is DISABLED - serivce is running"); + FURI_LOG_D(TAG, "RGB backlight DISABLED - serivce is running"); } } return 0; diff --git a/applications/services/rgb_backlight/rgb_backlight.h b/applications/services/rgb_backlight/rgb_backlight.h index fd683bf16..0661886c5 100644 --- a/applications/services/rgb_backlight/rgb_backlight.h +++ b/applications/services/rgb_backlight/rgb_backlight.h @@ -26,20 +26,12 @@ extern "C" { #endif -typedef struct { - char* name; - uint8_t red; - uint8_t green; - uint8_t blue; -} RGBBacklightColor; - typedef struct { FuriTimer* rainbow_timer; - int16_t current_red; - int16_t current_green; - int16_t current_blue; - uint8_t rainbow_stage; + // int16_t current_red; + // int16_t current_green; + // int16_t current_blue; RGBBacklightSettings* settings; @@ -48,8 +40,8 @@ typedef struct { #define RECORD_RGB_BACKLIGHT "rgb_backlight" void rgb_backlight_update(float brightness); -void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue); -void rgb_backlight_set_static_color(uint8_t index); +// void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue); +void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index); void rainbow_timer_stop(RGBBacklightApp* app); void rainbow_timer_start(RGBBacklightApp* app); void rainbow_timer_starter(RGBBacklightApp* app); diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index e2a2e5df7..4ca7140fd 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -16,20 +16,14 @@ typedef struct { //Common settings uint8_t version; - bool rgb_backlight_installed; + uint8_t rgb_backlight_installed; float brightness; - - //static and custom colors mode settings - uint8_t static_color_index; - uint8_t custom_red; - uint8_t custom_green; - uint8_t custom_blue; - + // static gradient mode settings - uint8_t static_vd1_index; - uint8_t static_vd2_index; - uint8_t static_vd3_index; - + uint8_t led_2_color_index; + uint8_t led_1_color_index; + uint8_t led_0_color_index; + // rainbow mode setings uint32_t rainbow_mode; uint32_t rainbow_speed_ms; @@ -88,9 +82,6 @@ void rgb_backlight_settings_load(RGBBacklightSettings* settings) { settings->brightness = 1.0f; settings->rainbow_speed_ms = 100; settings->rainbow_step = 1; - settings->custom_red=255; - settings->custom_green = 255; - settings->custom_blue=255; rgb_backlight_settings_save(settings); } } diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.h b/applications/services/rgb_backlight/rgb_backlight_settings.h index 694161c2b..fe504879f 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.h +++ b/applications/services/rgb_backlight/rgb_backlight_settings.h @@ -10,9 +10,9 @@ typedef struct { float brightness; // static gradient mode settings - uint8_t static_vd1_index; - uint8_t static_vd2_index; - uint8_t static_vd3_index; + uint8_t led_2_color_index; + uint8_t led_1_color_index; + uint8_t led_0_color_index; // rainbow mode setings uint32_t rainbow_mode; diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 1a738b492..75f462ce4 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -16,7 +16,7 @@ typedef struct { VariableItemList* variable_item_list_rgb; } NotificationAppSettings; -static VariableItem* temp_item; +//static VariableItem* temp_item; static const NotificationSequence sequence_note_c = { &message_note_c5, @@ -236,12 +236,33 @@ 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); + + // In case of user playing with rgb_backlight_installed swith: + // if user swith_off rgb_backlight_installed then force set default orange color + 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(); + // if user swith_on rgb_backlight_installed then start rainbow if its ON or set saved static colors + } else { + + if (app->notification->rgb_srv->settings->rainbow_mode >0) { + rainbow_timer_starter (app->notification->rgb_srv); + } else { + rgb_backlight_set_led_static_color (2,app->notification->rgb_srv->settings->led_2_color_index); + rgb_backlight_set_led_static_color (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); + } + } + // Lock/Unlock all rgb settings depent from rgb_backlight_installed switch int slide = 0; if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { slide = 1; } - for(int i = slide; i < (slide + 7); i++) { + for(int i = slide; i < (slide + 6); 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!"); @@ -251,6 +272,54 @@ static void rgb_backlight_installed_changed(VariableItem* item) { } } +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); + + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); + app->notification->rgb_srv->settings->led_2_color_index = index; + + rgb_backlight_set_led_static_color(2,index); + rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + + // dont update display color if rainbow working + if (!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) { + rgb_backlight_settings_save(app->notification->rgb_srv->settings); + } +} + +static void led_1_color_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_get_color_text(index)); + app->notification->rgb_srv->settings->led_1_color_index = index; + + rgb_backlight_set_led_static_color(1,index); + rgb_backlight_settings_save(app->notification->rgb_srv->settings); + + // dont update display color if rainbow working + if (!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) { + rgb_backlight_settings_save(app->notification->rgb_srv->settings); + } +} + +static void led_0_color_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_get_color_text(index)); + app->notification->rgb_srv->settings->led_0_color_index = index; + + rgb_backlight_set_led_static_color(0,index); + rgb_backlight_settings_save(app->notification->rgb_srv->settings); + + // dont update display color if rainbow working + if (!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) { + rgb_backlight_settings_save(app->notification->rgb_srv->settings); + } +} + static void rgb_backlight_rainbow_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -263,7 +332,9 @@ static void rgb_backlight_rainbow_changed(VariableItem* item) { // restore saved rgb backlight settings if we switch_off rainbow mode if(app->notification->rgb_srv->settings->rainbow_mode == 0) { - rgb_backlight_set_static_color(app->notification->rgb_srv->settings->static_color_index); + rgb_backlight_set_led_static_color (2,app->notification->rgb_srv->settings->led_2_color_index); + rgb_backlight_set_led_static_color (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); } } @@ -292,42 +363,6 @@ static void rgb_backlight_rainbow_step_changed(VariableItem* item) { } -static void vd1_color_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_get_color_text(index)); - app->notification->rgb_srv->settings->static_color_index = index; - - rgb_backlight_set_static_color(index); - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); - rgb_backlight_settings_save(app->notification->rgb_srv->settings); -} - -static void vd2_color_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_get_color_text(index)); - app->notification->rgb_srv->settings->static_color_index = index; - - rgb_backlight_set_static_color(index); - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); - rgb_backlight_settings_save(app->notification->rgb_srv->settings); -} - -static void vd3_color_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_get_color_text(index)); - app->notification->rgb_srv->settings->static_color_index = index; - - rgb_backlight_set_static_color(index); - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); - rgb_backlight_settings_save(app->notification->rgb_srv->settings); -} - // open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_backlight_installed is true) void variable_item_list_enter_callback(void* context, uint32_t index) { UNUSED(context); @@ -458,38 +493,50 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_text(item, rgb_backlight_installed_text[value_index]); } - // vd1 color + // led_1 color item = variable_item_list_add( app->variable_item_list_rgb, - "VD1 Color", + "LED 1 Color", rgb_backlight_get_color_count(), - vd1_color_changed, + led_2_color_changed, app); - value_index = app->notification->rgb_srv->settings->static_color_index; + value_index = app->notification->rgb_srv->settings->led_2_color_index; variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); - // vd2 color + // led_2 color item = variable_item_list_add( app->variable_item_list_rgb, - "VD2 Color", + "LED 2 Color", rgb_backlight_get_color_count(), - vd2_color_changed, + led_1_color_changed, app); - value_index = app->notification->rgb_srv->settings->static_color_index; + value_index = app->notification->rgb_srv->settings->led_1_color_index; variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); - // vd 3 color + // led 3 color item = variable_item_list_add( app->variable_item_list_rgb, - "VD3 Color", + "LED 3 Color", rgb_backlight_get_color_count(), - vd3_color_changed, + led_0_color_changed, app); - value_index = app->notification->rgb_srv->settings->static_color_index; + value_index = app->notification->rgb_srv->settings->led_0_color_index; variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); // Rainbow mode item = variable_item_list_add( diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index ce3992704..9cc8e15f6 100755 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,83.1,, +Version,+,86.0,, Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt_keys_storage.h,, @@ -3148,8 +3148,7 @@ Function,-,renameat,int,"int, const char*, int, const char*" Function,-,rewind,void,FILE* Function,+,rgb_backlight_get_color_count,uint8_t, Function,+,rgb_backlight_get_color_text,const char*,uint8_t -Function,+,rgb_backlight_set_custom_color,void,"uint8_t, uint8_t, uint8_t" -Function,+,rgb_backlight_set_static_color,void,uint8_t +Function,+,rgb_backlight_set_led_static_color,void,"uint8_t, uint8_t" Function,+,rgb_backlight_settings_load,void,RGBBacklightSettings* Function,+,rgb_backlight_settings_save,void,const RGBBacklightSettings* Function,+,rgb_backlight_update,void,float From a629118aaa7ee78220ccde21107dedc3f2db9a52 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 19 Mar 2025 00:46:00 +0700 Subject: [PATCH 4/8] Rainbow mode in progress --- .../services/rgb_backlight/rgb_backlight.c | 87 ++- .../services/rgb_backlight/rgb_backlight.h | 8 +- .../rgb_backlight/rgb_backlight_settings.c | 6 +- .../rgb_backlight/rgb_backlight_settings.h | 1 + .../notification_settings_app.c | 495 +++++++++--------- 5 files changed, 348 insertions(+), 249 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index 323cc5d48..6f9940ad0 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -23,6 +23,7 @@ #include #include #include "rgb_backlight.h" +#include #define COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightColor)) @@ -87,14 +88,22 @@ void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index) { // furi_record_close(RECORD_RGB_BACKLIGHT); } -// use RECORD for acces to rgb service instance and update current colors by custom -// void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue) { -// RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); -// app->current_red = red; -// app->current_green = green; -// app->current_blue = blue; -// furi_record_close(RECORD_RGB_BACKLIGHT); -// } +// use RECORD for acces to rgb service instance and update current colors by custom value +void rgb_backlight_set_led_custom_color(uint8_t led, uint8_t red, uint8_t green, uint8_t blue) { + // RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); + // float brightness = app->settings->brightness; + + if(led < SK6805_get_led_count()) { + + current_led[led].red = red; + current_led[led].green = green; + current_led[led].blue = blue; + + SK6805_set_led_color(led, red, green, blue); + } + + // furi_record_close(RECORD_RGB_BACKLIGHT); +} // use RECORD for acces to rgb service instance, use current_* colors and update backlight void rgb_backlight_update(float brightness) { @@ -132,19 +141,77 @@ void rainbow_timer_starter(RGBBacklightApp* app) { } } } + +// HSV to RGB based on +// https://www.radiokot.ru/forum/viewtopic.php?p=3000181&ysclid=m88wvoz34w244644702 +// https://radiolaba.ru/microcotrollers/tsvetnaya-lampa.html#comment-1790 +// https://alexgyver.ru/lessons/arduino-rgb/?ysclid=m88voflppa24464916 +void hsv_to_rgb(uint8_t red, uint8_t green, uint8_t blue, uint16_t hue ,uint8_t sat ,uint8_t val) { + float r = 1.0f; + float g = 1.0f; + float b = 1.0f; + + float H = hue / 255.0f; + float S = sat / 255.0f; + float V = val / 255.0f; + + uint8_t i = trunc(H * 6); + float f = H * 6 - i; + float p = V * (1 - S); + float q = V * (1 - f * S); + float t = V * (1 - (1 - f) * S); + + switch(i) { + case 0: + r = V, g = t, b = p; + break; + case 1: + r = q, g = V, b = p; + break; + case 2: + r = p, g = V, b = t; + break; + case 3: + r = p, g = q, b = V; + break; + case 4: + r = t, g = p, b = V; + break; + case 5: + r = V, g = p, b = q; + break; + } + red = r * 255; + green = g * 255; + blue = b * 255; +} + + static void rainbow_timer_callback(void* context) { furi_assert(context); RGBBacklightApp* app = context; + uint8_t r = 0; + uint8_t g = 0; + uint8_t b = 0; - if (app->settings->rgb_backlight_installed) { + if(app->settings->rgb_backlight_installed) { switch(app->settings->rainbow_mode) { case 1: + for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { + hsv_to_rgb(r,g,b,app->rainbow_hue, app->settings->rainbow_saturation,app->settings->brightness*255); + FURI_LOG_D( + TAG, "rgb %d,%d,%d", r, g, b); + //rgb_backlight_set_led_custom_color (i,*r,*g,*b); + //SK6805_update(); + } + break; case 2: break; default: break; } + app->rainbow_hue++; rgb_backlight_update(app->settings->brightness); } @@ -168,6 +235,8 @@ int32_t rgb_backlight_srv(void* p) { app->settings = malloc(sizeof(RGBBacklightSettings)); rgb_backlight_settings_load(app->settings); + app->rainbow_hue = 1; + furi_record_create(RECORD_RGB_BACKLIGHT, app); //if rgb_backlight_installed then start rainbow or set leds colors from saved settings (default index = 0) diff --git a/applications/services/rgb_backlight/rgb_backlight.h b/applications/services/rgb_backlight/rgb_backlight.h index 0661886c5..e8b78f461 100644 --- a/applications/services/rgb_backlight/rgb_backlight.h +++ b/applications/services/rgb_backlight/rgb_backlight.h @@ -28,10 +28,10 @@ extern "C" { typedef struct { FuriTimer* rainbow_timer; - - // int16_t current_red; - // int16_t current_green; - // int16_t current_blue; + uint8_t rainbow_hue; + uint8_t rainbow_red; + uint8_t rainbow_green; + uint8_t rainbow_blue; RGBBacklightSettings* settings; diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index 4ca7140fd..0b0388cae 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -18,16 +18,17 @@ typedef struct { uint8_t version; uint8_t rgb_backlight_installed; float brightness; - + // static gradient mode settings uint8_t led_2_color_index; uint8_t led_1_color_index; uint8_t led_0_color_index; - + // rainbow mode setings uint32_t rainbow_mode; uint32_t rainbow_speed_ms; uint16_t rainbow_step; + uint8_t rainbow_saturation; } RGBBacklightSettingsPrevious; void rgb_backlight_settings_load(RGBBacklightSettings* settings) { @@ -82,6 +83,7 @@ void rgb_backlight_settings_load(RGBBacklightSettings* settings) { settings->brightness = 1.0f; settings->rainbow_speed_ms = 100; settings->rainbow_step = 1; + settings->rainbow_saturation = 255; rgb_backlight_settings_save(settings); } } diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.h b/applications/services/rgb_backlight/rgb_backlight_settings.h index fe504879f..7c6e08c95 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.h +++ b/applications/services/rgb_backlight/rgb_backlight_settings.h @@ -18,6 +18,7 @@ typedef struct { uint32_t rainbow_mode; uint32_t rainbow_speed_ms; uint16_t rainbow_step; + uint8_t rainbow_saturation; } RGBBacklightSettings; diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 75f462ce4..7e8536ee7 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -262,7 +262,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 + 6); i++) { + for(int i = slide; i < (slide + 7); 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!"); @@ -362,267 +362,294 @@ static void rgb_backlight_rainbow_step_changed(VariableItem* item) { rgb_backlight_settings_save(app->notification->rgb_srv->settings); } +static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) { + NotificationAppSettings* app = variable_item_get_context(item); -// open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_backlight_installed is true) -void variable_item_list_enter_callback(void* context, uint32_t index) { - UNUSED(context); - NotificationAppSettings* app = context; + //saturation must be 1..255, so (0..254)+1 + uint8_t index = variable_item_get_current_value_index(item)+1; + char valtext[4] = {}; + 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); +} + // open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_backlight_installed is true) + void variable_item_list_enter_callback(void* context, uint32_t index) { + UNUSED(context); + NotificationAppSettings* app = context; - if(((app->notification->rgb_srv->settings->rgb_backlight_installed) || - (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) && - (index == 0)) { - view_dispatcher_switch_to_view(app->view_dispatcher, RGBViewId); + if(((app->notification->rgb_srv->settings->rgb_backlight_installed) || + (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) && + (index == 0)) { + view_dispatcher_switch_to_view(app->view_dispatcher, RGBViewId); + } } -} -// switch to main view on exit from rgb_settings_view -static uint32_t notification_app_rgb_settings_exit(void* context) { - UNUSED(context); - return MainViewId; -} -//--- RGB BACKLIGHT END --- - -static uint32_t notification_app_settings_exit(void* context) { - UNUSED(context); - return VIEW_NONE; -} - -static NotificationAppSettings* alloc_settings(void) { - NotificationAppSettings* app = malloc(sizeof(NotificationAppSettings)); - app->notification = furi_record_open(RECORD_NOTIFICATION); - app->gui = furi_record_open(RECORD_GUI); - - app->variable_item_list = variable_item_list_alloc(); - View* view = variable_item_list_get_view(app->variable_item_list); - - VariableItem* item; - uint8_t value_index; - - //set callback for exit from main view - view_set_previous_callback(view, notification_app_settings_exit); - - //--- RGB BACKLIGHT --- - // set callback for OK pressed in notification settings menu - variable_item_list_set_enter_callback( - app->variable_item_list, variable_item_list_enter_callback, app); - - //Show RGB settings only when debug_mode or rgb_backlight_installed is active - if((app->notification->rgb_srv->settings->rgb_backlight_installed) || - (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) { - item = variable_item_list_add(app->variable_item_list, "RGB settings", 0, NULL, app); + // switch to main view on exit from rgb_settings_view + static uint32_t notification_app_rgb_settings_exit(void* context) { + UNUSED(context); + return MainViewId; } //--- RGB BACKLIGHT END --- - item = variable_item_list_add( - app->variable_item_list, "LCD Contrast", CONTRAST_COUNT, contrast_changed, app); - value_index = - value_index_int32(app->notification->settings.contrast, contrast_value, CONTRAST_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, contrast_text[value_index]); + static uint32_t notification_app_settings_exit(void* context) { + UNUSED(context); + return VIEW_NONE; + } - item = variable_item_list_add( - app->variable_item_list, "LCD Backlight", BACKLIGHT_COUNT, backlight_changed, app); - value_index = value_index_float( - app->notification->settings.display_brightness, backlight_value, BACKLIGHT_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, backlight_text[value_index]); + static NotificationAppSettings* alloc_settings(void) { + NotificationAppSettings* app = malloc(sizeof(NotificationAppSettings)); + app->notification = furi_record_open(RECORD_NOTIFICATION); + app->gui = furi_record_open(RECORD_GUI); - item = variable_item_list_add( - app->variable_item_list, "Backlight Time", DELAY_COUNT, screen_changed, app); - value_index = value_index_uint32( - app->notification->settings.display_off_delay_ms, delay_value, DELAY_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, delay_text[value_index]); + app->variable_item_list = variable_item_list_alloc(); + View* view = variable_item_list_get_view(app->variable_item_list); - item = variable_item_list_add( - app->variable_item_list, "LED Brightness", BACKLIGHT_COUNT, led_changed, app); - value_index = value_index_float( - app->notification->settings.led_brightness, backlight_value, BACKLIGHT_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, backlight_text[value_index]); + VariableItem* item; + uint8_t value_index; + + //set callback for exit from main view + view_set_previous_callback(view, notification_app_settings_exit); + + //--- RGB BACKLIGHT --- + // set callback for OK pressed in notification settings menu + variable_item_list_set_enter_callback( + app->variable_item_list, variable_item_list_enter_callback, app); + + //Show RGB settings only when debug_mode or rgb_backlight_installed is active + if((app->notification->rgb_srv->settings->rgb_backlight_installed) || + (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) { + item = variable_item_list_add(app->variable_item_list, "RGB settings", 0, NULL, app); + } + //--- RGB BACKLIGHT END --- - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) { - item = variable_item_list_add(app->variable_item_list, "Volume", 1, NULL, app); - value_index = 0; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, "Stealth"); - } else { item = variable_item_list_add( - app->variable_item_list, "Volume", VOLUME_COUNT, volume_changed, app); + app->variable_item_list, "LCD Contrast", CONTRAST_COUNT, contrast_changed, app); + value_index = value_index_int32( + app->notification->settings.contrast, contrast_value, CONTRAST_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, contrast_text[value_index]); + + item = variable_item_list_add( + app->variable_item_list, "LCD Backlight", BACKLIGHT_COUNT, backlight_changed, app); value_index = value_index_float( - app->notification->settings.speaker_volume, volume_value, VOLUME_COUNT); + app->notification->settings.display_brightness, backlight_value, BACKLIGHT_COUNT); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, volume_text[value_index]); - } + variable_item_set_current_value_text(item, backlight_text[value_index]); - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) { - item = variable_item_list_add(app->variable_item_list, "Vibro", 1, NULL, app); - value_index = 0; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, "Stealth"); - } else { item = variable_item_list_add( - app->variable_item_list, "Vibro", VIBRO_COUNT, vibro_changed, app); - value_index = - value_index_bool(app->notification->settings.vibro_on, vibro_value, VIBRO_COUNT); + app->variable_item_list, "Backlight Time", DELAY_COUNT, screen_changed, app); + value_index = value_index_uint32( + app->notification->settings.display_off_delay_ms, delay_value, DELAY_COUNT); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, vibro_text[value_index]); - } + variable_item_set_current_value_text(item, delay_text[value_index]); - //--- RGB BACKLIGHT --- + item = variable_item_list_add( + app->variable_item_list, "LED Brightness", BACKLIGHT_COUNT, led_changed, app); + value_index = value_index_float( + app->notification->settings.led_brightness, backlight_value, BACKLIGHT_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, backlight_text[value_index]); - app->variable_item_list_rgb = variable_item_list_alloc(); - View* view_rgb = variable_item_list_get_view(app->variable_item_list_rgb); + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) { + item = variable_item_list_add(app->variable_item_list, "Volume", 1, NULL, app); + value_index = 0; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, "Stealth"); + } else { + item = variable_item_list_add( + app->variable_item_list, "Volume", VOLUME_COUNT, volume_changed, app); + value_index = value_index_float( + app->notification->settings.speaker_volume, volume_value, VOLUME_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, volume_text[value_index]); + } - // set callback for exit from rgb_settings_menu - view_set_previous_callback(view_rgb, notification_app_rgb_settings_exit); + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) { + item = variable_item_list_add(app->variable_item_list, "Vibro", 1, NULL, app); + value_index = 0; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, "Stealth"); + } else { + item = variable_item_list_add( + app->variable_item_list, "Vibro", VIBRO_COUNT, vibro_changed, app); + value_index = + value_index_bool(app->notification->settings.vibro_on, vibro_value, VIBRO_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, vibro_text[value_index]); + } - // // Show rgb_backlight_Installed_Swith only in Debug mode - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { + //--- RGB BACKLIGHT --- + + app->variable_item_list_rgb = variable_item_list_alloc(); + View* view_rgb = variable_item_list_get_view(app->variable_item_list_rgb); + + // set callback for exit from rgb_settings_menu + view_set_previous_callback(view_rgb, notification_app_rgb_settings_exit); + + // // Show rgb_backlight_Installed_Swith only in Debug mode + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { + item = variable_item_list_add( + app->variable_item_list_rgb, + "RGB backlight installed", + RGB_BACKLIGHT_INSTALLED_COUNT, + rgb_backlight_installed_changed, + app); + value_index = value_index_bool( + app->notification->rgb_srv->settings->rgb_backlight_installed, + rgb_backlight_installed_value, + RGB_BACKLIGHT_INSTALLED_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_installed_text[value_index]); + } + + // led_1 color item = variable_item_list_add( app->variable_item_list_rgb, - "RGB backlight installed", - RGB_BACKLIGHT_INSTALLED_COUNT, - rgb_backlight_installed_changed, + "LED 1 Color", + rgb_backlight_get_color_count(), + led_2_color_changed, app); - value_index = value_index_bool( - app->notification->rgb_srv->settings->rgb_backlight_installed, - rgb_backlight_installed_value, - RGB_BACKLIGHT_INSTALLED_COUNT); + value_index = app->notification->rgb_srv->settings->led_2_color_index; variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_installed_text[value_index]); + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + // led_2 color + item = variable_item_list_add( + app->variable_item_list_rgb, + "LED 2 Color", + rgb_backlight_get_color_count(), + led_1_color_changed, + app); + value_index = app->notification->rgb_srv->settings->led_1_color_index; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + // led 3 color + item = variable_item_list_add( + app->variable_item_list_rgb, + "LED 3 Color", + rgb_backlight_get_color_count(), + led_0_color_changed, + app); + value_index = app->notification->rgb_srv->settings->led_0_color_index; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + // Rainbow mode + item = variable_item_list_add( + app->variable_item_list_rgb, + "Rainbow mode", + RGB_BACKLIGHT_RAINBOW_MODE_COUNT, + rgb_backlight_rainbow_changed, + app); + value_index = value_index_uint32( + app->notification->rgb_srv->settings->rainbow_mode, + rgb_backlight_rainbow_mode_value, + RGB_BACKLIGHT_RAINBOW_MODE_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_rainbow_mode_text[value_index]); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + item = variable_item_list_add( + app->variable_item_list_rgb, + "Rainbow speed", + RGB_BACKLIGHT_RAINBOW_SPEED_COUNT, + rgb_backlight_rainbow_speed_changed, + app); + value_index = value_index_uint32( + app->notification->rgb_srv->settings->rainbow_speed_ms, + rgb_backlight_rainbow_speed_value, + RGB_BACKLIGHT_RAINBOW_SPEED_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_rainbow_speed_text[value_index]); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + item = variable_item_list_add( + app->variable_item_list_rgb, + "Rainbow step", + RGB_BACKLIGHT_RAINBOW_STEP_COUNT, + rgb_backlight_rainbow_step_changed, + app); + value_index = value_index_uint32( + app->notification->rgb_srv->settings->rainbow_step, + rgb_backlight_rainbow_step_value, + RGB_BACKLIGHT_RAINBOW_SPEED_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_rainbow_step_text[value_index]); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + item = variable_item_list_add( + app->variable_item_list_rgb, + "Saturation", + 255, + rgb_backlight_rainbow_saturation_changed, + app); + value_index = app->notification->rgb_srv->settings->rainbow_saturation; + variable_item_set_current_value_index(item, value_index); + char valtext[4] = {}; + snprintf(valtext, sizeof(valtext), "%d", value_index); + variable_item_set_current_value_text(item, valtext); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + //--- RGB BACKLIGHT END --- + + app->view_dispatcher = view_dispatcher_alloc(); + view_dispatcher_attach_to_gui( + app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); + view_dispatcher_add_view(app->view_dispatcher, MainViewId, view); + view_dispatcher_add_view(app->view_dispatcher, RGBViewId, view_rgb); + view_dispatcher_switch_to_view(app->view_dispatcher, MainViewId); + return app; } - - // led_1 color - item = variable_item_list_add( - app->variable_item_list_rgb, - "LED 1 Color", - rgb_backlight_get_color_count(), - led_2_color_changed, - app); - value_index = app->notification->rgb_srv->settings->led_2_color_index; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - // led_2 color - item = variable_item_list_add( - app->variable_item_list_rgb, - "LED 2 Color", - rgb_backlight_get_color_count(), - led_1_color_changed, - app); - value_index = app->notification->rgb_srv->settings->led_1_color_index; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - // led 3 color - item = variable_item_list_add( - app->variable_item_list_rgb, - "LED 3 Color", - rgb_backlight_get_color_count(), - led_0_color_changed, - app); - value_index = app->notification->rgb_srv->settings->led_0_color_index; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - // Rainbow mode - item = variable_item_list_add( - app->variable_item_list_rgb, - "Rainbow mode", - RGB_BACKLIGHT_RAINBOW_MODE_COUNT, - rgb_backlight_rainbow_changed, - app); - value_index = value_index_uint32( - app->notification->rgb_srv->settings->rainbow_mode, - rgb_backlight_rainbow_mode_value, - RGB_BACKLIGHT_RAINBOW_MODE_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_rainbow_mode_text[value_index]); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); + static void free_settings(NotificationAppSettings * app) { + view_dispatcher_remove_view(app->view_dispatcher, MainViewId); + view_dispatcher_remove_view(app->view_dispatcher, RGBViewId); + variable_item_list_free(app->variable_item_list); + variable_item_list_free(app->variable_item_list_rgb); + view_dispatcher_free(app->view_dispatcher); - item = variable_item_list_add( - app->variable_item_list_rgb, - "Rainbow speed", - RGB_BACKLIGHT_RAINBOW_SPEED_COUNT, - rgb_backlight_rainbow_speed_changed, - app); - value_index = value_index_uint32( - app->notification->rgb_srv->settings->rainbow_speed_ms, - rgb_backlight_rainbow_speed_value, - RGB_BACKLIGHT_RAINBOW_SPEED_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_rainbow_speed_text[value_index]); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); + furi_record_close(RECORD_GUI); + furi_record_close(RECORD_NOTIFICATION); + free(app); + } - item = variable_item_list_add( - app->variable_item_list_rgb, - "Rainbow step", - RGB_BACKLIGHT_RAINBOW_STEP_COUNT, - rgb_backlight_rainbow_step_changed, - app); - value_index = value_index_uint32( - app->notification->rgb_srv->settings->rainbow_step, - rgb_backlight_rainbow_step_value, - RGB_BACKLIGHT_RAINBOW_SPEED_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_rainbow_step_text[value_index]); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); + int32_t notification_settings_app(void* p) { + UNUSED(p); + NotificationAppSettings* app = alloc_settings(); + view_dispatcher_run(app->view_dispatcher); + notification_message_save_settings(app->notification); - //--- RGB BACKLIGHT END --- + // Automaticaly switch_off debug_mode when user exit from settings with enabled rgb_backlight_installed + // if(app->notification->settings.rgb_backlight_installed) { + // furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug); + // } - app->view_dispatcher = view_dispatcher_alloc(); - view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); - view_dispatcher_add_view(app->view_dispatcher, MainViewId, view); - view_dispatcher_add_view(app->view_dispatcher, RGBViewId, view_rgb); - view_dispatcher_switch_to_view(app->view_dispatcher, MainViewId); - return app; -} - -static void free_settings(NotificationAppSettings* app) { - view_dispatcher_remove_view(app->view_dispatcher, MainViewId); - view_dispatcher_remove_view(app->view_dispatcher, RGBViewId); - variable_item_list_free(app->variable_item_list); - variable_item_list_free(app->variable_item_list_rgb); - view_dispatcher_free(app->view_dispatcher); - - furi_record_close(RECORD_GUI); - furi_record_close(RECORD_NOTIFICATION); - free(app); -} - -int32_t notification_settings_app(void* p) { - UNUSED(p); - NotificationAppSettings* app = alloc_settings(); - view_dispatcher_run(app->view_dispatcher); - notification_message_save_settings(app->notification); - - // Automaticaly switch_off debug_mode when user exit from settings with enabled rgb_backlight_installed - // if(app->notification->settings.rgb_backlight_installed) { - // furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug); - // } - - free_settings(app); - return 0; -} + free_settings(app); + return 0; + } From 5eb38b786b72d28ef6d5a3e68e1c979f8b06207e Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 19 Mar 2025 18:53:02 +0700 Subject: [PATCH 5/8] RGB BACKLIGHT refactoring finished. - rgb_backlight by @Quen0n - rgb_backlight_settings and effects (like rainbow) idea by @Willy-JL For access to rgb backlight settings enable Debug mode and go to Settings-LCD and Notification-RGB backlight --- .../services/rgb_backlight/rgb_backlight.c | 219 +++--- .../services/rgb_backlight/rgb_backlight.h | 3 +- .../rgb_backlight/rgb_backlight_settings.c | 2 + .../rgb_backlight/rgb_backlight_settings.h | 7 +- .../notification_settings_app.c | 661 ++++++++++-------- 5 files changed, 475 insertions(+), 417 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index 6f9940ad0..8d05e68de 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -37,10 +37,10 @@ typedef struct { } RGBBacklightColor; //use one type RGBBacklightColor for current_leds_settings and for static colors definition -static RGBBacklightColor current_led [] = { - {"LED0",255,60,0}, - {"LED1",255,60,0}, - {"LED2",255,60,0}, +static RGBBacklightColor current_led[] = { + {"LED0", 255, 60, 0}, + {"LED1", 255, 60, 0}, + {"LED2", 255, 60, 0}, }; static const RGBBacklightColor colors[] = { @@ -70,45 +70,83 @@ const char* rgb_backlight_get_color_text(uint8_t index) { // use RECORD for acces to rgb service instance and update current colors by static void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index) { - // RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); - // float brightness = app->settings->brightness; - if(led < SK6805_get_led_count()) { uint8_t r = colors[index].red; uint8_t g = colors[index].green; uint8_t b = colors[index].blue; - - current_led[led].red = r; - current_led[led].green =g; + + current_led[led].red = r; + current_led[led].green = g; current_led[led].blue = b; SK6805_set_led_color(led, r, g, b); } - - // furi_record_close(RECORD_RGB_BACKLIGHT); } -// use RECORD for acces to rgb service instance and update current colors by custom value -void rgb_backlight_set_led_custom_color(uint8_t led, uint8_t red, uint8_t green, uint8_t blue) { - // RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); - // float brightness = app->settings->brightness; +// --- NOT USED IN CURRENT RELEASE, FOR FUTURE USAGE--- +// Update current colors by custom rgb value +// void rgb_backlight_set_led_custom_color(uint8_t led, uint8_t red, uint8_t green, uint8_t blue) { +// if(led < SK6805_get_led_count()) { +// current_led[led].red = red; +// current_led[led].green = green; +// current_led[led].blue = blue; +// SK6805_set_led_color(led, red, green, blue); +// } +// } +// --- NOT USED IN CURRENT RELEASE, FOR FUTURE USAGE--- - if(led < SK6805_get_led_count()) { +// HSV to RGB based on +// https://www.radiokot.ru/forum/viewtopic.php?p=3000181&ysclid=m88wvoz34w244644702 +// https://radiolaba.ru/microcotrollers/tsvetnaya-lampa.html#comment-1790 +// https://alexgyver.ru/lessons/arduino-rgb/?ysclid=m88voflppa24464916 +// led number (0-2), hue (0..255), sat (0..255), val (0...1) +void rgb_backlight_set_led_custom_hsv_color(uint8_t led, uint16_t hue, uint8_t sat, float V) { + //init value + float r = 1.0f; + float g = 1.0f; + float b = 1.0f; - current_led[led].red = red; - current_led[led].green = green; - current_led[led].blue = blue; + //from (0..255) to (0..1) + float H = hue / 255.0f; + float S = sat / 255.0f; - SK6805_set_led_color(led, red, green, blue); + uint8_t i = trunc(H * 6); + float f = H * 6 - i; + float p = V * (1 - S); + float q = V * (1 - f * S); + float t = V * (1 - (1 - f) * S); + + switch(i) { + case 0: + r = V, g = t, b = p; + break; + case 1: + r = q, g = V, b = p; + break; + case 2: + r = p, g = V, b = t; + break; + case 3: + r = p, g = q, b = V; + break; + case 4: + r = t, g = p, b = V; + break; + case 5: + r = V, g = p, b = q; + break; } - // furi_record_close(RECORD_RGB_BACKLIGHT); + //from (0..1) to (0..255) + current_led[led].red = r * 255; + current_led[led].green = g * 255; + current_led[led].blue = b * 255; } -// use RECORD for acces to rgb service instance, use current_* colors and update backlight +// use RECORD for acces to rgb service instance, set current_* colors to led and update backlight void rgb_backlight_update(float brightness) { RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); - + 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); @@ -142,83 +180,56 @@ void rainbow_timer_starter(RGBBacklightApp* app) { } } -// HSV to RGB based on -// https://www.radiokot.ru/forum/viewtopic.php?p=3000181&ysclid=m88wvoz34w244644702 -// https://radiolaba.ru/microcotrollers/tsvetnaya-lampa.html#comment-1790 -// https://alexgyver.ru/lessons/arduino-rgb/?ysclid=m88voflppa24464916 -void hsv_to_rgb(uint8_t red, uint8_t green, uint8_t blue, uint16_t hue ,uint8_t sat ,uint8_t val) { - float r = 1.0f; - float g = 1.0f; - float b = 1.0f; - - float H = hue / 255.0f; - float S = sat / 255.0f; - float V = val / 255.0f; - - uint8_t i = trunc(H * 6); - float f = H * 6 - i; - float p = V * (1 - S); - float q = V * (1 - f * S); - float t = V * (1 - (1 - f) * S); - - switch(i) { - case 0: - r = V, g = t, b = p; - break; - case 1: - r = q, g = V, b = p; - break; - case 2: - r = p, g = V, b = t; - break; - case 3: - r = p, g = q, b = V; - break; - case 4: - r = t, g = p, b = V; - break; - case 5: - r = V, g = p, b = q; - break; - } - red = r * 255; - green = g * 255; - blue = b * 255; -} - - static void rainbow_timer_callback(void* context) { furi_assert(context); RGBBacklightApp* app = context; - uint8_t r = 0; - uint8_t g = 0; - uint8_t b = 0; if(app->settings->rgb_backlight_installed) { - switch(app->settings->rainbow_mode) { - case 1: - for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - hsv_to_rgb(r,g,b,app->rainbow_hue, app->settings->rainbow_saturation,app->settings->brightness*255); - FURI_LOG_D( - TAG, "rgb %d,%d,%d", r, g, b); - //rgb_backlight_set_led_custom_color (i,*r,*g,*b); - //SK6805_update(); - } - - break; - case 2: - break; - default: - break; + app->rainbow_hue += app->settings->rainbow_step; + if(app->rainbow_hue > 254) { + app->rainbow_hue = 0; } - app->rainbow_hue++; + + uint8_t wide = app->settings->rainbow_wide; + + switch(app->settings->rainbow_mode) { + //rainbow mode + case 1: + for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { + rgb_backlight_set_led_custom_hsv_color( + i, + app->rainbow_hue, + app->settings->rainbow_saturation, + app->settings->brightness); + } + break; + + //wave mode + case 2: + uint16_t j = app->rainbow_hue + wide; + uint16_t k = app->rainbow_hue + wide * 2; + + if(app->rainbow_hue > (254 - wide)) { + j = j - 255; + } + if(app->rainbow_hue > (254 - wide * 2)) { + k = k - 255; + } + + rgb_backlight_set_led_custom_hsv_color( + 0, app->rainbow_hue, app->settings->rainbow_saturation, app->settings->brightness); + rgb_backlight_set_led_custom_hsv_color( + 1, j, app->settings->rainbow_saturation, app->settings->brightness); + rgb_backlight_set_led_custom_hsv_color( + 2, k, app->settings->rainbow_saturation, app->settings->brightness); + break; + + default: + break; + } + rgb_backlight_update(app->settings->brightness); } - - // if rainbow_mode is ..... do another effect - // if(app->settings.rainbow_mode == ...) { - // } - } int32_t rgb_backlight_srv(void* p) { @@ -227,7 +238,7 @@ int32_t rgb_backlight_srv(void* p) { // Define object app (full app with settings and running variables), // allocate memory and create RECORD for access to app structure from outside RGBBacklightApp* app = malloc(sizeof(RGBBacklightApp)); - + //define rainbow_timer and they callback app->rainbow_timer = furi_timer_alloc(rainbow_timer_callback, FuriTimerTypePeriodic, app); @@ -242,24 +253,24 @@ int32_t rgb_backlight_srv(void* p) { //if rgb_backlight_installed then start rainbow or set leds colors from saved settings (default index = 0) if(app->settings->rgb_backlight_installed) { if(app->settings->rainbow_mode > 0) { - // rainbow_timer_starter(app); + rainbow_timer_starter(app); } else { - 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_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); } - // if rgb_backlight not installed then set default static orange color(index=0) to all leds (0-2) and force light on + // if rgb_backlight not installed then set default static orange color(index=0) to all leds (0-2) and force light on } else { - rgb_backlight_set_led_static_color (2,0); - rgb_backlight_set_led_static_color (1,0); - rgb_backlight_set_led_static_color (0,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(); } while(1) { // place for message queue and other future options - furi_delay_ms (5000); + furi_delay_ms(5000); if(app->settings->rgb_backlight_installed) { FURI_LOG_D(TAG, "RGB backlight enabled - serivce is running"); } else { diff --git a/applications/services/rgb_backlight/rgb_backlight.h b/applications/services/rgb_backlight/rgb_backlight.h index e8b78f461..10aa9341f 100644 --- a/applications/services/rgb_backlight/rgb_backlight.h +++ b/applications/services/rgb_backlight/rgb_backlight.h @@ -28,7 +28,7 @@ extern "C" { typedef struct { FuriTimer* rainbow_timer; - uint8_t rainbow_hue; + uint16_t rainbow_hue; uint8_t rainbow_red; uint8_t rainbow_green; uint8_t rainbow_blue; @@ -40,6 +40,7 @@ typedef struct { #define RECORD_RGB_BACKLIGHT "rgb_backlight" void rgb_backlight_update(float brightness); +//not used now, for future use // void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue); void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index); void rainbow_timer_stop(RGBBacklightApp* app); diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index 0b0388cae..f612507e4 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -29,6 +29,7 @@ typedef struct { uint32_t rainbow_speed_ms; uint16_t rainbow_step; uint8_t rainbow_saturation; + uint8_t rainbow_wide; } RGBBacklightSettingsPrevious; void rgb_backlight_settings_load(RGBBacklightSettings* settings) { @@ -84,6 +85,7 @@ void rgb_backlight_settings_load(RGBBacklightSettings* settings) { settings->rainbow_speed_ms = 100; settings->rainbow_step = 1; settings->rainbow_saturation = 255; + settings->rainbow_wide = 50; rgb_backlight_settings_save(settings); } } diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.h b/applications/services/rgb_backlight/rgb_backlight_settings.h index 7c6e08c95..3f3af005f 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.h +++ b/applications/services/rgb_backlight/rgb_backlight_settings.h @@ -8,17 +8,18 @@ typedef struct { uint8_t version; uint8_t rgb_backlight_installed; float brightness; - + // static gradient mode settings uint8_t led_2_color_index; uint8_t led_1_color_index; uint8_t led_0_color_index; - + // rainbow mode setings uint32_t rainbow_mode; uint32_t rainbow_speed_ms; uint16_t rainbow_step; - uint8_t rainbow_saturation; + uint8_t rainbow_saturation; + uint8_t rainbow_wide; } RGBBacklightSettings; diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 7e8536ee7..98efc54b7 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -134,21 +134,29 @@ const uint32_t rgb_backlight_rainbow_speed_value[RGB_BACKLIGHT_RAINBOW_SPEED_COU 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000}; -#define RGB_BACKLIGHT_RAINBOW_STEP_COUNT 10 +#define RGB_BACKLIGHT_RAINBOW_STEP_COUNT 3 const char* const rgb_backlight_rainbow_step_text[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] = { "1", "2", "3", - "4", - "5", - "6", - "7", - "8", - "9", - "10", }; -const uint32_t rgb_backlight_rainbow_step_value[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] = - {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; +const uint32_t rgb_backlight_rainbow_step_value[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] = { + 1, + 2, + 3, +}; + +#define RGB_BACKLIGHT_RAINBOW_WIDE_COUNT 3 +const char* const rgb_backlight_rainbow_wide_text[RGB_BACKLIGHT_RAINBOW_WIDE_COUNT] = { + "1", + "2", + "3", +}; +const uint32_t rgb_backlight_rainbow_wide_value[RGB_BACKLIGHT_RAINBOW_WIDE_COUNT] = { + 30, + 40, + 50, +}; typedef enum { MainViewId, @@ -234,26 +242,29 @@ static void rgb_backlight_installed_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_installed_text[index]); - app->notification->rgb_srv->settings->rgb_backlight_installed = rgb_backlight_installed_value[index]; + app->notification->rgb_srv->settings->rgb_backlight_installed = + rgb_backlight_installed_value[index]; rgb_backlight_settings_save(app->notification->rgb_srv->settings); - + // In case of user playing with rgb_backlight_installed swith: - // if user swith_off rgb_backlight_installed then force set default orange color - 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); + // if user swith_off rgb_backlight_installed then force set default orange color - defence from stupid. + 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(); - // if user swith_on rgb_backlight_installed then start rainbow if its ON or set saved static colors + // 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) { - rainbow_timer_starter (app->notification->rgb_srv); + if(app->notification->rgb_srv->settings->rainbow_mode > 0) { + rainbow_timer_starter(app->notification->rgb_srv); } else { - rgb_backlight_set_led_static_color (2,app->notification->rgb_srv->settings->led_2_color_index); - rgb_backlight_set_led_static_color (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_set_led_static_color( + 2, app->notification->rgb_srv->settings->led_2_color_index); + rgb_backlight_set_led_static_color( + 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); } } @@ -262,7 +273,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 + 7); 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!"); @@ -279,13 +290,12 @@ static void led_2_color_changed(VariableItem* item) { variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); app->notification->rgb_srv->settings->led_2_color_index = index; - rgb_backlight_set_led_static_color(2,index); - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); - - // dont update display color if rainbow working - if (!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) { - rgb_backlight_settings_save(app->notification->rgb_srv->settings); + //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_settings_save(app->notification->rgb_srv->settings); } static void led_1_color_changed(VariableItem* item) { @@ -295,13 +305,13 @@ static void led_1_color_changed(VariableItem* item) { variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); app->notification->rgb_srv->settings->led_1_color_index = index; - rgb_backlight_set_led_static_color(1,index); - rgb_backlight_settings_save(app->notification->rgb_srv->settings); - - // dont update display color if rainbow working - if (!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) { - rgb_backlight_settings_save(app->notification->rgb_srv->settings); + //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_settings_save(app->notification->rgb_srv->settings); } static void led_0_color_changed(VariableItem* item) { @@ -311,13 +321,13 @@ static void led_0_color_changed(VariableItem* item) { variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); app->notification->rgb_srv->settings->led_0_color_index = index; - rgb_backlight_set_led_static_color(0,index); - rgb_backlight_settings_save(app->notification->rgb_srv->settings); - - // dont update display color if rainbow working - if (!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) { - rgb_backlight_settings_save(app->notification->rgb_srv->settings); + //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_settings_save(app->notification->rgb_srv->settings); } static void rgb_backlight_rainbow_changed(VariableItem* item) { @@ -332,9 +342,12 @@ static void rgb_backlight_rainbow_changed(VariableItem* item) { // restore saved rgb backlight settings if we switch_off rainbow mode if(app->notification->rgb_srv->settings->rainbow_mode == 0) { - rgb_backlight_set_led_static_color (2,app->notification->rgb_srv->settings->led_2_color_index); - rgb_backlight_set_led_static_color (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_set_led_static_color( + 2, app->notification->rgb_srv->settings->led_2_color_index); + rgb_backlight_set_led_static_color( + 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); } } @@ -362,294 +375,324 @@ static void rgb_backlight_rainbow_step_changed(VariableItem* item) { rgb_backlight_settings_save(app->notification->rgb_srv->settings); } -static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) { +static void rgb_backlight_rainbow_saturation_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); - //saturation must be 1..255, so (0..254)+1 - uint8_t index = variable_item_get_current_value_index(item)+1; + //saturation must be 1..255, so we do (0..254)+1 + uint8_t index = variable_item_get_current_value_index(item) + 1; char valtext[4] = {}; 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); } - // open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_backlight_installed is true) - void variable_item_list_enter_callback(void* context, uint32_t index) { - UNUSED(context); - NotificationAppSettings* app = context; - if(((app->notification->rgb_srv->settings->rgb_backlight_installed) || - (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) && - (index == 0)) { - view_dispatcher_switch_to_view(app->view_dispatcher, RGBViewId); - } +static void rgb_backlight_rainbow_wide_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_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) +void variable_item_list_enter_callback(void* context, uint32_t index) { + UNUSED(context); + NotificationAppSettings* app = context; + + if(((app->notification->rgb_srv->settings->rgb_backlight_installed) || + (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) && + (index == 0)) { + view_dispatcher_switch_to_view(app->view_dispatcher, RGBViewId); } +} - // switch to main view on exit from rgb_settings_view - static uint32_t notification_app_rgb_settings_exit(void* context) { - UNUSED(context); - return MainViewId; +// switch to main view on exit from rgb_settings_view +static uint32_t notification_app_rgb_settings_exit(void* context) { + UNUSED(context); + return MainViewId; +} +//--- RGB BACKLIGHT END --- + +static uint32_t notification_app_settings_exit(void* context) { + UNUSED(context); + return VIEW_NONE; +} + +static NotificationAppSettings* alloc_settings(void) { + NotificationAppSettings* app = malloc(sizeof(NotificationAppSettings)); + app->notification = furi_record_open(RECORD_NOTIFICATION); + app->gui = furi_record_open(RECORD_GUI); + + app->variable_item_list = variable_item_list_alloc(); + View* view = variable_item_list_get_view(app->variable_item_list); + + VariableItem* item; + uint8_t value_index; + + //set callback for exit from main view + view_set_previous_callback(view, notification_app_settings_exit); + + //--- RGB BACKLIGHT --- + // set callback for OK pressed in notification settings menu + variable_item_list_set_enter_callback( + app->variable_item_list, variable_item_list_enter_callback, app); + + //Show RGB settings only when debug_mode or rgb_backlight_installed is active + if((app->notification->rgb_srv->settings->rgb_backlight_installed) || + (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) { + item = variable_item_list_add(app->variable_item_list, "RGB settings", 0, NULL, app); } //--- RGB BACKLIGHT END --- - static uint32_t notification_app_settings_exit(void* context) { - UNUSED(context); - return VIEW_NONE; - } + item = variable_item_list_add( + app->variable_item_list, "LCD Contrast", CONTRAST_COUNT, contrast_changed, app); + value_index = + value_index_int32(app->notification->settings.contrast, contrast_value, CONTRAST_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, contrast_text[value_index]); - static NotificationAppSettings* alloc_settings(void) { - NotificationAppSettings* app = malloc(sizeof(NotificationAppSettings)); - app->notification = furi_record_open(RECORD_NOTIFICATION); - app->gui = furi_record_open(RECORD_GUI); + item = variable_item_list_add( + app->variable_item_list, "LCD Backlight", BACKLIGHT_COUNT, backlight_changed, app); + value_index = value_index_float( + app->notification->settings.display_brightness, backlight_value, BACKLIGHT_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, backlight_text[value_index]); - app->variable_item_list = variable_item_list_alloc(); - View* view = variable_item_list_get_view(app->variable_item_list); + item = variable_item_list_add( + app->variable_item_list, "Backlight Time", DELAY_COUNT, screen_changed, app); + value_index = value_index_uint32( + app->notification->settings.display_off_delay_ms, delay_value, DELAY_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, delay_text[value_index]); - VariableItem* item; - uint8_t value_index; + item = variable_item_list_add( + app->variable_item_list, "LED Brightness", BACKLIGHT_COUNT, led_changed, app); + value_index = value_index_float( + app->notification->settings.led_brightness, backlight_value, BACKLIGHT_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, backlight_text[value_index]); - //set callback for exit from main view - view_set_previous_callback(view, notification_app_settings_exit); - - //--- RGB BACKLIGHT --- - // set callback for OK pressed in notification settings menu - variable_item_list_set_enter_callback( - app->variable_item_list, variable_item_list_enter_callback, app); - - //Show RGB settings only when debug_mode or rgb_backlight_installed is active - if((app->notification->rgb_srv->settings->rgb_backlight_installed) || - (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) { - item = variable_item_list_add(app->variable_item_list, "RGB settings", 0, NULL, app); - } - //--- RGB BACKLIGHT END --- - - item = variable_item_list_add( - app->variable_item_list, "LCD Contrast", CONTRAST_COUNT, contrast_changed, app); - value_index = value_index_int32( - app->notification->settings.contrast, contrast_value, CONTRAST_COUNT); + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) { + item = variable_item_list_add(app->variable_item_list, "Volume", 1, NULL, app); + value_index = 0; variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, contrast_text[value_index]); - + variable_item_set_current_value_text(item, "Stealth"); + } else { item = variable_item_list_add( - app->variable_item_list, "LCD Backlight", BACKLIGHT_COUNT, backlight_changed, app); + app->variable_item_list, "Volume", VOLUME_COUNT, volume_changed, app); value_index = value_index_float( - app->notification->settings.display_brightness, backlight_value, BACKLIGHT_COUNT); + app->notification->settings.speaker_volume, volume_value, VOLUME_COUNT); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, backlight_text[value_index]); - - item = variable_item_list_add( - app->variable_item_list, "Backlight Time", DELAY_COUNT, screen_changed, app); - value_index = value_index_uint32( - app->notification->settings.display_off_delay_ms, delay_value, DELAY_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, delay_text[value_index]); - - item = variable_item_list_add( - app->variable_item_list, "LED Brightness", BACKLIGHT_COUNT, led_changed, app); - value_index = value_index_float( - app->notification->settings.led_brightness, backlight_value, BACKLIGHT_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, backlight_text[value_index]); - - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) { - item = variable_item_list_add(app->variable_item_list, "Volume", 1, NULL, app); - value_index = 0; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, "Stealth"); - } else { - item = variable_item_list_add( - app->variable_item_list, "Volume", VOLUME_COUNT, volume_changed, app); - value_index = value_index_float( - app->notification->settings.speaker_volume, volume_value, VOLUME_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, volume_text[value_index]); - } - - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) { - item = variable_item_list_add(app->variable_item_list, "Vibro", 1, NULL, app); - value_index = 0; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, "Stealth"); - } else { - item = variable_item_list_add( - app->variable_item_list, "Vibro", VIBRO_COUNT, vibro_changed, app); - value_index = - value_index_bool(app->notification->settings.vibro_on, vibro_value, VIBRO_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, vibro_text[value_index]); - } - - //--- RGB BACKLIGHT --- - - app->variable_item_list_rgb = variable_item_list_alloc(); - View* view_rgb = variable_item_list_get_view(app->variable_item_list_rgb); - - // set callback for exit from rgb_settings_menu - view_set_previous_callback(view_rgb, notification_app_rgb_settings_exit); - - // // Show rgb_backlight_Installed_Swith only in Debug mode - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { - item = variable_item_list_add( - app->variable_item_list_rgb, - "RGB backlight installed", - RGB_BACKLIGHT_INSTALLED_COUNT, - rgb_backlight_installed_changed, - app); - value_index = value_index_bool( - app->notification->rgb_srv->settings->rgb_backlight_installed, - rgb_backlight_installed_value, - RGB_BACKLIGHT_INSTALLED_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_installed_text[value_index]); - } - - // led_1 color - item = variable_item_list_add( - app->variable_item_list_rgb, - "LED 1 Color", - rgb_backlight_get_color_count(), - led_2_color_changed, - app); - value_index = app->notification->rgb_srv->settings->led_2_color_index; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - // led_2 color - item = variable_item_list_add( - app->variable_item_list_rgb, - "LED 2 Color", - rgb_backlight_get_color_count(), - led_1_color_changed, - app); - value_index = app->notification->rgb_srv->settings->led_1_color_index; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - // led 3 color - item = variable_item_list_add( - app->variable_item_list_rgb, - "LED 3 Color", - rgb_backlight_get_color_count(), - led_0_color_changed, - app); - value_index = app->notification->rgb_srv->settings->led_0_color_index; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - // Rainbow mode - item = variable_item_list_add( - app->variable_item_list_rgb, - "Rainbow mode", - RGB_BACKLIGHT_RAINBOW_MODE_COUNT, - rgb_backlight_rainbow_changed, - app); - value_index = value_index_uint32( - app->notification->rgb_srv->settings->rainbow_mode, - rgb_backlight_rainbow_mode_value, - RGB_BACKLIGHT_RAINBOW_MODE_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_rainbow_mode_text[value_index]); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - item = variable_item_list_add( - app->variable_item_list_rgb, - "Rainbow speed", - RGB_BACKLIGHT_RAINBOW_SPEED_COUNT, - rgb_backlight_rainbow_speed_changed, - app); - value_index = value_index_uint32( - app->notification->rgb_srv->settings->rainbow_speed_ms, - rgb_backlight_rainbow_speed_value, - RGB_BACKLIGHT_RAINBOW_SPEED_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_rainbow_speed_text[value_index]); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - item = variable_item_list_add( - app->variable_item_list_rgb, - "Rainbow step", - RGB_BACKLIGHT_RAINBOW_STEP_COUNT, - rgb_backlight_rainbow_step_changed, - app); - value_index = value_index_uint32( - app->notification->rgb_srv->settings->rainbow_step, - rgb_backlight_rainbow_step_value, - RGB_BACKLIGHT_RAINBOW_SPEED_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_backlight_rainbow_step_text[value_index]); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - item = variable_item_list_add( - app->variable_item_list_rgb, - "Saturation", - 255, - rgb_backlight_rainbow_saturation_changed, - app); - value_index = app->notification->rgb_srv->settings->rainbow_saturation; - variable_item_set_current_value_index(item, value_index); - char valtext[4] = {}; - snprintf(valtext, sizeof(valtext), "%d", value_index); - variable_item_set_current_value_text(item, valtext); - variable_item_set_locked( - item, - (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), - "RGB MOD \nOFF!"); - - //--- RGB BACKLIGHT END --- - - app->view_dispatcher = view_dispatcher_alloc(); - view_dispatcher_attach_to_gui( - app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); - view_dispatcher_add_view(app->view_dispatcher, MainViewId, view); - view_dispatcher_add_view(app->view_dispatcher, RGBViewId, view_rgb); - view_dispatcher_switch_to_view(app->view_dispatcher, MainViewId); - return app; + variable_item_set_current_value_text(item, volume_text[value_index]); } - static void free_settings(NotificationAppSettings * app) { - view_dispatcher_remove_view(app->view_dispatcher, MainViewId); - view_dispatcher_remove_view(app->view_dispatcher, RGBViewId); - variable_item_list_free(app->variable_item_list); - variable_item_list_free(app->variable_item_list_rgb); - view_dispatcher_free(app->view_dispatcher); - - furi_record_close(RECORD_GUI); - furi_record_close(RECORD_NOTIFICATION); - free(app); + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) { + item = variable_item_list_add(app->variable_item_list, "Vibro", 1, NULL, app); + value_index = 0; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, "Stealth"); + } else { + item = variable_item_list_add( + app->variable_item_list, "Vibro", VIBRO_COUNT, vibro_changed, app); + value_index = + value_index_bool(app->notification->settings.vibro_on, vibro_value, VIBRO_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, vibro_text[value_index]); } - int32_t notification_settings_app(void* p) { - UNUSED(p); - NotificationAppSettings* app = alloc_settings(); - view_dispatcher_run(app->view_dispatcher); - notification_message_save_settings(app->notification); + //--- RGB BACKLIGHT --- - // Automaticaly switch_off debug_mode when user exit from settings with enabled rgb_backlight_installed - // if(app->notification->settings.rgb_backlight_installed) { - // furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug); - // } + app->variable_item_list_rgb = variable_item_list_alloc(); + View* view_rgb = variable_item_list_get_view(app->variable_item_list_rgb); - free_settings(app); - return 0; + // set callback for exit from rgb_settings_menu + view_set_previous_callback(view_rgb, notification_app_rgb_settings_exit); + + // // Show rgb_backlight_installed swith only in Debug mode + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { + item = variable_item_list_add( + app->variable_item_list_rgb, + "RGB backlight installed", + RGB_BACKLIGHT_INSTALLED_COUNT, + rgb_backlight_installed_changed, + app); + value_index = value_index_bool( + app->notification->rgb_srv->settings->rgb_backlight_installed, + rgb_backlight_installed_value, + RGB_BACKLIGHT_INSTALLED_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_installed_text[value_index]); } + + // We (humans) are numbering LEDs from left to right as 1..3, but hardware have another order from right to left 2..0 + // led_1 color + item = variable_item_list_add( + app->variable_item_list_rgb, + "LED 1 Color", + rgb_backlight_get_color_count(), + led_2_color_changed, + app); + value_index = app->notification->rgb_srv->settings->led_2_color_index; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + // led_2 color + item = variable_item_list_add( + app->variable_item_list_rgb, + "LED 2 Color", + rgb_backlight_get_color_count(), + led_1_color_changed, + app); + value_index = app->notification->rgb_srv->settings->led_1_color_index; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + // led 3 color + item = variable_item_list_add( + app->variable_item_list_rgb, + "LED 3 Color", + rgb_backlight_get_color_count(), + led_0_color_changed, + app); + value_index = app->notification->rgb_srv->settings->led_0_color_index; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index)); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + // Rainbow mode + item = variable_item_list_add( + app->variable_item_list_rgb, + "Rainbow mode", + RGB_BACKLIGHT_RAINBOW_MODE_COUNT, + rgb_backlight_rainbow_changed, + app); + value_index = value_index_uint32( + app->notification->rgb_srv->settings->rainbow_mode, + rgb_backlight_rainbow_mode_value, + RGB_BACKLIGHT_RAINBOW_MODE_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_rainbow_mode_text[value_index]); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + item = variable_item_list_add( + app->variable_item_list_rgb, + "Rainbow speed", + RGB_BACKLIGHT_RAINBOW_SPEED_COUNT, + rgb_backlight_rainbow_speed_changed, + app); + value_index = value_index_uint32( + app->notification->rgb_srv->settings->rainbow_speed_ms, + rgb_backlight_rainbow_speed_value, + RGB_BACKLIGHT_RAINBOW_SPEED_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_rainbow_speed_text[value_index]); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + item = variable_item_list_add( + app->variable_item_list_rgb, + "Rainbow step", + RGB_BACKLIGHT_RAINBOW_STEP_COUNT, + rgb_backlight_rainbow_step_changed, + app); + value_index = value_index_uint32( + app->notification->rgb_srv->settings->rainbow_step, + rgb_backlight_rainbow_step_value, + RGB_BACKLIGHT_RAINBOW_STEP_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_rainbow_step_text[value_index]); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + item = variable_item_list_add( + app->variable_item_list_rgb, + "Saturation", + 255, + rgb_backlight_rainbow_saturation_changed, + app); + value_index = app->notification->rgb_srv->settings->rainbow_saturation; + variable_item_set_current_value_index(item, value_index); + char valtext[4] = {}; + snprintf(valtext, sizeof(valtext), "%d", value_index); + variable_item_set_current_value_text(item, valtext); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + item = variable_item_list_add( + app->variable_item_list_rgb, + "Wave wide", + RGB_BACKLIGHT_RAINBOW_WIDE_COUNT, + rgb_backlight_rainbow_wide_changed, + app); + value_index = value_index_uint32( + app->notification->rgb_srv->settings->rainbow_wide, + rgb_backlight_rainbow_wide_value, + RGB_BACKLIGHT_RAINBOW_WIDE_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_backlight_rainbow_wide_text[value_index]); + variable_item_set_locked( + item, + (app->notification->rgb_srv->settings->rgb_backlight_installed == 0), + "RGB MOD \nOFF!"); + + //--- RGB BACKLIGHT END --- + + app->view_dispatcher = view_dispatcher_alloc(); + view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); + view_dispatcher_add_view(app->view_dispatcher, MainViewId, view); + view_dispatcher_add_view(app->view_dispatcher, RGBViewId, view_rgb); + view_dispatcher_switch_to_view(app->view_dispatcher, MainViewId); + return app; +} + +static void free_settings(NotificationAppSettings* app) { + view_dispatcher_remove_view(app->view_dispatcher, MainViewId); + view_dispatcher_remove_view(app->view_dispatcher, RGBViewId); + variable_item_list_free(app->variable_item_list); + variable_item_list_free(app->variable_item_list_rgb); + view_dispatcher_free(app->view_dispatcher); + + furi_record_close(RECORD_GUI); + furi_record_close(RECORD_NOTIFICATION); + free(app); +} + +int32_t notification_settings_app(void* p) { + UNUSED(p); + NotificationAppSettings* app = alloc_settings(); + view_dispatcher_run(app->view_dispatcher); + notification_message_save_settings(app->notification); + + // Automaticaly switch_off debug_mode when user exit from settings with enabled rgb_backlight_installed + // if(app->notification->settings.rgb_backlight_installed) { + // furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug); + // } + + free_settings(app); + return 0; +} From f751b285322fb19ff9ac96cebf901c564f083810 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 19 Mar 2025 19:18:19 +0700 Subject: [PATCH 6/8] Reboot screen color cosmetic changes. --- applications/services/rgb_backlight/rgb_backlight.c | 6 +++--- .../notification_settings/notification_settings_app.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index 8d05e68de..f42a80dbe 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -38,9 +38,9 @@ typedef struct { //use one type RGBBacklightColor for current_leds_settings and for static colors definition static RGBBacklightColor current_led[] = { - {"LED0", 255, 60, 0}, - {"LED1", 255, 60, 0}, - {"LED2", 255, 60, 0}, + {"LED0", 0, 0, 0}, + {"LED1", 0, 0, 0}, + {"LED2", 0, 0, 0}, }; static const RGBBacklightColor colors[] = { diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 98efc54b7..f4d5c40bb 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -253,7 +253,7 @@ static void rgb_backlight_installed_changed(VariableItem* item) { rgb_backlight_set_led_static_color(1, 0); rgb_backlight_set_led_static_color(0, 0); SK6805_update(); - // start rainbow (if its Enabled) or set saved static colors if user swith_on rgb_backlight_installed switch + // 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) { rainbow_timer_starter(app->notification->rgb_srv); From dc7e96d1855f53878a28cfd905f367fd7609cd7c Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Fri, 21 Mar 2025 06:33:27 +0700 Subject: [PATCH 7/8] Code cleanup --- targets/f7/api_symbols.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index 9cc8e15f6..c94a009ee 100755 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,86.0,, +Version,+,83.2,, Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt_keys_storage.h,, From f52c9855d62c93176e61d1a311203e18c623a4f9 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Sun, 23 Mar 2025 19:36:38 +0700 Subject: [PATCH 8/8] Cosmetic code changes and removing unused parts. --- .../services/rgb_backlight/rgb_backlight.c | 35 ++++-------- .../services/rgb_backlight/rgb_backlight.h | 52 ++++++++++++++++-- .../notification_settings_app.c | 54 ++++++++++++------- 3 files changed, 93 insertions(+), 48 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index f42a80dbe..053654ec2 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -36,7 +36,7 @@ typedef struct { uint8_t blue; } RGBBacklightColor; -//use one type RGBBacklightColor for current_leds_settings and for static colors definition +// use one type RGBBacklightColor for current_leds_settings and for static colors definition static RGBBacklightColor current_led[] = { {"LED0", 0, 0, 0}, {"LED1", 0, 0, 0}, @@ -83,30 +83,18 @@ void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index) { } } -// --- NOT USED IN CURRENT RELEASE, FOR FUTURE USAGE--- -// Update current colors by custom rgb value -// void rgb_backlight_set_led_custom_color(uint8_t led, uint8_t red, uint8_t green, uint8_t blue) { -// if(led < SK6805_get_led_count()) { -// current_led[led].red = red; -// current_led[led].green = green; -// current_led[led].blue = blue; -// SK6805_set_led_color(led, red, green, blue); -// } -// } -// --- NOT USED IN CURRENT RELEASE, FOR FUTURE USAGE--- - // HSV to RGB based on // https://www.radiokot.ru/forum/viewtopic.php?p=3000181&ysclid=m88wvoz34w244644702 // https://radiolaba.ru/microcotrollers/tsvetnaya-lampa.html#comment-1790 // https://alexgyver.ru/lessons/arduino-rgb/?ysclid=m88voflppa24464916 // led number (0-2), hue (0..255), sat (0..255), val (0...1) void rgb_backlight_set_led_custom_hsv_color(uint8_t led, uint16_t hue, uint8_t sat, float V) { - //init value + // init value float r = 1.0f; float g = 1.0f; float b = 1.0f; - //from (0..255) to (0..1) + // from (0..255) to (0..1) float H = hue / 255.0f; float S = sat / 255.0f; @@ -137,7 +125,7 @@ void rgb_backlight_set_led_custom_hsv_color(uint8_t led, uint16_t hue, uint8_t s break; } - //from (0..1) to (0..255) + // from (0..1) to (0..255) current_led[led].red = r * 255; current_led[led].green = g * 255; current_led[led].blue = b * 255; @@ -159,12 +147,12 @@ void rgb_backlight_update(float brightness) { furi_record_close(RECORD_RGB_BACKLIGHT); } -//start furi timer for rainbow +// start furi timer for rainbow void rainbow_timer_start(RGBBacklightApp* app) { furi_timer_start(app->rainbow_timer, furi_ms_to_ticks(app->settings->rainbow_speed_ms)); } -//stop furi timer for rainbow +// stop furi timer for rainbow void rainbow_timer_stop(RGBBacklightApp* app) { furi_timer_stop(app->rainbow_timer); } @@ -173,10 +161,6 @@ void rainbow_timer_stop(RGBBacklightApp* app) { void rainbow_timer_starter(RGBBacklightApp* app) { if((app->settings->rainbow_mode > 0) && (app->settings->rgb_backlight_installed)) { rainbow_timer_start(app); - } else { - if(furi_timer_is_running(app->rainbow_timer)) { - rainbow_timer_stop(app); - } } } @@ -239,7 +223,7 @@ int32_t rgb_backlight_srv(void* p) { // allocate memory and create RECORD for access to app structure from outside RGBBacklightApp* app = malloc(sizeof(RGBBacklightApp)); - //define rainbow_timer and they callback + // define rainbow_timer and they callback app->rainbow_timer = furi_timer_alloc(rainbow_timer_callback, FuriTimerTypePeriodic, app); // settings load or create default @@ -250,10 +234,10 @@ int32_t rgb_backlight_srv(void* p) { furi_record_create(RECORD_RGB_BACKLIGHT, app); - //if rgb_backlight_installed then start rainbow or set leds colors from saved settings (default index = 0) + // if rgb_backlight_installed then start rainbow or set leds colors from saved settings (default index = 0) if(app->settings->rgb_backlight_installed) { if(app->settings->rainbow_mode > 0) { - rainbow_timer_starter(app); + rainbow_timer_start(app); } else { 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); @@ -269,7 +253,6 @@ int32_t rgb_backlight_srv(void* p) { } while(1) { - // place for message queue and other future options furi_delay_ms(5000); if(app->settings->rgb_backlight_installed) { FURI_LOG_D(TAG, "RGB backlight enabled - serivce is running"); diff --git a/applications/services/rgb_backlight/rgb_backlight.h b/applications/services/rgb_backlight/rgb_backlight.h index 10aa9341f..d6f8b5fce 100644 --- a/applications/services/rgb_backlight/rgb_backlight.h +++ b/applications/services/rgb_backlight/rgb_backlight.h @@ -32,21 +32,65 @@ typedef struct { uint8_t rainbow_red; uint8_t rainbow_green; uint8_t rainbow_blue; - RGBBacklightSettings* settings; - } RGBBacklightApp; #define RECORD_RGB_BACKLIGHT "rgb_backlight" +/** Update leds colors from current_led[i].color and selected bright + * + * @param brightness - Brightness 0..1 + * @return + */ void rgb_backlight_update(float brightness); -//not used now, for future use -// void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue); + +/** Set current_led[i].color for one led by static color index + * + * @param led - Led number (0..2) + * @param index - Static color index number + * @return + */ void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index); + +/** Stop rainbow timer + * + * @param app - Instance of RGBBacklightApp from FURI RECORD + * @return + */ void rainbow_timer_stop(RGBBacklightApp* app); + +/** Start rainbow timer + * + * @param app - Instance of RGBBacklightApp from FURI RECORD + * @return + */ + +/** Start rainbow timer + * + * @param app - Instance of RGBBacklightApp from FURI RECORD + * @return + */ void rainbow_timer_start(RGBBacklightApp* app); + +/** Start rainbow timer only if all conditions meet (rgb_backlight_installed && rainbow ON) + * + * @param app - Instance of RGBBacklightApp from FURI RECORD + * @return + */ void rainbow_timer_starter(RGBBacklightApp* app); + +/** Get name of static color by index + * + * @param index - Static colors index number + * @return - color name + */ const char* rgb_backlight_get_color_text(uint8_t index); + +/** Get static colors count + * + * @param + * @return - colors count + */ uint8_t rgb_backlight_get_color_count(void); #ifdef __cplusplus diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index f4d5c40bb..dd2206dc2 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -16,8 +16,6 @@ typedef struct { VariableItemList* variable_item_list_rgb; } NotificationAppSettings; -//static VariableItem* temp_item; - static const NotificationSequence sequence_note_c = { &message_note_c5, &message_delay_100, @@ -126,13 +124,32 @@ const char* const rgb_backlight_rainbow_mode_text[RGB_BACKLIGHT_RAINBOW_MODE_COU }; const uint32_t rgb_backlight_rainbow_mode_value[RGB_BACKLIGHT_RAINBOW_MODE_COUNT] = {0, 1, 2}; -#define RGB_BACKLIGHT_RAINBOW_SPEED_COUNT 20 +#define RGB_BACKLIGHT_RAINBOW_SPEED_COUNT 10 const char* const rgb_backlight_rainbow_speed_text[RGB_BACKLIGHT_RAINBOW_SPEED_COUNT] = { - "0.1s", "0.2s", "0.3s", "0.4s", "0.5s", "0.6s", "0.7", "0.8", "0.9", "1s", - "1.1s", "1.2s", "1.3s", "1.4s", "1.5s", "1.6s", "1.7s", "1.8s", "1.9s", "2s"}; + "0.1s", + "0.2s", + "0.3s", + "0.4s", + "0.5s", + "0.6s", + "0.7", + "0.8", + "0.9", + "1s", +}; + const uint32_t rgb_backlight_rainbow_speed_value[RGB_BACKLIGHT_RAINBOW_SPEED_COUNT] = { - 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, - 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000}; + 100, + 200, + 300, + 400, + 500, + 600, + 700, + 800, + 900, + 1000, +}; #define RGB_BACKLIGHT_RAINBOW_STEP_COUNT 3 const char* const rgb_backlight_rainbow_step_text[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] = { @@ -182,7 +199,7 @@ static void backlight_changed(VariableItem* item) { app->notification->settings.display_brightness = backlight_value[index]; //--- RGB BACKLIGHT --- - //set selected brightness to current rgb backlight service settings and save settings + // set selected brightness to current rgb backlight service settings and save settings app->notification->rgb_srv->settings->brightness = backlight_value[index]; rgb_backlight_settings_save(app->notification->rgb_srv->settings); //--- RGB BACKLIGHT END --- @@ -247,13 +264,14 @@ static void rgb_backlight_installed_changed(VariableItem* item) { rgb_backlight_settings_save(app->notification->rgb_srv->settings); // In case of user playing with rgb_backlight_installed swith: - // if user swith_off rgb_backlight_installed then force set default orange color - defence from stupid. + // if user swith_off rgb_backlight_installed (but may be he have mod installed) + // then force set default orange color - defence from stupid. 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(); - // start rainbow (if its Enabled) or set saved static colors if user swith_on rgb_backlight_installed switch + // 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) { rainbow_timer_starter(app->notification->rgb_srv); @@ -290,7 +308,7 @@ static void led_2_color_changed(VariableItem* item) { variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); app->notification->rgb_srv->settings->led_2_color_index = index; - //dont update screen color if rainbow timer working + // 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); @@ -305,7 +323,7 @@ static void led_1_color_changed(VariableItem* item) { variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); app->notification->rgb_srv->settings->led_1_color_index = index; - //dont update screen color if rainbow timer working + // 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); @@ -321,7 +339,7 @@ static void led_0_color_changed(VariableItem* item) { variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); app->notification->rgb_srv->settings->led_0_color_index = index; - //dont update screen color if rainbow timer working + // 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); @@ -360,7 +378,7 @@ static void rgb_backlight_rainbow_speed_changed(VariableItem* item) { app->notification->rgb_srv->settings->rainbow_speed_ms = rgb_backlight_rainbow_speed_value[index]; - //save settings and restart timer with new speed value + // 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); } @@ -378,7 +396,7 @@ static void rgb_backlight_rainbow_step_changed(VariableItem* item) { static void rgb_backlight_rainbow_saturation_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); - //saturation must be 1..255, so we do (0..254)+1 + // saturation must be 1..255, so we do (0..254)+1 uint8_t index = variable_item_get_current_value_index(item) + 1; char valtext[4] = {}; snprintf(valtext, sizeof(valtext), "%d", index); @@ -394,7 +412,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 + // 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); } @@ -442,7 +460,7 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_list_set_enter_callback( app->variable_item_list, variable_item_list_enter_callback, app); - //Show RGB settings only when debug_mode or rgb_backlight_installed is active + // Show RGB settings only when debug_mode or rgb_backlight_installed is active if((app->notification->rgb_srv->settings->rgb_backlight_installed) || (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) { item = variable_item_list_add(app->variable_item_list, "RGB settings", 0, NULL, app); @@ -513,7 +531,7 @@ static NotificationAppSettings* alloc_settings(void) { // set callback for exit from rgb_settings_menu view_set_previous_callback(view_rgb, notification_app_rgb_settings_exit); - // // Show rgb_backlight_installed swith only in Debug mode + // Show rgb_backlight_installed swith only in Debug mode if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { item = variable_item_list_add( app->variable_item_list_rgb,