mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-06-07 19:01:54 -07:00
Set rgb backlight leds individually
This commit is contained in:
@@ -4,7 +4,9 @@ enum VarItemListIndex {
|
||||
VarItemListIndexDarkMode,
|
||||
VarItemListIndexLeftHanded,
|
||||
VarItemListIndexRgbBacklight,
|
||||
VarItemListIndexLcdColor,
|
||||
VarItemListIndexLcdColor0,
|
||||
VarItemListIndexLcdColor1,
|
||||
VarItemListIndexLcdColor2,
|
||||
VarItemListIndexRainbowLcd,
|
||||
VarItemListIndexRainbowSpeed,
|
||||
VarItemListIndexRainbowInterval,
|
||||
@@ -56,13 +58,22 @@ static const struct {
|
||||
{"Brown", {165, 42, 42}},
|
||||
{"White", {255, 192, 203}},
|
||||
};
|
||||
static void xtreme_app_scene_misc_screen_lcd_color_changed(VariableItem* item) {
|
||||
static void xtreme_app_scene_misc_screen_lcd_color_changed(VariableItem* item, uint8_t led) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, lcd_colors[index].name);
|
||||
rgb_backlight_set_color(lcd_colors[index].color);
|
||||
rgb_backlight_set_color(led, lcd_colors[index].color);
|
||||
app->save_backlight = true;
|
||||
}
|
||||
static void xtreme_app_scene_misc_screen_lcd_color_0_changed(VariableItem* item) {
|
||||
xtreme_app_scene_misc_screen_lcd_color_changed(item, 0);
|
||||
}
|
||||
static void xtreme_app_scene_misc_screen_lcd_color_1_changed(VariableItem* item) {
|
||||
xtreme_app_scene_misc_screen_lcd_color_changed(item, 1);
|
||||
}
|
||||
static void xtreme_app_scene_misc_screen_lcd_color_2_changed(VariableItem* item) {
|
||||
xtreme_app_scene_misc_screen_lcd_color_changed(item, 2);
|
||||
}
|
||||
|
||||
const char* const rainbow_lcd_names[RGBBacklightRainbowModeCount] = {
|
||||
"OFF",
|
||||
@@ -148,24 +159,32 @@ void xtreme_app_scene_misc_screen_on_enter(void* context) {
|
||||
item = variable_item_list_add(var_item_list, "RGB Backlight", 1, NULL, app);
|
||||
variable_item_set_current_value_text(item, xtreme_settings->rgb_backlight ? "ON" : "OFF");
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"LCD Color",
|
||||
COUNT_OF(lcd_colors),
|
||||
xtreme_app_scene_misc_screen_lcd_color_changed,
|
||||
app);
|
||||
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) {
|
||||
struct {
|
||||
uint8_t led;
|
||||
const char* str;
|
||||
VariableItemChangeCallback cb;
|
||||
} lcd_cols[] = {
|
||||
{0, "LCD Left", xtreme_app_scene_misc_screen_lcd_color_0_changed},
|
||||
{1, "LCD Middle", xtreme_app_scene_misc_screen_lcd_color_1_changed},
|
||||
{2, "LCD Right", xtreme_app_scene_misc_screen_lcd_color_2_changed},
|
||||
};
|
||||
size_t lcd_sz = COUNT_OF(lcd_colors);
|
||||
|
||||
for(size_t i = 0; i < COUNT_OF(lcd_cols); i++) {
|
||||
item = variable_item_list_add(var_item_list, lcd_cols[i].str, lcd_sz, lcd_cols[i].cb, app);
|
||||
RgbColor color = rgb_backlight_get_color(lcd_cols[i].led);
|
||||
bool found = false;
|
||||
for(size_t i = 0; i < lcd_sz; i++) {
|
||||
if(rgbcmp(&color, &lcd_colors[i].color) != 0) continue;
|
||||
value_index = i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
variable_item_set_current_value_index(item, found ? value_index : lcd_sz);
|
||||
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!");
|
||||
}
|
||||
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(
|
||||
var_item_list,
|
||||
@@ -252,7 +271,13 @@ bool xtreme_app_scene_misc_screen_on_event(void* context, SceneManagerEvent even
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VarItemListIndexLcdColor:
|
||||
case VarItemListIndexLcdColor0:
|
||||
case VarItemListIndexLcdColor1:
|
||||
case VarItemListIndexLcdColor2:
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager,
|
||||
XtremeAppSceneMiscScreenColor,
|
||||
event.event - VarItemListIndexLcdColor0);
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneMiscScreenColor);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -16,7 +16,8 @@ void xtreme_app_scene_misc_screen_color_on_enter(void* context) {
|
||||
|
||||
byte_input_set_header_text(byte_input, "Set LCD Color (#RRGGBB)");
|
||||
|
||||
app->lcd_color = rgb_backlight_get_color();
|
||||
app->lcd_color = rgb_backlight_get_color(
|
||||
scene_manager_get_scene_state(app->scene_manager, XtremeAppSceneMiscScreenColor));
|
||||
|
||||
byte_input_set_result_callback(
|
||||
byte_input,
|
||||
@@ -37,7 +38,9 @@ bool xtreme_app_scene_misc_screen_color_on_event(void* context, SceneManagerEven
|
||||
consumed = true;
|
||||
switch(event.event) {
|
||||
case ByteInputResultOk:
|
||||
rgb_backlight_set_color(app->lcd_color);
|
||||
rgb_backlight_set_color(
|
||||
scene_manager_get_scene_state(app->scene_manager, XtremeAppSceneMiscScreenColor),
|
||||
app->lcd_color);
|
||||
app->save_backlight = true;
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
break;
|
||||
|
||||
@@ -2558,14 +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,RgbColor,
|
||||
Function,+,rgb_backlight_get_color,RgbColor,uint8_t
|
||||
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,RgbColor
|
||||
Function,+,rgb_backlight_set_color,void,"uint8_t, 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
|
||||
|
||||
|
@@ -20,7 +20,6 @@
|
||||
#include <furi_hal.h>
|
||||
|
||||
/* Настройки */
|
||||
#define SK6805_LED_COUNT 3 //Количество светодиодов на плате подсветки
|
||||
#define SK6805_LED_PIN &led_pin //Порт подключения светодиодов
|
||||
|
||||
#ifdef FURI_DEBUG
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define SK6805_LED_COUNT 3 //Количество светодиодов на плате подсветки
|
||||
|
||||
/**
|
||||
* @brief Инициализация линии управления подсветкой
|
||||
*/
|
||||
@@ -48,4 +50,4 @@ 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_ */
|
||||
#endif /* SK6805_H_ */
|
||||
|
||||
+28
-17
@@ -27,12 +27,17 @@
|
||||
#define RGB_BACKLIGHT_SETTINGS_PATH CFG_PATH("rgb_backlight.settings")
|
||||
|
||||
static struct {
|
||||
RgbColor color;
|
||||
RgbColor colors[SK6805_LED_COUNT];
|
||||
RGBBacklightRainbowMode rainbow_mode;
|
||||
uint8_t rainbow_speed;
|
||||
uint32_t rainbow_interval;
|
||||
} rgb_settings = {
|
||||
.color = {255, 69, 0},
|
||||
.colors =
|
||||
{
|
||||
{255, 69, 0},
|
||||
{255, 69, 0},
|
||||
{255, 69, 0},
|
||||
},
|
||||
.rainbow_mode = RGBBacklightRainbowModeOff,
|
||||
.rainbow_speed = 5,
|
||||
.rainbow_interval = 250,
|
||||
@@ -43,7 +48,7 @@ static struct {
|
||||
bool enabled;
|
||||
bool last_rainbow;
|
||||
uint8_t last_brightness;
|
||||
RgbColor last_color;
|
||||
RgbColor last_colors[SK6805_LED_COUNT];
|
||||
FuriTimer* rainbow_timer;
|
||||
HsvColor rainbow_hsv;
|
||||
} rgb_state = {
|
||||
@@ -51,7 +56,12 @@ static struct {
|
||||
.enabled = false,
|
||||
.last_rainbow = true,
|
||||
.last_brightness = 0,
|
||||
.last_color = {0, 0, 0},
|
||||
.last_colors =
|
||||
{
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
},
|
||||
.rainbow_timer = NULL,
|
||||
.rainbow_hsv = {0, 255, 255},
|
||||
};
|
||||
@@ -110,19 +120,21 @@ void rgb_backlight_save_settings(void) {
|
||||
RGB_BACKLIGHT_SETTINGS_VERSION);
|
||||
}
|
||||
|
||||
void rgb_backlight_set_color(RgbColor color) {
|
||||
void rgb_backlight_set_color(uint8_t index, RgbColor color) {
|
||||
if(index >= COUNT_OF(rgb_settings.colors)) return;
|
||||
if(!rgb_state.settings_loaded) {
|
||||
rgb_backlight_load_settings();
|
||||
}
|
||||
rgb_settings.color = color;
|
||||
rgb_settings.colors[index] = color;
|
||||
rgb_backlight_reconfigure(rgb_state.enabled);
|
||||
}
|
||||
|
||||
RgbColor rgb_backlight_get_color() {
|
||||
RgbColor rgb_backlight_get_color(uint8_t index) {
|
||||
if(index >= COUNT_OF(rgb_settings.colors)) return (RgbColor){0, 0, 0};
|
||||
if(!rgb_state.settings_loaded) {
|
||||
rgb_backlight_load_settings();
|
||||
}
|
||||
return rgb_settings.color;
|
||||
return rgb_settings.colors[index];
|
||||
}
|
||||
|
||||
void rgb_backlight_set_rainbow_mode(RGBBacklightRainbowMode rainbow_mode) {
|
||||
@@ -179,20 +191,19 @@ void rgb_backlight_update(uint8_t brightness, bool tick) {
|
||||
switch(rgb_settings.rainbow_mode) {
|
||||
case RGBBacklightRainbowModeOff: {
|
||||
if(!rgb_state.last_rainbow && rgb_state.last_brightness == brightness &&
|
||||
rgbcmp(&rgb_state.last_color, &rgb_settings.color) == 0) {
|
||||
memcmp(rgb_state.last_colors, rgb_settings.colors, sizeof(rgb_settings.colors)) == 0) {
|
||||
return;
|
||||
}
|
||||
rgb_state.last_rainbow = false;
|
||||
rgb_state.last_color = rgb_settings.color;
|
||||
|
||||
RgbColor rgb = rgb_settings.color;
|
||||
rgb.r *= (brightness / 255.0f);
|
||||
rgb.g *= (brightness / 255.0f);
|
||||
rgb.b *= (brightness / 255.0f);
|
||||
FURI_LOG_I("RgbBacklight", "rgb %d %d %d", rgb.r, rgb.g, rgb.b);
|
||||
memcpy(rgb_state.last_colors, rgb_settings.colors, sizeof(rgb_settings.colors));
|
||||
|
||||
float bright = brightness / 255.0f;
|
||||
for(uint8_t i = 0; i < SK6805_get_led_count(); i++) {
|
||||
SK6805_set_led_color(i, rgb.r, rgb.g, rgb.b);
|
||||
SK6805_set_led_color(
|
||||
i,
|
||||
rgb_settings.colors[i].r * bright,
|
||||
rgb_settings.colors[i].g * bright,
|
||||
rgb_settings.colors[i].b * bright);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -51,11 +51,12 @@ void rgb_backlight_save_settings();
|
||||
/**
|
||||
* @brief Change the color of the backlight
|
||||
*
|
||||
* @param index What led to set the color to (0 - SK6805_LED_COUNT-1)
|
||||
* @param color RGB color to use
|
||||
*/
|
||||
void rgb_backlight_set_color(RgbColor color);
|
||||
void rgb_backlight_set_color(uint8_t index, RgbColor color);
|
||||
|
||||
RgbColor rgb_backlight_get_color();
|
||||
RgbColor rgb_backlight_get_color(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief Change rainbow mode
|
||||
|
||||
Reference in New Issue
Block a user