From 7a19c9e5494839e2aa496aebd9932e5b47c0ffa1 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 12 Mar 2025 18:15:38 +0700 Subject: [PATCH] Still in progress --- .../services/notification/application.fam | 2 +- .../services/notification/notification_app.c | 239 +++++++++--------- .../services/notification/notification_app.h | 20 +- .../services/rgb_backlight/application.fam | 2 +- .../services/rgb_backlight/rgb_backlight.c | 176 +++++++++---- .../services/rgb_backlight/rgb_backlight.h | 24 +- .../rgb_backlight/rgb_backlight_settings.c | 2 +- .../rgb_backlight/rgb_backlight_settings.h | 8 +- .../notification_settings_app.c | 88 ++++--- .../notification_settings/rgb_backlight.c | 229 ----------------- .../notification_settings/rgb_backlight.h | 94 ------- lib/drivers/SK6805.h | 7 + targets/f7/api_symbols.csv | 9 +- targets/f7/furi_hal/furi_hal_light.c | 4 +- 14 files changed, 361 insertions(+), 543 deletions(-) delete mode 100644 applications/settings/notification_settings/rgb_backlight.c delete mode 100644 applications/settings/notification_settings/rgb_backlight.h diff --git a/applications/services/notification/application.fam b/applications/services/notification/application.fam index 82f94085a..fbfdca848 100644 --- a/applications/services/notification/application.fam +++ b/applications/services/notification/application.fam @@ -4,7 +4,7 @@ App( apptype=FlipperAppType.SERVICE, entry_point="notification_srv", cdefines=["SRV_NOTIFICATION"], - requires=["input"], + requires=["input","rgb_backlight"], provides=["notification_settings"], stack_size=int(1.5 * 1024), order=100, diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 8096c2cc3..afb900706 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -9,7 +9,7 @@ #include "notification.h" #include "notification_messages.h" #include "notification_app.h" -#include "applications/settings/notification_settings/rgb_backlight.h" +#include "applications/services/rgb_backlight/rgb_backlight.h" #define TAG "NotificationSrv" @@ -189,110 +189,110 @@ static void notification_display_timer(void* ctx) { notification_message(app, &sequence_display_backlight_off); } -// --- RGB MOD RAINBOW SECTION --- +// // --- RGB MOD RAINBOW SECTION --- -//start furi timer for rgb_mod_rainbow -static void rgb_mod_rainbow_timer_start(NotificationApp* app) { - furi_timer_start( - app->rgb_mod_rainbow_timer, furi_ms_to_ticks(app->settings.rgb_mod_rainbow_speed_ms)); -} +// //start furi timer for rgb_mod_rainbow +// static void rgb_mod_rainbow_timer_start(NotificationApp* app) { +// furi_timer_start( +// app->rgb_mod_rainbow_timer, furi_ms_to_ticks(app->settings.rgb_mod_rainbow_speed_ms)); +// } -//stop furi timer for rgb_mod_rainbow -static void rgb_mod_rainbow_timer_stop(NotificationApp* app) { - furi_timer_stop(app->rgb_mod_rainbow_timer); -} +// //stop furi timer for rgb_mod_rainbow +// static void rgb_mod_rainbow_timer_stop(NotificationApp* app) { +// furi_timer_stop(app->rgb_mod_rainbow_timer); +// } -// start/restart/stop rgb_mod_rainbow_timer only if rgb_mod_installed and apply rainbow colors to backlight -static void rgb_mod_rainbow_timer_starter(NotificationApp* app) { - if(app->settings.rgb_mod_installed) { - if(app->settings.rgb_mod_rainbow_mode > 0) { - rgb_mod_rainbow_update( - app->rgb_mod_rainbow_red, - app->rgb_mod_rainbow_green, - app->rgb_mod_rainbow_blue, - app->settings.display_brightness); - rgb_mod_rainbow_timer_start(app); - } else { - if(furi_timer_is_running(app->rgb_mod_rainbow_timer)) { - rgb_mod_rainbow_timer_stop(app); - } - } - } -} +// // start/restart/stop rgb_mod_rainbow_timer only if rgb_mod_installed and apply rainbow colors to backlight +// static void rgb_mod_rainbow_timer_starter(NotificationApp* app) { +// if(app->settings.rgb_mod_installed) { +// if(app->settings.rgb_mod_rainbow_mode > 0) { +// rgb_mod_rainbow_update( +// app->rgb_mod_rainbow_red, +// app->rgb_mod_rainbow_green, +// app->rgb_mod_rainbow_blue, +// app->settings.display_brightness); +// rgb_mod_rainbow_timer_start(app); +// } else { +// if(furi_timer_is_running(app->rgb_mod_rainbow_timer)) { +// rgb_mod_rainbow_timer_stop(app); +// } +// } +// } +// } -// callback for rgb_mod_rainbow_timer (what we do when timer end) -static void rgb_mod_rainbow_timer_callback(void* context) { - furi_assert(context); - NotificationApp* app = context; +// // callback for rgb_mod_rainbow_timer (what we do when timer end) +// static void rgb_mod_rainbow_timer_callback(void* context) { +// furi_assert(context); +// NotificationApp* app = context; - // if rgb_mode_rainbow_mode is rainbow do rainbow effect - if(app->settings.rgb_mod_rainbow_mode == 1) { - switch(app->rgb_mod_rainbow_stage) { - // from red to yellow - case 1: - app->rgb_mod_rainbow_green += app->settings.rgb_mod_rainbow_step; - if(app->rgb_mod_rainbow_green >= 255) { - app->rgb_mod_rainbow_green = 255; - app->rgb_mod_rainbow_stage++; - } - break; - // yellow red to green - case 2: - app->rgb_mod_rainbow_red -= app->settings.rgb_mod_rainbow_step; - if(app->rgb_mod_rainbow_red <= 0) { - app->rgb_mod_rainbow_red = 0; - app->rgb_mod_rainbow_stage++; - } - break; - // from green to light blue - case 3: - app->rgb_mod_rainbow_blue += app->settings.rgb_mod_rainbow_step; - if(app->rgb_mod_rainbow_blue >= 255) { - app->rgb_mod_rainbow_blue = 255; - app->rgb_mod_rainbow_stage++; - } - break; - //from light blue to blue - case 4: - app->rgb_mod_rainbow_green -= app->settings.rgb_mod_rainbow_step; - if(app->rgb_mod_rainbow_green <= 0) { - app->rgb_mod_rainbow_green = 0; - app->rgb_mod_rainbow_stage++; - } - break; - //from blue to violet - case 5: - app->rgb_mod_rainbow_red += app->settings.rgb_mod_rainbow_step; - if(app->rgb_mod_rainbow_red >= 255) { - app->rgb_mod_rainbow_red = 255; - app->rgb_mod_rainbow_stage++; - } - break; - //from violet to red - case 6: - app->rgb_mod_rainbow_blue -= app->settings.rgb_mod_rainbow_step; - if(app->rgb_mod_rainbow_blue <= 0) { - app->rgb_mod_rainbow_blue = 0; - app->rgb_mod_rainbow_stage = 1; - } - break; - default: - break; - } +// // if rgb_mode_rainbow_mode is rainbow do rainbow effect +// if(app->settings.rgb_mod_rainbow_mode == 1) { +// switch(app->rgb_mod_rainbow_stage) { +// // from red to yellow +// case 1: +// app->rgb_mod_rainbow_green += app->settings.rgb_mod_rainbow_step; +// if(app->rgb_mod_rainbow_green >= 255) { +// app->rgb_mod_rainbow_green = 255; +// app->rgb_mod_rainbow_stage++; +// } +// break; +// // yellow red to green +// case 2: +// app->rgb_mod_rainbow_red -= app->settings.rgb_mod_rainbow_step; +// if(app->rgb_mod_rainbow_red <= 0) { +// app->rgb_mod_rainbow_red = 0; +// app->rgb_mod_rainbow_stage++; +// } +// break; +// // from green to light blue +// case 3: +// app->rgb_mod_rainbow_blue += app->settings.rgb_mod_rainbow_step; +// if(app->rgb_mod_rainbow_blue >= 255) { +// app->rgb_mod_rainbow_blue = 255; +// app->rgb_mod_rainbow_stage++; +// } +// break; +// //from light blue to blue +// case 4: +// app->rgb_mod_rainbow_green -= app->settings.rgb_mod_rainbow_step; +// if(app->rgb_mod_rainbow_green <= 0) { +// app->rgb_mod_rainbow_green = 0; +// app->rgb_mod_rainbow_stage++; +// } +// break; +// //from blue to violet +// case 5: +// app->rgb_mod_rainbow_red += app->settings.rgb_mod_rainbow_step; +// if(app->rgb_mod_rainbow_red >= 255) { +// app->rgb_mod_rainbow_red = 255; +// app->rgb_mod_rainbow_stage++; +// } +// break; +// //from violet to red +// case 6: +// app->rgb_mod_rainbow_blue -= app->settings.rgb_mod_rainbow_step; +// if(app->rgb_mod_rainbow_blue <= 0) { +// app->rgb_mod_rainbow_blue = 0; +// app->rgb_mod_rainbow_stage = 1; +// } +// break; +// default: +// break; +// } - rgb_mod_rainbow_update( - app->rgb_mod_rainbow_red, - app->rgb_mod_rainbow_green, - app->rgb_mod_rainbow_blue, - app->settings.display_brightness); - } +// rgb_mod_rainbow_update( +// app->rgb_mod_rainbow_red, +// app->rgb_mod_rainbow_green, +// app->rgb_mod_rainbow_blue, +// app->settings.display_brightness); +// } - // if rgb_mode_rainbow_mode is ..... do another effect - // if(app->settings.rgb_mod_rainbow_mode == 2) { - // } -} +// // if rgb_mode_rainbow_mode is ..... do another effect +// // if(app->settings.rgb_mod_rainbow_mode == 2) { +// // } +// } -// --- END OF RGB MOD RAINBOW SECTION --- +// // --- END OF RGB MOD RAINBOW SECTION --- // message processing static void notification_process_notification_message( @@ -326,7 +326,7 @@ static void notification_process_notification_message( reset_mask |= reset_display_mask; //start rgb_mod_rainbow_timer when display backlight is ON and all corresponding settings is ON too - rgb_mod_rainbow_timer_starter(app); + rainbow_timer_starter(app->rgb_srv); } else { reset_mask &= ~reset_display_mask; @@ -335,8 +335,8 @@ static void notification_process_notification_message( furi_timer_stop(app->display_timer); } //stop rgb_mod_rainbow_timer when display backlight is OFF - if(furi_timer_is_running(app->rgb_mod_rainbow_timer)) { - rgb_mod_rainbow_timer_stop(app); + if(furi_timer_is_running(app->rgb_srv->rainbow_timer)) { + rainbow_timer_stop(app->rgb_srv); } } break; @@ -664,25 +664,26 @@ static NotificationApp* notification_app_alloc(void) { furi_pubsub_subscribe(app->event_record, input_event_callback, app); notification_message(app, &sequence_display_backlight_on); - // --- RGB MOD INIT SETTINGS SECTION --- + // // --- RGB MOD INIT SETTINGS SECTION --- - app->settings.rgb_mod_installed = false; - app->settings.rgb_mod_rainbow_mode = 0; - app->settings.rgb_mod_rainbow_speed_ms = 100; - app->settings.rgb_mod_rainbow_step = 5; - app->rgb_mod_rainbow_red = 255; - app->rgb_mod_rainbow_green = 0; - app->rgb_mod_rainbow_blue = 0; - app->rgb_mod_rainbow_stage = 1; + // app->settings.rgb_mod_installed = false; + // app->settings.rgb_mod_rainbow_mode = 0; + // app->settings.rgb_mod_rainbow_speed_ms = 100; + // app->settings.rgb_mod_rainbow_step = 5; + // app->rgb_mod_rainbow_red = 255; + // app->rgb_mod_rainbow_green = 0; + // app->rgb_mod_rainbow_blue = 0; + // app->rgb_mod_rainbow_stage = 1; + + // //define rgb_mod_rainbow_timer and they callback + // app->rgb_mod_rainbow_timer = + // furi_timer_alloc(rgb_mod_rainbow_timer_callback, FuriTimerTypePeriodic, app); + // // --- END OF RGB MOD INIT SETTINGS SECTION --- - //define rgb_mod_rainbow_timer and they callback - app->rgb_mod_rainbow_timer = - furi_timer_alloc(rgb_mod_rainbow_timer_callback, FuriTimerTypePeriodic, app); return app; - - // --- END OF RGB MOD INIT SETTINGS SECTION --- } + static void notification_storage_callback(const void* message, void* context) { furi_assert(context); NotificationApp* app = context; @@ -703,8 +704,8 @@ static void notification_apply_settings(NotificationApp* app) { } notification_apply_lcd_contrast(app); - //start rgb_mod_rainbow_timer on system init if they ON in config - rgb_mod_rainbow_timer_starter(app); + // //start rgb_mod_rainbow_timer on system init if they ON in config + // rgb_mod_rainbow_timer_starter(app); } static void notification_init_settings(NotificationApp* app) { @@ -723,7 +724,7 @@ static void notification_init_settings(NotificationApp* app) { int32_t notification_srv(void* p) { UNUSED(p); NotificationApp* app = notification_app_alloc(); - + app->rgb_srv = furi_record_open (RECORD_RGB_BACKLIGHT); notification_init_settings(app); notification_vibro_off(); @@ -748,8 +749,8 @@ int32_t notification_srv(void* p) { break; case SaveSettingsMessage: //call rgb_mod_timer_control (start or stop) when we save settings - rgb_mod_rainbow_timer_starter(app); - rgb_backlight_save_settings(); + rainbow_timer_starter(app->rgb_srv); + rgb_backlight_settings_save(app->rgb_srv->settings); notification_save_settings(app); break; case LoadSettingsMessage: diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index 54b3ab7a9..4383ca6bc 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -3,6 +3,7 @@ #include "notification.h" #include "notification_messages.h" #include "notification_settings_filename.h" +#include "applications/services/rgb_backlight/rgb_backlight.h" #define NOTIFICATION_LED_COUNT 3 #define NOTIFICATION_EVENT_COMPLETE 0x00000001U @@ -45,10 +46,10 @@ typedef struct { int8_t contrast; bool vibro_on; /// --- RGB MOD SETTINGS SECTION --- - bool rgb_mod_installed; - uint32_t rgb_mod_rainbow_mode; - uint32_t rgb_mod_rainbow_speed_ms; - uint16_t rgb_mod_rainbow_step; + // bool rgb_mod_installed; + // uint32_t rgb_mod_rainbow_mode; + // uint32_t rgb_mod_rainbow_speed_ms; + // uint16_t rgb_mod_rainbow_step; /// --- END OF RGB MOD SETTINGS SECTION --- } NotificationSettings; @@ -63,14 +64,15 @@ struct NotificationApp { uint8_t display_led_lock; // --- RGB RAINBOW MODE VARIABLES SECTION --- - FuriTimer* rgb_mod_rainbow_timer; - int16_t rgb_mod_rainbow_red; - int16_t rgb_mod_rainbow_green; - int16_t rgb_mod_rainbow_blue; - uint8_t rgb_mod_rainbow_stage; + // FuriTimer* rgb_mod_rainbow_timer; + // int16_t rgb_mod_rainbow_red; + // int16_t rgb_mod_rainbow_green; + // int16_t rgb_mod_rainbow_blue; + // uint8_t rgb_mod_rainbow_stage; // --- ENd OF RGB RAINBOW MODE VARIABLES SECTION --- NotificationSettings settings; + RGBBacklightApp* rgb_srv; }; void notification_message_save_settings(NotificationApp* app); \ No newline at end of file diff --git a/applications/services/rgb_backlight/application.fam b/applications/services/rgb_backlight/application.fam index bb42d7b83..5e05233db 100644 --- a/applications/services/rgb_backlight/application.fam +++ b/applications/services/rgb_backlight/application.fam @@ -5,6 +5,6 @@ App( entry_point="rgb_backlight_srv", cdefines=["SRV_RGB_BACKLIGHT"], stack_size=1 * 1024, - order=99, + order=95, sdk_headers=["rgb_backlight.h"], ) \ No newline at end of file diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index f198ae13f..64c04b9cb 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -25,11 +25,11 @@ #include "rgb_backlight.h" -#define STATIC_COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightStaticColor)) +#define PREDEFINED_COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightPredefinedColor)) #define TAG "RGB_BACKLIGHT_SRV" -static const RGBBacklightStaticColor colors[] = { +static const RGBBacklightPredefinedColor colors[] = { {"Orange", 255, 60, 0}, {"Yellow", 255, 144, 0}, {"Spring", 167, 255, 0}, @@ -46,16 +46,89 @@ static const RGBBacklightStaticColor colors[] = { {"Custom", 0, 0, 0}, }; -void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue, float brightness) { +uint8_t rgb_backlight_get_color_count(void) { + return PREDEFINED_COLOR_COUNT; + } + +const char* rgb_backlight_get_color_text(uint8_t index) { + return colors[index].name; + } + + +void rgb_backlight_set_static_color(uint8_t index, float brightness) { + // use RECORD for acces to rgb service instance and use current_* colors and static colors + RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); + for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - uint8_t r = red * (brightness); - uint8_t g = green * (brightness); - uint8_t b = blue * (brightness); + app->current_red = colors[index].red; + app->current_green = colors[index].green; + app->current_blue = colors[index].blue; + + uint8_t r = app->current_red * brightness; + uint8_t g = app->current_green * brightness; + uint8_t b = app->current_blue * brightness; + SK6805_set_led_color(i, r, g, b); } + + furi_record_close(RECORD_RGB_BACKLIGHT); SK6805_update(); } +// void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue, float brightness) { +// for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { +// uint8_t r = red * (brightness); +// uint8_t g = green * (brightness); +// uint8_t b = blue * (brightness); +// SK6805_set_led_color(i, r, g, b); +// } +// SK6805_update(); +// } + +// apply new brightness to current display color set +void rgb_backlight_update (float brightness) { + // use RECORD for acces to rgb service instance and use current_* colors + RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); + + for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { + uint8_t r = app->current_red * brightness; + uint8_t g = app->current_green * brightness; + uint8_t b = app->current_blue * brightness; + SK6805_set_led_color(i, r, g, b); + } + + furi_record_close(RECORD_RGB_BACKLIGHT); + SK6805_update(); +} +//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 +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 +void rainbow_timer_starter(RGBBacklightApp* app) { + if(app->settings->rgb_mod_installed) { + if(app->settings->rainbow_mode > 0) { + // rgb_backlight_set_custom_color( + // app->rainbow_red, + // app->rainbow_green, + // app->rainbow_blue, + // app->settings->brightness); + rainbow_timer_start(app); + } else { + if(furi_timer_is_running(app->rainbow_timer)) { + rainbow_timer_stop(app); + } + } + } +} + static void rainbow_timer_callback(void* context) { furi_assert(context); RGBBacklightApp* app = context; @@ -63,51 +136,51 @@ static void rainbow_timer_callback(void* context) { // if rgb_mode_rainbow_mode is rainbow do rainbow effect if(app->settings->rainbow_mode == 1) { switch(app->rainbow_stage) { - // from red to yellow + // from red to yellow (255,0,0) - (255,255,0) case 1: - app->rainbow_green += app->settings->rainbow_step; - if(app->rainbow_green >= 255) { - app->rainbow_green = 255; + app->current_green += app->settings->rainbow_step; + if(app->current_green >= 255) { + app->current_green = 255; app->rainbow_stage++; } break; - // yellow red to green + // yellow to green (255,255,0) - (0,255,0) case 2: - app->rainbow_red -= app->settings->rainbow_step; - if(app->rainbow_red <= 0) { - app->rainbow_red = 0; + 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 + // from green to light blue (0,255,0) - (0,255,255) case 3: - app->rainbow_blue += app->settings->rainbow_step; - if(app->rainbow_blue >= 255) { - app->rainbow_blue = 255; + 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 + //from light blue to blue (0,255,255) - (0,0,255) case 4: - app->rainbow_green -= app->settings->rainbow_step; - if(app->rainbow_green <= 0) { - app->rainbow_green = 0; + app->current_green -= app->settings->rainbow_step; + if(app->current_green <= 0) { + app->current_green = 0; app->rainbow_stage++; } break; - //from blue to violet + //from blue to violet (0,0,255) - (255,0,255) case 5: - app->rainbow_red += app->settings->rainbow_step; - if(app->rainbow_red >= 255) { - app->rainbow_red = 255; + app->current_red += app->settings->rainbow_step; + if(app->current_red >= 255) { + app->current_red = 255; app->rainbow_stage++; } break; - //from violet to red + //from violet to red (255,0,255) - (255,0,0) case 6: - app->rainbow_blue -= app->settings->rainbow_step; - if(app->rainbow_blue <= 0) { - app->rainbow_blue = 0; + app->current_blue -= app->settings->rainbow_step; + if(app->current_blue <= 0) { + app->current_blue = 0; app->rainbow_stage = 1; } break; @@ -115,25 +188,23 @@ static void rainbow_timer_callback(void* context) { break; } - rgb_backlight_set_custom_color( - app->rainbow_red, - app->rainbow_green, - app->rainbow_blue, - app->settings->brightness); + // rgb_backlight_set_custom_color( + // app->current_red, + // app->current_green, + // app->current_blue, + // app->settings->brightness); } + + rgb_backlight_update (app->settings->brightness); // if rgb_mode_rainbow_mode is ..... do another effect // if(app->settings.rainbow_mode == 2) { // } } -void rgb_backlight_settings_apply(RGBBacklightSettings* settings) { - UNUSED (settings); - //запуск таймера если все включено - // применить сохраненые настройки цвета к дисплею статику или кастом если индекс=13 -} +int32_t rgb_backlight_srv (void* p) { + UNUSED(p); -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)); @@ -143,11 +214,28 @@ int32_t rgb_backlight_srv (void* p){ app->rainbow_timer = furi_timer_alloc(rainbow_timer_callback, FuriTimerTypePeriodic, app); - // load or init new settings and apply it + // settings load or create default rgb_backlight_settings_load (app->settings); - rgb_backlight_settings_apply (app->settings); - UNUSED(p); + // Init app variables + app->current_red = 255; + app->current_green = 60; + app->current_green = 0; + app->rainbow_stage = 1; + + // а нужно ли это все при старте сервиса, если мы получим сигнал на подсветку от Нотификейшена. Может вынести в ИНИТ и при старте нотиф дернуть его 1 раз + // 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, app->settings->brightness); + } + // if not rgb_mod_installed set default static orange color (index=0) + } else { + rgb_backlight_set_static_color(0, app->settings->brightness); + } + while(1) { FURI_LOG_I(TAG, "working"); furi_delay_ms(2000); diff --git a/applications/services/rgb_backlight/rgb_backlight.h b/applications/services/rgb_backlight/rgb_backlight.h index 88f3270c1..531d3a9e7 100644 --- a/applications/services/rgb_backlight/rgb_backlight.h +++ b/applications/services/rgb_backlight/rgb_backlight.h @@ -17,23 +17,28 @@ along with this program. If not, see . */ +#pragma once #include #include "rgb_backlight_settings.h" #include "SK6805.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { char* name; uint8_t red; uint8_t green; uint8_t blue; -} RGBBacklightStaticColor; +} RGBBacklightPredefinedColor; typedef struct { FuriTimer* rainbow_timer; - int16_t rainbow_red; - int16_t rainbow_green; - int16_t rainbow_blue; + int16_t current_red; + int16_t current_green; + int16_t current_blue; uint8_t rainbow_stage; RGBBacklightSettings* settings; @@ -42,3 +47,14 @@ typedef struct { #define RECORD_RGB_BACKLIGHT "rgb_backlight" +void rgb_backlight_update (float brightness); +void rgb_backlight_set_static_color(uint8_t index, float brightness); +void rainbow_timer_stop(RGBBacklightApp* app); +void rainbow_timer_start(RGBBacklightApp* app); +void rainbow_timer_starter(RGBBacklightApp* app); +const char* rgb_backlight_get_color_text(uint8_t index); +uint8_t rgb_backlight_get_color_count(void); + +#ifdef __cplusplus +} +#endif diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index 62cc47994..9cf1c1440 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -17,7 +17,7 @@ typedef struct { uint8_t version; bool rgb_mod_installed; - uint8_t display_static_color_index; + uint8_t static_color_index; uint8_t custom_r; uint8_t custom_g; uint8_t custom_b; diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.h b/applications/services/rgb_backlight/rgb_backlight_settings.h index f7a4af177..48b0c43b9 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.h +++ b/applications/services/rgb_backlight/rgb_backlight_settings.h @@ -7,10 +7,10 @@ typedef struct { uint8_t version; bool rgb_mod_installed; - uint8_t display_static_color_index; - uint8_t custom_r; - uint8_t custom_g; - uint8_t custom_b; + uint8_t static_color_index; + uint8_t custom_red; + uint8_t custom_green; + uint8_t custom_blue; float brightness; 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 8c6871acd..c2262d327 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -4,7 +4,6 @@ #include #include #include -#include #define MAX_NOTIFICATION_SETTINGS 4 @@ -170,6 +169,8 @@ static void backlight_changed(VariableItem* item) { variable_item_set_current_value_text(item, backlight_text[index]); app->notification->settings.display_brightness = backlight_value[index]; + //save brightness to rgb backlight settings too + app->notification->rgb_srv->settings->brightness = backlight_value[index]; notification_message(app->notification, &sequence_display_backlight_on); } @@ -225,21 +226,21 @@ static void rgb_mod_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_mod_text[index]); - app->notification->settings.rgb_mod_installed = rgb_mod_value[index]; + app->notification->rgb_srv->settings->rgb_mod_installed = rgb_mod_value[index]; } static void rgb_mod_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->settings.rgb_mod_rainbow_mode = rgb_mod_rainbow_mode_value[index]; + app->notification->rgb_srv->settings->rainbow_mode = rgb_mod_rainbow_mode_value[index]; // 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(app->notification->settings.rgb_mod_rainbow_mode > 0) { + if(app->notification->rgb_srv->settings->rainbow_mode > 0) { variable_item_set_locked(t_item, true, "Rainbow mode\nenabled!"); } else { variable_item_set_locked(t_item, false, "Rainbow mode\nenabled!"); @@ -249,8 +250,8 @@ static void rgb_mod_rainbow_changed(VariableItem* item) { notification_message_save_settings(app->notification); // restore saved rgb backlight settings if we switch_off rainbow mode - if(app->notification->settings.rgb_mod_rainbow_mode == 0) { - rgb_backlight_update(app->notification->settings.display_brightness * 255, true); + if(app->notification->rgb_srv->settings->rainbow_mode == 0) { + rgb_backlight_update(app->notification->settings.display_brightness); } } @@ -258,7 +259,7 @@ static void rgb_mod_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->settings.rgb_mod_rainbow_speed_ms = rgb_mod_rainbow_speed_value[index]; + app->notification->rgb_srv->settings->rainbow_speed_ms = rgb_mod_rainbow_speed_value[index]; //use message for restart rgb_mod_rainbow_timer with new delay notification_message_save_settings(app->notification); } @@ -267,14 +268,14 @@ static void rgb_mod_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->settings.rgb_mod_rainbow_step = rgb_mod_rainbow_step_value[index]; + app->notification->rgb_srv->settings->rainbow_step = rgb_mod_rainbow_step_value[index]; } -// Set RGB backlight color +// --- Set RGB backlight colors --- static void color_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - rgb_backlight_set_color(index); + rgb_backlight_set_static_color(index,app->notification->rgb_srv->settings->brightness); variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); notification_message(app->notification, &sequence_display_backlight_on); } @@ -283,12 +284,18 @@ static void color_changed(VariableItem* item) { 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); - rgb_backlight_set_custom_color(index, 0); + + //Set custom red to settings and current color + app->notification->rgb_srv->settings->custom_red = index; + app->notification->rgb_srv->current_red = index; + app->notification->rgb_srv->settings->static_color_index=13; + rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + char valtext[4] = {}; snprintf(valtext, sizeof(valtext), "%d", index); variable_item_set_current_value_text(item, valtext); - rgb_backlight_set_color(13); - rgb_backlight_update(app->notification->settings.display_brightness * 0xFF, true); + + // 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)); @@ -297,12 +304,19 @@ static void color_set_custom_red(VariableItem* item) { 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); - rgb_backlight_set_custom_color(index, 1); - char valtext[4] = {}; + + //Set custom green to settings and current color + app->notification->rgb_srv->settings->custom_green = index; + app->notification->rgb_srv->current_green = index; + app->notification->rgb_srv->settings->static_color_index=13; + rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + + char valtext[4] = {}; snprintf(valtext, sizeof(valtext), "%d", index); variable_item_set_current_value_text(item, valtext); - rgb_backlight_set_color(13); - rgb_backlight_update(app->notification->settings.display_brightness * 0xFF, true); + // rgb_backlight_set_color(13); + // rgb_backlight_update(app->rgb_srv->settings->brightness); + // 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)); @@ -311,12 +325,18 @@ static void color_set_custom_green(VariableItem* item) { 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); - rgb_backlight_set_custom_color(index, 2); + //Set custom blue to settings and current color + app->notification->rgb_srv->settings->custom_blue = index; + app->notification->rgb_srv->current_blue = index; + app->notification->rgb_srv->settings->static_color_index=13; + rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + char valtext[4] = {}; snprintf(valtext, sizeof(valtext), "%d", index); variable_item_set_current_value_text(item, valtext); - rgb_backlight_set_color(13); - rgb_backlight_update(app->notification->settings.display_brightness * 0xFF, true); + // rgb_backlight_set_color(13); + // rgb_backlight_update(app->rgb_srv->settings->brightness); + // 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)); @@ -328,7 +348,7 @@ void variable_item_list_enter_callback(void* context, uint32_t index) { UNUSED(context); NotificationAppSettings* app = context; - if(((app->notification->settings.rgb_mod_installed) || + if(((app->notification->rgb_srv->settings->rgb_mod_installed) || (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) && (index == 0)) { view_dispatcher_switch_to_view(app->view_dispatcher, RGBViewId); @@ -366,7 +386,7 @@ static NotificationAppSettings* alloc_settings(void) { uint8_t value_index; //Show RGB settings only when debug_mode or rgb_mod_installed is active - if((app->notification->settings.rgb_mod_installed) || + if((app->notification->rgb_srv->settings->rgb_mod_installed) || (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) { item = variable_item_list_add(app->variable_item_list, "RGB mod settings", 0, NULL, app); } @@ -442,7 +462,7 @@ static NotificationAppSettings* alloc_settings(void) { rgb_mod_installed_changed, app); value_index = value_index_bool( - app->notification->settings.rgb_mod_installed, rgb_mod_value, RGB_MOD_COUNT); + app->notification->rgb_srv->settings->rgb_mod_installed, rgb_mod_value, RGB_MOD_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, rgb_mod_text[value_index]); } @@ -454,41 +474,41 @@ static NotificationAppSettings* alloc_settings(void) { rgb_backlight_get_color_count(), color_changed, app); - value_index = rgb_backlight_get_settings()->display_color_index; + 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->settings.rgb_mod_rainbow_mode > 0), "Rainbow mode\nenabled!"); + item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); temp_item = item; // Custom Color - REFACTOR THIS item = variable_item_list_add( app->variable_item_list_rgb, "Custom Red", 255, color_set_custom_red, app); - value_index = rgb_backlight_get_settings()->custom_r; + value_index = app->notification->rgb_srv->settings->custom_red; 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->settings.rgb_mod_rainbow_mode > 0), "Rainbow mode\nenabled!"); + item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); item = variable_item_list_add( app->variable_item_list_rgb, "Custom Green", 255, color_set_custom_green, app); - value_index = rgb_backlight_get_settings()->custom_g; + value_index = app->notification->rgb_srv->settings->custom_green; 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->settings.rgb_mod_rainbow_mode > 0), "Rainbow mode\nenabled!"); + item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); item = variable_item_list_add( app->variable_item_list_rgb, "Custom Blue", 255, color_set_custom_blue, app); - value_index = rgb_backlight_get_settings()->custom_b; + 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->settings.rgb_mod_rainbow_mode > 0), "Rainbow mode\nenabled!"); + item, (app->notification->rgb_srv->settings->rainbow_mode > 0), "Rainbow mode\nenabled!"); // Rainbow (based on Willy-JL idea) settings item = variable_item_list_add( @@ -498,7 +518,7 @@ static NotificationAppSettings* alloc_settings(void) { rgb_mod_rainbow_changed, app); value_index = value_index_uint32( - app->notification->settings.rgb_mod_rainbow_mode, + app->notification->rgb_srv->settings->rainbow_mode, rgb_mod_rainbow_mode_value, RGB_MOD_RAINBOW_MODE_COUNT); variable_item_set_current_value_index(item, value_index); @@ -511,7 +531,7 @@ static NotificationAppSettings* alloc_settings(void) { rgb_mod_rainbow_speed_changed, app); value_index = value_index_uint32( - app->notification->settings.rgb_mod_rainbow_speed_ms, + app->notification->rgb_srv->settings->rainbow_speed_ms, rgb_mod_rainbow_speed_value, RGB_MOD_RAINBOW_SPEED_COUNT); variable_item_set_current_value_index(item, value_index); @@ -524,7 +544,7 @@ static NotificationAppSettings* alloc_settings(void) { rgb_mod_rainbow_step_changed, app); value_index = value_index_uint32( - app->notification->settings.rgb_mod_rainbow_step, + app->notification->rgb_srv->settings->rainbow_step, rgb_mod_rainbow_step_value, RGB_MOD_RAINBOW_SPEED_COUNT); variable_item_set_current_value_index(item, value_index); diff --git a/applications/settings/notification_settings/rgb_backlight.c b/applications/settings/notification_settings/rgb_backlight.c deleted file mode 100644 index 4fcb898f7..000000000 --- a/applications/settings/notification_settings/rgb_backlight.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - RGB backlight FlipperZero driver - Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "rgb_backlight.h" -#include -#include - -#define RGB_BACKLIGHT_SETTINGS_VERSION 6 -#define RGB_BACKLIGHT_SETTINGS_FILE_NAME ".rgb_backlight.settings" -#define RGB_BACKLIGHT_SETTINGS_PATH INT_PATH(RGB_BACKLIGHT_SETTINGS_FILE_NAME) - -#define COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightColor)) - -#define TAG "RGB Backlight" - -static RGBBacklightSettings rgb_settings = { - .version = RGB_BACKLIGHT_SETTINGS_VERSION, - .display_color_index = 0, - .custom_r = 254, - .custom_g = 254, - .custom_b = 254, - .settings_is_loaded = false}; - -static const RGBBacklightColor colors[] = { - {"Orange", 255, 60, 0}, - {"Yellow", 255, 144, 0}, - {"Spring", 167, 255, 0}, - {"Lime", 0, 255, 0}, - {"Aqua", 0, 255, 127}, - {"Cyan", 0, 210, 210}, - {"Azure", 0, 127, 255}, - {"Blue", 0, 0, 255}, - {"Purple", 127, 0, 255}, - {"Magenta", 210, 0, 210}, - {"Pink", 255, 0, 127}, - {"Red", 255, 0, 0}, - {"White", 254, 210, 200}, - {"Custom", 0, 0, 0}, -}; - -uint8_t rgb_backlight_get_color_count(void) { - return COLOR_COUNT; -} - -const char* rgb_backlight_get_color_text(uint8_t index) { - return colors[index].name; -} - -void rgb_backlight_load_settings(void) { - // Do not load settings if we are in other boot modes than normal - if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { - rgb_settings.settings_is_loaded = true; - return; - } - - // Wait for all required services to start and create their records - uint8_t timeout = 0; - while(!furi_record_exists(RECORD_STORAGE)) { - timeout++; - if(timeout > 150) { - rgb_settings.settings_is_loaded = true; - return; - } - furi_delay_ms(5); - } - - RGBBacklightSettings settings; - File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE)); - const size_t settings_size = sizeof(RGBBacklightSettings); - - FURI_LOG_D(TAG, "loading settings from \"%s\"", RGB_BACKLIGHT_SETTINGS_PATH); - bool fs_result = - storage_file_open(file, RGB_BACKLIGHT_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING); - - if(fs_result) { - uint16_t bytes_count = storage_file_read(file, &settings, settings_size); - - if(bytes_count != settings_size) { - fs_result = false; - } - } - - if(fs_result) { - FURI_LOG_D(TAG, "load success"); - if(settings.version != RGB_BACKLIGHT_SETTINGS_VERSION) { - FURI_LOG_E( - TAG, - "version(%d != %d) mismatch", - settings.version, - RGB_BACKLIGHT_SETTINGS_VERSION); - } else { - memcpy(&rgb_settings, &settings, settings_size); - } - } else { - FURI_LOG_E(TAG, "load failed, %s", storage_file_get_error_desc(file)); - } - - storage_file_close(file); - storage_file_free(file); - furi_record_close(RECORD_STORAGE); - rgb_settings.settings_is_loaded = true; -} - -void rgb_backlight_save_settings(void) { - RGBBacklightSettings settings; - File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE)); - const size_t settings_size = sizeof(RGBBacklightSettings); - - FURI_LOG_D(TAG, "saving settings to \"%s\"", RGB_BACKLIGHT_SETTINGS_PATH); - - memcpy(&settings, &rgb_settings, settings_size); - - bool fs_result = - storage_file_open(file, RGB_BACKLIGHT_SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS); - - if(fs_result) { - uint16_t bytes_count = storage_file_write(file, &settings, settings_size); - - if(bytes_count != settings_size) { - fs_result = false; - } - } - - if(fs_result) { - FURI_LOG_D(TAG, "save success"); - } else { - FURI_LOG_E(TAG, "save failed, %s", storage_file_get_error_desc(file)); - } - - storage_file_close(file); - storage_file_free(file); - furi_record_close(RECORD_STORAGE); -} - -RGBBacklightSettings* rgb_backlight_get_settings(void) { - if(!rgb_settings.settings_is_loaded) { - rgb_backlight_load_settings(); - } - return &rgb_settings; -} - -void rgb_backlight_set_color(uint8_t color_index) { - if(color_index > (rgb_backlight_get_color_count() - 1)) color_index = 0; - rgb_settings.display_color_index = color_index; -} - -void rgb_backlight_set_custom_color(uint8_t color, uint8_t index) { - if(index > 2) return; - if(index == 0) { - rgb_settings.custom_r = color; - } else if(index == 1) { - rgb_settings.custom_g = color; - } else if(index == 2) { - rgb_settings.custom_b = color; - } -} - -void rgb_backlight_update(uint8_t brightness, bool bypass) { - if(!rgb_settings.settings_is_loaded) { - rgb_backlight_load_settings(); - } - - if(!bypass) { - static uint8_t last_color_index = 255; - static uint8_t last_brightness = 123; - - if(last_brightness == brightness && last_color_index == rgb_settings.display_color_index) { - return; - } - - last_brightness = brightness; - last_color_index = rgb_settings.display_color_index; - } - - for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - if(rgb_settings.display_color_index == 13) { - uint8_t r = rgb_settings.custom_r * (brightness / 255.0f); - uint8_t g = rgb_settings.custom_g * (brightness / 255.0f); - uint8_t b = rgb_settings.custom_b * (brightness / 255.0f); - - SK6805_set_led_color(i, r, g, b); - } else { - if((colors[rgb_settings.display_color_index].red == 0) && - (colors[rgb_settings.display_color_index].green == 0) && - (colors[rgb_settings.display_color_index].blue == 0)) { - uint8_t r = colors[0].red * (brightness / 255.0f); - uint8_t g = colors[0].green * (brightness / 255.0f); - uint8_t b = colors[0].blue * (brightness / 255.0f); - - SK6805_set_led_color(i, r, g, b); - } else { - uint8_t r = colors[rgb_settings.display_color_index].red * (brightness / 255.0f); - uint8_t g = colors[rgb_settings.display_color_index].green * (brightness / 255.0f); - uint8_t b = colors[rgb_settings.display_color_index].blue * (brightness / 255.0f); - - SK6805_set_led_color(i, r, g, b); - } - } - } - - SK6805_update(); -} - -// --- RGB MOD RAINBOW --- -void rgb_mod_rainbow_update(uint8_t red, uint8_t green, uint8_t blue, float brightness) { - for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - uint8_t r = red * (brightness); - uint8_t g = green * (brightness); - uint8_t b = blue * (brightness); - SK6805_set_led_color(i, r, g, b); - } - SK6805_update(); -} -// --- END OF RGB MOD RAINBOW --- diff --git a/applications/settings/notification_settings/rgb_backlight.h b/applications/settings/notification_settings/rgb_backlight.h deleted file mode 100644 index 66e0e26a1..000000000 --- a/applications/settings/notification_settings/rgb_backlight.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - RGB backlight FlipperZero driver - Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include -#include "SK6805.h" - -typedef struct { - char* name; - uint8_t red; - uint8_t green; - uint8_t blue; -} RGBBacklightColor; - -typedef struct { - uint8_t version; - uint8_t display_color_index; - uint8_t custom_r; - uint8_t custom_g; - uint8_t custom_b; - bool settings_is_loaded; -} RGBBacklightSettings; - -/** - * @brief Получить текущие настройки RGB-подсветки - * - * @return Указатель на структуру настроек - */ -RGBBacklightSettings* rgb_backlight_get_settings(void); - -/** - * @brief Загрузить настройки подсветки с SD-карты - */ -void rgb_backlight_load_settings(void); - -/** - * @brief Сохранить текущие настройки RGB-подсветки - */ -void rgb_backlight_save_settings(void); - -/** - * @brief Применить текущие настройки RGB-подсветки - * - * @param brightness Яркость свечения (0-255) - * @param bypass Применить настройки принудительно - */ -void rgb_backlight_update(uint8_t brightness, bool bypass); - -/** - * @brief Установить цвет RGB-подсветки - * - * @param color_index Индекс цвета (0 - rgb_backlight_get_color_count()) - */ -void rgb_backlight_set_color(uint8_t color_index); - -/** - * @brief Set custom color values by index - 0=R 1=G 2=B - * - * @param color - color value (0-255) - * @param index - color index (0-2) 0=R 1=G 2=B - */ -void rgb_backlight_set_custom_color(uint8_t color, uint8_t index); - -/** - * @brief Получить количество доступных цветов - * - * @return Число доступных вариантов цвета - */ -uint8_t rgb_backlight_get_color_count(void); - -/** - * @brief Получить текстовое название цвета - * - * @param index Индекс из доступных вариантов цвета - * @return Указатель на строку с названием цвета - */ -const char* rgb_backlight_get_color_text(uint8_t index); - -// set custom color to display; -void rgb_mod_rainbow_update(uint8_t red, uint8_t green, uint8_t blue, float brightness); diff --git a/lib/drivers/SK6805.h b/lib/drivers/SK6805.h index c97054f6d..733f394ad 100644 --- a/lib/drivers/SK6805.h +++ b/lib/drivers/SK6805.h @@ -15,6 +15,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifdef __cplusplus +extern "C" { +#endif #ifndef SK6805_H_ #define SK6805_H_ @@ -49,3 +52,7 @@ void SK6805_set_led_color(uint8_t led_index, uint8_t r, uint8_t g, uint8_t b); void SK6805_update(void); #endif /* SK6805_H_ */ + +#ifdef __cplusplus +} +#endif diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index 310a669ef..f25b9c273 100644 --- 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,+,84.1,, 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,, @@ -3125,6 +3125,9 @@ Function,-,putw,int,"int, FILE*" Function,-,qsort,void,"void*, size_t, size_t, __compar_fn_t" Function,-,qsort_r,void,"void*, size_t, size_t, int (*)(const void*, const void*, void*), void*" Function,-,quick_exit,void,int +Function,+,rainbow_timer_start,void,RGBBacklightApp* +Function,+,rainbow_timer_starter,void,RGBBacklightApp* +Function,+,rainbow_timer_stop,void,RGBBacklightApp* Function,+,rand,int, Function,-,rand_r,int,unsigned* Function,+,random,long, @@ -3143,8 +3146,12 @@ Function,-,remquol,long double,"long double, long double, int*" Function,-,rename,int,"const char*, const char*" 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_static_color,void,"uint8_t, float" Function,+,rgb_backlight_settings_load,void,RGBBacklightSettings* Function,+,rgb_backlight_settings_save,void,const RGBBacklightSettings* +Function,+,rgb_backlight_update,void,float Function,-,rindex,char*,"const char*, int" Function,-,rint,double,double Function,-,rintf,float,float diff --git a/targets/f7/furi_hal/furi_hal_light.c b/targets/f7/furi_hal/furi_hal_light.c index 9ee542034..6cc60da11 100644 --- a/targets/f7/furi_hal/furi_hal_light.c +++ b/targets/f7/furi_hal/furi_hal_light.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include "applications/services/rgb_backlight/rgb_backlight.h" #define LED_CURRENT_RED (50u) #define LED_CURRENT_GREEN (50u) @@ -46,7 +46,7 @@ void furi_hal_light_set(Light light, uint8_t value) { uint8_t prev = lp5562_get_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelWhite); lp5562_execute_ramp( &furi_hal_i2c_handle_power, LP5562Engine1, LP5562ChannelWhite, prev, value, 100); - rgb_backlight_update(value, false); + rgb_backlight_update(value); } furi_hal_i2c_release(&furi_hal_i2c_handle_power); }