mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Cosmetic code changes and removing unused parts.
This commit is contained in:
@@ -36,7 +36,7 @@ typedef struct {
|
||||
uint8_t blue;
|
||||
} 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[] = {
|
||||
{"LED0", 0, 0, 0},
|
||||
{"LED1", 0, 0, 0},
|
||||
@@ -83,30 +83,18 @@ void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- NOT USED IN CURRENT RELEASE, FOR FUTURE USAGE---
|
||||
// Update current colors by custom rgb value
|
||||
// void rgb_backlight_set_led_custom_color(uint8_t led, uint8_t red, uint8_t green, uint8_t blue) {
|
||||
// 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---
|
||||
|
||||
// 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
|
||||
// init value
|
||||
float r = 1.0f;
|
||||
float g = 1.0f;
|
||||
float b = 1.0f;
|
||||
|
||||
//from (0..255) to (0..1)
|
||||
// from (0..255) to (0..1)
|
||||
float H = hue / 255.0f;
|
||||
float S = sat / 255.0f;
|
||||
|
||||
@@ -137,7 +125,7 @@ void rgb_backlight_set_led_custom_hsv_color(uint8_t led, uint16_t hue, uint8_t s
|
||||
break;
|
||||
}
|
||||
|
||||
//from (0..1) to (0..255)
|
||||
// from (0..1) to (0..255)
|
||||
current_led[led].red = r * 255;
|
||||
current_led[led].green = g * 255;
|
||||
current_led[led].blue = b * 255;
|
||||
@@ -159,12 +147,12 @@ void rgb_backlight_update(float brightness) {
|
||||
furi_record_close(RECORD_RGB_BACKLIGHT);
|
||||
}
|
||||
|
||||
//start furi timer for rainbow
|
||||
// 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
|
||||
// stop furi timer for rainbow
|
||||
void rainbow_timer_stop(RGBBacklightApp* app) {
|
||||
furi_timer_stop(app->rainbow_timer);
|
||||
}
|
||||
@@ -173,10 +161,6 @@ void rainbow_timer_stop(RGBBacklightApp* app) {
|
||||
void rainbow_timer_starter(RGBBacklightApp* app) {
|
||||
if((app->settings->rainbow_mode > 0) && (app->settings->rgb_backlight_installed)) {
|
||||
rainbow_timer_start(app);
|
||||
} else {
|
||||
if(furi_timer_is_running(app->rainbow_timer)) {
|
||||
rainbow_timer_stop(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +223,7 @@ int32_t rgb_backlight_srv(void* p) {
|
||||
// allocate memory and create RECORD for access to app structure from outside
|
||||
RGBBacklightApp* app = malloc(sizeof(RGBBacklightApp));
|
||||
|
||||
//define rainbow_timer and they callback
|
||||
// define rainbow_timer and they callback
|
||||
app->rainbow_timer = furi_timer_alloc(rainbow_timer_callback, FuriTimerTypePeriodic, app);
|
||||
|
||||
// settings load or create default
|
||||
@@ -250,10 +234,10 @@ int32_t rgb_backlight_srv(void* p) {
|
||||
|
||||
furi_record_create(RECORD_RGB_BACKLIGHT, app);
|
||||
|
||||
//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->rainbow_mode > 0) {
|
||||
rainbow_timer_starter(app);
|
||||
rainbow_timer_start(app);
|
||||
} else {
|
||||
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);
|
||||
@@ -269,7 +253,6 @@ int32_t rgb_backlight_srv(void* p) {
|
||||
}
|
||||
|
||||
while(1) {
|
||||
// place for message queue and other future options
|
||||
furi_delay_ms(5000);
|
||||
if(app->settings->rgb_backlight_installed) {
|
||||
FURI_LOG_D(TAG, "RGB backlight enabled - serivce is running");
|
||||
|
||||
@@ -32,21 +32,65 @@ typedef struct {
|
||||
uint8_t rainbow_red;
|
||||
uint8_t rainbow_green;
|
||||
uint8_t rainbow_blue;
|
||||
|
||||
RGBBacklightSettings* settings;
|
||||
|
||||
} RGBBacklightApp;
|
||||
|
||||
#define RECORD_RGB_BACKLIGHT "rgb_backlight"
|
||||
|
||||
/** Update leds colors from current_led[i].color and selected bright
|
||||
*
|
||||
* @param brightness - Brightness 0..1
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
|
||||
/** Set current_led[i].color for one led by static color index
|
||||
*
|
||||
* @param led - Led number (0..2)
|
||||
* @param index - Static color index number
|
||||
* @return
|
||||
*/
|
||||
void rgb_backlight_set_led_static_color(uint8_t led, uint8_t index);
|
||||
|
||||
/** Stop rainbow timer
|
||||
*
|
||||
* @param app - Instance of RGBBacklightApp from FURI RECORD
|
||||
* @return
|
||||
*/
|
||||
void rainbow_timer_stop(RGBBacklightApp* app);
|
||||
|
||||
/** Start rainbow timer
|
||||
*
|
||||
* @param app - Instance of RGBBacklightApp from FURI RECORD
|
||||
* @return
|
||||
*/
|
||||
|
||||
/** Start rainbow timer
|
||||
*
|
||||
* @param app - Instance of RGBBacklightApp from FURI RECORD
|
||||
* @return
|
||||
*/
|
||||
void rainbow_timer_start(RGBBacklightApp* app);
|
||||
|
||||
/** Start rainbow timer only if all conditions meet (rgb_backlight_installed && rainbow ON)
|
||||
*
|
||||
* @param app - Instance of RGBBacklightApp from FURI RECORD
|
||||
* @return
|
||||
*/
|
||||
void rainbow_timer_starter(RGBBacklightApp* app);
|
||||
|
||||
/** Get name of static color by index
|
||||
*
|
||||
* @param index - Static colors index number
|
||||
* @return - color name
|
||||
*/
|
||||
const char* rgb_backlight_get_color_text(uint8_t index);
|
||||
|
||||
/** Get static colors count
|
||||
*
|
||||
* @param
|
||||
* @return - colors count
|
||||
*/
|
||||
uint8_t rgb_backlight_get_color_count(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -16,8 +16,6 @@ typedef struct {
|
||||
VariableItemList* variable_item_list_rgb;
|
||||
} NotificationAppSettings;
|
||||
|
||||
//static VariableItem* temp_item;
|
||||
|
||||
static const NotificationSequence sequence_note_c = {
|
||||
&message_note_c5,
|
||||
&message_delay_100,
|
||||
@@ -126,13 +124,32 @@ const char* const rgb_backlight_rainbow_mode_text[RGB_BACKLIGHT_RAINBOW_MODE_COU
|
||||
};
|
||||
const uint32_t rgb_backlight_rainbow_mode_value[RGB_BACKLIGHT_RAINBOW_MODE_COUNT] = {0, 1, 2};
|
||||
|
||||
#define RGB_BACKLIGHT_RAINBOW_SPEED_COUNT 20
|
||||
#define RGB_BACKLIGHT_RAINBOW_SPEED_COUNT 10
|
||||
const char* const rgb_backlight_rainbow_speed_text[RGB_BACKLIGHT_RAINBOW_SPEED_COUNT] = {
|
||||
"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"};
|
||||
"0.1s",
|
||||
"0.2s",
|
||||
"0.3s",
|
||||
"0.4s",
|
||||
"0.5s",
|
||||
"0.6s",
|
||||
"0.7",
|
||||
"0.8",
|
||||
"0.9",
|
||||
"1s",
|
||||
};
|
||||
|
||||
const uint32_t rgb_backlight_rainbow_speed_value[RGB_BACKLIGHT_RAINBOW_SPEED_COUNT] = {
|
||||
100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,
|
||||
1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000};
|
||||
100,
|
||||
200,
|
||||
300,
|
||||
400,
|
||||
500,
|
||||
600,
|
||||
700,
|
||||
800,
|
||||
900,
|
||||
1000,
|
||||
};
|
||||
|
||||
#define RGB_BACKLIGHT_RAINBOW_STEP_COUNT 3
|
||||
const char* const rgb_backlight_rainbow_step_text[RGB_BACKLIGHT_RAINBOW_STEP_COUNT] = {
|
||||
@@ -182,7 +199,7 @@ static void backlight_changed(VariableItem* item) {
|
||||
app->notification->settings.display_brightness = backlight_value[index];
|
||||
|
||||
//--- RGB BACKLIGHT ---
|
||||
//set selected brightness to current rgb backlight service settings and save settings
|
||||
// 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 ---
|
||||
@@ -247,13 +264,14 @@ static void rgb_backlight_installed_changed(VariableItem* item) {
|
||||
rgb_backlight_settings_save(app->notification->rgb_srv->settings);
|
||||
|
||||
// In case of user playing with rgb_backlight_installed swith:
|
||||
// if user swith_off rgb_backlight_installed then force set default orange color - defence from stupid.
|
||||
// if user swith_off rgb_backlight_installed (but may be he have mod installed)
|
||||
// then force set default orange color - defence from stupid.
|
||||
if(index == 0) {
|
||||
rgb_backlight_set_led_static_color(2, 0);
|
||||
rgb_backlight_set_led_static_color(1, 0);
|
||||
rgb_backlight_set_led_static_color(0, 0);
|
||||
SK6805_update();
|
||||
// start rainbow (if its Enabled) or set saved static colors if user swith_on rgb_backlight_installed switch
|
||||
// start rainbow (if its Enabled) or set saved static colors if user swith_on rgb_backlight_installed switch
|
||||
} else {
|
||||
if(app->notification->rgb_srv->settings->rainbow_mode > 0) {
|
||||
rainbow_timer_starter(app->notification->rgb_srv);
|
||||
@@ -290,7 +308,7 @@ static void led_2_color_changed(VariableItem* item) {
|
||||
variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index));
|
||||
app->notification->rgb_srv->settings->led_2_color_index = index;
|
||||
|
||||
//dont update screen color if rainbow timer working
|
||||
// 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);
|
||||
@@ -305,7 +323,7 @@ static void led_1_color_changed(VariableItem* item) {
|
||||
variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index));
|
||||
app->notification->rgb_srv->settings->led_1_color_index = index;
|
||||
|
||||
//dont update screen color if rainbow timer working
|
||||
// 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(1, index);
|
||||
rgb_backlight_update(app->notification->rgb_srv->settings->brightness);
|
||||
@@ -321,7 +339,7 @@ static void led_0_color_changed(VariableItem* item) {
|
||||
variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index));
|
||||
app->notification->rgb_srv->settings->led_0_color_index = index;
|
||||
|
||||
//dont update screen color if rainbow timer working
|
||||
// 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(0, index);
|
||||
rgb_backlight_update(app->notification->rgb_srv->settings->brightness);
|
||||
@@ -360,7 +378,7 @@ static void rgb_backlight_rainbow_speed_changed(VariableItem* item) {
|
||||
app->notification->rgb_srv->settings->rainbow_speed_ms =
|
||||
rgb_backlight_rainbow_speed_value[index];
|
||||
|
||||
//save settings and restart timer with new speed value
|
||||
// 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);
|
||||
}
|
||||
@@ -378,7 +396,7 @@ static void rgb_backlight_rainbow_step_changed(VariableItem* item) {
|
||||
static void rgb_backlight_rainbow_saturation_changed(VariableItem* item) {
|
||||
NotificationAppSettings* app = variable_item_get_context(item);
|
||||
|
||||
//saturation must be 1..255, so we do (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;
|
||||
char valtext[4] = {};
|
||||
snprintf(valtext, sizeof(valtext), "%d", index);
|
||||
@@ -394,7 +412,7 @@ static void rgb_backlight_rainbow_wide_changed(VariableItem* 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
|
||||
// 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);
|
||||
}
|
||||
@@ -442,7 +460,7 @@ static NotificationAppSettings* alloc_settings(void) {
|
||||
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_backlight_installed is active
|
||||
// Show RGB settings only when debug_mode or rgb_backlight_installed is active
|
||||
if((app->notification->rgb_srv->settings->rgb_backlight_installed) ||
|
||||
(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug))) {
|
||||
item = variable_item_list_add(app->variable_item_list, "RGB settings", 0, NULL, app);
|
||||
@@ -513,7 +531,7 @@ static NotificationAppSettings* alloc_settings(void) {
|
||||
// set callback for exit from rgb_settings_menu
|
||||
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)) {
|
||||
item = variable_item_list_add(
|
||||
app->variable_item_list_rgb,
|
||||
|
||||
Reference in New Issue
Block a user