mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Move rgb bl color presets to userspace
This commit is contained in:
@@ -30,11 +30,34 @@ static void xtreme_app_scene_misc_screen_hand_orient_changed(VariableItem* item)
|
||||
}
|
||||
}
|
||||
|
||||
static const struct {
|
||||
char* name;
|
||||
RgbColor color;
|
||||
} lcd_colors[] = {
|
||||
{"Orange", {255, 69, 0}},
|
||||
{"Red", {255, 0, 0}},
|
||||
{"Maroon", {128, 0, 0}},
|
||||
{"Yellow", {255, 255, 0}},
|
||||
{"Olive", {128, 128, 0}},
|
||||
{"Lime", {0, 255, 0}},
|
||||
{"Green", {0, 128, 0}},
|
||||
{"Aqua", {0, 255, 127}},
|
||||
{"Cyan", {0, 210, 210}},
|
||||
{"Azure", {0, 127, 255}},
|
||||
{"Teal", {0, 128, 128}},
|
||||
{"Blue", {0, 0, 255}},
|
||||
{"Navy", {0, 0, 128}},
|
||||
{"Purple", {128, 0, 128}},
|
||||
{"Fuchsia", {255, 0, 255}},
|
||||
{"Pink", {173, 31, 173}},
|
||||
{"Brown", {165, 42, 42}},
|
||||
{"White", {255, 192, 203}},
|
||||
};
|
||||
static void xtreme_app_scene_misc_screen_lcd_color_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index));
|
||||
rgb_backlight_set_color(index);
|
||||
variable_item_set_current_value_text(item, lcd_colors[index].name);
|
||||
rgb_backlight_set_color(lcd_colors[index].color);
|
||||
app->save_backlight = true;
|
||||
}
|
||||
|
||||
@@ -121,12 +144,20 @@ void xtreme_app_scene_misc_screen_on_enter(void* context) {
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"LCD Color",
|
||||
rgb_backlight_get_color_count(),
|
||||
COUNT_OF(lcd_colors),
|
||||
xtreme_app_scene_misc_screen_lcd_color_changed,
|
||||
app);
|
||||
value_index = rgb_backlight_get_color();
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index));
|
||||
RgbColor color = rgb_backlight_get_color();
|
||||
bool found = false;
|
||||
for(size_t i = 0; i < COUNT_OF(lcd_colors); i++) {
|
||||
if(rgbcmp(&color, &lcd_colors[i].color) == 0) {
|
||||
value_index = i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
variable_item_set_current_value_index(item, found ? value_index : COUNT_OF(lcd_colors));
|
||||
variable_item_set_current_value_text(item, found ? lcd_colors[value_index].name : "Custom");
|
||||
variable_item_set_locked(item, !xtreme_settings->rgb_backlight, "Needs RGB\nBacklight!");
|
||||
|
||||
item = variable_item_list_add(
|
||||
|
||||
@@ -2558,16 +2558,14 @@ Function,-,rfal_platform_spi_release,void,
|
||||
Function,-,rfal_set_callback_context,void,void*
|
||||
Function,-,rfal_set_state_changed_callback,void,RfalStateChangedCallback
|
||||
Function,+,rgb2hsv,HsvColor,RgbColor
|
||||
Function,+,rgb_backlight_get_color,uint8_t,
|
||||
Function,+,rgb_backlight_get_color_count,uint8_t,
|
||||
Function,+,rgb_backlight_get_color_text,const char*,uint8_t
|
||||
Function,+,rgb_backlight_get_color,RgbColor,
|
||||
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_color,void,RgbColor
|
||||
Function,+,rgb_backlight_set_rainbow_interval,void,uint32_t
|
||||
Function,+,rgb_backlight_set_rainbow_mode,void,RGBBacklightRainbowMode
|
||||
Function,+,rgb_backlight_set_rainbow_speed,void,uint8_t
|
||||
|
||||
|
@@ -27,47 +27,23 @@
|
||||
#define RGB_BACKLIGHT_SETTINGS_PATH CFG_PATH("rgb_backlight.settings")
|
||||
|
||||
static struct {
|
||||
uint8_t display_color_index;
|
||||
RgbColor color;
|
||||
RGBBacklightRainbowMode rainbow_mode;
|
||||
uint8_t rainbow_speed;
|
||||
uint32_t rainbow_interval;
|
||||
} rgb_settings = {
|
||||
.display_color_index = 0,
|
||||
.color = {255, 69, 0},
|
||||
.rainbow_mode = RGBBacklightRainbowModeOff,
|
||||
.rainbow_speed = 5,
|
||||
.rainbow_interval = 1000,
|
||||
};
|
||||
|
||||
static const struct {
|
||||
char* name;
|
||||
RgbColor color;
|
||||
} colors[] = {
|
||||
{"Orange", {255, 69, 0}},
|
||||
{"Red", {255, 0, 0}},
|
||||
{"Maroon", {128, 0, 0}},
|
||||
{"Yellow", {255, 255, 0}},
|
||||
{"Olive", {128, 128, 0}},
|
||||
{"Lime", {0, 255, 0}},
|
||||
{"Green", {0, 128, 0}},
|
||||
{"Aqua", {0, 255, 127}},
|
||||
{"Cyan", {0, 210, 210}},
|
||||
{"Azure", {0, 127, 255}},
|
||||
{"Teal", {0, 128, 128}},
|
||||
{"Blue", {0, 0, 255}},
|
||||
{"Navy", {0, 0, 128}},
|
||||
{"Purple", {128, 0, 128}},
|
||||
{"Fuchsia", {255, 0, 255}},
|
||||
{"Pink", {173, 31, 173}},
|
||||
{"Brown", {165, 42, 42}},
|
||||
{"White", {255, 192, 203}},
|
||||
};
|
||||
|
||||
static struct {
|
||||
bool settings_loaded;
|
||||
bool enabled;
|
||||
bool last_rainbow;
|
||||
uint8_t last_brightness;
|
||||
uint8_t last_color_index;
|
||||
RgbColor last_color;
|
||||
FuriTimer* rainbow_timer;
|
||||
HsvColor rainbow_hsv;
|
||||
} rgb_state = {
|
||||
@@ -75,7 +51,7 @@ static struct {
|
||||
.enabled = false,
|
||||
.last_rainbow = true,
|
||||
.last_brightness = 0,
|
||||
.last_color_index = 255,
|
||||
.last_color = {0, 0, 0},
|
||||
.rainbow_timer = NULL,
|
||||
.rainbow_hsv =
|
||||
{
|
||||
@@ -85,14 +61,6 @@ static struct {
|
||||
},
|
||||
};
|
||||
|
||||
uint8_t rgb_backlight_get_color_count(void) {
|
||||
return COUNT_OF(colors);
|
||||
}
|
||||
|
||||
const char* rgb_backlight_get_color_text(uint8_t index) {
|
||||
return colors[index].name;
|
||||
}
|
||||
|
||||
static void rainbow_timer(void* ctx) {
|
||||
UNUSED(ctx);
|
||||
rgb_backlight_update(rgb_state.last_brightness, true);
|
||||
@@ -147,20 +115,19 @@ void rgb_backlight_save_settings(void) {
|
||||
RGB_BACKLIGHT_SETTINGS_VERSION);
|
||||
}
|
||||
|
||||
void rgb_backlight_set_color(uint8_t color_index) {
|
||||
void rgb_backlight_set_color(RgbColor color) {
|
||||
if(!rgb_state.settings_loaded) {
|
||||
rgb_backlight_load_settings();
|
||||
}
|
||||
if(color_index > (rgb_backlight_get_color_count() - 1)) color_index = 0;
|
||||
rgb_settings.display_color_index = color_index;
|
||||
rgb_settings.color = color;
|
||||
rgb_backlight_reconfigure(rgb_state.enabled);
|
||||
}
|
||||
|
||||
uint8_t rgb_backlight_get_color() {
|
||||
RgbColor rgb_backlight_get_color() {
|
||||
if(!rgb_state.settings_loaded) {
|
||||
rgb_backlight_load_settings();
|
||||
}
|
||||
return rgb_settings.display_color_index;
|
||||
return rgb_settings.color;
|
||||
}
|
||||
|
||||
void rgb_backlight_set_rainbow_mode(RGBBacklightRainbowMode rainbow_mode) {
|
||||
@@ -216,15 +183,14 @@ void rgb_backlight_update(uint8_t brightness, bool tick) {
|
||||
|
||||
switch(rgb_settings.rainbow_mode) {
|
||||
case RGBBacklightRainbowModeOff: {
|
||||
if(rgb_state.last_brightness == brightness &&
|
||||
rgb_state.last_color_index == rgb_settings.display_color_index &&
|
||||
!rgb_state.last_rainbow) {
|
||||
if(!rgb_state.last_rainbow && rgb_state.last_brightness == brightness &&
|
||||
rgbcmp(&rgb_state.last_color, &rgb_settings.color) == 0) {
|
||||
return;
|
||||
}
|
||||
rgb_state.last_rainbow = false;
|
||||
rgb_state.last_color_index = rgb_settings.display_color_index;
|
||||
rgb_state.last_color = rgb_settings.color;
|
||||
|
||||
RgbColor rgb = colors[rgb_settings.display_color_index].color;
|
||||
RgbColor rgb = rgb_settings.color;
|
||||
rgb.r *= (brightness / 255.0f);
|
||||
rgb.g *= (brightness / 255.0f);
|
||||
rgb.b *= (brightness / 255.0f);
|
||||
|
||||
@@ -31,21 +31,6 @@ typedef enum {
|
||||
RGBBacklightRainbowModeCount,
|
||||
} RGBBacklightRainbowMode;
|
||||
|
||||
/**
|
||||
* @brief Получить количество доступных цветов
|
||||
*
|
||||
* @return Число доступных вариантов цвета
|
||||
*/
|
||||
uint8_t rgb_backlight_get_color_count(void);
|
||||
|
||||
/**
|
||||
* @brief Получить текстовое название цвета
|
||||
*
|
||||
* @param index Индекс из доступных вариантов цвета
|
||||
* @return Указатель на строку с названием цвета
|
||||
*/
|
||||
const char* rgb_backlight_get_color_text(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief Reconfigure rgb backlight with new settings
|
||||
*
|
||||
@@ -64,13 +49,13 @@ void rgb_backlight_load_settings();
|
||||
void rgb_backlight_save_settings();
|
||||
|
||||
/**
|
||||
* @brief Установить цвет RGB-подсветки
|
||||
* @brief Change the color of the backlight
|
||||
*
|
||||
* @param color_index Индекс цвета (0 - rgb_backlight_get_color_count())
|
||||
* @param color RGB color to use
|
||||
*/
|
||||
void rgb_backlight_set_color(uint8_t color_index);
|
||||
void rgb_backlight_set_color(RgbColor color);
|
||||
|
||||
uint8_t rgb_backlight_get_color();
|
||||
RgbColor rgb_backlight_get_color();
|
||||
|
||||
/**
|
||||
* @brief Change rainbow mode
|
||||
|
||||
Reference in New Issue
Block a user