mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-19 04:44:47 -07:00
RGB BACKLIGHT refactoring finished.
- rgb_backlight by @Quen0n - rgb_backlight_settings and effects (like rainbow) idea by @Willy-JL For access to rgb backlight settings enable Debug mode and go to Settings-LCD and Notification-RGB backlight
This commit is contained in:
@@ -37,10 +37,10 @@ typedef struct {
|
|||||||
} RGBBacklightColor;
|
} RGBBacklightColor;
|
||||||
|
|
||||||
//use one type RGBBacklightColor for current_leds_settings and for static colors definition
|
//use one type RGBBacklightColor for current_leds_settings and for static colors definition
|
||||||
static RGBBacklightColor current_led [] = {
|
static RGBBacklightColor current_led[] = {
|
||||||
{"LED0",255,60,0},
|
{"LED0", 255, 60, 0},
|
||||||
{"LED1",255,60,0},
|
{"LED1", 255, 60, 0},
|
||||||
{"LED2",255,60,0},
|
{"LED2", 255, 60, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const RGBBacklightColor colors[] = {
|
static const RGBBacklightColor colors[] = {
|
||||||
@@ -70,42 +70,80 @@ const char* rgb_backlight_get_color_text(uint8_t index) {
|
|||||||
|
|
||||||
// use RECORD for acces to rgb service instance and update current colors by static
|
// use RECORD for acces to rgb service instance and update current colors by static
|
||||||
void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index) {
|
void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index) {
|
||||||
// RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT);
|
|
||||||
// float brightness = app->settings->brightness;
|
|
||||||
|
|
||||||
if(led < SK6805_get_led_count()) {
|
if(led < SK6805_get_led_count()) {
|
||||||
uint8_t r = colors[index].red;
|
uint8_t r = colors[index].red;
|
||||||
uint8_t g = colors[index].green;
|
uint8_t g = colors[index].green;
|
||||||
uint8_t b = colors[index].blue;
|
uint8_t b = colors[index].blue;
|
||||||
|
|
||||||
current_led[led].red = r;
|
current_led[led].red = r;
|
||||||
current_led[led].green =g;
|
current_led[led].green = g;
|
||||||
current_led[led].blue = b;
|
current_led[led].blue = b;
|
||||||
|
|
||||||
SK6805_set_led_color(led, r, g, b);
|
SK6805_set_led_color(led, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
// furi_record_close(RECORD_RGB_BACKLIGHT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// use RECORD for acces to rgb service instance and update current colors by custom value
|
// --- NOT USED IN CURRENT RELEASE, FOR FUTURE USAGE---
|
||||||
void rgb_backlight_set_led_custom_color(uint8_t led, uint8_t red, uint8_t green, uint8_t blue) {
|
// Update current colors by custom rgb value
|
||||||
// RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT);
|
// void rgb_backlight_set_led_custom_color(uint8_t led, uint8_t red, uint8_t green, uint8_t blue) {
|
||||||
// float brightness = app->settings->brightness;
|
// if(led < SK6805_get_led_count()) {
|
||||||
|
// current_led[led].red = red;
|
||||||
|
// current_led[led].green = green;
|
||||||
|
// current_led[led].blue = blue;
|
||||||
|
// SK6805_set_led_color(led, red, green, blue);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// --- NOT USED IN CURRENT RELEASE, FOR FUTURE USAGE---
|
||||||
|
|
||||||
if(led < SK6805_get_led_count()) {
|
// HSV to RGB based on
|
||||||
|
// https://www.radiokot.ru/forum/viewtopic.php?p=3000181&ysclid=m88wvoz34w244644702
|
||||||
|
// https://radiolaba.ru/microcotrollers/tsvetnaya-lampa.html#comment-1790
|
||||||
|
// https://alexgyver.ru/lessons/arduino-rgb/?ysclid=m88voflppa24464916
|
||||||
|
// led number (0-2), hue (0..255), sat (0..255), val (0...1)
|
||||||
|
void rgb_backlight_set_led_custom_hsv_color(uint8_t led, uint16_t hue, uint8_t sat, float V) {
|
||||||
|
//init value
|
||||||
|
float r = 1.0f;
|
||||||
|
float g = 1.0f;
|
||||||
|
float b = 1.0f;
|
||||||
|
|
||||||
current_led[led].red = red;
|
//from (0..255) to (0..1)
|
||||||
current_led[led].green = green;
|
float H = hue / 255.0f;
|
||||||
current_led[led].blue = blue;
|
float S = sat / 255.0f;
|
||||||
|
|
||||||
SK6805_set_led_color(led, red, green, blue);
|
uint8_t i = trunc(H * 6);
|
||||||
|
float f = H * 6 - i;
|
||||||
|
float p = V * (1 - S);
|
||||||
|
float q = V * (1 - f * S);
|
||||||
|
float t = V * (1 - (1 - f) * S);
|
||||||
|
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
r = V, g = t, b = p;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
r = q, g = V, b = p;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
r = p, g = V, b = t;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
r = p, g = q, b = V;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
r = t, g = p, b = V;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
r = V, g = p, b = q;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// furi_record_close(RECORD_RGB_BACKLIGHT);
|
//from (0..1) to (0..255)
|
||||||
|
current_led[led].red = r * 255;
|
||||||
|
current_led[led].green = g * 255;
|
||||||
|
current_led[led].blue = b * 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
// use RECORD for acces to rgb service instance, use current_* colors and update backlight
|
// use RECORD for acces to rgb service instance, set current_* colors to led and update backlight
|
||||||
void rgb_backlight_update(float brightness) {
|
void rgb_backlight_update(float brightness) {
|
||||||
RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT);
|
RGBBacklightApp* app = furi_record_open(RECORD_RGB_BACKLIGHT);
|
||||||
|
|
||||||
@@ -142,83 +180,56 @@ void rainbow_timer_starter(RGBBacklightApp* app) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HSV to RGB based on
|
|
||||||
// https://www.radiokot.ru/forum/viewtopic.php?p=3000181&ysclid=m88wvoz34w244644702
|
|
||||||
// https://radiolaba.ru/microcotrollers/tsvetnaya-lampa.html#comment-1790
|
|
||||||
// https://alexgyver.ru/lessons/arduino-rgb/?ysclid=m88voflppa24464916
|
|
||||||
void hsv_to_rgb(uint8_t red, uint8_t green, uint8_t blue, uint16_t hue ,uint8_t sat ,uint8_t val) {
|
|
||||||
float r = 1.0f;
|
|
||||||
float g = 1.0f;
|
|
||||||
float b = 1.0f;
|
|
||||||
|
|
||||||
float H = hue / 255.0f;
|
|
||||||
float S = sat / 255.0f;
|
|
||||||
float V = val / 255.0f;
|
|
||||||
|
|
||||||
uint8_t i = trunc(H * 6);
|
|
||||||
float f = H * 6 - i;
|
|
||||||
float p = V * (1 - S);
|
|
||||||
float q = V * (1 - f * S);
|
|
||||||
float t = V * (1 - (1 - f) * S);
|
|
||||||
|
|
||||||
switch(i) {
|
|
||||||
case 0:
|
|
||||||
r = V, g = t, b = p;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
r = q, g = V, b = p;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
r = p, g = V, b = t;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
r = p, g = q, b = V;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
r = t, g = p, b = V;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
r = V, g = p, b = q;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
red = r * 255;
|
|
||||||
green = g * 255;
|
|
||||||
blue = b * 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void rainbow_timer_callback(void* context) {
|
static void rainbow_timer_callback(void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
RGBBacklightApp* app = context;
|
RGBBacklightApp* app = context;
|
||||||
uint8_t r = 0;
|
|
||||||
uint8_t g = 0;
|
|
||||||
uint8_t b = 0;
|
|
||||||
|
|
||||||
if(app->settings->rgb_backlight_installed) {
|
if(app->settings->rgb_backlight_installed) {
|
||||||
switch(app->settings->rainbow_mode) {
|
app->rainbow_hue += app->settings->rainbow_step;
|
||||||
case 1:
|
if(app->rainbow_hue > 254) {
|
||||||
for(uint8_t i = 0; i < SK6805_get_led_count(); i++) {
|
app->rainbow_hue = 0;
|
||||||
hsv_to_rgb(r,g,b,app->rainbow_hue, app->settings->rainbow_saturation,app->settings->brightness*255);
|
|
||||||
FURI_LOG_D(
|
|
||||||
TAG, "rgb %d,%d,%d", r, g, b);
|
|
||||||
//rgb_backlight_set_led_custom_color (i,*r,*g,*b);
|
|
||||||
//SK6805_update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t wide = app->settings->rainbow_wide;
|
||||||
|
|
||||||
|
switch(app->settings->rainbow_mode) {
|
||||||
|
//rainbow mode
|
||||||
|
case 1:
|
||||||
|
for(uint8_t i = 0; i < SK6805_get_led_count(); i++) {
|
||||||
|
rgb_backlight_set_led_custom_hsv_color(
|
||||||
|
i,
|
||||||
|
app->rainbow_hue,
|
||||||
|
app->settings->rainbow_saturation,
|
||||||
|
app->settings->brightness);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//wave mode
|
||||||
case 2:
|
case 2:
|
||||||
|
uint16_t j = app->rainbow_hue + wide;
|
||||||
|
uint16_t k = app->rainbow_hue + wide * 2;
|
||||||
|
|
||||||
|
if(app->rainbow_hue > (254 - wide)) {
|
||||||
|
j = j - 255;
|
||||||
|
}
|
||||||
|
if(app->rainbow_hue > (254 - wide * 2)) {
|
||||||
|
k = k - 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
rgb_backlight_set_led_custom_hsv_color(
|
||||||
|
0, app->rainbow_hue, app->settings->rainbow_saturation, app->settings->brightness);
|
||||||
|
rgb_backlight_set_led_custom_hsv_color(
|
||||||
|
1, j, app->settings->rainbow_saturation, app->settings->brightness);
|
||||||
|
rgb_backlight_set_led_custom_hsv_color(
|
||||||
|
2, k, app->settings->rainbow_saturation, app->settings->brightness);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
app->rainbow_hue++;
|
|
||||||
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) {
|
||||||
@@ -242,24 +253,24 @@ int32_t rgb_backlight_srv(void* p) {
|
|||||||
//if rgb_backlight_installed then start rainbow or set leds colors from saved settings (default index = 0)
|
//if rgb_backlight_installed then start rainbow or set leds colors from saved settings (default index = 0)
|
||||||
if(app->settings->rgb_backlight_installed) {
|
if(app->settings->rgb_backlight_installed) {
|
||||||
if(app->settings->rainbow_mode > 0) {
|
if(app->settings->rainbow_mode > 0) {
|
||||||
// rainbow_timer_starter(app);
|
rainbow_timer_starter(app);
|
||||||
} else {
|
} else {
|
||||||
rgb_backlight_set_led_static_color (2,app->settings->led_2_color_index);
|
rgb_backlight_set_led_static_color(2, app->settings->led_2_color_index);
|
||||||
rgb_backlight_set_led_static_color (1,app->settings->led_1_color_index);
|
rgb_backlight_set_led_static_color(1, app->settings->led_1_color_index);
|
||||||
rgb_backlight_set_led_static_color (0,app->settings->led_0_color_index);
|
rgb_backlight_set_led_static_color(0, app->settings->led_0_color_index);
|
||||||
rgb_backlight_update (app->settings->brightness);
|
rgb_backlight_update(app->settings->brightness);
|
||||||
}
|
}
|
||||||
// if rgb_backlight not installed then set default static orange color(index=0) to all leds (0-2) and force light on
|
// if rgb_backlight not installed then set default static orange color(index=0) to all leds (0-2) and force light on
|
||||||
} else {
|
} else {
|
||||||
rgb_backlight_set_led_static_color (2,0);
|
rgb_backlight_set_led_static_color(2, 0);
|
||||||
rgb_backlight_set_led_static_color (1,0);
|
rgb_backlight_set_led_static_color(1, 0);
|
||||||
rgb_backlight_set_led_static_color (0,0);
|
rgb_backlight_set_led_static_color(0, 0);
|
||||||
SK6805_update();
|
SK6805_update();
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
// place for message queue and other future options
|
// place for message queue and other future options
|
||||||
furi_delay_ms (5000);
|
furi_delay_ms(5000);
|
||||||
if(app->settings->rgb_backlight_installed) {
|
if(app->settings->rgb_backlight_installed) {
|
||||||
FURI_LOG_D(TAG, "RGB backlight enabled - serivce is running");
|
FURI_LOG_D(TAG, "RGB backlight enabled - serivce is running");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FuriTimer* rainbow_timer;
|
FuriTimer* rainbow_timer;
|
||||||
uint8_t rainbow_hue;
|
uint16_t rainbow_hue;
|
||||||
uint8_t rainbow_red;
|
uint8_t rainbow_red;
|
||||||
uint8_t rainbow_green;
|
uint8_t rainbow_green;
|
||||||
uint8_t rainbow_blue;
|
uint8_t rainbow_blue;
|
||||||
@@ -40,6 +40,7 @@ typedef struct {
|
|||||||
#define RECORD_RGB_BACKLIGHT "rgb_backlight"
|
#define RECORD_RGB_BACKLIGHT "rgb_backlight"
|
||||||
|
|
||||||
void rgb_backlight_update(float brightness);
|
void rgb_backlight_update(float brightness);
|
||||||
|
//not used now, for future use
|
||||||
// void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue);
|
// void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue);
|
||||||
void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index);
|
void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index);
|
||||||
void rainbow_timer_stop(RGBBacklightApp* app);
|
void rainbow_timer_stop(RGBBacklightApp* app);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ typedef struct {
|
|||||||
uint32_t rainbow_speed_ms;
|
uint32_t rainbow_speed_ms;
|
||||||
uint16_t rainbow_step;
|
uint16_t rainbow_step;
|
||||||
uint8_t rainbow_saturation;
|
uint8_t rainbow_saturation;
|
||||||
|
uint8_t rainbow_wide;
|
||||||
} RGBBacklightSettingsPrevious;
|
} RGBBacklightSettingsPrevious;
|
||||||
|
|
||||||
void rgb_backlight_settings_load(RGBBacklightSettings* settings) {
|
void rgb_backlight_settings_load(RGBBacklightSettings* settings) {
|
||||||
@@ -84,6 +85,7 @@ void rgb_backlight_settings_load(RGBBacklightSettings* settings) {
|
|||||||
settings->rainbow_speed_ms = 100;
|
settings->rainbow_speed_ms = 100;
|
||||||
settings->rainbow_step = 1;
|
settings->rainbow_step = 1;
|
||||||
settings->rainbow_saturation = 255;
|
settings->rainbow_saturation = 255;
|
||||||
|
settings->rainbow_wide = 50;
|
||||||
rgb_backlight_settings_save(settings);
|
rgb_backlight_settings_save(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ typedef struct {
|
|||||||
uint32_t rainbow_speed_ms;
|
uint32_t rainbow_speed_ms;
|
||||||
uint16_t rainbow_step;
|
uint16_t rainbow_step;
|
||||||
uint8_t rainbow_saturation;
|
uint8_t rainbow_saturation;
|
||||||
|
uint8_t rainbow_wide;
|
||||||
|
|
||||||
} RGBBacklightSettings;
|
} RGBBacklightSettings;
|
||||||
|
|
||||||
|
|||||||
@@ -134,21 +134,29 @@ const uint32_t rgb_backlight_rainbow_speed_value[RGB_BACKLIGHT_RAINBOW_SPEED_COU
|
|||||||
100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,
|
100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,
|
||||||
1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000};
|
1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000};
|
||||||
|
|
||||||
#define RGB_BACKLIGHT_RAINBOW_STEP_COUNT 10
|
#define RGB_BACKLIGHT_RAINBOW_STEP_COUNT 3
|
||||||
const char* const rgb_backlight_rainbow_step_text[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] = {
|
const char* const rgb_backlight_rainbow_step_text[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] = {
|
||||||
"1",
|
"1",
|
||||||
"2",
|
"2",
|
||||||
"3",
|
"3",
|
||||||
"4",
|
|
||||||
"5",
|
|
||||||
"6",
|
|
||||||
"7",
|
|
||||||
"8",
|
|
||||||
"9",
|
|
||||||
"10",
|
|
||||||
};
|
};
|
||||||
const uint32_t rgb_backlight_rainbow_step_value[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] =
|
const uint32_t rgb_backlight_rainbow_step_value[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] = {
|
||||||
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define RGB_BACKLIGHT_RAINBOW_WIDE_COUNT 3
|
||||||
|
const char* const rgb_backlight_rainbow_wide_text[RGB_BACKLIGHT_RAINBOW_WIDE_COUNT] = {
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
};
|
||||||
|
const uint32_t rgb_backlight_rainbow_wide_value[RGB_BACKLIGHT_RAINBOW_WIDE_COUNT] = {
|
||||||
|
30,
|
||||||
|
40,
|
||||||
|
50,
|
||||||
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MainViewId,
|
MainViewId,
|
||||||
@@ -234,26 +242,29 @@ static void rgb_backlight_installed_changed(VariableItem* item) {
|
|||||||
NotificationAppSettings* app = variable_item_get_context(item);
|
NotificationAppSettings* app = variable_item_get_context(item);
|
||||||
uint8_t index = variable_item_get_current_value_index(item);
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
variable_item_set_current_value_text(item, rgb_backlight_installed_text[index]);
|
variable_item_set_current_value_text(item, rgb_backlight_installed_text[index]);
|
||||||
app->notification->rgb_srv->settings->rgb_backlight_installed = rgb_backlight_installed_value[index];
|
app->notification->rgb_srv->settings->rgb_backlight_installed =
|
||||||
|
rgb_backlight_installed_value[index];
|
||||||
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
||||||
|
|
||||||
// In case of user playing with rgb_backlight_installed swith:
|
// In case of user playing with rgb_backlight_installed swith:
|
||||||
// if user swith_off rgb_backlight_installed then force set default orange color
|
// if user swith_off rgb_backlight_installed then force set default orange color - defence from stupid.
|
||||||
if (index == 0) {
|
if(index == 0) {
|
||||||
rgb_backlight_set_led_static_color (2,0);
|
rgb_backlight_set_led_static_color(2, 0);
|
||||||
rgb_backlight_set_led_static_color (1,0);
|
rgb_backlight_set_led_static_color(1, 0);
|
||||||
rgb_backlight_set_led_static_color (0,0);
|
rgb_backlight_set_led_static_color(0, 0);
|
||||||
SK6805_update();
|
SK6805_update();
|
||||||
// if user swith_on rgb_backlight_installed then start rainbow if its ON or set saved static colors
|
// start rainbow (if its Enabled) or set saved static colors if user swith_on rgb_backlight_installed switch
|
||||||
} else {
|
} else {
|
||||||
|
if(app->notification->rgb_srv->settings->rainbow_mode > 0) {
|
||||||
if (app->notification->rgb_srv->settings->rainbow_mode >0) {
|
rainbow_timer_starter(app->notification->rgb_srv);
|
||||||
rainbow_timer_starter (app->notification->rgb_srv);
|
|
||||||
} else {
|
} else {
|
||||||
rgb_backlight_set_led_static_color (2,app->notification->rgb_srv->settings->led_2_color_index);
|
rgb_backlight_set_led_static_color(
|
||||||
rgb_backlight_set_led_static_color (1,app->notification->rgb_srv->settings->led_1_color_index);
|
2, app->notification->rgb_srv->settings->led_2_color_index);
|
||||||
rgb_backlight_set_led_static_color (0,app->notification->rgb_srv->settings->led_0_color_index);
|
rgb_backlight_set_led_static_color(
|
||||||
rgb_backlight_update (app->notification->settings.display_brightness);
|
1, app->notification->rgb_srv->settings->led_1_color_index);
|
||||||
|
rgb_backlight_set_led_static_color(
|
||||||
|
0, app->notification->rgb_srv->settings->led_0_color_index);
|
||||||
|
rgb_backlight_update(app->notification->settings.display_brightness);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +273,7 @@ static void rgb_backlight_installed_changed(VariableItem* item) {
|
|||||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||||
slide = 1;
|
slide = 1;
|
||||||
}
|
}
|
||||||
for(int i = slide; i < (slide + 7); i++) {
|
for(int i = slide; i < (slide + 8); i++) {
|
||||||
VariableItem* t_item = variable_item_list_get(app->variable_item_list_rgb, i);
|
VariableItem* t_item = variable_item_list_get(app->variable_item_list_rgb, i);
|
||||||
if(index == 0) {
|
if(index == 0) {
|
||||||
variable_item_set_locked(t_item, true, "RGB\nOFF!");
|
variable_item_set_locked(t_item, true, "RGB\nOFF!");
|
||||||
@@ -279,13 +290,12 @@ static void led_2_color_changed(VariableItem* item) {
|
|||||||
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->led_2_color_index = index;
|
app->notification->rgb_srv->settings->led_2_color_index = index;
|
||||||
|
|
||||||
rgb_backlight_set_led_static_color(2,index);
|
//dont update screen color if rainbow timer working
|
||||||
|
if(!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) {
|
||||||
|
rgb_backlight_set_led_static_color(2, index);
|
||||||
rgb_backlight_update(app->notification->rgb_srv->settings->brightness);
|
rgb_backlight_update(app->notification->rgb_srv->settings->brightness);
|
||||||
|
|
||||||
// dont update display color if rainbow working
|
|
||||||
if (!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) {
|
|
||||||
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
|
||||||
}
|
}
|
||||||
|
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void led_1_color_changed(VariableItem* item) {
|
static void led_1_color_changed(VariableItem* item) {
|
||||||
@@ -295,13 +305,13 @@ static void led_1_color_changed(VariableItem* item) {
|
|||||||
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->led_1_color_index = index;
|
app->notification->rgb_srv->settings->led_1_color_index = index;
|
||||||
|
|
||||||
rgb_backlight_set_led_static_color(1,index);
|
//dont update screen color if rainbow timer working
|
||||||
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
if(!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) {
|
||||||
|
rgb_backlight_set_led_static_color(1, index);
|
||||||
// dont update display color if rainbow working
|
rgb_backlight_update(app->notification->rgb_srv->settings->brightness);
|
||||||
if (!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) {
|
|
||||||
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void led_0_color_changed(VariableItem* item) {
|
static void led_0_color_changed(VariableItem* item) {
|
||||||
@@ -311,13 +321,13 @@ static void led_0_color_changed(VariableItem* item) {
|
|||||||
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->led_0_color_index = index;
|
app->notification->rgb_srv->settings->led_0_color_index = index;
|
||||||
|
|
||||||
rgb_backlight_set_led_static_color(0,index);
|
//dont update screen color if rainbow timer working
|
||||||
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
if(!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) {
|
||||||
|
rgb_backlight_set_led_static_color(0, index);
|
||||||
// dont update display color if rainbow working
|
rgb_backlight_update(app->notification->rgb_srv->settings->brightness);
|
||||||
if (!furi_timer_is_running(app->notification->rgb_srv->rainbow_timer)) {
|
|
||||||
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rgb_backlight_rainbow_changed(VariableItem* item) {
|
static void rgb_backlight_rainbow_changed(VariableItem* item) {
|
||||||
@@ -332,9 +342,12 @@ static void rgb_backlight_rainbow_changed(VariableItem* item) {
|
|||||||
|
|
||||||
// restore saved rgb backlight settings if we switch_off rainbow mode
|
// restore saved rgb backlight settings if we switch_off rainbow mode
|
||||||
if(app->notification->rgb_srv->settings->rainbow_mode == 0) {
|
if(app->notification->rgb_srv->settings->rainbow_mode == 0) {
|
||||||
rgb_backlight_set_led_static_color (2,app->notification->rgb_srv->settings->led_2_color_index);
|
rgb_backlight_set_led_static_color(
|
||||||
rgb_backlight_set_led_static_color (1,app->notification->rgb_srv->settings->led_1_color_index);
|
2, app->notification->rgb_srv->settings->led_2_color_index);
|
||||||
rgb_backlight_set_led_static_color (0,app->notification->rgb_srv->settings->led_0_color_index);
|
rgb_backlight_set_led_static_color(
|
||||||
|
1, app->notification->rgb_srv->settings->led_1_color_index);
|
||||||
|
rgb_backlight_set_led_static_color(
|
||||||
|
0, app->notification->rgb_srv->settings->led_0_color_index);
|
||||||
rgb_backlight_update(app->notification->rgb_srv->settings->brightness);
|
rgb_backlight_update(app->notification->rgb_srv->settings->brightness);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -362,19 +375,32 @@ static void rgb_backlight_rainbow_step_changed(VariableItem* item) {
|
|||||||
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) {
|
static void rgb_backlight_rainbow_saturation_changed(VariableItem* item) {
|
||||||
NotificationAppSettings* app = variable_item_get_context(item);
|
NotificationAppSettings* app = variable_item_get_context(item);
|
||||||
|
|
||||||
//saturation must be 1..255, so (0..254)+1
|
//saturation must be 1..255, so we do (0..254)+1
|
||||||
uint8_t index = variable_item_get_current_value_index(item)+1;
|
uint8_t index = variable_item_get_current_value_index(item) + 1;
|
||||||
char valtext[4] = {};
|
char valtext[4] = {};
|
||||||
snprintf(valtext, sizeof(valtext), "%d", index);
|
snprintf(valtext, sizeof(valtext), "%d", index);
|
||||||
variable_item_set_current_value_text(item, valtext);
|
variable_item_set_current_value_text(item, valtext);
|
||||||
app->notification->rgb_srv->settings->rainbow_saturation = index;
|
app->notification->rgb_srv->settings->rainbow_saturation = index;
|
||||||
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
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_backlight_installed is true)
|
|
||||||
void variable_item_list_enter_callback(void* context, uint32_t index) {
|
static void rgb_backlight_rainbow_wide_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_backlight_rainbow_wide_text[index]);
|
||||||
|
app->notification->rgb_srv->settings->rainbow_wide = rgb_backlight_rainbow_wide_value[index];
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// open rgb_settings_view if user press OK on first (index=0) menu string and (debug mode or rgb_backlight_installed is true)
|
||||||
|
void variable_item_list_enter_callback(void* context, uint32_t index) {
|
||||||
UNUSED(context);
|
UNUSED(context);
|
||||||
NotificationAppSettings* app = context;
|
NotificationAppSettings* app = context;
|
||||||
|
|
||||||
@@ -383,21 +409,21 @@ static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) {
|
|||||||
(index == 0)) {
|
(index == 0)) {
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, RGBViewId);
|
view_dispatcher_switch_to_view(app->view_dispatcher, RGBViewId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch to main view on exit from rgb_settings_view
|
// switch to main view on exit from rgb_settings_view
|
||||||
static uint32_t notification_app_rgb_settings_exit(void* context) {
|
static uint32_t notification_app_rgb_settings_exit(void* context) {
|
||||||
UNUSED(context);
|
UNUSED(context);
|
||||||
return MainViewId;
|
return MainViewId;
|
||||||
}
|
}
|
||||||
//--- RGB BACKLIGHT END ---
|
//--- RGB BACKLIGHT END ---
|
||||||
|
|
||||||
static uint32_t notification_app_settings_exit(void* context) {
|
static uint32_t notification_app_settings_exit(void* context) {
|
||||||
UNUSED(context);
|
UNUSED(context);
|
||||||
return VIEW_NONE;
|
return VIEW_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NotificationAppSettings* alloc_settings(void) {
|
static NotificationAppSettings* alloc_settings(void) {
|
||||||
NotificationAppSettings* app = malloc(sizeof(NotificationAppSettings));
|
NotificationAppSettings* app = malloc(sizeof(NotificationAppSettings));
|
||||||
app->notification = furi_record_open(RECORD_NOTIFICATION);
|
app->notification = furi_record_open(RECORD_NOTIFICATION);
|
||||||
app->gui = furi_record_open(RECORD_GUI);
|
app->gui = furi_record_open(RECORD_GUI);
|
||||||
@@ -425,8 +451,8 @@ static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) {
|
|||||||
|
|
||||||
item = variable_item_list_add(
|
item = variable_item_list_add(
|
||||||
app->variable_item_list, "LCD Contrast", CONTRAST_COUNT, contrast_changed, app);
|
app->variable_item_list, "LCD Contrast", CONTRAST_COUNT, contrast_changed, app);
|
||||||
value_index = value_index_int32(
|
value_index =
|
||||||
app->notification->settings.contrast, contrast_value, CONTRAST_COUNT);
|
value_index_int32(app->notification->settings.contrast, contrast_value, CONTRAST_COUNT);
|
||||||
variable_item_set_current_value_index(item, value_index);
|
variable_item_set_current_value_index(item, value_index);
|
||||||
variable_item_set_current_value_text(item, contrast_text[value_index]);
|
variable_item_set_current_value_text(item, contrast_text[value_index]);
|
||||||
|
|
||||||
@@ -487,7 +513,7 @@ static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) {
|
|||||||
// set callback for exit from rgb_settings_menu
|
// set callback for exit from rgb_settings_menu
|
||||||
view_set_previous_callback(view_rgb, notification_app_rgb_settings_exit);
|
view_set_previous_callback(view_rgb, notification_app_rgb_settings_exit);
|
||||||
|
|
||||||
// // Show rgb_backlight_Installed_Swith only in Debug mode
|
// // Show rgb_backlight_installed swith only in Debug mode
|
||||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||||
item = variable_item_list_add(
|
item = variable_item_list_add(
|
||||||
app->variable_item_list_rgb,
|
app->variable_item_list_rgb,
|
||||||
@@ -503,6 +529,7 @@ static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) {
|
|||||||
variable_item_set_current_value_text(item, rgb_backlight_installed_text[value_index]);
|
variable_item_set_current_value_text(item, rgb_backlight_installed_text[value_index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We (humans) are numbering LEDs from left to right as 1..3, but hardware have another order from right to left 2..0
|
||||||
// led_1 color
|
// led_1 color
|
||||||
item = variable_item_list_add(
|
item = variable_item_list_add(
|
||||||
app->variable_item_list_rgb,
|
app->variable_item_list_rgb,
|
||||||
@@ -592,7 +619,7 @@ static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) {
|
|||||||
value_index = value_index_uint32(
|
value_index = value_index_uint32(
|
||||||
app->notification->rgb_srv->settings->rainbow_step,
|
app->notification->rgb_srv->settings->rainbow_step,
|
||||||
rgb_backlight_rainbow_step_value,
|
rgb_backlight_rainbow_step_value,
|
||||||
RGB_BACKLIGHT_RAINBOW_SPEED_COUNT);
|
RGB_BACKLIGHT_RAINBOW_STEP_COUNT);
|
||||||
variable_item_set_current_value_index(item, value_index);
|
variable_item_set_current_value_index(item, value_index);
|
||||||
variable_item_set_current_value_text(item, rgb_backlight_rainbow_step_text[value_index]);
|
variable_item_set_current_value_text(item, rgb_backlight_rainbow_step_text[value_index]);
|
||||||
variable_item_set_locked(
|
variable_item_set_locked(
|
||||||
@@ -616,18 +643,34 @@ static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) {
|
|||||||
(app->notification->rgb_srv->settings->rgb_backlight_installed == 0),
|
(app->notification->rgb_srv->settings->rgb_backlight_installed == 0),
|
||||||
"RGB MOD \nOFF!");
|
"RGB MOD \nOFF!");
|
||||||
|
|
||||||
|
item = variable_item_list_add(
|
||||||
|
app->variable_item_list_rgb,
|
||||||
|
"Wave wide",
|
||||||
|
RGB_BACKLIGHT_RAINBOW_WIDE_COUNT,
|
||||||
|
rgb_backlight_rainbow_wide_changed,
|
||||||
|
app);
|
||||||
|
value_index = value_index_uint32(
|
||||||
|
app->notification->rgb_srv->settings->rainbow_wide,
|
||||||
|
rgb_backlight_rainbow_wide_value,
|
||||||
|
RGB_BACKLIGHT_RAINBOW_WIDE_COUNT);
|
||||||
|
variable_item_set_current_value_index(item, value_index);
|
||||||
|
variable_item_set_current_value_text(item, rgb_backlight_rainbow_wide_text[value_index]);
|
||||||
|
variable_item_set_locked(
|
||||||
|
item,
|
||||||
|
(app->notification->rgb_srv->settings->rgb_backlight_installed == 0),
|
||||||
|
"RGB MOD \nOFF!");
|
||||||
|
|
||||||
//--- RGB BACKLIGHT END ---
|
//--- RGB BACKLIGHT END ---
|
||||||
|
|
||||||
app->view_dispatcher = view_dispatcher_alloc();
|
app->view_dispatcher = view_dispatcher_alloc();
|
||||||
view_dispatcher_attach_to_gui(
|
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||||
app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
|
||||||
view_dispatcher_add_view(app->view_dispatcher, MainViewId, view);
|
view_dispatcher_add_view(app->view_dispatcher, MainViewId, view);
|
||||||
view_dispatcher_add_view(app->view_dispatcher, RGBViewId, view_rgb);
|
view_dispatcher_add_view(app->view_dispatcher, RGBViewId, view_rgb);
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, MainViewId);
|
view_dispatcher_switch_to_view(app->view_dispatcher, MainViewId);
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_settings(NotificationAppSettings * app) {
|
static void free_settings(NotificationAppSettings* app) {
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, MainViewId);
|
view_dispatcher_remove_view(app->view_dispatcher, MainViewId);
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, RGBViewId);
|
view_dispatcher_remove_view(app->view_dispatcher, RGBViewId);
|
||||||
variable_item_list_free(app->variable_item_list);
|
variable_item_list_free(app->variable_item_list);
|
||||||
@@ -637,9 +680,9 @@ static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) {
|
|||||||
furi_record_close(RECORD_GUI);
|
furi_record_close(RECORD_GUI);
|
||||||
furi_record_close(RECORD_NOTIFICATION);
|
furi_record_close(RECORD_NOTIFICATION);
|
||||||
free(app);
|
free(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t notification_settings_app(void* p) {
|
int32_t notification_settings_app(void* p) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
NotificationAppSettings* app = alloc_settings();
|
NotificationAppSettings* app = alloc_settings();
|
||||||
view_dispatcher_run(app->view_dispatcher);
|
view_dispatcher_run(app->view_dispatcher);
|
||||||
@@ -652,4 +695,4 @@ static void rgb_backlight_rainbow_saturation_changed (VariableItem* item) {
|
|||||||
|
|
||||||
free_settings(app);
|
free_settings(app);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user