mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-29 06:24:45 -07:00
Fix rgb backlight configuration and setup
This commit is contained in:
@@ -36,7 +36,6 @@ static void xtreme_app_scene_misc_screen_lcd_color_changed(VariableItem* item) {
|
||||
variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index));
|
||||
rgb_backlight_set_color(index);
|
||||
app->save_backlight = true;
|
||||
notification_message(app->notification, &sequence_display_backlight_on);
|
||||
}
|
||||
|
||||
const char* const rainbow_lcd_names[RGBBacklightRainbowModeCount] = {
|
||||
@@ -208,6 +207,7 @@ bool xtreme_app_scene_misc_screen_on_event(void* context, SceneManagerEvent even
|
||||
XTREME_SETTINGS()->rgb_backlight = !XTREME_SETTINGS()->rgb_backlight;
|
||||
app->save_settings = true;
|
||||
notification_message(app->notification, &sequence_display_backlight_on);
|
||||
rgb_backlight_reconfigure(XTREME_SETTINGS()->rgb_backlight);
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneMiscScreen);
|
||||
}
|
||||
|
||||
@@ -2564,6 +2564,7 @@ Function,+,rgb_backlight_get_rainbow_interval,uint32_t,
|
||||
Function,+,rgb_backlight_get_rainbow_mode,RGBBacklightRainbowMode,
|
||||
Function,+,rgb_backlight_get_rainbow_speed,uint8_t,
|
||||
Function,-,rgb_backlight_load_settings,void,
|
||||
Function,+,rgb_backlight_reconfigure,void,_Bool
|
||||
Function,+,rgb_backlight_save_settings,void,
|
||||
Function,+,rgb_backlight_set_color,void,uint8_t
|
||||
Function,+,rgb_backlight_set_rainbow_interval,void,uint32_t
|
||||
|
||||
|
@@ -64,6 +64,7 @@ static const struct {
|
||||
|
||||
static struct {
|
||||
bool settings_loaded;
|
||||
bool enabled;
|
||||
bool last_rainbow;
|
||||
uint8_t last_brightness;
|
||||
uint8_t last_color_index;
|
||||
@@ -71,6 +72,7 @@ static struct {
|
||||
HsvColor rainbow_hsv;
|
||||
} rgb_state = {
|
||||
.settings_loaded = false,
|
||||
.enabled = false,
|
||||
.last_rainbow = true,
|
||||
.last_brightness = 0,
|
||||
.last_color_index = 255,
|
||||
@@ -96,8 +98,13 @@ static void rainbow_timer(void* ctx) {
|
||||
rgb_backlight_update(rgb_state.last_brightness, true);
|
||||
}
|
||||
|
||||
static void rainbow_configure() {
|
||||
if(rgb_settings.rainbow_mode != RGBBacklightRainbowModeOff) {
|
||||
void rgb_backlight_reconfigure(bool enabled) {
|
||||
if(enabled && !rgb_state.settings_loaded) {
|
||||
rgb_backlight_load_settings();
|
||||
}
|
||||
rgb_state.enabled = enabled;
|
||||
|
||||
if(rgb_state.enabled && rgb_settings.rainbow_mode != RGBBacklightRainbowModeOff) {
|
||||
if(rgb_state.rainbow_timer == NULL) {
|
||||
rgb_state.rainbow_timer = furi_timer_alloc(rainbow_timer, FuriTimerTypePeriodic, NULL);
|
||||
} else {
|
||||
@@ -109,6 +116,8 @@ static void rainbow_configure() {
|
||||
furi_timer_free(rgb_state.rainbow_timer);
|
||||
rgb_state.rainbow_timer = NULL;
|
||||
}
|
||||
|
||||
rgb_backlight_update(rgb_state.last_brightness, false);
|
||||
}
|
||||
|
||||
void rgb_backlight_load_settings(void) {
|
||||
@@ -126,7 +135,7 @@ void rgb_backlight_load_settings(void) {
|
||||
RGB_BACKLIGHT_SETTINGS_VERSION);
|
||||
|
||||
rgb_state.settings_loaded = true;
|
||||
rainbow_configure();
|
||||
rgb_backlight_reconfigure(rgb_state.enabled);
|
||||
}
|
||||
|
||||
void rgb_backlight_save_settings(void) {
|
||||
@@ -144,6 +153,7 @@ 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;
|
||||
rgb_backlight_reconfigure(rgb_state.enabled);
|
||||
}
|
||||
|
||||
uint8_t rgb_backlight_get_color() {
|
||||
@@ -159,7 +169,7 @@ void rgb_backlight_set_rainbow_mode(RGBBacklightRainbowMode rainbow_mode) {
|
||||
}
|
||||
if(rainbow_mode > (RGBBacklightRainbowModeCount - 1)) rainbow_mode = 0;
|
||||
rgb_settings.rainbow_mode = rainbow_mode;
|
||||
rainbow_configure();
|
||||
rgb_backlight_reconfigure(rgb_state.enabled);
|
||||
}
|
||||
|
||||
RGBBacklightRainbowMode rgb_backlight_get_rainbow_mode() {
|
||||
@@ -188,7 +198,7 @@ void rgb_backlight_set_rainbow_interval(uint32_t rainbow_interval) {
|
||||
rgb_backlight_load_settings();
|
||||
}
|
||||
rgb_settings.rainbow_interval = rainbow_interval;
|
||||
rainbow_configure();
|
||||
rgb_backlight_reconfigure(rgb_state.enabled);
|
||||
}
|
||||
|
||||
uint32_t rgb_backlight_get_rainbow_interval() {
|
||||
@@ -199,6 +209,7 @@ uint32_t rgb_backlight_get_rainbow_interval() {
|
||||
}
|
||||
|
||||
void rgb_backlight_update(uint8_t brightness, bool tick) {
|
||||
if(!rgb_state.enabled) return;
|
||||
if(!rgb_state.settings_loaded) {
|
||||
rgb_backlight_load_settings();
|
||||
}
|
||||
|
||||
@@ -46,6 +46,13 @@ uint8_t rgb_backlight_get_color_count(void);
|
||||
*/
|
||||
const char* rgb_backlight_get_color_text(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief Reconfigure rgb backlight with new settings
|
||||
*
|
||||
* @param enabled Whether the rgb backlight is enabled
|
||||
*/
|
||||
void rgb_backlight_reconfigure(bool enabled);
|
||||
|
||||
/**
|
||||
* @brief Загрузить настройки подсветки с SD-карты
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "xtreme.h"
|
||||
#include <furi_hal.h>
|
||||
#include <rgb_backlight.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
|
||||
#define TAG "XtremeSettings"
|
||||
@@ -194,6 +195,8 @@ void XTREME_SETTINGS_LOAD() {
|
||||
}
|
||||
flipper_format_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
rgb_backlight_reconfigure(x->rgb_backlight);
|
||||
}
|
||||
|
||||
void XTREME_SETTINGS_SAVE() {
|
||||
|
||||
Reference in New Issue
Block a user