From 3c7d9e63fb30d1e7ab3d4469faafd9239470eef0 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Fri, 28 Feb 2025 23:14:18 +0700 Subject: [PATCH 01/17] Start working on combining rgb_backlight and original_backlight. --- .../services/notification/notification_app.c | 2 + .../notification_settings_app.c | 90 +++++++- .../notification_settings/rgb_backlight.c | 217 ++++++++++++++++++ .../notification_settings/rgb_backlight.h | 91 ++++++++ lib/drivers/SK6805.c | 103 +++++++++ lib/drivers/SK6805.h | 51 ++++ targets/f7/furi_hal/furi_hal_light.c | 34 +-- 7 files changed, 571 insertions(+), 17 deletions(-) create mode 100644 applications/settings/notification_settings/rgb_backlight.c create mode 100644 applications/settings/notification_settings/rgb_backlight.h create mode 100644 lib/drivers/SK6805.c create mode 100644 lib/drivers/SK6805.h diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 35d2fe675..1af97e2f4 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -9,6 +9,7 @@ #include "notification.h" #include "notification_messages.h" #include "notification_app.h" +#include "applications/settings/notification_settings/rgb_backlight.h" #define TAG "NotificationSrv" @@ -616,6 +617,7 @@ int32_t notification_srv(void* p) { break; case SaveSettingsMessage: notification_save_settings(app); + rgb_backlight_save_settings(); break; case LoadSettingsMessage: notification_load_settings(app); diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 2462b32bd..8e045cebf 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -3,6 +3,7 @@ #include #include #include +#include #define MAX_NOTIFICATION_SETTINGS 4 @@ -13,6 +14,8 @@ typedef struct { VariableItemList* variable_item_list; } NotificationAppSettings; +static VariableItem* temp_item; + static const NotificationSequence sequence_note_c = { &message_note_c5, &message_delay_100, @@ -168,6 +171,59 @@ static void vibro_changed(VariableItem* item) { notification_message(app->notification, &sequence_single_vibro); } +// Set RGB backlight color +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); + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); + notification_message(app->notification, &sequence_display_backlight_on); +} + +// TODO: refactor and fix this +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); + 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)); + notification_message(app->notification, &sequence_display_backlight_on); +} +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] = {}; + 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)); + notification_message(app->notification, &sequence_display_backlight_on); +} +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); + 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)); + notification_message(app->notification, &sequence_display_backlight_on); +} + static uint32_t notification_app_settings_exit(void* context) { UNUSED(context); return VIEW_NONE; @@ -192,8 +248,40 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, contrast_text[value_index]); + // RGB Colors item = variable_item_list_add( - app->variable_item_list, "LCD Backlight", BACKLIGHT_COUNT, backlight_changed, app); + app->variable_item_list, "LCD Color", rgb_backlight_get_color_count(), color_changed, app); + value_index = rgb_backlight_get_settings()->display_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)); + temp_item = item; + + // Custom Color - REFACTOR THIS + item = variable_item_list_add( + app->variable_item_list, "Custom Red", 255, color_set_custom_red, app); + value_index = rgb_backlight_get_settings()->custom_r; + 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); + + item = variable_item_list_add( + app->variable_item_list, "Custom Green", 255, color_set_custom_green, app); + value_index = rgb_backlight_get_settings()->custom_g; + variable_item_set_current_value_index(item, value_index); + snprintf(valtext, sizeof(valtext), "%d", value_index); + variable_item_set_current_value_text(item, valtext); + + item = variable_item_list_add( + app->variable_item_list, "Custom Blue", 255, color_set_custom_blue, app); + value_index = rgb_backlight_get_settings()->custom_b; + variable_item_set_current_value_index(item, value_index); + snprintf(valtext, sizeof(valtext), "%d", value_index); + variable_item_set_current_value_text(item, valtext); + // End of RGB + + item = variable_item_list_add( + app->variable_item_list, "LCD Brightness", 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); diff --git a/applications/settings/notification_settings/rgb_backlight.c b/applications/settings/notification_settings/rgb_backlight.c new file mode 100644 index 000000000..4edd77568 --- /dev/null +++ b/applications/settings/notification_settings/rgb_backlight.c @@ -0,0 +1,217 @@ +/* + 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(); +} diff --git a/applications/settings/notification_settings/rgb_backlight.h b/applications/settings/notification_settings/rgb_backlight.h new file mode 100644 index 000000000..f215ed312 --- /dev/null +++ b/applications/settings/notification_settings/rgb_backlight.h @@ -0,0 +1,91 @@ +/* + 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); diff --git a/lib/drivers/SK6805.c b/lib/drivers/SK6805.c new file mode 100644 index 000000000..8158c55a4 --- /dev/null +++ b/lib/drivers/SK6805.c @@ -0,0 +1,103 @@ +/* + SK6805 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 "SK6805.h" +#include + +/* Настройки */ +#define SK6805_LED_COUNT 3 //Количество светодиодов на плате подсветки +#define SK6805_LED_PIN &led_pin //Порт подключения светодиодов + +#ifdef FURI_DEBUG +#define DEBUG_PIN &gpio_ext_pa7 +#define DEBUG_INIT() \ + furi_hal_gpio_init(DEBUG_PIN, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh) +#define DEBUG_SET_HIGH() furi_hal_gpio_write(DEBUG_PIN, true) +#define DEBUG_SET_LOW() furi_hal_gpio_write(DEBUG_PIN, false) +#else +#define DEBUG_INIT() +#define DEBUG_SET_HIGH() +#define DEBUG_SET_LOW() +#endif + +static const GpioPin led_pin = {.port = GPIOA, .pin = LL_GPIO_PIN_8}; +static uint8_t led_buffer[SK6805_LED_COUNT][3]; + +void SK6805_init(void) { + DEBUG_INIT(); + furi_hal_gpio_write(SK6805_LED_PIN, false); + furi_hal_gpio_init(SK6805_LED_PIN, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh); +} + +uint8_t SK6805_get_led_count(void) { + return (const uint8_t)SK6805_LED_COUNT; +} +void SK6805_set_led_color(uint8_t led_index, uint8_t r, uint8_t g, uint8_t b) { + furi_check(led_index < SK6805_LED_COUNT); + + led_buffer[led_index][0] = g; + led_buffer[led_index][1] = r; + led_buffer[led_index][2] = b; +} + +void SK6805_update(void) { + SK6805_init(); + FURI_CRITICAL_ENTER(); + furi_delay_us(150); + uint32_t end; + /* Последовательная отправка цветов светодиодов */ + for(uint8_t lednumber = 0; lednumber < SK6805_LED_COUNT; lednumber++) { + //Последовательная отправка цветов светодиода + for(uint8_t color = 0; color < 3; color++) { + //Последовательная отправка битов цвета + uint8_t i = 0b10000000; + while(i != 0) { + if(led_buffer[lednumber][color] & (i)) { + furi_hal_gpio_write(SK6805_LED_PIN, true); + DEBUG_SET_HIGH(); + end = DWT->CYCCNT + 30; + //T1H 600 us (615 us) + while(DWT->CYCCNT < end) { + } + furi_hal_gpio_write(SK6805_LED_PIN, false); + DEBUG_SET_LOW(); + end = DWT->CYCCNT + 26; + //T1L 600 us (587 us) + while(DWT->CYCCNT < end) { + } + } else { + furi_hal_gpio_write(SK6805_LED_PIN, true); + DEBUG_SET_HIGH(); + end = DWT->CYCCNT + 11; + //T0H 300 ns (312 ns) + while(DWT->CYCCNT < end) { + } + furi_hal_gpio_write(SK6805_LED_PIN, false); + DEBUG_SET_LOW(); + end = DWT->CYCCNT + 43; + //T0L 900 ns (890 ns) + while(DWT->CYCCNT < end) { + } + } + i >>= 1; + } + } + } + furi_delay_us(150); + FURI_CRITICAL_EXIT(); +} diff --git a/lib/drivers/SK6805.h b/lib/drivers/SK6805.h new file mode 100644 index 000000000..c97054f6d --- /dev/null +++ b/lib/drivers/SK6805.h @@ -0,0 +1,51 @@ +/* + SK6805 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 . +*/ + +#ifndef SK6805_H_ +#define SK6805_H_ + +#include + +/** + * @brief Инициализация линии управления подсветкой + */ +void SK6805_init(void); + +/** + * @brief Получить количество светодиодов в подсветке + * + * @return Количество светодиодов + */ +uint8_t SK6805_get_led_count(void); + +/** + * @brief Установить цвет свечения светодиода + * + * @param led_index номер светодиода (от 0 до SK6805_get_led_count()) + * @param r значение красного (0-255) + * @param g значение зелёного (0-255) + * @param b значение синего (0-255) + */ +void SK6805_set_led_color(uint8_t led_index, uint8_t r, uint8_t g, uint8_t b); + +/** + * @brief Обновление состояния подсветки дисплея + */ +void SK6805_update(void); + +#endif /* SK6805_H_ */ diff --git a/targets/f7/furi_hal/furi_hal_light.c b/targets/f7/furi_hal/furi_hal_light.c index 621478d14..9ee542034 100644 --- a/targets/f7/furi_hal/furi_hal_light.c +++ b/targets/f7/furi_hal/furi_hal_light.c @@ -3,6 +3,7 @@ #include #include #include +#include #define LED_CURRENT_RED (50u) #define LED_CURRENT_GREEN (50u) @@ -31,22 +32,23 @@ void furi_hal_light_init(void) { } void furi_hal_light_set(Light light, uint8_t value) { - furi_hal_i2c_acquire(&furi_hal_i2c_handle_power); - if(light & LightRed) { - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value); - } - if(light & LightGreen) { - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value); - } - if(light & LightBlue) { - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value); - } - if(light & LightBacklight) { - 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); - } - furi_hal_i2c_release(&furi_hal_i2c_handle_power); + furi_hal_i2c_acquire(&furi_hal_i2c_handle_power); + if(light & LightRed) { + lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value); + } + if(light & LightGreen) { + lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value); + } + if(light & LightBlue) { + lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value); + } + if(light & LightBacklight) { + 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); + } + furi_hal_i2c_release(&furi_hal_i2c_handle_power); } void furi_hal_light_blink_start(Light light, uint8_t brightness, uint16_t on_time, uint16_t period) { From bb170140e2e9dcd9e3aa7e681280adb620daaf3b Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Sat, 1 Mar 2025 22:55:25 +0700 Subject: [PATCH 02/17] =?UTF-8?q?=D0=A1ombining=20rgb=5Fbacklight=20and=20?= =?UTF-8?q?original=5Fbacklight=20finished.=20-=20RGB=20Colors=20settings?= =?UTF-8?q?=20available=20only=20when=20Settings-Notification-RGB=5FMOD=5F?= =?UTF-8?q?Installed=20swithed=20ON=20-=20RGB=5FMOD=5FInstalled=20switch?= =?UTF-8?q?=20(ON|OFF)=20available=20in=20Notification=20only=20with=20Deb?= =?UTF-8?q?ug=20mode=20swithed=20ON.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/notification/notification_app.c | 1 + .../services/notification/notification_app.h | 3 +- .../notification_settings_app.c | 92 +++++++++++++------ 3 files changed, 67 insertions(+), 29 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 1af97e2f4..e02a16a1d 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -523,6 +523,7 @@ static NotificationApp* notification_app_alloc(void) { app->settings.led_brightness = 1.0f; app->settings.display_off_delay_ms = 30000; app->settings.vibro_on = true; + app->settings.rgb_mod_installed = false; app->display.value[LayerInternal] = 0x00; app->display.value[LayerNotification] = 0x00; diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index e19546574..056a762df 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -33,7 +33,7 @@ typedef struct { Light light; } NotificationLedLayer; -#define NOTIFICATION_SETTINGS_VERSION 0x02 +#define NOTIFICATION_SETTINGS_VERSION 0x03 #define NOTIFICATION_SETTINGS_PATH INT_PATH(NOTIFICATION_SETTINGS_FILE_NAME) typedef struct { @@ -44,6 +44,7 @@ typedef struct { uint32_t display_off_delay_ms; int8_t contrast; bool vibro_on; + bool rgb_mod_installed; } NotificationSettings; struct NotificationApp { diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 8e045cebf..527e0ba22 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -107,6 +108,13 @@ const char* const vibro_text[VIBRO_COUNT] = { }; const bool vibro_value[VIBRO_COUNT] = {false, true}; +#define RGB_MOD_COUNT 2 +const char* const rgb_mod_text[RGB_MOD_COUNT] = { + "OFF", + "ON", +}; +const bool rgb_mod_value[RGB_MOD_COUNT] = {false, true}; + static void contrast_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -171,6 +179,13 @@ static void vibro_changed(VariableItem* item) { notification_message(app->notification, &sequence_single_vibro); } +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]; +} + // Set RGB backlight color static void color_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); @@ -248,38 +263,59 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, contrast_text[value_index]); - // RGB Colors - item = variable_item_list_add( - app->variable_item_list, "LCD Color", rgb_backlight_get_color_count(), color_changed, app); - value_index = rgb_backlight_get_settings()->display_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)); - temp_item = item; + // 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 MOD Installed", + RGB_MOD_COUNT, + rgb_mod_installed_changed, + app); + value_index = value_index_bool( + app->notification->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]); + } - // Custom Color - REFACTOR THIS - item = variable_item_list_add( - app->variable_item_list, "Custom Red", 255, color_set_custom_red, app); - value_index = rgb_backlight_get_settings()->custom_r; - 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); + //Show RGB settings only when debug mode enabled or rgb_mod_installed is true + if((furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) || + (app->notification->settings.rgb_mod_installed)) { + // RGB Colors + item = variable_item_list_add( + app->variable_item_list, + "LCD Color", + rgb_backlight_get_color_count(), + color_changed, + app); + value_index = rgb_backlight_get_settings()->display_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)); + temp_item = item; - item = variable_item_list_add( - app->variable_item_list, "Custom Green", 255, color_set_custom_green, app); - value_index = rgb_backlight_get_settings()->custom_g; - variable_item_set_current_value_index(item, value_index); - snprintf(valtext, sizeof(valtext), "%d", value_index); - variable_item_set_current_value_text(item, valtext); + // Custom Color - REFACTOR THIS + item = variable_item_list_add( + app->variable_item_list, "Custom Red", 255, color_set_custom_red, app); + value_index = rgb_backlight_get_settings()->custom_r; + 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); - item = variable_item_list_add( - app->variable_item_list, "Custom Blue", 255, color_set_custom_blue, app); - value_index = rgb_backlight_get_settings()->custom_b; - variable_item_set_current_value_index(item, value_index); - snprintf(valtext, sizeof(valtext), "%d", value_index); - variable_item_set_current_value_text(item, valtext); - // End of RGB + item = variable_item_list_add( + app->variable_item_list, "Custom Green", 255, color_set_custom_green, app); + value_index = rgb_backlight_get_settings()->custom_g; + variable_item_set_current_value_index(item, value_index); + snprintf(valtext, sizeof(valtext), "%d", value_index); + variable_item_set_current_value_text(item, valtext); + item = variable_item_list_add( + app->variable_item_list, "Custom Blue", 255, color_set_custom_blue, app); + value_index = rgb_backlight_get_settings()->custom_b; + variable_item_set_current_value_index(item, value_index); + snprintf(valtext, sizeof(valtext), "%d", value_index); + variable_item_set_current_value_text(item, valtext); + // End of RGB + } item = variable_item_list_add( app->variable_item_list, "LCD Brightness", BACKLIGHT_COUNT, backlight_changed, app); value_index = value_index_float( From 08304ccff5a881f05578d8904dfc192bb5b5511e Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Sat, 1 Mar 2025 23:58:07 +0700 Subject: [PATCH 03/17] Small usability changes --- .../notification_settings/notification_settings_app.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 527e0ba22..a34ac5b4a 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -277,9 +277,8 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_text(item, rgb_mod_text[value_index]); } - //Show RGB settings only when debug mode enabled or rgb_mod_installed is true - if((furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) || - (app->notification->settings.rgb_mod_installed)) { + //Show RGB settings only when rgb_mod_installed is true + if(app->notification->settings.rgb_mod_installed) { // RGB Colors item = variable_item_list_add( app->variable_item_list, From 7ac1452618e2c0774cdb03776dea28b21ad6ff42 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 4 Mar 2025 22:13:59 +0700 Subject: [PATCH 04/17] Start working on RGB mod Rainbow effect (inspired by Willy-JL idea). --- .../services/notification/notification_app.c | 57 +++- .../services/notification/notification_app.h | 12 + .../notification_settings_app.c | 267 ++++++++++++++---- 3 files changed, 277 insertions(+), 59 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index e02a16a1d..229f7c5ea 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -512,18 +512,49 @@ static void input_event_callback(const void* value, void* context) { notification_message(app, &sequence_display_backlight_on); } +// 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)); +} + +//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/stop rgb_mod_rainbow_timer only if rgb_mod_installed +static void rgb_mod_rainbow_timer_control(NotificationApp* app) { + if(app->settings.rgb_mod_installed) { + if(app->settings.rgb_mod_rainbow) { + rgb_mod_rainbow_timer_start(app); + } else { + 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); + FURI_LOG_I("RAINBOW", "Rainbow timer callback - change color"); +} + +// END OF RGB MOD RAINBOW SECTION + // App alloc static NotificationApp* notification_app_alloc(void) { NotificationApp* app = malloc(sizeof(NotificationApp)); app->queue = furi_message_queue_alloc(8, sizeof(NotificationAppMessage)); - app->display_timer = furi_timer_alloc(notification_display_timer, FuriTimerTypeOnce, app); + app->display_timer = furi_timer_alloc(notification_display_timer, FuriTimerTypePeriodic, app); app->settings.speaker_volume = 1.0f; app->settings.display_brightness = 1.0f; app->settings.led_brightness = 1.0f; app->settings.display_off_delay_ms = 30000; app->settings.vibro_on = true; - app->settings.rgb_mod_installed = false; app->display.value[LayerInternal] = 0x00; app->display.value[LayerNotification] = 0x00; @@ -552,7 +583,25 @@ 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 SECTION + + //rgb mod + app->settings.rgb_mod_installed = false; + + //rgb mod rainbow init settings + app->settings.rgb_mod_rainbow = false; + app->settings.rgb_mod_rainbow_speed_ms = 1000; + app->settings.rgb_mod_rainbow_step = 1; + app->rgb_mod_rainbow_color1 = 1; + app->rgb_mod_rainbow_color2 = 1; + app->rgb_mod_rainbow_color3 = 1; + + //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 SECTION } static void notification_storage_callback(const void* message, void* context) { @@ -575,6 +624,8 @@ static void notification_apply_settings(NotificationApp* app) { } notification_apply_lcd_contrast(app); + // on system init start rgb_mod_rainbow_timer if they ON in config + rgb_mod_rainbow_timer_control(app); } static void notification_init_settings(NotificationApp* app) { @@ -619,6 +670,8 @@ int32_t notification_srv(void* p) { case SaveSettingsMessage: notification_save_settings(app); rgb_backlight_save_settings(); + //call rgb_mod_timer_control when we save settings + rgb_mod_rainbow_timer_control(app); break; case LoadSettingsMessage: notification_load_settings(app); diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index 056a762df..098ef5ee7 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -44,7 +44,12 @@ typedef struct { uint32_t display_off_delay_ms; int8_t contrast; bool vibro_on; + bool rgb_mod_installed; + bool rgb_mod_rainbow; + uint32_t rgb_mod_rainbow_speed_ms; + uint32_t rgb_mod_rainbow_step; + } NotificationSettings; struct NotificationApp { @@ -56,6 +61,13 @@ struct NotificationApp { NotificationLedLayer led[NOTIFICATION_LED_COUNT]; uint8_t display_led_lock; + // rainbow mode section + FuriTimer* rgb_mod_rainbow_timer; + int8_t rgb_mod_rainbow_color1; + int8_t rgb_mod_rainbow_color2; + int8_t rgb_mod_rainbow_color3; + + NotificationSettings settings; }; diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index a34ac5b4a..941284c89 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -13,6 +13,7 @@ typedef struct { Gui* gui; ViewDispatcher* view_dispatcher; VariableItemList* variable_item_list; + VariableItemList* variable_item_list_rgb; } NotificationAppSettings; static VariableItem* temp_item; @@ -115,6 +116,50 @@ const char* const rgb_mod_text[RGB_MOD_COUNT] = { }; const bool rgb_mod_value[RGB_MOD_COUNT] = {false, true}; +#define RGB_MOD_RAINBOW_COUNT 2 +const char* const rgb_mod_rainbow_text[RGB_MOD_RAINBOW_COUNT] = { + "OFF", + "ON", +}; +const bool rgb_mod_rainbow_value[RGB_MOD_RAINBOW_COUNT] = {false, true}; + +#define RGB_MOD_RAINBOW_SPEED_COUNT 14 +const char* const rgb_mod_rainbow_speed_text[RGB_MOD_RAINBOW_SPEED_COUNT] = { + "0.1s", + "0.2s", + "0.3s", + "0.4s", + "0.6s", + "0.8s", + "1s", + "1.2s", + "1.4s", + "1.6s", + "1.8s", + "2s", + "2.5s", + "3s"}; +const uint32_t rgb_mod_rainbow_speed_value[RGB_MOD_RAINBOW_SPEED_COUNT] = + {100, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000}; + +#define RGB_MOD_RAINBOW_STEP_COUNT 7 +const char* const rgb_mod_rainbow_step_text[RGB_MOD_RAINBOW_SPEED_COUNT] = { + "1", + "2", + "5", + "7", + "10", + "15", + "20", + }; +const uint32_t rgb_mod_rainbow_step_value[RGB_MOD_RAINBOW_STEP_COUNT] = + {1, 2, 5, 7, 10, 15, 20}; + +typedef enum { + MainViewId, + RGBViewId, +} ViewId; + static void contrast_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -186,6 +231,27 @@ static void rgb_mod_installed_changed(VariableItem* item) { app->notification->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_text[index]); + app->notification->settings.rgb_mod_rainbow = rgb_mod_rainbow_value[index]; +} + +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]; +} + +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]; +} + // Set RGB backlight color static void color_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); @@ -244,6 +310,23 @@ static uint32_t notification_app_settings_exit(void* context) { return VIEW_NONE; } +// open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_mod_install is true) +void variable_item_list_enter_callback(void* context, uint32_t index) { + UNUSED(context); + NotificationAppSettings* app = context; + + if(((app->notification->settings.rgb_mod_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; +} + static NotificationAppSettings* alloc_settings(void) { NotificationAppSettings* app = malloc(sizeof(NotificationAppSettings)); app->notification = furi_record_open(RECORD_NOTIFICATION); @@ -251,11 +334,21 @@ static NotificationAppSettings* alloc_settings(void) { app->variable_item_list = variable_item_list_alloc(); View* view = variable_item_list_get_view(app->variable_item_list); + //set callback for exit from view view_set_previous_callback(view, notification_app_settings_exit); + // set callback for OK pressed in menu + variable_item_list_set_enter_callback( + app->variable_item_list, variable_item_list_enter_callback, app); VariableItem* item; uint8_t value_index; + //Show RGB settings only when debug_mode or rgb_mod_installed is active + if((app->notification->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); + } + item = variable_item_list_add( app->variable_item_list, "LCD Contrast", CONTRAST_COUNT, contrast_changed, app); value_index = @@ -263,58 +356,6 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, contrast_text[value_index]); - // 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 MOD Installed", - RGB_MOD_COUNT, - rgb_mod_installed_changed, - app); - value_index = value_index_bool( - app->notification->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]); - } - - //Show RGB settings only when rgb_mod_installed is true - if(app->notification->settings.rgb_mod_installed) { - // RGB Colors - item = variable_item_list_add( - app->variable_item_list, - "LCD Color", - rgb_backlight_get_color_count(), - color_changed, - app); - value_index = rgb_backlight_get_settings()->display_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)); - temp_item = item; - - // Custom Color - REFACTOR THIS - item = variable_item_list_add( - app->variable_item_list, "Custom Red", 255, color_set_custom_red, app); - value_index = rgb_backlight_get_settings()->custom_r; - 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); - - item = variable_item_list_add( - app->variable_item_list, "Custom Green", 255, color_set_custom_green, app); - value_index = rgb_backlight_get_settings()->custom_g; - variable_item_set_current_value_index(item, value_index); - snprintf(valtext, sizeof(valtext), "%d", value_index); - variable_item_set_current_value_text(item, valtext); - - item = variable_item_list_add( - app->variable_item_list, "Custom Blue", 255, color_set_custom_blue, app); - value_index = rgb_backlight_get_settings()->custom_b; - variable_item_set_current_value_index(item, value_index); - snprintf(valtext, sizeof(valtext), "%d", value_index); - variable_item_set_current_value_text(item, valtext); - // End of RGB - } item = variable_item_list_add( app->variable_item_list, "LCD Brightness", BACKLIGHT_COUNT, backlight_changed, app); value_index = value_index_float( @@ -364,17 +405,123 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_text(item, vibro_text[value_index]); } + // RGB settings view + 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 + 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_COUNT, + rgb_mod_installed_changed, + app); + value_index = value_index_bool( + app->notification->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]); + } + + // RGB Colors settings + item = variable_item_list_add( + app->variable_item_list_rgb, + "LCD Color", + rgb_backlight_get_color_count(), + color_changed, + app); + value_index = rgb_backlight_get_settings()->display_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, "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; + 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, "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; + 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, "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; + 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, "Rainbow mode\nenabled!"); + // End of RGB + + // Rainbow (based on Willy-JL idea) settings + item = variable_item_list_add( + app->variable_item_list_rgb, + "Rainbow mode", + RGB_MOD_RAINBOW_COUNT, + rgb_mod_rainbow_changed, + app); + value_index = value_index_bool( + app->notification->settings.rgb_mod_rainbow, rgb_mod_rainbow_value, RGB_MOD_RAINBOW_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rgb_mod_rainbow_text[value_index]); + + item = variable_item_list_add( + app->variable_item_list_rgb, + "Rainbow speed", + RGB_MOD_RAINBOW_SPEED_COUNT, + rgb_mod_rainbow_speed_changed, + app); + value_index = value_index_uint32( + app->notification->settings.rgb_mod_rainbow_speed_ms, + rgb_mod_rainbow_speed_value, + RGB_MOD_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]); + + item = variable_item_list_add( + app->variable_item_list_rgb, + "Rainbow step", + RGB_MOD_RAINBOW_STEP_COUNT, + rgb_mod_rainbow_step_changed, + app); + value_index = value_index_uint32( + app->notification->settings.rgb_mod_rainbow_step, + rgb_mod_rainbow_step_value, + RGB_MOD_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]); + + // End of Rainbow settings + app->view_dispatcher = view_dispatcher_alloc(); view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); - view_dispatcher_add_view(app->view_dispatcher, 0, view); - view_dispatcher_switch_to_view(app->view_dispatcher, 0); - + 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, 0); + 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); @@ -387,6 +534,12 @@ int32_t notification_settings_app(void* 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_mod_installed + // if(app->notification->settings.rgb_mod_installed) { + // furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug); + // } + free_settings(app); return 0; -} + } From 82fd6b213093226e232d0534396c62f74b3c29fe Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 4 Mar 2025 23:34:11 +0700 Subject: [PATCH 05/17] RGB Rainbow still in development. --- .../services/notification/notification_app.c | 93 ++++++++++++------- .../services/notification/notification_app.h | 6 +- 2 files changed, 64 insertions(+), 35 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 229f7c5ea..3811c2fde 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -189,6 +189,61 @@ static void notification_display_timer(void* ctx) { notification_message(app, &sequence_display_backlight_off); } +// 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)); +} + +//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/stop rgb_mod_rainbow_timer only if rgb_mod_installed +static void rgb_mod_rainbow_timer_control(NotificationApp* app) { + if(app->settings.rgb_mod_installed) { + if(app->settings.rgb_mod_rainbow) { + 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; + +// УЧЕСТЬ СТЕП и его вероятность превысить 255 +// При выключении радуги активировать настроенный в меню цвет + + app->rgb_mod_rainbow_color3++; + + if(app->rgb_mod_rainbow_color3 == 255) { + app->rgb_mod_rainbow_color2++; + app->rgb_mod_rainbow_color3 = 1; + } + + if(app->rgb_mod_rainbow_color2 == 255) { + app->rgb_mod_rainbow_color1++; + app->rgb_mod_rainbow_color2 = 1; + } + if(app->rgb_mod_rainbow_color1 == 255) { + app->rgb_mod_rainbow_color1 = 1; + } + FURI_LOG_I("RAINBOW", "Color3 %u", app->rgb_mod_rainbow_color3); + FURI_LOG_I("RAINBOW", "Color2 %u", app->rgb_mod_rainbow_color2); + FURI_LOG_I("RAINBOW", "Color1 %u", app->rgb_mod_rainbow_color1); +} + +// END OF RGB MOD RAINBOW SECTION + // message processing static void notification_process_notification_message( NotificationApp* app, @@ -219,12 +274,18 @@ static void notification_process_notification_message( &app->display, notification_message->data.led.value * display_brightness_setting); reset_mask |= reset_display_mask; + //start rgb_mod_rainbow_timer when display backlight is ON + rgb_mod_rainbow_timer_control(app); } else { reset_mask &= ~reset_display_mask; notification_reset_notification_led_layer(&app->display); if(furi_timer_is_running(app->display_timer)) { 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); + } } break; case NotificationMessageTypeLedDisplayBacklightEnforceOn: @@ -512,38 +573,6 @@ static void input_event_callback(const void* value, void* context) { notification_message(app, &sequence_display_backlight_on); } -// 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)); -} - -//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/stop rgb_mod_rainbow_timer only if rgb_mod_installed -static void rgb_mod_rainbow_timer_control(NotificationApp* app) { - if(app->settings.rgb_mod_installed) { - if(app->settings.rgb_mod_rainbow) { - rgb_mod_rainbow_timer_start(app); - } else { - 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); - FURI_LOG_I("RAINBOW", "Rainbow timer callback - change color"); -} - -// END OF RGB MOD RAINBOW SECTION - // App alloc static NotificationApp* notification_app_alloc(void) { NotificationApp* app = malloc(sizeof(NotificationApp)); diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index 098ef5ee7..13cfb7aac 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -63,9 +63,9 @@ struct NotificationApp { // rainbow mode section FuriTimer* rgb_mod_rainbow_timer; - int8_t rgb_mod_rainbow_color1; - int8_t rgb_mod_rainbow_color2; - int8_t rgb_mod_rainbow_color3; + uint8_t rgb_mod_rainbow_color1; + uint8_t rgb_mod_rainbow_color2; + uint8_t rgb_mod_rainbow_color3; NotificationSettings settings; From bf50f0cd2099f6023e38e0f2865610a80ffea2be Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 5 Mar 2025 22:47:28 +0700 Subject: [PATCH 06/17] Cosmetic changes. --- .../services/notification/notification_app.c | 43 +++++++++++-------- .../services/notification/notification_app.h | 9 ++-- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 3811c2fde..c9c1faa3b 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -220,26 +220,31 @@ static void rgb_mod_rainbow_timer_callback(void* context) { furi_assert(context); NotificationApp* app = context; -// УЧЕСТЬ СТЕП и его вероятность превысить 255 // При выключении радуги активировать настроенный в меню цвет - app->rgb_mod_rainbow_color3++; - - if(app->rgb_mod_rainbow_color3 == 255) { - app->rgb_mod_rainbow_color2++; - app->rgb_mod_rainbow_color3 = 1; + if(app->rgb_mod_rainbow_red >= 255) { + app->rgb_mod_rainbow_red = 1; + app->rgb_mod_rainbow_green += app->settings.rgb_mod_rainbow_step; } - if(app->rgb_mod_rainbow_color2 == 255) { - app->rgb_mod_rainbow_color1++; - app->rgb_mod_rainbow_color2 = 1; + if(app->rgb_mod_rainbow_green >= 255) { + app->rgb_mod_rainbow_green = 1; + app->rgb_mod_rainbow_blue += app->settings.rgb_mod_rainbow_step; } - if(app->rgb_mod_rainbow_color1 == 255) { - app->rgb_mod_rainbow_color1 = 1; + + if(app->rgb_mod_rainbow_blue >= 255) { + app->rgb_mod_rainbow_blue = 1; } - FURI_LOG_I("RAINBOW", "Color3 %u", app->rgb_mod_rainbow_color3); - FURI_LOG_I("RAINBOW", "Color2 %u", app->rgb_mod_rainbow_color2); - FURI_LOG_I("RAINBOW", "Color1 %u", app->rgb_mod_rainbow_color1); + + rgb_backlight_set_custom_color(app->rgb_mod_rainbow_red, 0); + rgb_backlight_set_custom_color(app->rgb_mod_rainbow_green, 1); + rgb_backlight_set_custom_color(app->rgb_mod_rainbow_blue, 2); + + FURI_LOG_I("RAINBOW", "RED %u", app->rgb_mod_rainbow_red); + FURI_LOG_I("RAINBOW", "GREEN %u", app->rgb_mod_rainbow_green); + FURI_LOG_I("RAINBOW", "BLUE %u", app->rgb_mod_rainbow_blue); + + app->rgb_mod_rainbow_red += app->settings.rgb_mod_rainbow_step; } // END OF RGB MOD RAINBOW SECTION @@ -274,7 +279,7 @@ static void notification_process_notification_message( &app->display, notification_message->data.led.value * display_brightness_setting); reset_mask |= reset_display_mask; - //start rgb_mod_rainbow_timer when display backlight is ON + //start rgb_mod_rainbow_timer when display backlight is ON and all corresponding settings is ON too rgb_mod_rainbow_timer_control(app); } else { reset_mask &= ~reset_display_mask; @@ -621,9 +626,9 @@ static NotificationApp* notification_app_alloc(void) { app->settings.rgb_mod_rainbow = false; app->settings.rgb_mod_rainbow_speed_ms = 1000; app->settings.rgb_mod_rainbow_step = 1; - app->rgb_mod_rainbow_color1 = 1; - app->rgb_mod_rainbow_color2 = 1; - app->rgb_mod_rainbow_color3 = 1; + app->rgb_mod_rainbow_red = 1; + app->rgb_mod_rainbow_green = 1; + app->rgb_mod_rainbow_blue = 1; //define rgb_mod_rainbow_timer and they callback app->rgb_mod_rainbow_timer = @@ -699,7 +704,7 @@ int32_t notification_srv(void* p) { case SaveSettingsMessage: notification_save_settings(app); rgb_backlight_save_settings(); - //call rgb_mod_timer_control when we save settings + //call rgb_mod_timer_control (start or stop) when we save settings rgb_mod_rainbow_timer_control(app); break; case LoadSettingsMessage: diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index 13cfb7aac..5220abcd9 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -48,7 +48,7 @@ typedef struct { bool rgb_mod_installed; bool rgb_mod_rainbow; uint32_t rgb_mod_rainbow_speed_ms; - uint32_t rgb_mod_rainbow_step; + uint16_t rgb_mod_rainbow_step; } NotificationSettings; @@ -63,11 +63,10 @@ struct NotificationApp { // rainbow mode section FuriTimer* rgb_mod_rainbow_timer; - uint8_t rgb_mod_rainbow_color1; - uint8_t rgb_mod_rainbow_color2; - uint8_t rgb_mod_rainbow_color3; + uint16_t rgb_mod_rainbow_red; + uint16_t rgb_mod_rainbow_green; + uint16_t rgb_mod_rainbow_blue; - NotificationSettings settings; }; From 5e6c2383895d40244a746c51689daa6ff0299431 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Mon, 10 Mar 2025 20:51:09 +0700 Subject: [PATCH 07/17] RGB mod rainbow effect done. --- .../services/notification/notification_app.c | 133 ++++++++++++------ .../services/notification/notification_app.h | 19 +-- .../notification_settings_app.c | 95 +++++++------ .../notification_settings/rgb_backlight.c | 12 ++ .../notification_settings/rgb_backlight.h | 3 + 5 files changed, 169 insertions(+), 93 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index c9c1faa3b..8096c2cc3 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -189,7 +189,7 @@ 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) { @@ -202,10 +202,15 @@ static void rgb_mod_rainbow_timer_stop(NotificationApp* app) { furi_timer_stop(app->rgb_mod_rainbow_timer); } -// start/stop rgb_mod_rainbow_timer only if rgb_mod_installed -static void rgb_mod_rainbow_timer_control(NotificationApp* 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) { + 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)) { @@ -220,34 +225,74 @@ 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(app->rgb_mod_rainbow_red >= 255) { - app->rgb_mod_rainbow_red = 1; - app->rgb_mod_rainbow_green += app->settings.rgb_mod_rainbow_step; + rgb_mod_rainbow_update( + app->rgb_mod_rainbow_red, + app->rgb_mod_rainbow_green, + app->rgb_mod_rainbow_blue, + app->settings.display_brightness); } - if(app->rgb_mod_rainbow_green >= 255) { - app->rgb_mod_rainbow_green = 1; - app->rgb_mod_rainbow_blue += app->settings.rgb_mod_rainbow_step; - } - - if(app->rgb_mod_rainbow_blue >= 255) { - app->rgb_mod_rainbow_blue = 1; - } - - rgb_backlight_set_custom_color(app->rgb_mod_rainbow_red, 0); - rgb_backlight_set_custom_color(app->rgb_mod_rainbow_green, 1); - rgb_backlight_set_custom_color(app->rgb_mod_rainbow_blue, 2); - - FURI_LOG_I("RAINBOW", "RED %u", app->rgb_mod_rainbow_red); - FURI_LOG_I("RAINBOW", "GREEN %u", app->rgb_mod_rainbow_green); - FURI_LOG_I("RAINBOW", "BLUE %u", app->rgb_mod_rainbow_blue); - - app->rgb_mod_rainbow_red += app->settings.rgb_mod_rainbow_step; + // 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( @@ -279,8 +324,10 @@ static void notification_process_notification_message( &app->display, notification_message->data.led.value * display_brightness_setting); 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_control(app); + rgb_mod_rainbow_timer_starter(app); + } else { reset_mask &= ~reset_display_mask; notification_reset_notification_led_layer(&app->display); @@ -617,25 +664,23 @@ 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 SECTION + // --- RGB MOD INIT SETTINGS SECTION --- - //rgb mod app->settings.rgb_mod_installed = false; - - //rgb mod rainbow init settings - app->settings.rgb_mod_rainbow = false; - app->settings.rgb_mod_rainbow_speed_ms = 1000; - app->settings.rgb_mod_rainbow_step = 1; - app->rgb_mod_rainbow_red = 1; - app->rgb_mod_rainbow_green = 1; - app->rgb_mod_rainbow_blue = 1; + 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); return app; - // END OF RGB SECTION + // --- END OF RGB MOD INIT SETTINGS SECTION --- } static void notification_storage_callback(const void* message, void* context) { @@ -658,8 +703,8 @@ static void notification_apply_settings(NotificationApp* app) { } notification_apply_lcd_contrast(app); - // on system init start rgb_mod_rainbow_timer if they ON in config - rgb_mod_rainbow_timer_control(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) { @@ -702,10 +747,10 @@ int32_t notification_srv(void* p) { notification_process_internal_message(app, &message); break; case SaveSettingsMessage: - notification_save_settings(app); - rgb_backlight_save_settings(); //call rgb_mod_timer_control (start or stop) when we save settings - rgb_mod_rainbow_timer_control(app); + rgb_mod_rainbow_timer_starter(app); + rgb_backlight_save_settings(); + notification_save_settings(app); break; case LoadSettingsMessage: notification_load_settings(app); diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index 5220abcd9..54b3ab7a9 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -44,11 +44,12 @@ typedef struct { uint32_t display_off_delay_ms; int8_t contrast; bool vibro_on; - + /// --- RGB MOD SETTINGS SECTION --- bool rgb_mod_installed; - bool rgb_mod_rainbow; + 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; @@ -61,13 +62,15 @@ struct NotificationApp { NotificationLedLayer led[NOTIFICATION_LED_COUNT]; uint8_t display_led_lock; - // rainbow mode section + // --- RGB RAINBOW MODE VARIABLES SECTION --- FuriTimer* rgb_mod_rainbow_timer; - uint16_t rgb_mod_rainbow_red; - uint16_t rgb_mod_rainbow_green; - uint16_t rgb_mod_rainbow_blue; - + 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; }; -void notification_message_save_settings(NotificationApp* app); +void notification_message_save_settings(NotificationApp* app); \ No newline at end of file diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 941284c89..0def6769b 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -116,44 +116,36 @@ const char* const rgb_mod_text[RGB_MOD_COUNT] = { }; const bool rgb_mod_value[RGB_MOD_COUNT] = {false, true}; -#define RGB_MOD_RAINBOW_COUNT 2 -const char* const rgb_mod_rainbow_text[RGB_MOD_RAINBOW_COUNT] = { +#define RGB_MOD_RAINBOW_MODE_COUNT 2 +const char* const rgb_mod_rainbow_mode_text[RGB_MOD_RAINBOW_MODE_COUNT] = { "OFF", - "ON", + "Rainbow", }; -const bool rgb_mod_rainbow_value[RGB_MOD_RAINBOW_COUNT] = {false, true}; +const uint32_t rgb_mod_rainbow_mode_value[RGB_MOD_RAINBOW_MODE_COUNT] = {0, 1}; -#define RGB_MOD_RAINBOW_SPEED_COUNT 14 +#define RGB_MOD_RAINBOW_SPEED_COUNT 20 const char* const rgb_mod_rainbow_speed_text[RGB_MOD_RAINBOW_SPEED_COUNT] = { - "0.1s", - "0.2s", - "0.3s", - "0.4s", - "0.6s", - "0.8s", - "1s", - "1.2s", - "1.4s", - "1.6s", - "1.8s", - "2s", - "2.5s", - "3s"}; -const uint32_t rgb_mod_rainbow_speed_value[RGB_MOD_RAINBOW_SPEED_COUNT] = - {100, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000}; + "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] = { + 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 7 +#define RGB_MOD_RAINBOW_STEP_COUNT 10 const char* const rgb_mod_rainbow_step_text[RGB_MOD_RAINBOW_SPEED_COUNT] = { "1", "2", + "3", + "4", "5", + "6", "7", + "8", + "9", "10", - "15", - "20", - }; +}; const uint32_t rgb_mod_rainbow_step_value[RGB_MOD_RAINBOW_STEP_COUNT] = - {1, 2, 5, 7, 10, 15, 20}; + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; typedef enum { MainViewId, @@ -234,8 +226,25 @@ static void rgb_mod_installed_changed(VariableItem* item) { 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_text[index]); - app->notification->settings.rgb_mod_rainbow = rgb_mod_rainbow_value[index]; + 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]; + + // Lock/Unlock color settings if rainbow mode Enabled/Disabled + for(int i = 0; i < 4; i++) { + VariableItem* t_item = variable_item_list_get(app->variable_item_list_rgb, i); + if(app->notification->settings.rgb_mod_rainbow_mode > 0) { + variable_item_set_locked(t_item, true, "Rainbow mode\nenabled!"); + } else { + variable_item_set_locked(t_item, false, "Rainbow mode\nenabled!"); + } + } + //save settings and start/stop rgb_mod_rainbow_timer + 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); + } } static void rgb_mod_rainbow_speed_changed(VariableItem* item) { @@ -243,6 +252,8 @@ static void rgb_mod_rainbow_speed_changed(VariableItem* 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]; + //use message for restart rgb_mod_rainbow_timer with new delay + notification_message_save_settings(app->notification); } static void rgb_mod_rainbow_step_changed(VariableItem* item) { @@ -316,7 +327,8 @@ void variable_item_list_enter_callback(void* context, uint32_t index) { NotificationAppSettings* app = context; if(((app->notification->settings.rgb_mod_installed) || - (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) && (index == 0)) { + (furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) && + (index == 0)) { view_dispatcher_switch_to_view(app->view_dispatcher, RGBViewId); } } @@ -405,7 +417,7 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_text(item, vibro_text[value_index]); } - // RGB settings view + // --- RGB SETTINGS VIEW --- 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 @@ -436,7 +448,7 @@ static NotificationAppSettings* alloc_settings(void) { 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, "Rainbow mode\nenabled!"); + item, (app->notification->settings.rgb_mod_rainbow_mode > 0), "Rainbow mode\nenabled!"); temp_item = item; // Custom Color - REFACTOR THIS @@ -448,7 +460,7 @@ static NotificationAppSettings* alloc_settings(void) { 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, "Rainbow mode\nenabled!"); + item, (app->notification->settings.rgb_mod_rainbow_mode > 0), "Rainbow mode\nenabled!"); item = variable_item_list_add( app->variable_item_list_rgb, "Custom Green", 255, color_set_custom_green, app); @@ -457,7 +469,7 @@ static NotificationAppSettings* alloc_settings(void) { 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, "Rainbow mode\nenabled!"); + item, (app->notification->settings.rgb_mod_rainbow_mode > 0), "Rainbow mode\nenabled!"); item = variable_item_list_add( app->variable_item_list_rgb, "Custom Blue", 255, color_set_custom_blue, app); @@ -466,20 +478,21 @@ static NotificationAppSettings* alloc_settings(void) { 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, "Rainbow mode\nenabled!"); - // End of RGB + item, (app->notification->settings.rgb_mod_rainbow_mode > 0), "Rainbow mode\nenabled!"); // Rainbow (based on Willy-JL idea) settings item = variable_item_list_add( app->variable_item_list_rgb, "Rainbow mode", - RGB_MOD_RAINBOW_COUNT, + RGB_MOD_RAINBOW_MODE_COUNT, rgb_mod_rainbow_changed, app); - value_index = value_index_bool( - app->notification->settings.rgb_mod_rainbow, rgb_mod_rainbow_value, RGB_MOD_RAINBOW_COUNT); + value_index = value_index_uint32( + app->notification->settings.rgb_mod_rainbow_mode, + rgb_mod_rainbow_mode_value, + RGB_MOD_RAINBOW_MODE_COUNT); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, rgb_mod_rainbow_text[value_index]); + variable_item_set_current_value_text(item, rgb_mod_rainbow_mode_text[value_index]); item = variable_item_list_add( app->variable_item_list_rgb, @@ -507,7 +520,7 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, rgb_mod_rainbow_step_text[value_index]); - // End of Rainbow settings + // --- End of RGB SETTING VIEW --- app->view_dispatcher = view_dispatcher_alloc(); view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); @@ -542,4 +555,4 @@ int32_t notification_settings_app(void* p) { free_settings(app); return 0; - } +} diff --git a/applications/settings/notification_settings/rgb_backlight.c b/applications/settings/notification_settings/rgb_backlight.c index 4edd77568..4fcb898f7 100644 --- a/applications/settings/notification_settings/rgb_backlight.c +++ b/applications/settings/notification_settings/rgb_backlight.c @@ -215,3 +215,15 @@ void rgb_backlight_update(uint8_t brightness, bool bypass) { 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 index f215ed312..66e0e26a1 100644 --- a/applications/settings/notification_settings/rgb_backlight.h +++ b/applications/settings/notification_settings/rgb_backlight.h @@ -89,3 +89,6 @@ uint8_t rgb_backlight_get_color_count(void); * @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); From 82d3f452cd8093fff0d30f6dc4b94bb46c625b68 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Mon, 10 Mar 2025 21:02:37 +0700 Subject: [PATCH 08/17] Code cosmetic changes. --- .../notification_settings_app.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 0def6769b..da54ea8f2 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -109,6 +109,7 @@ const char* const vibro_text[VIBRO_COUNT] = { }; const bool vibro_value[VIBRO_COUNT] = {false, true}; +// --- RGB MOD RAINBOW --- #define RGB_MOD_COUNT 2 const char* const rgb_mod_text[RGB_MOD_COUNT] = { "OFF", @@ -152,6 +153,8 @@ typedef enum { RGBViewId, } ViewId; +// --- END OF RGB MOD RAINBOW --- + static void contrast_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -216,6 +219,8 @@ static void vibro_changed(VariableItem* item) { notification_message(app->notification, &sequence_single_vibro); } +// --- RGB MOD AND RAINBOW --- + 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); @@ -316,11 +321,6 @@ static void color_set_custom_blue(VariableItem* item) { notification_message(app->notification, &sequence_display_backlight_on); } -static uint32_t notification_app_settings_exit(void* context) { - UNUSED(context); - return VIEW_NONE; -} - // open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_mod_install is true) void variable_item_list_enter_callback(void* context, uint32_t index) { UNUSED(context); @@ -338,6 +338,12 @@ static uint32_t notification_app_rgb_settings_exit(void* context) { UNUSED(context); return MainViewId; } +// --- END OF RGB MOD AND RAINBOW --- + +static uint32_t notification_app_settings_exit(void* context) { + UNUSED(context); + return VIEW_NONE; +} static NotificationAppSettings* alloc_settings(void) { NotificationAppSettings* app = malloc(sizeof(NotificationAppSettings)); @@ -346,8 +352,10 @@ static NotificationAppSettings* alloc_settings(void) { app->variable_item_list = variable_item_list_alloc(); View* view = variable_item_list_get_view(app->variable_item_list); + //set callback for exit from view view_set_previous_callback(view, notification_app_settings_exit); + // set callback for OK pressed in menu variable_item_list_set_enter_callback( app->variable_item_list, variable_item_list_enter_callback, app); From 687a6fd630c2f401897f7484c2796a12088d8375 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 11 Mar 2025 15:11:01 +0700 Subject: [PATCH 09/17] User Interface bug removed. --- .../notification_settings/notification_settings_app.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index da54ea8f2..8c6871acd 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -234,8 +234,10 @@ static void rgb_mod_rainbow_changed(VariableItem* 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]; - // Lock/Unlock color settings if rainbow mode Enabled/Disabled - for(int i = 0; i < 4; i++) { + // 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) { variable_item_set_locked(t_item, true, "Rainbow mode\nenabled!"); From 9e6593c09e7c57745b1546892fb5f090df78b06a Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 11 Mar 2025 18:54:12 +0700 Subject: [PATCH 10/17] Start moving RGB MOD from Notification to RGB MOD service. --- applications/services/application.fam | 1 + .../services/rgb_backlight/application.fam | 11 +++++++++++ .../services/rgb_backlight/rgb_backlight.c | 15 +++++++++++++++ .../services/rgb_backlight/rgb_backlight.h | 0 applications/settings/application.fam | 2 ++ .../rgb_backlight_settings/application.fam | 9 +++++++++ .../rgb_backlight_settings.c | 13 +++++++++++++ .../rgb_backlight_settings.h | 0 lib/drivers/SK6805.c | 4 ++-- targets/f7/api_symbols.csv | 1 + 10 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 applications/services/rgb_backlight/application.fam create mode 100644 applications/services/rgb_backlight/rgb_backlight.c create mode 100644 applications/services/rgb_backlight/rgb_backlight.h create mode 100644 applications/settings/rgb_backlight_settings/application.fam create mode 100644 applications/settings/rgb_backlight_settings/rgb_backlight_settings.c create mode 100644 applications/settings/rgb_backlight_settings/rgb_backlight_settings.h diff --git a/applications/services/application.fam b/applications/services/application.fam index 90631408a..8cfb22cdb 100644 --- a/applications/services/application.fam +++ b/applications/services/application.fam @@ -11,5 +11,6 @@ App( "loader", "power", "namechanger_srv", + "rgb_backlight", ], ) diff --git a/applications/services/rgb_backlight/application.fam b/applications/services/rgb_backlight/application.fam new file mode 100644 index 000000000..168a7bbd0 --- /dev/null +++ b/applications/services/rgb_backlight/application.fam @@ -0,0 +1,11 @@ +App( + appid="rgb_backlight", + name="RgbBackLightSrv", + apptype=FlipperAppType.SERVICE, + entry_point="rgb_backlight_srv", + cdefines=["SRV_RGB_BACKLIGHT"], + stack_size=1 * 1024, + order=99, + sdk_headers=["rgb_backlight.h"], + provides=["rgb_backlight_settings"], +) \ No newline at end of file diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c new file mode 100644 index 000000000..046cd4771 --- /dev/null +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include "rgb_backlight.h" + +#define TAG "RGB_BACKLIGHT_SRV" + +int32_t rgb_backlight_srv (void* p){ +UNUSED (p); +while (1){ + FURI_LOG_I (TAG,"working"); + furi_delay_ms (2000); +} +return 0; +} \ No newline at end of file diff --git a/applications/services/rgb_backlight/rgb_backlight.h b/applications/services/rgb_backlight/rgb_backlight.h new file mode 100644 index 000000000..e69de29bb diff --git a/applications/settings/application.fam b/applications/settings/application.fam index 1d6db35a7..8e184a706 100644 --- a/applications/settings/application.fam +++ b/applications/settings/application.fam @@ -6,6 +6,8 @@ App( "passport", "system_settings", "clock_settings", + "input_settings", + "rgb_backlight_settings", "about", ], ) diff --git a/applications/settings/rgb_backlight_settings/application.fam b/applications/settings/rgb_backlight_settings/application.fam new file mode 100644 index 000000000..50621228a --- /dev/null +++ b/applications/settings/rgb_backlight_settings/application.fam @@ -0,0 +1,9 @@ +App( + appid="rgb_backlight_settings", + name="RGB backlight", + apptype=FlipperAppType.SETTINGS, + entry_point="rgb_backlight_settings", + requires=["rgb_backlight"], + stack_size=1 * 1024, + order=110, +) \ No newline at end of file diff --git a/applications/settings/rgb_backlight_settings/rgb_backlight_settings.c b/applications/settings/rgb_backlight_settings/rgb_backlight_settings.c new file mode 100644 index 000000000..096852063 --- /dev/null +++ b/applications/settings/rgb_backlight_settings/rgb_backlight_settings.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include "rgb_backlight_settings.h" + +#define TAG "RGB_BACKLIGHT_SETTINGS" + +int32_t rgb_backlight_settings (void* p){ +UNUSED (p); +FURI_LOG_I (TAG,"Settings"); +furi_delay_ms (2000); +return 0; +} \ No newline at end of file diff --git a/applications/settings/rgb_backlight_settings/rgb_backlight_settings.h b/applications/settings/rgb_backlight_settings/rgb_backlight_settings.h new file mode 100644 index 000000000..e69de29bb diff --git a/lib/drivers/SK6805.c b/lib/drivers/SK6805.c index 8158c55a4..b6f525eb8 100644 --- a/lib/drivers/SK6805.c +++ b/lib/drivers/SK6805.c @@ -58,7 +58,7 @@ void SK6805_set_led_color(uint8_t led_index, uint8_t r, uint8_t g, uint8_t b) { void SK6805_update(void) { SK6805_init(); FURI_CRITICAL_ENTER(); - furi_delay_us(150); + furi_delay_us(100); uint32_t end; /* Последовательная отправка цветов светодиодов */ for(uint8_t lednumber = 0; lednumber < SK6805_LED_COUNT; lednumber++) { @@ -98,6 +98,6 @@ void SK6805_update(void) { } } } - furi_delay_us(150); + furi_delay_us(100); FURI_CRITICAL_EXIT(); } diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index 7ad21efb5..f78775215 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -39,6 +39,7 @@ Header,+,applications/services/locale/locale.h,, Header,+,applications/services/notification/notification.h,, Header,+,applications/services/notification/notification_messages.h,, Header,+,applications/services/power/power_service/power.h,, +Header,+,applications/services/rgb_backlight/rgb_backlight.h,, Header,+,applications/services/rpc/rpc_app.h,, Header,+,applications/services/storage/storage.h,, Header,+,lib/bit_lib/bit_lib.h,, From 4045628ac6552d4631376d90d417c295fda70d71 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 12 Mar 2025 02:19:17 +0700 Subject: [PATCH 11/17] Working on moving RGB routines from Notification to RGB service --- applications/services/input/input_settings.c | 1 - .../services/rgb_backlight/application.fam | 1 - .../services/rgb_backlight/rgb_backlight.c | 153 +++++++++++++++++- .../services/rgb_backlight/rgb_backlight.h | 44 +++++ .../rgb_backlight/rgb_backlight_settings.c | 95 +++++++++++ .../rgb_backlight/rgb_backlight_settings.h | 31 ++++ applications/settings/application.fam | 1 - .../rgb_backlight_settings/application.fam | 9 -- .../rgb_backlight_settings.c | 13 -- .../rgb_backlight_settings.h | 0 targets/f7/api_symbols.csv | 8 +- 11 files changed, 324 insertions(+), 32 deletions(-) create mode 100644 applications/services/rgb_backlight/rgb_backlight_settings.c create mode 100644 applications/services/rgb_backlight/rgb_backlight_settings.h delete mode 100644 applications/settings/rgb_backlight_settings/application.fam delete mode 100644 applications/settings/rgb_backlight_settings/rgb_backlight_settings.c delete mode 100644 applications/settings/rgb_backlight_settings/rgb_backlight_settings.h diff --git a/applications/services/input/input_settings.c b/applications/services/input/input_settings.c index cd3de6d50..f1f18ba3d 100644 --- a/applications/services/input/input_settings.c +++ b/applications/services/input/input_settings.c @@ -30,7 +30,6 @@ void input_settings_load(InputSettings* settings) { sizeof(InputSettings), INPUT_SETTINGS_MAGIC, INPUT_SETTINGS_VER); - // if config previous version - load it and inicialize new settings } // in case of another config version we exit from useless cycle to next step } while(false); diff --git a/applications/services/rgb_backlight/application.fam b/applications/services/rgb_backlight/application.fam index 168a7bbd0..bb42d7b83 100644 --- a/applications/services/rgb_backlight/application.fam +++ b/applications/services/rgb_backlight/application.fam @@ -7,5 +7,4 @@ App( stack_size=1 * 1024, order=99, sdk_headers=["rgb_backlight.h"], - provides=["rgb_backlight_settings"], ) \ 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 046cd4771..f198ae13f 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -1,15 +1,156 @@ +/* + RGB BackLight Service based on + 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 #include +#include +#include #include "rgb_backlight.h" + +#define STATIC_COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightStaticColor)) + #define TAG "RGB_BACKLIGHT_SRV" -int32_t rgb_backlight_srv (void* p){ -UNUSED (p); -while (1){ - FURI_LOG_I (TAG,"working"); - furi_delay_ms (2000); +static const RGBBacklightStaticColor 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}, +}; + +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(); } -return 0; + +static void rainbow_timer_callback(void* context) { + furi_assert(context); + RGBBacklightApp* app = 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 + case 1: + app->rainbow_green += app->settings->rainbow_step; + if(app->rainbow_green >= 255) { + app->rainbow_green = 255; + app->rainbow_stage++; + } + break; + // yellow red to green + case 2: + app->rainbow_red -= app->settings->rainbow_step; + if(app->rainbow_red <= 0) { + app->rainbow_red = 0; + app->rainbow_stage++; + } + break; + // from green to light blue + case 3: + app->rainbow_blue += app->settings->rainbow_step; + if(app->rainbow_blue >= 255) { + app->rainbow_blue = 255; + app->rainbow_stage++; + } + break; + //from light blue to blue + case 4: + app->rainbow_green -= app->settings->rainbow_step; + if(app->rainbow_green <= 0) { + app->rainbow_green = 0; + app->rainbow_stage++; + } + break; + //from blue to violet + case 5: + app->rainbow_red += app->settings->rainbow_step; + if(app->rainbow_red >= 255) { + app->rainbow_red = 255; + app->rainbow_stage++; + } + break; + //from violet to red + case 6: + app->rainbow_blue -= app->settings->rainbow_step; + if(app->rainbow_blue <= 0) { + app->rainbow_blue = 0; + app->rainbow_stage = 1; + } + break; + default: + break; + } + + rgb_backlight_set_custom_color( + app->rainbow_red, + app->rainbow_green, + app->rainbow_blue, + 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){ + // 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)); + furi_record_create(RECORD_RGB_BACKLIGHT, app); + + //define rainbow_timer and they callback + app->rainbow_timer = + furi_timer_alloc(rainbow_timer_callback, FuriTimerTypePeriodic, app); + + // load or init new settings and apply it + rgb_backlight_settings_load (app->settings); + rgb_backlight_settings_apply (app->settings); + + UNUSED(p); + while(1) { + FURI_LOG_I(TAG, "working"); + furi_delay_ms(2000); + } + return 0; } \ No newline at end of file diff --git a/applications/services/rgb_backlight/rgb_backlight.h b/applications/services/rgb_backlight/rgb_backlight.h index e69de29bb..88f3270c1 100644 --- a/applications/services/rgb_backlight/rgb_backlight.h +++ b/applications/services/rgb_backlight/rgb_backlight.h @@ -0,0 +1,44 @@ +/* + RGB BackLight Service based on + 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 "rgb_backlight_settings.h" +#include "SK6805.h" + +typedef struct { + char* name; + uint8_t red; + uint8_t green; + uint8_t blue; +} RGBBacklightStaticColor; + +typedef struct { + FuriTimer* rainbow_timer; + + int16_t rainbow_red; + int16_t rainbow_green; + int16_t rainbow_blue; + uint8_t rainbow_stage; + + RGBBacklightSettings* settings; + +} RGBBacklightApp; + +#define RECORD_RGB_BACKLIGHT "rgb_backlight" + diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c new file mode 100644 index 000000000..62cc47994 --- /dev/null +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -0,0 +1,95 @@ +#include "rgb_backlight_settings.h" + +#include +#include + +#define TAG "RGBBackligthSettings" + +#define RGB_BACKLIGHT_SETTINGS_FILE_NAME ".rgb_backlight.settings" +#define RGB_BACKLIGHT_SETTINGS_PATH INT_PATH(RGB_BACKLIGHT_SETTINGS_FILE_NAME) + +#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 + +//pervious settings must be copyed from previous rgb_backlight_settings.h file +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; + + uint32_t rainbow_mode; + uint32_t rainbow_speed_ms; + uint16_t rainbow_step; +} RGBBacklightSettingsPrevious; + +void rgb_backlight_settings_load(RGBBacklightSettings* settings) { + furi_assert(settings); + + bool success = false; + + //a useless cycle do-while, may will be used in future with anoter condition + do { + // take version from settings file metadata, if cant then break and fill settings with 0 and save to settings file; + uint8_t version; + if(!saved_struct_get_metadata(RGB_BACKLIGHT_SETTINGS_PATH, NULL, &version, NULL)) break; + + // if config actual version - load it directly + if(version == RGB_BACKLIGHT_SETTINGS_VER) { + success = saved_struct_load( + RGB_BACKLIGHT_SETTINGS_PATH, + settings, + sizeof(RGBBacklightSettings), + RGB_BACKLIGHT_SETTINGS_MAGIC, + RGB_BACKLIGHT_SETTINGS_VER); + // if config previous version - load it and inicialize new settings + } else if(version == RGB_BACKLIGHT_SETTINGS_VER_PREV) { + RGBBacklightSettingsPrevious* settings_previous = malloc(sizeof(RGBBacklightSettingsPrevious)); + + success = saved_struct_load( + RGB_BACKLIGHT_SETTINGS_PATH, + settings_previous, + sizeof(RGBBacklightSettingsPrevious), + RGB_BACKLIGHT_SETTINGS_MAGIC, + RGB_BACKLIGHT_SETTINGS_VER_PREV); + // new settings initialization + if(success) { + // copy loaded old settings as part of new + uint32_t size = sizeof(settings); + memcpy(settings, settings_previous, size); + // set new options to initial value + // settings.something = something; + } + + free(settings_previous); + } + // in case of another config version we exit from useless cycle to next step + } while(false); + + // fill settings with 0 and save to settings file; + // Orange color (index=0) will be default + if(!success) { + FURI_LOG_W(TAG, "Failed to load file, using defaults 0"); + memset(settings, 0, sizeof(RGBBacklightSettings)); + rgb_backlight_settings_save(settings); + } +} + +void rgb_backlight_settings_save(const RGBBacklightSettings* settings) { + furi_assert(settings); + + const bool success = saved_struct_save( + RGB_BACKLIGHT_SETTINGS_PATH, + settings, + sizeof(RGBBacklightSettings), + RGB_BACKLIGHT_SETTINGS_MAGIC, + RGB_BACKLIGHT_SETTINGS_VER); + + if(!success) { + FURI_LOG_E(TAG, "Failed to save rgb_backlight_settings file"); + } +} diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.h b/applications/services/rgb_backlight/rgb_backlight_settings.h new file mode 100644 index 000000000..f7a4af177 --- /dev/null +++ b/applications/services/rgb_backlight/rgb_backlight_settings.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include + +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; + float brightness; + + uint32_t rainbow_mode; + uint32_t rainbow_speed_ms; + uint16_t rainbow_step; + +} RGBBacklightSettings; + +#ifdef __cplusplus +extern "C" { +#endif + +void rgb_backlight_settings_load(RGBBacklightSettings* settings); +void rgb_backlight_settings_save(const RGBBacklightSettings* settings); + +#ifdef __cplusplus +} +#endif diff --git a/applications/settings/application.fam b/applications/settings/application.fam index 8e184a706..2ad4aa030 100644 --- a/applications/settings/application.fam +++ b/applications/settings/application.fam @@ -7,7 +7,6 @@ App( "system_settings", "clock_settings", "input_settings", - "rgb_backlight_settings", "about", ], ) diff --git a/applications/settings/rgb_backlight_settings/application.fam b/applications/settings/rgb_backlight_settings/application.fam deleted file mode 100644 index 50621228a..000000000 --- a/applications/settings/rgb_backlight_settings/application.fam +++ /dev/null @@ -1,9 +0,0 @@ -App( - appid="rgb_backlight_settings", - name="RGB backlight", - apptype=FlipperAppType.SETTINGS, - entry_point="rgb_backlight_settings", - requires=["rgb_backlight"], - stack_size=1 * 1024, - order=110, -) \ No newline at end of file diff --git a/applications/settings/rgb_backlight_settings/rgb_backlight_settings.c b/applications/settings/rgb_backlight_settings/rgb_backlight_settings.c deleted file mode 100644 index 096852063..000000000 --- a/applications/settings/rgb_backlight_settings/rgb_backlight_settings.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include "rgb_backlight_settings.h" - -#define TAG "RGB_BACKLIGHT_SETTINGS" - -int32_t rgb_backlight_settings (void* p){ -UNUSED (p); -FURI_LOG_I (TAG,"Settings"); -furi_delay_ms (2000); -return 0; -} \ No newline at end of file diff --git a/applications/settings/rgb_backlight_settings/rgb_backlight_settings.h b/applications/settings/rgb_backlight_settings/rgb_backlight_settings.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index f78775215..310a669ef 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,83.0,, +Version,+,83.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,, @@ -411,6 +411,10 @@ Function,-,LL_mDelay,void,uint32_t Function,-,Osal_MemCmp,int,"const void*, const void*, unsigned int" Function,-,Osal_MemCpy,void*,"void*, const void*, unsigned int" Function,-,Osal_MemSet,void*,"void*, int, unsigned int" +Function,+,SK6805_get_led_count,uint8_t, +Function,+,SK6805_init,void, +Function,+,SK6805_set_led_color,void,"uint8_t, uint8_t, uint8_t, uint8_t" +Function,+,SK6805_update,void, Function,-,SystemCoreClockUpdate,void, Function,-,SystemInit,void, Function,-,_Exit,void,int @@ -3139,6 +3143,8 @@ 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_settings_load,void,RGBBacklightSettings* +Function,+,rgb_backlight_settings_save,void,const RGBBacklightSettings* Function,-,rindex,char*,"const char*, int" Function,-,rint,double,double Function,-,rintf,float,float From 7a19c9e5494839e2aa496aebd9932e5b47c0ffa1 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 12 Mar 2025 18:15:38 +0700 Subject: [PATCH 12/17] 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); } From e589cf7246d9aab24cfa7d9b5c2980ea4910147a Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Thu, 13 Mar 2025 00:42:03 +0700 Subject: [PATCH 13/17] Still working --- applications/services/rgb_backlight/rgb_backlight.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index 64c04b9cb..bb1480793 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -71,8 +71,8 @@ void rgb_backlight_set_static_color(uint8_t index, float brightness) { SK6805_set_led_color(i, r, g, b); } - furi_record_close(RECORD_RGB_BACKLIGHT); SK6805_update(); + furi_record_close(RECORD_RGB_BACKLIGHT); } // void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue, float brightness) { @@ -208,6 +208,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)); + furi_record_create(RECORD_RGB_BACKLIGHT, app); //define rainbow_timer and they callback @@ -215,12 +216,13 @@ int32_t rgb_backlight_srv (void* p) { furi_timer_alloc(rainbow_timer_callback, FuriTimerTypePeriodic, app); // settings load or create default + app->settings = malloc(sizeof(RGBBacklightSettings)); rgb_backlight_settings_load (app->settings); // Init app variables app->current_red = 255; app->current_green = 60; - app->current_green = 0; + app->current_blue = 0; app->rainbow_stage = 1; // а нужно ли это все при старте сервиса, если мы получим сигнал на подсветку от Нотификейшена. Может вынести в ИНИТ и при старте нотиф дернуть его 1 раз From c9313c6f52c3d530e63e7f0ebc4138a5fdc905e3 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Thu, 13 Mar 2025 18:06:39 +0700 Subject: [PATCH 14/17] still fucking )) --- .../services/notification/notification_app.c | 6 +- .../services/rgb_backlight/rgb_backlight.c | 88 ++++++++----------- .../services/rgb_backlight/rgb_backlight.h | 4 +- .../rgb_backlight/rgb_backlight_settings.c | 2 + .../notification_settings_app.c | 19 ++-- targets/f7/api_symbols.csv | 4 +- 6 files changed, 56 insertions(+), 67 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index afb900706..df3bf213e 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -748,9 +748,9 @@ int32_t notification_srv(void* p) { notification_process_internal_message(app, &message); break; case SaveSettingsMessage: - //call rgb_mod_timer_control (start or stop) when we save settings - rainbow_timer_starter(app->rgb_srv); - rgb_backlight_settings_save(app->rgb_srv->settings); + // //call rgb_mod_timer_control (start or stop) when we 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/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index bb1480793..f449edbee 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 PREDEFINED_COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightPredefinedColor)) +#define COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightColor)) #define TAG "RGB_BACKLIGHT_SRV" -static const RGBBacklightPredefinedColor colors[] = { +static const RGBBacklightColor colors[] = { {"Orange", 255, 60, 0}, {"Yellow", 255, 144, 0}, {"Spring", 167, 255, 0}, @@ -47,43 +47,32 @@ static const RGBBacklightPredefinedColor colors[] = { }; uint8_t rgb_backlight_get_color_count(void) { - return PREDEFINED_COLOR_COUNT; + return 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 +// use RECORD for acces to rgb service instance and update current colors by static +void rgb_backlight_set_static_color(uint8_t index) { RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); - - for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - 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); - } - - SK6805_update(); + app->current_red = colors[index].red; + app->current_green = colors[index].green; + app->current_blue = colors[index].blue; + furi_record_close(RECORD_RGB_BACKLIGHT); } -// 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(); -// } +// 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); +} // apply new brightness to current display color set void rgb_backlight_update (float brightness) { @@ -96,10 +85,10 @@ void rgb_backlight_update (float brightness) { uint8_t b = app->current_blue * brightness; SK6805_set_led_color(i, r, g, b); } - - furi_record_close(RECORD_RGB_BACKLIGHT); SK6805_update(); + furi_record_close(RECORD_RGB_BACKLIGHT); } + //start furi timer for rainbow void rainbow_timer_start(RGBBacklightApp* app) { furi_timer_start( @@ -115,11 +104,6 @@ void rainbow_timer_stop(RGBBacklightApp* app) { 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)) { @@ -133,7 +117,7 @@ static void rainbow_timer_callback(void* context) { furi_assert(context); RGBBacklightApp* app = context; - // if rgb_mode_rainbow_mode is rainbow do rainbow effect + // 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) @@ -187,18 +171,12 @@ static void rainbow_timer_callback(void* context) { default: break; } - - // rgb_backlight_set_custom_color( - // app->current_red, - // app->current_green, - // app->current_blue, - // app->settings->brightness); - } - + } + //rgb_backlight_set_custom_color(app->current_red,app->current_green,app->current_blue); rgb_backlight_update (app->settings->brightness); - // if rgb_mode_rainbow_mode is ..... do another effect - // if(app->settings.rainbow_mode == 2) { + // if rainbow_mode is ..... do another effect + // if(app->settings.rainbow_mode == ...) { // } } @@ -206,7 +184,7 @@ int32_t rgb_backlight_srv (void* p) { UNUSED(p); // Define object app (full app with settings and running variables), - // allocate memory and create record for access to app structure from outside + // allocate memory and create RECORD for access to app structure from outside RGBBacklightApp* app = malloc(sizeof(RGBBacklightApp)); furi_record_create(RECORD_RGB_BACKLIGHT, app); @@ -220,22 +198,28 @@ int32_t rgb_backlight_srv (void* p) { rgb_backlight_settings_load (app->settings); // Init app variables - app->current_red = 255; - app->current_green = 60; - app->current_blue = 0; app->rainbow_stage = 1; + // app->current_red = 255; + // app->current_green = 60; + // app->current_blue = 0; + // а нужно ли это все при старте сервиса, если мы получим сигнал на подсветку от Нотификейшена. Может вынести в ИНИТ и при старте нотиф дернуть его 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 ) { + // app->current_red = 255; + // app->current_green = 0; + // app->current_blue = 0; rainbow_timer_starter(app); } else { - rgb_backlight_set_static_color(app->settings->static_color_index, app->settings->brightness); + rgb_backlight_set_static_color(app->settings->static_color_index); + rgb_backlight_update (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); + rgb_backlight_set_static_color(0); + rgb_backlight_update (app->settings->brightness); } while(1) { diff --git a/applications/services/rgb_backlight/rgb_backlight.h b/applications/services/rgb_backlight/rgb_backlight.h index 531d3a9e7..b0f5530ee 100644 --- a/applications/services/rgb_backlight/rgb_backlight.h +++ b/applications/services/rgb_backlight/rgb_backlight.h @@ -31,7 +31,7 @@ typedef struct { uint8_t red; uint8_t green; uint8_t blue; -} RGBBacklightPredefinedColor; +} RGBBacklightColor; typedef struct { FuriTimer* rainbow_timer; @@ -48,7 +48,7 @@ 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 rgb_backlight_set_static_color(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 9cf1c1440..45a7ae65e 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -91,5 +91,7 @@ void rgb_backlight_settings_save(const RGBBacklightSettings* settings) { if(!success) { FURI_LOG_E(TAG, "Failed to save rgb_backlight_settings file"); + } else { + FURI_LOG_I(TAG, "Settings saved"); } } diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index c2262d327..c62c78dd8 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -246,12 +246,13 @@ static void rgb_mod_rainbow_changed(VariableItem* item) { variable_item_set_locked(t_item, false, "Rainbow mode\nenabled!"); } } - //save settings and start/stop rgb_mod_rainbow_timer - notification_message_save_settings(app->notification); + + rainbow_timer_starter(app->notification->rgb_srv); + rgb_backlight_settings_save(app->notification->rgb_srv->settings); // restore saved rgb backlight settings if we switch_off rainbow mode if(app->notification->rgb_srv->settings->rainbow_mode == 0) { - rgb_backlight_update(app->notification->settings.display_brightness); + rgb_backlight_update(app->notification->rgb_srv->settings->brightness); } } @@ -271,16 +272,17 @@ static void rgb_mod_rainbow_step_changed(VariableItem* item) { app->notification->rgb_srv->settings->rainbow_step = rgb_mod_rainbow_step_value[index]; } -// --- Set RGB backlight colors --- +// Set rgb_backlight colors static and custom 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_static_color(index,app->notification->rgb_srv->settings->brightness); + rgb_backlight_set_static_color(index); variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); + + rgb_backlight_update(app->notification->rgb_srv->settings->brightness); notification_message(app->notification, &sequence_display_backlight_on); } -// TODO: refactor and fix this 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); @@ -289,8 +291,7 @@ static void color_set_custom_red(VariableItem* item) { 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); @@ -299,6 +300,8 @@ static void color_set_custom_red(VariableItem* item) { // 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); notification_message(app->notification, &sequence_display_backlight_on); } static void color_set_custom_green(VariableItem* item) { diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index f25b9c273..ecb5047e8 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,84.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,7 +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_static_color,void,"uint8_t, float" +Function,+,rgb_backlight_set_static_color,void,uint8_t Function,+,rgb_backlight_settings_load,void,RGBBacklightSettings* Function,+,rgb_backlight_settings_save,void,const RGBBacklightSettings* Function,+,rgb_backlight_update,void,float From 9b3d737693c072a91ed7bf47548358b168fa3ff0 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Fri, 14 Mar 2025 02:18:14 +0700 Subject: [PATCH 15/17] Moving RGB Backlight setings and effect to rgb service finished. --- .../services/notification/notification_app.c | 3 - .../services/rgb_backlight/rgb_backlight.c | 95 ++++----- .../services/rgb_backlight/rgb_backlight.h | 3 +- .../rgb_backlight/rgb_backlight_settings.c | 8 +- .../notification_settings_app.c | 193 +++++++++++------- targets/f7/api_symbols.csv | 3 +- targets/f7/furi_hal/furi_hal_light.c | 36 ++-- 7 files changed, 194 insertions(+), 147 deletions(-) mode change 100644 => 100755 targets/f7/api_symbols.csv diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index df3bf213e..4bd93cfbc 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -748,9 +748,6 @@ int32_t notification_srv(void* p) { notification_process_internal_message(app, &message); break; case SaveSettingsMessage: - // //call rgb_mod_timer_control (start or stop) when we 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/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index f449edbee..5510ea916 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -24,7 +24,6 @@ #include #include "rgb_backlight.h" - #define COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightColor)) #define TAG "RGB_BACKLIGHT_SRV" @@ -47,21 +46,27 @@ static const RGBBacklightColor colors[] = { }; uint8_t rgb_backlight_get_color_count(void) { - return COLOR_COUNT; - } + return COLOR_COUNT; +} const char* rgb_backlight_get_color_text(uint8_t index) { - return colors[index].name; - } + return colors[index].name; +} // use RECORD for acces to rgb service instance and update current colors by static void rgb_backlight_set_static_color(uint8_t index) { RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT); - app->current_red = colors[index].red; - app->current_green = colors[index].green; - app->current_blue = colors[index].blue; - + //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); } @@ -74,15 +79,14 @@ void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue) { furi_record_close(RECORD_RGB_BACKLIGHT); } -// 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 +// 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); - + 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; + 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); SK6805_set_led_color(i, r, g, b); } SK6805_update(); @@ -91,8 +95,7 @@ void rgb_backlight_update (float brightness) { //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)); + furi_timer_start(app->rainbow_timer, furi_ms_to_ticks(app->settings->rainbow_speed_ms)); } //stop furi timer for rainbow @@ -102,17 +105,15 @@ void rainbow_timer_stop(RGBBacklightApp* app) { // 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) { - rainbow_timer_start(app); - } else { - if(furi_timer_is_running(app->rainbow_timer)) { - rainbow_timer_stop(app); - } + + if((app->settings->rainbow_mode > 0) && (app->settings->rgb_mod_installed)) { + 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; @@ -171,60 +172,50 @@ static void rainbow_timer_callback(void* context) { default: break; } - } - //rgb_backlight_set_custom_color(app->current_red,app->current_green,app->current_blue); - rgb_backlight_update (app->settings->brightness); + } + 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) { +int32_t rgb_backlight_srv(void* p) { UNUSED(p); - // Define object app (full app with settings and running variables), + // 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)); - furi_record_create(RECORD_RGB_BACKLIGHT, app); //define rainbow_timer and they callback - app->rainbow_timer = - furi_timer_alloc(rainbow_timer_callback, FuriTimerTypePeriodic, app); + app->rainbow_timer = furi_timer_alloc(rainbow_timer_callback, FuriTimerTypePeriodic, app); // settings load or create default app->settings = malloc(sizeof(RGBBacklightSettings)); - rgb_backlight_settings_load (app->settings); + rgb_backlight_settings_load(app->settings); // Init app variables app->rainbow_stage = 1; - // app->current_red = 255; - // app->current_green = 60; - // app->current_blue = 0; - - // а нужно ли это все при старте сервиса, если мы получим сигнал на подсветку от Нотификейшена. Может вынести в ИНИТ и при старте нотиф дернуть его 1 раз - // if rgb_mod_installed start rainbow or set static color from settings (default index = 0) + // 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 ) { - // app->current_red = 255; - // app->current_green = 0; - // app->current_blue = 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); + rgb_backlight_update(app->settings->brightness); } - // if not rgb_mod_installed set default static orange color (index=0) + // if rgb mod not installed - set default static orange color (index=0) } else { rgb_backlight_set_static_color(0); - rgb_backlight_update (app->settings->brightness); - } + rgb_backlight_update(app->settings->brightness); + } while(1) { - FURI_LOG_I(TAG, "working"); - furi_delay_ms(2000); + // place for message queue and other future options + furi_delay_ms(5000); + FURI_LOG_I(TAG, "Service is running"); } return 0; -} \ No newline at end of file +} diff --git a/applications/services/rgb_backlight/rgb_backlight.h b/applications/services/rgb_backlight/rgb_backlight.h index b0f5530ee..fd683bf16 100644 --- a/applications/services/rgb_backlight/rgb_backlight.h +++ b/applications/services/rgb_backlight/rgb_backlight.h @@ -47,7 +47,8 @@ typedef struct { #define RECORD_RGB_BACKLIGHT "rgb_backlight" -void rgb_backlight_update (float brightness); +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 rainbow_timer_stop(RGBBacklightApp* app); void rainbow_timer_start(RGBBacklightApp* app); diff --git a/applications/services/rgb_backlight/rgb_backlight_settings.c b/applications/services/rgb_backlight/rgb_backlight_settings.c index 45a7ae65e..7e69eb0dc 100644 --- a/applications/services/rgb_backlight/rgb_backlight_settings.c +++ b/applications/services/rgb_backlight/rgb_backlight_settings.c @@ -48,7 +48,8 @@ void rgb_backlight_settings_load(RGBBacklightSettings* settings) { RGB_BACKLIGHT_SETTINGS_VER); // if config previous version - load it and inicialize new settings } else if(version == RGB_BACKLIGHT_SETTINGS_VER_PREV) { - RGBBacklightSettingsPrevious* settings_previous = malloc(sizeof(RGBBacklightSettingsPrevious)); + RGBBacklightSettingsPrevious* settings_previous = + malloc(sizeof(RGBBacklightSettingsPrevious)); success = saved_struct_load( RGB_BACKLIGHT_SETTINGS_PATH, @@ -73,8 +74,11 @@ void rgb_backlight_settings_load(RGBBacklightSettings* settings) { // fill settings with 0 and save to settings file; // Orange color (index=0) will be default if(!success) { - FURI_LOG_W(TAG, "Failed to load file, using defaults 0"); + FURI_LOG_W(TAG, "Failed to load file, using defaults"); memset(settings, 0, sizeof(RGBBacklightSettings)); + settings->brightness = 1.0f; + settings->rainbow_speed_ms = 100; + settings->rainbow_step = 1; rgb_backlight_settings_save(settings); } } diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index c62c78dd8..82e4526ae 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -4,6 +4,7 @@ #include #include #include +#include "applications/services/rgb_backlight/rgb_backlight.h" #define MAX_NOTIFICATION_SETTINGS 4 @@ -108,13 +109,13 @@ const char* const vibro_text[VIBRO_COUNT] = { }; const bool vibro_value[VIBRO_COUNT] = {false, true}; -// --- RGB MOD RAINBOW --- -#define RGB_MOD_COUNT 2 -const char* const rgb_mod_text[RGB_MOD_COUNT] = { +// --- 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_value[RGB_MOD_COUNT] = {false, true}; +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] = { @@ -152,7 +153,7 @@ typedef enum { RGBViewId, } ViewId; -// --- END OF RGB MOD RAINBOW --- +// --- RGB BACKLIGHT END --- static void contrast_changed(VariableItem* item) { NotificationAppSettings* app = variable_item_get_context(item); @@ -169,8 +170,13 @@ 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 + + //--- RGB BACKLIGHT --- + //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 --- + notification_message(app->notification, &sequence_display_backlight_on); } @@ -220,130 +226,155 @@ static void vibro_changed(VariableItem* item) { notification_message(app->notification, &sequence_single_vibro); } -// --- RGB MOD AND RAINBOW --- +//--- RGB BACKLIGHT --- 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->rgb_srv->settings->rgb_mod_installed = rgb_mod_value[index]; + 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]; + rgb_backlight_settings_save(app->notification->rgb_srv->settings); + // Lock/Unlock rgb settings depent from rgb_mod_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 MOD\nOFF!"); + } else { + variable_item_set_locked(t_item, false, "RGB MOD\nOFF!"); + } + } } 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->rgb_srv->settings->rainbow_mode = rgb_mod_rainbow_mode_value[index]; + 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++) { + 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->rgb_srv->settings->rainbow_mode > 0) { + if(index > 0) { variable_item_set_locked(t_item, true, "Rainbow mode\nenabled!"); } else { variable_item_set_locked(t_item, false, "Rainbow mode\nenabled!"); } } - - rainbow_timer_starter(app->notification->rgb_srv); - rgb_backlight_settings_save(app->notification->rgb_srv->settings); // restore saved rgb backlight settings if we switch_off rainbow mode if(app->notification->rgb_srv->settings->rainbow_mode == 0) { - rgb_backlight_update(app->notification->rgb_srv->settings->brightness); + rgb_backlight_set_static_color(app->notification->rgb_srv->settings->static_color_index); + rgb_backlight_update(app->notification->rgb_srv->settings->brightness); } } 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->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); + + //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) { 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]; + + rgb_backlight_settings_save(app->notification->rgb_srv->settings); } // Set rgb_backlight colors static and custom + 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_static_color(index); - variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); + 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); - notification_message(app->notification, &sequence_display_backlight_on); + rgb_backlight_settings_save(app->notification->rgb_srv->settings); } 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; app->notification->rgb_srv->current_red = index; - app->notification->rgb_srv->settings->static_color_index=13; - + 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); - notification_message(app->notification, &sequence_display_backlight_on); + rgb_backlight_settings_save(app->notification->rgb_srv->settings); } 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; - 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->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)); - notification_message(app->notification, &sequence_display_backlight_on); -} -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; - 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); + //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; 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->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)); - notification_message(app->notification, &sequence_display_backlight_on); + + 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); + + //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; + + 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); } // open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_mod_install is true) @@ -363,7 +394,7 @@ static uint32_t notification_app_rgb_settings_exit(void* context) { UNUSED(context); return MainViewId; } -// --- END OF RGB MOD AND RAINBOW --- +//--- RGB BACKLIGHT END --- static uint32_t notification_app_settings_exit(void* context) { UNUSED(context); @@ -378,21 +409,23 @@ static NotificationAppSettings* alloc_settings(void) { app->variable_item_list = variable_item_list_alloc(); View* view = variable_item_list_get_view(app->variable_item_list); - //set callback for exit from view - view_set_previous_callback(view, notification_app_settings_exit); - - // set callback for OK pressed in menu - variable_item_list_set_enter_callback( - app->variable_item_list, variable_item_list_enter_callback, app); - 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_mod_installed is active 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); } + //--- RGB BACKLIGHT END --- item = variable_item_list_add( app->variable_item_list, "LCD Contrast", CONTRAST_COUNT, contrast_changed, app); @@ -450,9 +483,10 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_text(item, vibro_text[value_index]); } - // --- RGB SETTINGS VIEW --- + //--- 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 view_set_previous_callback(view_rgb, notification_app_rgb_settings_exit); @@ -461,16 +495,18 @@ static NotificationAppSettings* alloc_settings(void) { item = variable_item_list_add( app->variable_item_list_rgb, "RGB MOD Installed", - RGB_MOD_COUNT, + RGB_MOD_INSTALLED_COUNT, rgb_mod_installed_changed, app); value_index = value_index_bool( - app->notification->rgb_srv->settings->rgb_mod_installed, rgb_mod_value, RGB_MOD_COUNT); + 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_text[value_index]); + variable_item_set_current_value_text(item, rgb_mod_installed_text[value_index]); } - // RGB Colors settings + // Static Colors settings item = variable_item_list_add( app->variable_item_list_rgb, "LCD Color", @@ -482,6 +518,9 @@ static NotificationAppSettings* alloc_settings(void) { 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_mod_installed == 0), "RGB MOD \nOFF!"); + temp_item = item; // Custom Color - REFACTOR THIS @@ -494,6 +533,8 @@ static NotificationAppSettings* alloc_settings(void) { 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_mod_installed == 0), "RGB MOD \nOFF!"); item = variable_item_list_add( app->variable_item_list_rgb, "Custom Green", 255, color_set_custom_green, app); @@ -503,6 +544,8 @@ static NotificationAppSettings* alloc_settings(void) { 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_mod_installed == 0), "RGB MOD \nOFF!"); item = variable_item_list_add( app->variable_item_list_rgb, "Custom Blue", 255, color_set_custom_blue, app); @@ -512,6 +555,8 @@ static NotificationAppSettings* alloc_settings(void) { 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_mod_installed == 0), "RGB MOD \nOFF!"); // Rainbow (based on Willy-JL idea) settings item = variable_item_list_add( @@ -526,6 +571,8 @@ static NotificationAppSettings* alloc_settings(void) { RGB_MOD_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_locked( + item, (app->notification->rgb_srv->settings->rgb_mod_installed == 0), "RGB MOD \nOFF!"); item = variable_item_list_add( app->variable_item_list_rgb, @@ -539,6 +586,8 @@ static NotificationAppSettings* alloc_settings(void) { RGB_MOD_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_locked( + item, (app->notification->rgb_srv->settings->rgb_mod_installed == 0), "RGB MOD \nOFF!"); item = variable_item_list_add( app->variable_item_list_rgb, @@ -552,8 +601,10 @@ static NotificationAppSettings* alloc_settings(void) { RGB_MOD_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_locked( + item, (app->notification->rgb_srv->settings->rgb_mod_installed == 0), "RGB MOD \nOFF!"); - // --- End of RGB SETTING VIEW --- + //--- RGB BACKLIGHT END --- app->view_dispatcher = view_dispatcher_alloc(); view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv old mode 100644 new mode 100755 index ecb5047e8..07bbe80f7 --- 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.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,, @@ -3148,6 +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_settings_load,void,RGBBacklightSettings* Function,+,rgb_backlight_settings_save,void,const RGBBacklightSettings* diff --git a/targets/f7/furi_hal/furi_hal_light.c b/targets/f7/furi_hal/furi_hal_light.c index 6cc60da11..2d6b4bbfe 100644 --- a/targets/f7/furi_hal/furi_hal_light.c +++ b/targets/f7/furi_hal/furi_hal_light.c @@ -32,23 +32,25 @@ void furi_hal_light_init(void) { } void furi_hal_light_set(Light light, uint8_t value) { - furi_hal_i2c_acquire(&furi_hal_i2c_handle_power); - if(light & LightRed) { - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value); - } - if(light & LightGreen) { - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value); - } - if(light & LightBlue) { - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value); - } - if(light & LightBacklight) { - 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); - } - furi_hal_i2c_release(&furi_hal_i2c_handle_power); + furi_hal_i2c_acquire(&furi_hal_i2c_handle_power); + if(light & LightRed) { + lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value); + } + if(light & LightGreen) { + lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value); + } + if(light & LightBlue) { + lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value); + } + if(light & LightBacklight) { + 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 --- + rgb_backlight_update(value / 255.0f); + // --- RGB BACKLIGHT END --- + } + furi_hal_i2c_release(&furi_hal_i2c_handle_power); } void furi_hal_light_blink_start(Light light, uint8_t brightness, uint16_t on_time, uint16_t period) { From cf63e9c03623ba0ea400303d7aeb756d216cef24 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Fri, 14 Mar 2025 18:40:19 +0700 Subject: [PATCH 16/17] Restore Input_vibro_touch compability with rgb_backlight. rgb_backlight driver litle bit improvements --- applications/services/input/input.c | 4 +++- lib/drivers/SK6805.c | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/applications/services/input/input.c b/applications/services/input/input.c index 41759a1dd..93c5d1867 100644 --- a/applications/services/input/input.c +++ b/applications/services/input/input.c @@ -157,8 +157,10 @@ int32_t input_srv(void* p) { // Send Press/Release event event.type = pin_states[i].state ? InputTypePress : InputTypeRelease; furi_pubsub_publish(event_pubsub, &event); - // do vibro if user setup vibro touch level in Settings-Input. + // vibro signal if user setup vibro touch level in Settings-Input. if(settings->vibro_touch_level) { + //delay 1 ticks for compatibility with rgb_backlight_mod + furi_delay_tick(1); furi_hal_vibro_on(true); furi_delay_tick(settings->vibro_touch_level); furi_hal_vibro_on(false); diff --git a/lib/drivers/SK6805.c b/lib/drivers/SK6805.c index b6f525eb8..2ad8e18d3 100644 --- a/lib/drivers/SK6805.c +++ b/lib/drivers/SK6805.c @@ -98,6 +98,5 @@ void SK6805_update(void) { } } } - furi_delay_us(100); FURI_CRITICAL_EXIT(); } From 9da510389a7ec95afa8379e7ad96cb5687145192 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 15 Mar 2025 07:58:51 +0300 Subject: [PATCH 17/17] small fixes --- .../services/notification/notification_app.c | 128 +----------------- .../services/notification/notification_app.h | 15 -- .../notification_settings_app.c | 2 +- 3 files changed, 3 insertions(+), 142 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 4bd93cfbc..cf03d4389 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -189,111 +189,6 @@ static void notification_display_timer(void* ctx) { notification_message(app, &sequence_display_backlight_off); } -// // --- 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)); -// } - -// //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); -// } -// } -// } -// } - -// // 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; -// } - -// 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) { -// // } -// } - -// // --- END OF RGB MOD RAINBOW SECTION --- - // message processing static void notification_process_notification_message( NotificationApp* app, @@ -629,7 +524,7 @@ static void input_event_callback(const void* value, void* context) { static NotificationApp* notification_app_alloc(void) { NotificationApp* app = malloc(sizeof(NotificationApp)); app->queue = furi_message_queue_alloc(8, sizeof(NotificationAppMessage)); - app->display_timer = furi_timer_alloc(notification_display_timer, FuriTimerTypePeriodic, app); + app->display_timer = furi_timer_alloc(notification_display_timer, FuriTimerTypeOnce, app); app->settings.speaker_volume = 1.0f; app->settings.display_brightness = 1.0f; @@ -664,26 +559,9 @@ 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 --- - - // 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 --- - return app; } - static void notification_storage_callback(const void* message, void* context) { furi_assert(context); NotificationApp* app = context; @@ -704,8 +582,6 @@ 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); } static void notification_init_settings(NotificationApp* app) { @@ -724,7 +600,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); + app->rgb_srv = furi_record_open(RECORD_RGB_BACKLIGHT); notification_init_settings(app); notification_vibro_off(); diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index 4383ca6bc..0209ffa0b 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -45,13 +45,6 @@ typedef struct { uint32_t display_off_delay_ms; 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; - /// --- END OF RGB MOD SETTINGS SECTION --- - } NotificationSettings; struct NotificationApp { @@ -63,14 +56,6 @@ struct NotificationApp { NotificationLedLayer led[NOTIFICATION_LED_COUNT]; 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; - // --- ENd OF RGB RAINBOW MODE VARIABLES SECTION --- - NotificationSettings settings; RGBBacklightApp* rgb_srv; }; diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c index 82e4526ae..ff90e96e7 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -435,7 +435,7 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_text(item, contrast_text[value_index]); item = variable_item_list_add( - app->variable_item_list, "LCD Brightness", BACKLIGHT_COUNT, backlight_changed, app); + 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);