From a4d0c467f91e8e2bdbc3278ef6f8997bbe224a46 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 18 Mar 2025 18:41:50 +0700 Subject: [PATCH] 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