From 2f8d49d764bd04849aac496c8c4615d1dac799ca Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 13 Aug 2023 18:23:08 +0200 Subject: [PATCH 01/17] Add icons to esubghz chat menu --nobuild --- .../external/esubghz_chat/assets/hex_10px.png | Bin 0 -> 171 bytes .../scenes/esubghz_chat_key_menu.c | 20 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 applications/external/esubghz_chat/assets/hex_10px.png diff --git a/applications/external/esubghz_chat/assets/hex_10px.png b/applications/external/esubghz_chat/assets/hex_10px.png new file mode 100644 index 0000000000000000000000000000000000000000..582e288c6dc61ccfffd8bcfe52dd386f7f253bfa GIT binary patch literal 171 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2VGXn$T+1LD%K#pXIYeY$Kep*R+Vo@rCV@iHf zs)A>3VtQ&&YGO)d;mK4Rpdz*apAgsoT|gGYuCKccfRweTi(^Q|t)v77#s&r^#Ri6? zgp>pp4h4gw94ZV<9gTuoEKitN1f1mbxTmrKl{kkU?C6>B)uBZIXxa+~g^a@Zbs*zB MUHx3vIVCg!0RLJn-v9sr literal 0 HcmV?d00001 diff --git a/applications/external/esubghz_chat/scenes/esubghz_chat_key_menu.c b/applications/external/esubghz_chat/scenes/esubghz_chat_key_menu.c index 4e54e692f..13483bf53 100644 --- a/applications/external/esubghz_chat/scenes/esubghz_chat_key_menu.c +++ b/applications/external/esubghz_chat/scenes/esubghz_chat_key_menu.c @@ -76,20 +76,30 @@ void scene_on_enter_key_menu(void* context) { menu_add_item( state->menu, "No encryption", - NULL, + &I_chat_10px, ESubGhzChatKeyMenuItems_NoEncryption, key_menu_cb, state); menu_add_item( - state->menu, "Password", NULL, ESubGhzChatKeyMenuItems_Password, key_menu_cb, state); + state->menu, + "Password", + &I_keyboard_10px, + ESubGhzChatKeyMenuItems_Password, + key_menu_cb, + state); menu_add_item( - state->menu, "Hex Key", NULL, ESubGhzChatKeyMenuItems_HexKey, key_menu_cb, state); + state->menu, "Hex Key", &I_hex_10px, ESubGhzChatKeyMenuItems_HexKey, key_menu_cb, state); menu_add_item( - state->menu, "Generate Key", NULL, ESubGhzChatKeyMenuItems_GenKey, key_menu_cb, state); + state->menu, + "Generate Key", + &I_u2f_10px, + ESubGhzChatKeyMenuItems_GenKey, + key_menu_cb, + state); menu_add_item( state->menu, "Read Key from NFC", - NULL, + &I_Nfc_10px, ESubGhzChatKeyMenuItems_ReadKeyFromNfc, key_menu_cb, state); From 6f64300aa9b8bf736d921ea0c8140313e70c194f Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 14 Aug 2023 01:03:44 +0200 Subject: [PATCH 02/17] Update api symbols --- firmware/targets/f7/api_symbols.csv | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 9a88fe7f7..b53c19e90 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1171,18 +1171,18 @@ Function,+,furi_hal_cortex_timer_is_expired,_Bool,FuriHalCortexTimer Function,+,furi_hal_cortex_timer_wait,void,FuriHalCortexTimer Function,+,furi_hal_crypto_ctr,_Bool,"const uint8_t*, const uint8_t*, const uint8_t*, uint8_t*, size_t" Function,+,furi_hal_crypto_decrypt,_Bool,"const uint8_t*, uint8_t*, size_t" +Function,+,furi_hal_crypto_enclave_ensure_key,_Bool,uint8_t +Function,+,furi_hal_crypto_enclave_load_key,_Bool,"uint8_t, const uint8_t*" +Function,+,furi_hal_crypto_enclave_store_key,_Bool,"FuriHalCryptoKey*, uint8_t*" +Function,+,furi_hal_crypto_enclave_unload_key,_Bool,uint8_t +Function,+,furi_hal_crypto_enclave_verify,_Bool,"uint8_t*, uint8_t*" Function,+,furi_hal_crypto_encrypt,_Bool,"const uint8_t*, uint8_t*, size_t" Function,+,furi_hal_crypto_gcm,_Bool,"const uint8_t*, const uint8_t*, const uint8_t*, size_t, const uint8_t*, uint8_t*, size_t, uint8_t*, _Bool" Function,+,furi_hal_crypto_gcm_decrypt_and_verify,FuriHalCryptoGCMState,"const uint8_t*, const uint8_t*, const uint8_t*, size_t, const uint8_t*, uint8_t*, size_t, const uint8_t*" Function,+,furi_hal_crypto_gcm_encrypt_and_tag,FuriHalCryptoGCMState,"const uint8_t*, const uint8_t*, const uint8_t*, size_t, const uint8_t*, uint8_t*, size_t, uint8_t*" Function,-,furi_hal_crypto_init,void, Function,+,furi_hal_crypto_load_key,_Bool,"const uint8_t*, const uint8_t*" -Function,+,furi_hal_crypto_enclave_store_key,_Bool,"FuriHalCryptoKey*, uint8_t*" -Function,+,furi_hal_crypto_enclave_load_key,_Bool,"uint8_t, const uint8_t*" -Function,+,furi_hal_crypto_enclave_unload_key,_Bool,uint8_t Function,+,furi_hal_crypto_unload_key,_Bool, -Function,+,furi_hal_crypto_enclave_verify,_Bool,"uint8_t*, uint8_t*" -Function,+,furi_hal_crypto_enclave_ensure_key,_Bool,uint8_t Function,+,furi_hal_debug_disable,void, Function,+,furi_hal_debug_enable,void, Function,+,furi_hal_debug_is_gdb_session_active,_Bool, From 5e8efe8281206c3b7e7a5256efa74aa8561f47ae Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 14 Aug 2023 01:17:37 +0200 Subject: [PATCH 03/17] Add colors toolbox (rgb and hsv) --- firmware/targets/f7/api_symbols.csv | 2 + lib/toolbox/colors.c | 87 +++++++++++++++++++++++++++++ lib/toolbox/colors.h | 27 +++++++++ 3 files changed, 116 insertions(+) create mode 100644 lib/toolbox/colors.c create mode 100644 lib/toolbox/colors.h diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index b53c19e90..3613133bd 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1733,6 +1733,7 @@ Function,+,hex_char_to_hex_nibble,_Bool,"char, uint8_t*" Function,+,hex_char_to_uint8,_Bool,"char, char, uint8_t*" Function,+,hex_chars_to_uint64,_Bool,"const char*, uint64_t*" Function,+,hex_chars_to_uint8,_Bool,"const char*, uint8_t*" +Function,+,hsv2rgb,RgbColor,HsvColor Function,-,hypot,double,"double, double" Function,-,hypotf,float,"float, float" Function,-,hypotl,long double,"long double, long double" @@ -2555,6 +2556,7 @@ Function,-,rfal_platform_spi_acquire,void, 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_count,uint8_t, Function,+,rgb_backlight_get_color_text,const char*,uint8_t Function,+,rgb_backlight_get_settings,RGBBacklightSettings*, diff --git a/lib/toolbox/colors.c b/lib/toolbox/colors.c new file mode 100644 index 000000000..0de9ecf85 --- /dev/null +++ b/lib/toolbox/colors.c @@ -0,0 +1,87 @@ +// https://stackoverflow.com/a/14733008 + +#include "colors.h" + +RgbColor hsv2rgb(HsvColor hsv) { + RgbColor rgb; + uint8_t region, remainder, p, q, t; + + if(hsv.s == 0) { + rgb.r = hsv.v; + rgb.g = hsv.v; + rgb.b = hsv.v; + return rgb; + } + + region = hsv.h / 43; + remainder = (hsv.h - (region * 43)) * 6; + + p = (hsv.v * (255 - hsv.s)) >> 8; + q = (hsv.v * (255 - ((hsv.s * remainder) >> 8))) >> 8; + t = (hsv.v * (255 - ((hsv.s * (255 - remainder)) >> 8))) >> 8; + + switch(region) { + case 0: + rgb.r = hsv.v; + rgb.g = t; + rgb.b = p; + break; + case 1: + rgb.r = q; + rgb.g = hsv.v; + rgb.b = p; + break; + case 2: + rgb.r = p; + rgb.g = hsv.v; + rgb.b = t; + break; + case 3: + rgb.r = p; + rgb.g = q; + rgb.b = hsv.v; + break; + case 4: + rgb.r = t; + rgb.g = p; + rgb.b = hsv.v; + break; + default: + rgb.r = hsv.v; + rgb.g = p; + rgb.b = q; + break; + } + + return rgb; +} + +HsvColor rgb2hsv(RgbColor rgb) { + HsvColor hsv; + uint8_t rgbMin, rgbMax; + + rgbMin = rgb.r < rgb.g ? (rgb.r < rgb.b ? rgb.r : rgb.b) : (rgb.g < rgb.b ? rgb.g : rgb.b); + rgbMax = rgb.r > rgb.g ? (rgb.r > rgb.b ? rgb.r : rgb.b) : (rgb.g > rgb.b ? rgb.g : rgb.b); + + hsv.v = rgbMax; + if(hsv.v == 0) { + hsv.h = 0; + hsv.s = 0; + return hsv; + } + + hsv.s = 255 * ((long)rgbMax - (long)rgbMin) / hsv.v; + if(hsv.s == 0) { + hsv.h = 0; + return hsv; + } + + if(rgbMax == rgb.r) + hsv.h = 0 + 43 * (rgb.g - rgb.b) / (rgbMax - rgbMin); + else if(rgbMax == rgb.g) + hsv.h = 85 + 43 * (rgb.b - rgb.r) / (rgbMax - rgbMin); + else + hsv.h = 171 + 43 * (rgb.r - rgb.g) / (rgbMax - rgbMin); + + return hsv; +} diff --git a/lib/toolbox/colors.h b/lib/toolbox/colors.h new file mode 100644 index 000000000..8fc930dbf --- /dev/null +++ b/lib/toolbox/colors.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct RgbColor { + uint8_t r; + uint8_t g; + uint8_t b; +} RgbColor; + +typedef struct HsvColor { + uint8_t h; + uint8_t s; + uint8_t v; +} HsvColor; + +RgbColor hsv2rgb(HsvColor hsv); + +HsvColor rgb2hsv(RgbColor rgb); + +#ifdef __cplusplus +} +#endif From 520b4ace2ec7606ed76b00dd69d19c23f6578dbc Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 14 Aug 2023 03:19:18 +0200 Subject: [PATCH 04/17] Forma value and name settings arrays --- .../xtreme_app_scene_interface_graphics.c | 52 ++++++++++++++++--- .../xtreme_app_scene_interface_statusbar.c | 11 +++- .../scenes/xtreme_app_scene_misc_dolphin.c | 28 ++++++++-- 3 files changed, 78 insertions(+), 13 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_graphics.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_graphics.c index d4c8e42fa..c03b2abb3 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_graphics.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_graphics.c @@ -27,10 +27,34 @@ static void xtreme_app_scene_interface_graphics_asset_pack_changed(VariableItem* app->apply_pack = true; } -const char* const anim_speed_names[] = - {"25%", "50%", "75%", "100%", "125%", "150%", "175%", "200%", "225%", "250%", "275%", "300%"}; -const uint32_t anim_speed_values[COUNT_OF(anim_speed_names)] = - {25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300}; +const char* const anim_speed_names[] = { + "25%", + "50%", + "75%", + "100%", + "125%", + "150%", + "175%", + "200%", + "225%", + "250%", + "275%", + "300%", +}; +const uint32_t anim_speed_values[COUNT_OF(anim_speed_names)] = { + 25, + 50, + 75, + 100, + 125, + 150, + 175, + 200, + 225, + 250, + 275, + 300, +}; static void xtreme_app_scene_interface_graphics_anim_speed_changed(VariableItem* item) { XtremeApp* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -52,9 +76,23 @@ const char* const cycle_anims_names[] = { "2 H", "6 H", "12 H", - "24 H"}; -const int32_t cycle_anims_values[COUNT_OF(cycle_anims_names)] = - {-1, 0, 30, 60, 300, 600, 900, 1800, 3600, 7200, 21600, 43200, 86400}; + "24 H", +}; +const int32_t cycle_anims_values[COUNT_OF(cycle_anims_names)] = { + -1, + 0, + 30, + 60, + 300, + 600, + 900, + 1800, + 3600, + 7200, + 21600, + 43200, + 86400, +}; static void xtreme_app_scene_interface_graphics_cycle_anims_changed(VariableItem* item) { XtremeApp* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c index 50b3c14ec..953c08c95 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c @@ -13,8 +13,15 @@ void xtreme_app_scene_interface_statusbar_var_item_list_callback(void* context, view_dispatcher_send_custom_event(app->view_dispatcher, index); } -const char* const battery_icon_names[BatteryIconCount] = - {"OFF", "Bar", "%", "Inv. %", "Retro 3", "Retro 5", "Bar %"}; +const char* const battery_icon_names[BatteryIconCount] = { + "OFF", + "Bar", + "%", + "Inv. %", + "Retro 3", + "Retro 5", + "Bar %", +}; static void xtreme_app_scene_interface_statusbar_battery_icon_changed(VariableItem* item) { XtremeApp* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_dolphin.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_dolphin.c index e6425d20b..e4d344e09 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_dolphin.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_dolphin.c @@ -29,10 +29,30 @@ static void xtreme_app_scene_misc_dolphin_dolphin_angry_changed(VariableItem* it app->save_angry = true; } -const char* const butthurt_timer_names[] = - {"OFF", "30 M", "1 H", "2 H", "4 H", "6 H", "8 H", "12 H", "24 H", "48 H"}; -const uint32_t butthurt_timer_values[COUNT_OF(butthurt_timer_names)] = - {0, 1800, 3600, 7200, 14400, 21600, 28800, 43200, 86400, 172800}; +const char* const butthurt_timer_names[] = { + "OFF", + "30 M", + "1 H", + "2 H", + "4 H", + "6 H", + "8 H", + "12 H", + "24 H", + "48 H", +}; +const uint32_t butthurt_timer_values[COUNT_OF(butthurt_timer_names)] = { + 0, + 1800, + 3600, + 7200, + 14400, + 21600, + 28800, + 43200, + 86400, + 172800, +}; static void xtreme_app_scene_misc_dolphin_butthurt_timer_changed(VariableItem* item) { XtremeApp* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); From fed21fae64d48e4a9e64c127f52f060ec956068b Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 14 Aug 2023 05:28:49 +0200 Subject: [PATCH 05/17] Rainbow rgb backlight + full rgb code rework --- .../scenes/xtreme_app_scene_misc_screen.c | 99 +++++- firmware/targets/f7/api_symbols.csv | 10 +- firmware/targets/f7/furi_hal/furi_hal_light.c | 2 +- lib/drivers/rgb_backlight.c | 317 +++++++++++------- lib/drivers/rgb_backlight.h | 104 +++--- 5 files changed, 371 insertions(+), 161 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c index b86326aae..14d6ed439 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c @@ -39,6 +39,65 @@ static void xtreme_app_scene_misc_screen_lcd_color_changed(VariableItem* item) { notification_message(app->notification, &sequence_display_backlight_on); } +const char* const rainbow_lcd_names[RGBBacklightRainbowModeCount] = { + "OFF", + "Wave", + "Static", +}; +static void xtreme_app_scene_misc_screen_rainbow_lcd_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, rainbow_lcd_names[index]); + rgb_backlight_set_rainbow_mode(index); + app->save_backlight = true; +} + +static void xtreme_app_scene_misc_screen_rainbow_speed_changed(VariableItem* item) { + XtremeApp* app = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item) + 1; + char str[4]; + snprintf(str, sizeof(str), "%d", index); + variable_item_set_current_value_text(item, str); + rgb_backlight_set_rainbow_speed(index); + app->save_backlight = true; +} + +const char* const rainbow_interval_names[] = { + "0.25 S", + "0.50 S", + "0.75 S", + "1.00 S", + "1.25 S", + "1.50 S", + "1.75 S", + "2.00 S", + "2.50 S", + "3.00 S", + "4.00 S", + "5.00 S", +}; +const uint32_t rainbow_interval_values[COUNT_OF(rainbow_interval_names)] = { + 250, + 500, + 750, + 1000, + 1250, + 1500, + 1750, + 2000, + 2500, + 3000, + 4000, + 5000, +}; +static void xtreme_app_scene_misc_screen_rainbow_interval_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, rainbow_interval_names[index]); + rgb_backlight_set_rainbow_interval(rainbow_interval_values[index]); + app->save_backlight = true; +} + void xtreme_app_scene_misc_screen_on_enter(void* context) { XtremeApp* app = context; XtremeSettings* xtreme_settings = XTREME_SETTINGS(); @@ -66,11 +125,49 @@ void xtreme_app_scene_misc_screen_on_enter(void* context) { rgb_backlight_get_color_count(), xtreme_app_scene_misc_screen_lcd_color_changed, app); - value_index = rgb_backlight_get_settings()->display_color_index; + 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)); variable_item_set_locked(item, !xtreme_settings->rgb_backlight, "Needs RGB\nBacklight!"); + item = variable_item_list_add( + var_item_list, + "Rainbow LCD", + RGBBacklightRainbowModeCount, + xtreme_app_scene_misc_screen_rainbow_lcd_changed, + app); + value_index = rgb_backlight_get_rainbow_mode(); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rainbow_lcd_names[value_index]); + variable_item_set_locked(item, !xtreme_settings->rgb_backlight, "Needs RGB\nBacklight!"); + + item = variable_item_list_add( + var_item_list, + "Rainbow Speed", + 25, + xtreme_app_scene_misc_screen_rainbow_speed_changed, + app); + value_index = rgb_backlight_get_rainbow_speed(); + variable_item_set_current_value_index(item, value_index - 1); + char str[4]; + snprintf(str, sizeof(str), "%d", value_index); + variable_item_set_current_value_text(item, str); + variable_item_set_locked(item, !xtreme_settings->rgb_backlight, "Needs RGB\nBacklight!"); + + item = variable_item_list_add( + var_item_list, + "Rainbow Interval", + COUNT_OF(rainbow_interval_values), + xtreme_app_scene_misc_screen_rainbow_interval_changed, + app); + value_index = value_index_uint32( + rgb_backlight_get_rainbow_interval(), + rainbow_interval_values, + COUNT_OF(rainbow_interval_values)); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, rainbow_interval_names[value_index]); + variable_item_set_locked(item, !xtreme_settings->rgb_backlight, "Needs RGB\nBacklight!"); + variable_item_list_set_enter_callback( var_item_list, xtreme_app_scene_misc_screen_var_item_list_callback, app); diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 3613133bd..b04807412 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -2557,13 +2557,19 @@ 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_settings,RGBBacklightSettings*, +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_save_settings,void, Function,+,rgb_backlight_set_color,void,uint8_t -Function,-,rgb_backlight_update,void,uint8_t +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 +Function,-,rgb_backlight_update,void,"uint8_t, _Bool" Function,-,rindex,char*,"const char*, int" Function,-,rint,double,double Function,-,rintf,float,float diff --git a/firmware/targets/f7/furi_hal/furi_hal_light.c b/firmware/targets/f7/furi_hal/furi_hal_light.c index 2673b8a58..df7c23d56 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_light.c +++ b/firmware/targets/f7/furi_hal/furi_hal_light.c @@ -45,7 +45,7 @@ void furi_hal_light_set(Light light, uint8_t value) { } if(light & LightBacklight) { if(XTREME_SETTINGS()->rgb_backlight) { - rgb_backlight_update(value); + rgb_backlight_update(value, false); } else { uint8_t prev = lp5562_get_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelWhite); diff --git a/lib/drivers/rgb_backlight.c b/lib/drivers/rgb_backlight.c index ec39efb0b..7b947c058 100644 --- a/lib/drivers/rgb_backlight.c +++ b/lib/drivers/rgb_backlight.c @@ -1,6 +1,7 @@ /* RGB backlight FlipperZero driver Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + Heavily modified by Willy-JL and Z3bro This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,156 +20,244 @@ #include "rgb_backlight.h" #include #include +#include -#define RGB_BACKLIGHT_SETTINGS_VERSION 5 +#define RGB_BACKLIGHT_SETTINGS_MAGIC 0x15 +#define RGB_BACKLIGHT_SETTINGS_VERSION 6 #define RGB_BACKLIGHT_SETTINGS_PATH CFG_PATH("rgb_backlight.settings") -#define COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightColor)) - -#define TAG "RGB Backlight" - -static RGBBacklightSettings rgb_settings = { - .version = RGB_BACKLIGHT_SETTINGS_VERSION, +static struct { + uint8_t display_color_index; + RGBBacklightRainbowMode rainbow_mode; + uint8_t rainbow_speed; + uint32_t rainbow_interval; +} rgb_settings = { .display_color_index = 0, - .settings_is_loaded = false}; + .rainbow_mode = RGBBacklightRainbowModeOff, + .rainbow_speed = 5, + .rainbow_interval = 1000, +}; -static const RGBBacklightColor 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 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 last_rainbow; + uint8_t last_brightness; + uint8_t last_color_index; + FuriTimer* rainbow_timer; + HsvColor rainbow_hsv; +} rgb_state = { + .settings_loaded = false, + .last_rainbow = true, + .last_brightness = 0, + .last_color_index = 255, + .rainbow_timer = NULL, + .rainbow_hsv = + { + .h = 0, + .s = 255, + .v = 255, + }, }; uint8_t rgb_backlight_get_color_count(void) { - return COLOR_COUNT; + 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); +} + +static void rainbow_configure() { + if(rgb_settings.rainbow_mode != RGBBacklightRainbowModeOff) { + if(rgb_state.rainbow_timer == NULL) { + rgb_state.rainbow_timer = furi_timer_alloc(rainbow_timer, FuriTimerTypePeriodic, NULL); + } else { + furi_timer_stop(rgb_state.rainbow_timer); + } + furi_timer_start(rgb_state.rainbow_timer, rgb_settings.rainbow_interval); + } else if(rgb_state.rainbow_timer != NULL) { + furi_timer_stop(rgb_state.rainbow_timer); + furi_timer_free(rgb_state.rainbow_timer); + rgb_state.rainbow_timer = NULL; + } +} + void rgb_backlight_load_settings(void) { //Не загружать данные из внутренней памяти при загрузке в режиме DFU - if(!furi_hal_is_normal_boot()) { - rgb_settings.settings_is_loaded = true; + if(!furi_hal_is_normal_boot() || rgb_state.settings_loaded) { + rgb_state.settings_loaded = true; return; } - RGBBacklightSettings settings; - File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE)); - const size_t settings_size = sizeof(RGBBacklightSettings); + saved_struct_load( + RGB_BACKLIGHT_SETTINGS_PATH, + &rgb_settings, + sizeof(rgb_settings), + RGB_BACKLIGHT_SETTINGS_MAGIC, + RGB_BACKLIGHT_SETTINGS_VERSION); - FURI_LOG_I(TAG, "loading settings from \"%s\"", RGB_BACKLIGHT_SETTINGS_PATH); - bool fs_result = - storage_file_open(file, RGB_BACKLIGHT_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING); - - if(fs_result) { - uint16_t bytes_count = storage_file_read(file, &settings, settings_size); - - if(bytes_count != settings_size) { - fs_result = false; - } - } - - if(fs_result) { - FURI_LOG_I(TAG, "load success"); - if(settings.version != RGB_BACKLIGHT_SETTINGS_VERSION) { - FURI_LOG_E( - TAG, - "version(%d != %d) mismatch", - settings.version, - RGB_BACKLIGHT_SETTINGS_VERSION); - } else { - memcpy(&rgb_settings, &settings, settings_size); - } - } else { - FURI_LOG_E(TAG, "load failed, %s", storage_file_get_error_desc(file)); - } - - storage_file_close(file); - storage_file_free(file); - furi_record_close(RECORD_STORAGE); - rgb_settings.settings_is_loaded = true; + rgb_state.settings_loaded = true; + rainbow_configure(); } void rgb_backlight_save_settings(void) { - RGBBacklightSettings settings; - File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE)); - const size_t settings_size = sizeof(RGBBacklightSettings); - - FURI_LOG_I(TAG, "saving settings to \"%s\"", RGB_BACKLIGHT_SETTINGS_PATH); - - memcpy(&settings, &rgb_settings, settings_size); - - bool fs_result = - storage_file_open(file, RGB_BACKLIGHT_SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS); - - if(fs_result) { - uint16_t bytes_count = storage_file_write(file, &settings, settings_size); - - if(bytes_count != settings_size) { - fs_result = false; - } - } - - if(fs_result) { - FURI_LOG_I(TAG, "save success"); - } else { - FURI_LOG_E(TAG, "save failed, %s", storage_file_get_error_desc(file)); - } - - storage_file_close(file); - storage_file_free(file); - furi_record_close(RECORD_STORAGE); -} - -RGBBacklightSettings* rgb_backlight_get_settings(void) { - if(!rgb_settings.settings_is_loaded) { - rgb_backlight_load_settings(); - } - return &rgb_settings; + saved_struct_save( + RGB_BACKLIGHT_SETTINGS_PATH, + &rgb_settings, + sizeof(rgb_settings), + RGB_BACKLIGHT_SETTINGS_MAGIC, + RGB_BACKLIGHT_SETTINGS_VERSION); } void rgb_backlight_set_color(uint8_t color_index) { + 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; } -void rgb_backlight_update(uint8_t brightness) { - if(!rgb_settings.settings_is_loaded) { +uint8_t rgb_backlight_get_color() { + if(!rgb_state.settings_loaded) { + rgb_backlight_load_settings(); + } + return rgb_settings.display_color_index; +} + +void rgb_backlight_set_rainbow_mode(RGBBacklightRainbowMode rainbow_mode) { + if(!rgb_state.settings_loaded) { + rgb_backlight_load_settings(); + } + if(rainbow_mode > (RGBBacklightRainbowModeCount - 1)) rainbow_mode = 0; + rgb_settings.rainbow_mode = rainbow_mode; + rainbow_configure(); +} + +RGBBacklightRainbowMode rgb_backlight_get_rainbow_mode() { + if(!rgb_state.settings_loaded) { + rgb_backlight_load_settings(); + } + return rgb_settings.rainbow_mode; +} + +void rgb_backlight_set_rainbow_speed(uint8_t rainbow_speed) { + if(!rgb_state.settings_loaded) { + rgb_backlight_load_settings(); + } + rgb_settings.rainbow_speed = rainbow_speed; +} + +uint8_t rgb_backlight_get_rainbow_speed() { + if(!rgb_state.settings_loaded) { + rgb_backlight_load_settings(); + } + return rgb_settings.rainbow_speed; +} + +void rgb_backlight_set_rainbow_interval(uint32_t rainbow_interval) { + if(!rgb_state.settings_loaded) { + rgb_backlight_load_settings(); + } + rgb_settings.rainbow_interval = rainbow_interval; + rainbow_configure(); +} + +uint32_t rgb_backlight_get_rainbow_interval() { + if(!rgb_state.settings_loaded) { + rgb_backlight_load_settings(); + } + return rgb_settings.rainbow_interval; +} + +void rgb_backlight_update(uint8_t brightness, bool tick) { + if(!rgb_state.settings_loaded) { rgb_backlight_load_settings(); } - static uint8_t last_color_index = 255; - static uint8_t last_brightness = 123; + 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) { + return; + } + rgb_state.last_rainbow = false; + rgb_state.last_color_index = rgb_settings.display_color_index; - if(last_brightness == brightness && last_color_index == rgb_settings.display_color_index) - return; + RgbColor rgb = colors[rgb_settings.display_color_index].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); - last_brightness = brightness; - last_color_index = rgb_settings.display_color_index; - - for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { - uint8_t r = colors[rgb_settings.display_color_index].red * (brightness / 255.0f); - uint8_t g = colors[rgb_settings.display_color_index].green * (brightness / 255.0f); - uint8_t b = colors[rgb_settings.display_color_index].blue * (brightness / 255.0f); - - SK6805_set_led_color(i, r, g, b); + for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { + SK6805_set_led_color(i, rgb.r, rgb.g, rgb.b); + } + break; } + case RGBBacklightRainbowModeWave: + case RGBBacklightRainbowModeSolid: { + rgb_state.last_rainbow = true; + + if(tick && brightness) { + rgb_state.rainbow_hsv.h += rgb_settings.rainbow_speed; + } else { + if(rgb_state.last_brightness == brightness && rgb_state.last_rainbow) { + return; + } + rgb_state.rainbow_hsv.v = brightness; + } + + HsvColor hsv = rgb_state.rainbow_hsv; + FURI_LOG_I("RgbBacklight", "hsv %d %d %d", hsv.h, hsv.s, hsv.v); + RgbColor rgb = hsv2rgb(hsv); + FURI_LOG_I("RgbBacklight", "rgb %d %d %d", rgb.r, rgb.g, rgb.b); + + for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { + if(i && rgb_settings.rainbow_mode == RGBBacklightRainbowModeWave) { + hsv.h += (50 * i); + rgb = hsv2rgb(hsv); + FURI_LOG_I("RgbBacklight", "rgb %d %d %d", rgb.r, rgb.g, rgb.b); + } + SK6805_set_led_color(i, rgb.r, rgb.g, rgb.b); + } + break; + } + + default: + return; + } + + rgb_state.last_brightness = brightness; SK6805_update(); } diff --git a/lib/drivers/rgb_backlight.h b/lib/drivers/rgb_backlight.h index c00eb0716..8493dd7a8 100644 --- a/lib/drivers/rgb_backlight.h +++ b/lib/drivers/rgb_backlight.h @@ -18,54 +18,18 @@ #include #include "SK6805.h" +#include #ifdef __cplusplus extern "C" { #endif -typedef struct { - char* name; - uint8_t red; - uint8_t green; - uint8_t blue; -} RGBBacklightColor; - -typedef struct { - uint8_t version; - uint8_t display_color_index; - bool settings_is_loaded; -} RGBBacklightSettings; - -/** - * @brief Получить текущие настройки RGB-подсветки - * - * @return Указатель на структуру настроек - */ -RGBBacklightSettings* rgb_backlight_get_settings(void); - -/** - * @brief Загрузить настройки подсветки с SD-карты - */ -void rgb_backlight_load_settings(void); - -/** - * @brief Сохранить текущие настройки RGB-подсветки - */ -void rgb_backlight_save_settings(void); - -/** - * @brief Применить текущие настройки RGB-подсветки - * - * @param brightness Яркость свечения (0-255) - */ -void rgb_backlight_update(uint8_t brightness); - -/** - * @brief Установить цвет RGB-подсветки - * - * @param color_index Индекс цвета (0 - rgb_backlight_get_color_count()) - */ -void rgb_backlight_set_color(uint8_t color_index); +typedef enum { + RGBBacklightRainbowModeOff, + RGBBacklightRainbowModeWave, + RGBBacklightRainbowModeSolid, + RGBBacklightRainbowModeCount, +} RGBBacklightRainbowMode; /** * @brief Получить количество доступных цветов @@ -82,6 +46,60 @@ uint8_t rgb_backlight_get_color_count(void); */ const char* rgb_backlight_get_color_text(uint8_t index); +/** + * @brief Загрузить настройки подсветки с SD-карты + */ +void rgb_backlight_load_settings(); + +/** + * @brief Сохранить текущие настройки RGB-подсветки + */ +void rgb_backlight_save_settings(); + +/** + * @brief Установить цвет RGB-подсветки + * + * @param color_index Индекс цвета (0 - rgb_backlight_get_color_count()) + */ +void rgb_backlight_set_color(uint8_t color_index); + +uint8_t rgb_backlight_get_color(); + +/** + * @brief Change rainbow mode + * + * @param rainbow_mode What mode to use (0 - RGBBacklightRainbowModeCount) + */ +void rgb_backlight_set_rainbow_mode(RGBBacklightRainbowMode rainbow_mode); + +RGBBacklightRainbowMode rgb_backlight_get_rainbow_mode(); + +/** + * @brief Change rainbow speed + * + * @param rainbow_speed What speed to use (0 - 255) + */ +void rgb_backlight_set_rainbow_speed(uint8_t rainbow_speed); + +uint8_t rgb_backlight_get_rainbow_speed(); + +/** + * @brief Change rainbow interval + * + * @param rainbow_interval What interval to use + */ +void rgb_backlight_set_rainbow_interval(uint32_t rainbow_interval); + +uint32_t rgb_backlight_get_rainbow_interval(); + +/** + * @brief Применить текущие настройки RGB-подсветки + * + * @param brightness Яркость свечения (0-255) + * @param tick Whether this update was a tick (for rainbow) + */ +void rgb_backlight_update(uint8_t brightness, bool tick); + #ifdef __cplusplus } #endif From d413d30a2db68e5fe27cdff2f7d4319f240376a1 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 00:20:46 +0200 Subject: [PATCH 06/17] Fix rgb backlight configuration and setup --- .../scenes/xtreme_app_scene_misc_screen.c | 2 +- firmware/targets/f7/api_symbols.csv | 1 + lib/drivers/rgb_backlight.c | 21 ++++++++++++++----- lib/drivers/rgb_backlight.h | 7 +++++++ lib/xtreme/settings.c | 3 +++ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c index 14d6ed439..fc624c8e7 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c @@ -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); } diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index b04807412..7cb0ef0ee 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -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 diff --git a/lib/drivers/rgb_backlight.c b/lib/drivers/rgb_backlight.c index 7b947c058..86ee4291e 100644 --- a/lib/drivers/rgb_backlight.c +++ b/lib/drivers/rgb_backlight.c @@ -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(); } diff --git a/lib/drivers/rgb_backlight.h b/lib/drivers/rgb_backlight.h index 8493dd7a8..97fe561ce 100644 --- a/lib/drivers/rgb_backlight.h +++ b/lib/drivers/rgb_backlight.h @@ -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-карты */ diff --git a/lib/xtreme/settings.c b/lib/xtreme/settings.c index 9198161cb..49bf67d0b 100644 --- a/lib/xtreme/settings.c +++ b/lib/xtreme/settings.c @@ -1,5 +1,6 @@ #include "xtreme.h" #include +#include #include #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() { From 9a3036387f11137e4a1441ee102324d94b3c1c76 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 00:59:44 +0200 Subject: [PATCH 07/17] Add color compare api --- firmware/targets/f7/api_symbols.csv | 2 ++ lib/toolbox/colors.c | 8 ++++++++ lib/toolbox/colors.h | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 7cb0ef0ee..1c0925050 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1734,6 +1734,7 @@ Function,+,hex_char_to_uint8,_Bool,"char, char, uint8_t*" Function,+,hex_chars_to_uint64,_Bool,"const char*, uint64_t*" Function,+,hex_chars_to_uint8,_Bool,"const char*, uint8_t*" Function,+,hsv2rgb,RgbColor,HsvColor +Function,+,hsvcmp,int,"HsvColor*, HsvColor*" Function,-,hypot,double,"double, double" Function,-,hypotf,float,"float, float" Function,-,hypotl,long double,"long double, long double" @@ -2571,6 +2572,7 @@ 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 Function,-,rgb_backlight_update,void,"uint8_t, _Bool" +Function,+,rgbcmp,int,"RgbColor*, RgbColor*" Function,-,rindex,char*,"const char*, int" Function,-,rint,double,double Function,-,rintf,float,float diff --git a/lib/toolbox/colors.c b/lib/toolbox/colors.c index 0de9ecf85..612a5f501 100644 --- a/lib/toolbox/colors.c +++ b/lib/toolbox/colors.c @@ -2,6 +2,14 @@ #include "colors.h" +inline int rgbcmp(RgbColor* a, RgbColor* b) { + return memcmp(a, b, sizeof(RgbColor)); +} + +inline int hsvcmp(HsvColor* a, HsvColor* b) { + return memcmp(a, b, sizeof(HsvColor)); +} + RgbColor hsv2rgb(HsvColor hsv) { RgbColor rgb; uint8_t region, remainder, p, q, t; diff --git a/lib/toolbox/colors.h b/lib/toolbox/colors.h index 8fc930dbf..2d90a72db 100644 --- a/lib/toolbox/colors.h +++ b/lib/toolbox/colors.h @@ -1,6 +1,7 @@ #pragma once #include +#include #ifdef __cplusplus extern "C" { @@ -18,6 +19,10 @@ typedef struct HsvColor { uint8_t v; } HsvColor; +int rgbcmp(RgbColor* a, RgbColor* b); + +int hsvcmp(HsvColor* a, HsvColor* b); + RgbColor hsv2rgb(HsvColor hsv); HsvColor rgb2hsv(RgbColor rgb); From ad689e0926941d7da0d820a33e78b9d374ca2357 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 01:23:45 +0200 Subject: [PATCH 08/17] Move rgb bl color presets to userspace --- .../scenes/xtreme_app_scene_misc_screen.c | 43 ++++++++++++-- firmware/targets/f7/api_symbols.csv | 6 +- lib/drivers/rgb_backlight.c | 58 ++++--------------- lib/drivers/rgb_backlight.h | 23 ++------ 4 files changed, 55 insertions(+), 75 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c index fc624c8e7..cef463b02 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c @@ -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( diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 1c0925050..ceeb2eaa8 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -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 diff --git a/lib/drivers/rgb_backlight.c b/lib/drivers/rgb_backlight.c index 86ee4291e..a8604034e 100644 --- a/lib/drivers/rgb_backlight.c +++ b/lib/drivers/rgb_backlight.c @@ -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); diff --git a/lib/drivers/rgb_backlight.h b/lib/drivers/rgb_backlight.h index 97fe561ce..7199550ae 100644 --- a/lib/drivers/rgb_backlight.h +++ b/lib/drivers/rgb_backlight.h @@ -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 From 6a618b6e199d29ea08f3bc583370e8f4a8fcc6ca Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 01:24:12 +0200 Subject: [PATCH 09/17] Cleanup and fixes --- .../main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c | 4 ++++ firmware/targets/f7/api_symbols.csv | 4 ++-- lib/drivers/rgb_backlight.c | 7 +------ lib/toolbox/colors.c | 4 ++-- lib/toolbox/colors.h | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c index cef463b02..76ae26baf 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c @@ -5,6 +5,9 @@ enum VarItemListIndex { VarItemListIndexLeftHanded, VarItemListIndexRgbBacklight, VarItemListIndexLcdColor, + VarItemListIndexRainbowLcd, + VarItemListIndexRainbowSpeed, + VarItemListIndexRainbowInterval, }; void xtreme_app_scene_misc_screen_var_item_list_callback(void* context, uint32_t index) { @@ -237,6 +240,7 @@ bool xtreme_app_scene_misc_screen_on_event(void* context, SceneManagerEvent even if(change) { XTREME_SETTINGS()->rgb_backlight = !XTREME_SETTINGS()->rgb_backlight; app->save_settings = true; + app->save_backlight = true; notification_message(app->notification, &sequence_display_backlight_on); rgb_backlight_reconfigure(XTREME_SETTINGS()->rgb_backlight); scene_manager_previous_scene(app->scene_manager); diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index ceeb2eaa8..d259477b2 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1734,7 +1734,7 @@ Function,+,hex_char_to_uint8,_Bool,"char, char, uint8_t*" Function,+,hex_chars_to_uint64,_Bool,"const char*, uint64_t*" Function,+,hex_chars_to_uint8,_Bool,"const char*, uint8_t*" Function,+,hsv2rgb,RgbColor,HsvColor -Function,+,hsvcmp,int,"HsvColor*, HsvColor*" +Function,+,hsvcmp,int,"const HsvColor*, const HsvColor*" Function,-,hypot,double,"double, double" Function,-,hypotf,float,"float, float" Function,-,hypotl,long double,"long double, long double" @@ -2570,7 +2570,7 @@ 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 Function,-,rgb_backlight_update,void,"uint8_t, _Bool" -Function,+,rgbcmp,int,"RgbColor*, RgbColor*" +Function,+,rgbcmp,int,"const RgbColor*, const RgbColor*" Function,-,rindex,char*,"const char*, int" Function,-,rint,double,double Function,-,rintf,float,float diff --git a/lib/drivers/rgb_backlight.c b/lib/drivers/rgb_backlight.c index a8604034e..e0956f700 100644 --- a/lib/drivers/rgb_backlight.c +++ b/lib/drivers/rgb_backlight.c @@ -53,12 +53,7 @@ static struct { .last_brightness = 0, .last_color = {0, 0, 0}, .rainbow_timer = NULL, - .rainbow_hsv = - { - .h = 0, - .s = 255, - .v = 255, - }, + .rainbow_hsv = {0, 255, 255}, }; static void rainbow_timer(void* ctx) { diff --git a/lib/toolbox/colors.c b/lib/toolbox/colors.c index 612a5f501..33ad8152c 100644 --- a/lib/toolbox/colors.c +++ b/lib/toolbox/colors.c @@ -2,11 +2,11 @@ #include "colors.h" -inline int rgbcmp(RgbColor* a, RgbColor* b) { +inline int rgbcmp(const RgbColor* a, const RgbColor* b) { return memcmp(a, b, sizeof(RgbColor)); } -inline int hsvcmp(HsvColor* a, HsvColor* b) { +inline int hsvcmp(const HsvColor* a, const HsvColor* b) { return memcmp(a, b, sizeof(HsvColor)); } diff --git a/lib/toolbox/colors.h b/lib/toolbox/colors.h index 2d90a72db..902b1a5d0 100644 --- a/lib/toolbox/colors.h +++ b/lib/toolbox/colors.h @@ -19,9 +19,9 @@ typedef struct HsvColor { uint8_t v; } HsvColor; -int rgbcmp(RgbColor* a, RgbColor* b); +int rgbcmp(const RgbColor* a, const RgbColor* b); -int hsvcmp(HsvColor* a, HsvColor* b); +int hsvcmp(const HsvColor* a, const HsvColor* b); RgbColor hsv2rgb(HsvColor hsv); From cee43d5b790b4235587e84b5c56ec4adb7f8ca6f Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 01:51:04 +0200 Subject: [PATCH 10/17] Custom lcd color --- .../scenes/xtreme_app_scene_config.h | 1 + .../scenes/xtreme_app_scene_misc_screen.c | 3 + .../xtreme_app_scene_misc_screen_color.c | 56 +++++++++++++++++++ applications/main/xtreme_app/xtreme_app.c | 6 ++ applications/main/xtreme_app/xtreme_app.h | 4 ++ 5 files changed, 70 insertions(+) create mode 100644 applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_config.h b/applications/main/xtreme_app/scenes/xtreme_app_scene_config.h index 4d9b161ed..16a9436ad 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_config.h +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_config.h @@ -16,5 +16,6 @@ ADD_SCENE(xtreme_app, protocols_freqs_add, ProtocolsFreqsAdd) ADD_SCENE(xtreme_app, protocols_gpio, ProtocolsGpio) ADD_SCENE(xtreme_app, misc, Misc) ADD_SCENE(xtreme_app, misc_screen, MiscScreen) +ADD_SCENE(xtreme_app, misc_screen_color, MiscScreenColor) ADD_SCENE(xtreme_app, misc_dolphin, MiscDolphin) ADD_SCENE(xtreme_app, misc_rename, MiscRename) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c index 76ae26baf..795da826c 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c @@ -248,6 +248,9 @@ bool xtreme_app_scene_misc_screen_on_event(void* context, SceneManagerEvent even } break; } + case VarItemListIndexLcdColor: + scene_manager_next_scene(app->scene_manager, XtremeAppSceneMiscScreenColor); + break; default: break; } diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c new file mode 100644 index 000000000..f364e4d1a --- /dev/null +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c @@ -0,0 +1,56 @@ +#include "../xtreme_app.h" + +enum ByteInputResult { + ByteInputResultOk, +}; + +void xtreme_app_scene_misc_screen_color_byte_input_callback(void* context) { + XtremeApp* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, ByteInputResultOk); +} + +void xtreme_app_scene_misc_screen_color_on_enter(void* context) { + XtremeApp* app = context; + ByteInput* byte_input = app->byte_input; + + byte_input_set_header_text(byte_input, "Set LCD Color (#RRGGBB)"); + + app->lcd_color = rgb_backlight_get_color(); + + byte_input_set_result_callback( + byte_input, + xtreme_app_scene_misc_screen_color_byte_input_callback, + NULL, + app, + (void*)&app->lcd_color, + sizeof(app->lcd_color)); + + view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewByteInput); +} + +bool xtreme_app_scene_misc_screen_color_on_event(void* context, SceneManagerEvent event) { + XtremeApp* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + consumed = true; + switch(event.event) { + case ByteInputResultOk: + rgb_backlight_set_color(app->lcd_color); + app->save_backlight = true; + scene_manager_previous_scene(app->scene_manager); + break; + default: + break; + } + } + + return consumed; +} + +void xtreme_app_scene_misc_screen_color_on_exit(void* context) { + XtremeApp* app = context; + byte_input_set_result_callback(app->byte_input, NULL, NULL, NULL, NULL, 0); + byte_input_set_header_text(app->byte_input, ""); +} diff --git a/applications/main/xtreme_app/xtreme_app.c b/applications/main/xtreme_app/xtreme_app.c index f73390e52..ce198a3e4 100644 --- a/applications/main/xtreme_app/xtreme_app.c +++ b/applications/main/xtreme_app/xtreme_app.c @@ -193,6 +193,10 @@ XtremeApp* xtreme_app_alloc() { view_dispatcher_add_view( app->view_dispatcher, XtremeAppViewTextInput, text_input_get_view(app->text_input)); + app->byte_input = byte_input_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, XtremeAppViewByteInput, byte_input_get_view(app->byte_input)); + app->popup = popup_alloc(); view_dispatcher_add_view(app->view_dispatcher, XtremeAppViewPopup, popup_get_view(app->popup)); @@ -315,6 +319,8 @@ void xtreme_app_free(XtremeApp* app) { submenu_free(app->submenu); view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewTextInput); text_input_free(app->text_input); + view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewByteInput); + byte_input_free(app->byte_input); view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewPopup); popup_free(app->popup); view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewDialogEx); diff --git a/applications/main/xtreme_app/xtreme_app.h b/applications/main/xtreme_app/xtreme_app.h index 995b00310..7fbee8bcb 100644 --- a/applications/main/xtreme_app/xtreme_app.h +++ b/applications/main/xtreme_app/xtreme_app.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ typedef struct { VariableItemList* var_item_list; Submenu* submenu; TextInput* text_input; + ByteInput* byte_input; Popup* popup; DialogEx* dialog_ex; @@ -57,6 +59,7 @@ typedef struct { uint8_t subghz_hopper_index; char subghz_freq_buffer[XTREME_SUBGHZ_FREQ_BUFFER_SIZE]; bool subghz_extend; + RgbColor lcd_color; char device_name[FURI_HAL_VERSION_ARRAY_NAME_LENGTH]; int32_t dolphin_level; int32_t dolphin_angry; @@ -79,6 +82,7 @@ typedef enum { XtremeAppViewVarItemList, XtremeAppViewSubmenu, XtremeAppViewTextInput, + XtremeAppViewByteInput, XtremeAppViewPopup, XtremeAppViewDialogEx, } XtremeAppView; From c79e13ff649ebb777c3bd014a854edaebae993ac Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 02:47:45 +0200 Subject: [PATCH 11/17] Update evil portal and esp flasher icons --nobuild --- .../external/esp_flasher/application.fam | 2 +- .../external/esp_flasher/update_10px.png | Bin 0 -> 156 bytes .../external/esp_flasher/wifi_10px.png | Bin 1781 -> 0 bytes .../evil_portal/icons/evil_portal_10px.png | Bin 1781 -> 156 bytes 4 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 applications/external/esp_flasher/update_10px.png delete mode 100644 applications/external/esp_flasher/wifi_10px.png diff --git a/applications/external/esp_flasher/application.fam b/applications/external/esp_flasher/application.fam index c9b04f2ed..2a3085511 100644 --- a/applications/external/esp_flasher/application.fam +++ b/applications/external/esp_flasher/application.fam @@ -7,7 +7,7 @@ App( requires=["gui"], stack_size=4 * 1024, order=90, - fap_icon="wifi_10px.png", + fap_icon="update_10px.png", fap_category="GPIO", fap_private_libs=[ Lib( diff --git a/applications/external/esp_flasher/update_10px.png b/applications/external/esp_flasher/update_10px.png new file mode 100644 index 0000000000000000000000000000000000000000..5a97651c486c421d11cb6ba8a74c02bb4804b373 GIT binary patch literal 156 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2xGmzZ=C-xtZVk{1FcVbv~PUa<$!;&U>c zv7h@-A}f&37T^=&`v3obAT#vPO>_%)r2R7=#&*=dVZs3d(!BIEF}EPF|6p ukWrBEqn^R#n}xxd;)EOgX$%+tGc!!fS^in|uYPoPg;=lp^061{vuK;mH0)!Ap1aEfjZ9#3COD(NEb)27p@I<-_@3^l{^ zJWV$>(?ozk<#ATw8OqAlhM~(!QY3km@JtqrIO0cDpn%lH9@2bCo0YXs;FvbUxn`)k z*i!=x!_%Q@x?Xi*{6@+a~SXQkz!SWHWcsb$^(6;>hKME;X z2F#C&@!TFtG&W`_aF>8J=K6AfvtYR5MW6F=ld0V%qHJ2KEx&Lj$ta(eFA7EV0@lS9 z3lxzxq6WkS3up+1Kyii72Ie%0kIw=PL%)}m70w9jbpr)NsYyb8 zJMsvNA`daU;~>vzcTnUo15vl_+OF=#%yQ$(Q&5MYCuiK3ViGt#NsF`|a;%_4zM2aoS%6{;vOnh}dV&+$;la51vmz|(PT2kC7> z4aZ`UqccUm8+VhBc@c67?plgWi68SK#ZW&o;wry~ZWrzC#?D|uW^alzJy;PgX_OM8&`5>HN- zezwFvLg}@wWQ4OJgU+cbVl$d(F^i;V|IgRmd^a_-4%IBOS=Kge;NjAc%S|z1Y*Ei7 z7`aZzLY~=nQ76_TL}+YM(=~`2JBzsEq*1US(oT;!*LqKTY!*Y$6~kq>hspB1U>R(+ zfYV^|L-!V(Bpbc%djFYEuYc5QN%Dnr&;9Yw)#snQ{?-RkcJOWM!}Gms%3q(obL%Er ziEn@L-j7dhz5Vr9H}KQ1Uj1|b*V}jgzWLMVKMy{+^U80llJ&7Tn0i|~-ETJDeg9wV C&oCwc diff --git a/applications/external/evil_portal/icons/evil_portal_10px.png b/applications/external/evil_portal/icons/evil_portal_10px.png index c13534660e188305fba6c5625ec1ce6841e238f0..eed8789a405660a0fe46df99fd734b403bdf852b 100644 GIT binary patch delta 139 zcmV;60CfNL4V(dx8Gi-<0050L&%FQu00DDSM?wIu&K&6g002};L_t(2QR literal 1781 zcmcIl&u`pB6gH`Z%BmFygoHpsmU98Y_~+VQo4O&%2C@S^in|uYPoPg;=lp^061{vuK;mH0)!Ap1aEfjZ9#3COD(NEb)27p@I<-_@3^l{^ zJWV$>(?ozk<#ATw8OqAlhM~(!QY3km@JtqrIO0cDpn%lH9@2bCo0YXs;FvbUxn`)k z*i!=x!_%Q@x?Xi*{6@+a~SXQkz!SWHWcsb$^(6;>hKME;X z2F#C&@!TFtG&W`_aF>8J=K6AfvtYR5MW6F=ld0V%qHJ2KEx&Lj$ta(eFA7EV0@lS9 z3lxzxq6WkS3up+1Kyii72Ie%0kIw=PL%)}m70w9jbpr)NsYyb8 zJMsvNA`daU;~>vzcTnUo15vl_+OF=#%yQ$(Q&5MYCuiK3ViGt#NsF`|a;%_4zM2aoS%6{;vOnh}dV&+$;la51vmz|(PT2kC7> z4aZ`UqccUm8+VhBc@c67?plgWi68SK#ZW&o;wry~ZWrzC#?D|uW^alzJy;PgX_OM8&`5>HN- zezwFvLg}@wWQ4OJgU+cbVl$d(F^i;V|IgRmd^a_-4%IBOS=Kge;NjAc%S|z1Y*Ei7 z7`aZzLY~=nQ76_TL}+YM(=~`2JBzsEq*1US(oT;!*LqKTY!*Y$6~kq>hspB1U>R(+ zfYV^|L-!V(Bpbc%djFYEuYc5QN%Dnr&;9Yw)#snQ{?-RkcJOWM!}Gms%3q(obL%Er ziEn@L-j7dhz5Vr9H}KQ1Uj1|b*V}jgzWLMVKMy{+^U80llJ&7Tn0i|~-ETJDeg9wV C&oCwc From 3543ecff2e75a1be292a2dc194f3854027971d07 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 02:51:37 +0200 Subject: [PATCH 12/17] Update some rgb backlight settings --- .../scenes/xtreme_app_scene_misc_screen.c | 20 +++++++++++-------- lib/drivers/rgb_backlight.c | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c index 795da826c..768943312 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c @@ -88,20 +88,24 @@ static void xtreme_app_scene_misc_screen_rainbow_speed_changed(VariableItem* ite } const char* const rainbow_interval_names[] = { + "0.1 S", + "0.2 S", "0.25 S", - "0.50 S", + "0.5 S", "0.75 S", - "1.00 S", + "1 S", "1.25 S", - "1.50 S", + "1.5 S", "1.75 S", - "2.00 S", - "2.50 S", - "3.00 S", - "4.00 S", - "5.00 S", + "2 S", + "2.5 S", + "3 S", + "4 S", + "5 S", }; const uint32_t rainbow_interval_values[COUNT_OF(rainbow_interval_names)] = { + 100, + 200, 250, 500, 750, diff --git a/lib/drivers/rgb_backlight.c b/lib/drivers/rgb_backlight.c index e0956f700..efb231755 100644 --- a/lib/drivers/rgb_backlight.c +++ b/lib/drivers/rgb_backlight.c @@ -35,7 +35,7 @@ static struct { .color = {255, 69, 0}, .rainbow_mode = RGBBacklightRainbowModeOff, .rainbow_speed = 5, - .rainbow_interval = 1000, + .rainbow_interval = 250, }; static struct { From 51136a89699871920fc2ea48771684d159718114 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 03:31:48 +0200 Subject: [PATCH 13/17] Set rgb backlight leds individually --- .../scenes/xtreme_app_scene_misc_screen.c | 59 +++++++++++++------ .../xtreme_app_scene_misc_screen_color.c | 7 ++- firmware/targets/f7/api_symbols.csv | 4 +- lib/drivers/SK6805.c | 1 - lib/drivers/SK6805.h | 4 +- lib/drivers/rgb_backlight.c | 45 ++++++++------ lib/drivers/rgb_backlight.h | 5 +- 7 files changed, 83 insertions(+), 42 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c index 768943312..92567e4f0 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c @@ -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: diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c index f364e4d1a..a998a1cb3 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c @@ -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; diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index d259477b2..0fe163927 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -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 diff --git a/lib/drivers/SK6805.c b/lib/drivers/SK6805.c index 572e1df97..7b7436e1d 100644 --- a/lib/drivers/SK6805.c +++ b/lib/drivers/SK6805.c @@ -20,7 +20,6 @@ #include /* Настройки */ -#define SK6805_LED_COUNT 3 //Количество светодиодов на плате подсветки #define SK6805_LED_PIN &led_pin //Порт подключения светодиодов #ifdef FURI_DEBUG diff --git a/lib/drivers/SK6805.h b/lib/drivers/SK6805.h index 7c58956fa..ed0dcdb36 100644 --- a/lib/drivers/SK6805.h +++ b/lib/drivers/SK6805.h @@ -21,6 +21,8 @@ #include +#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_ */ \ No newline at end of file +#endif /* SK6805_H_ */ diff --git a/lib/drivers/rgb_backlight.c b/lib/drivers/rgb_backlight.c index efb231755..055749887 100644 --- a/lib/drivers/rgb_backlight.c +++ b/lib/drivers/rgb_backlight.c @@ -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; } diff --git a/lib/drivers/rgb_backlight.h b/lib/drivers/rgb_backlight.h index 7199550ae..35874faba 100644 --- a/lib/drivers/rgb_backlight.h +++ b/lib/drivers/rgb_backlight.h @@ -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 From a416bbe1caeb1cab69512b6a7017f379eb7ff0ac Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 03:38:53 +0200 Subject: [PATCH 14/17] Cleanup and settings fixes --- lib/drivers/SK6805.c | 3 +++ lib/drivers/rgb_backlight.c | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/drivers/SK6805.c b/lib/drivers/SK6805.c index 7b7436e1d..898e9454e 100644 --- a/lib/drivers/SK6805.c +++ b/lib/drivers/SK6805.c @@ -19,6 +19,8 @@ #include "SK6805.h" #include +#define TAG "SK6805" + /* Настройки */ #define SK6805_LED_PIN &led_pin //Порт подключения светодиодов @@ -52,6 +54,7 @@ void SK6805_set_led_color(uint8_t led_index, uint8_t r, uint8_t g, uint8_t b) { led_buffer[led_index][0] = g; led_buffer[led_index][1] = r; led_buffer[led_index][2] = b; + FURI_LOG_T(TAG, "led: %d, r: %d, g: %d, b: %d", led_index, r, g, b); } void SK6805_update(void) { diff --git a/lib/drivers/rgb_backlight.c b/lib/drivers/rgb_backlight.c index 055749887..c93d31757 100644 --- a/lib/drivers/rgb_backlight.c +++ b/lib/drivers/rgb_backlight.c @@ -138,10 +138,10 @@ RgbColor rgb_backlight_get_color(uint8_t index) { } void rgb_backlight_set_rainbow_mode(RGBBacklightRainbowMode rainbow_mode) { + if(rainbow_mode >= RGBBacklightRainbowModeCount) return; if(!rgb_state.settings_loaded) { rgb_backlight_load_settings(); } - if(rainbow_mode > (RGBBacklightRainbowModeCount - 1)) rainbow_mode = 0; rgb_settings.rainbow_mode = rainbow_mode; rgb_backlight_reconfigure(rgb_state.enabled); } @@ -168,6 +168,7 @@ uint8_t rgb_backlight_get_rainbow_speed() { } void rgb_backlight_set_rainbow_interval(uint32_t rainbow_interval) { + if(rainbow_interval < 100) return; if(!rgb_state.settings_loaded) { rgb_backlight_load_settings(); } @@ -222,15 +223,12 @@ void rgb_backlight_update(uint8_t brightness, bool tick) { } HsvColor hsv = rgb_state.rainbow_hsv; - FURI_LOG_I("RgbBacklight", "hsv %d %d %d", hsv.h, hsv.s, hsv.v); RgbColor rgb = hsv2rgb(hsv); - FURI_LOG_I("RgbBacklight", "rgb %d %d %d", rgb.r, rgb.g, rgb.b); for(uint8_t i = 0; i < SK6805_get_led_count(); i++) { if(i && rgb_settings.rainbow_mode == RGBBacklightRainbowModeWave) { hsv.h += (50 * i); rgb = hsv2rgb(hsv); - FURI_LOG_I("RgbBacklight", "rgb %d %d %d", rgb.r, rgb.g, rgb.b); } SK6805_set_led_color(i, rgb.r, rgb.g, rgb.b); } From d29a02f6e6bb05d6444d2023fcccc8f8a5b3ad9f Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 03:43:54 +0200 Subject: [PATCH 15/17] Show custom hex color in rgb backlight menu --- .../xtreme_app/scenes/xtreme_app_scene_misc_screen.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c index 92567e4f0..936694aaa 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c @@ -181,8 +181,13 @@ void xtreme_app_scene_misc_screen_on_enter(void* context) { 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"); + if(found) { + variable_item_set_current_value_text(item, lcd_colors[value_index].name); + } else { + char str[7]; + snprintf(str, sizeof(str), "%02X%02X%02X", color.r, color.g, color.b); + variable_item_set_current_value_text(item, str); + } variable_item_set_locked(item, !xtreme_settings->rgb_backlight, "Needs RGB\nBacklight!"); } From ee7260d45ffe644bab51caa8e0125c1235bef884 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 03:49:16 +0200 Subject: [PATCH 16/17] Translate russian rgb backlight comments --- lib/drivers/SK6805.c | 8 ++++---- lib/drivers/rgb_backlight.c | 2 +- lib/drivers/rgb_backlight.h | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/drivers/SK6805.c b/lib/drivers/SK6805.c index 898e9454e..e64ecba32 100644 --- a/lib/drivers/SK6805.c +++ b/lib/drivers/SK6805.c @@ -22,7 +22,7 @@ #define TAG "SK6805" /* Настройки */ -#define SK6805_LED_PIN &led_pin //Порт подключения светодиодов +#define SK6805_LED_PIN &led_pin // LED connection port #ifdef FURI_DEBUG #define DEBUG_PIN &gpio_ext_pa7 @@ -61,11 +61,11 @@ void SK6805_update(void) { SK6805_init(); furi_kernel_lock(); uint32_t end; - /* Последовательная отправка цветов светодиодов */ + // Sequential sending LEDs for(uint8_t lednumber = 0; lednumber < SK6805_LED_COUNT; lednumber++) { - //Последовательная отправка цветов светодиода + // Sequential sending colors for(uint8_t color = 0; color < 3; color++) { - //Последовательная отправка битов цвета + // Sequentially sending color bits uint8_t i = 0b10000000; while(i != 0) { if(led_buffer[lednumber][color] & (i)) { diff --git a/lib/drivers/rgb_backlight.c b/lib/drivers/rgb_backlight.c index c93d31757..8806801ac 100644 --- a/lib/drivers/rgb_backlight.c +++ b/lib/drivers/rgb_backlight.c @@ -94,7 +94,7 @@ void rgb_backlight_reconfigure(bool enabled) { } void rgb_backlight_load_settings(void) { - //Не загружать данные из внутренней памяти при загрузке в режиме DFU + // Do not load data from internal memory when booting in DFU mode if(!furi_hal_is_normal_boot() || rgb_state.settings_loaded) { rgb_state.settings_loaded = true; return; diff --git a/lib/drivers/rgb_backlight.h b/lib/drivers/rgb_backlight.h index 35874faba..d436bec4c 100644 --- a/lib/drivers/rgb_backlight.h +++ b/lib/drivers/rgb_backlight.h @@ -1,6 +1,7 @@ /* RGB backlight FlipperZero driver Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + Heavily modified by Willy-JL and Z3bro This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,12 +40,12 @@ typedef enum { void rgb_backlight_reconfigure(bool enabled); /** - * @brief Загрузить настройки подсветки с SD-карты + * @brief Load backlight settings from SD card */ void rgb_backlight_load_settings(); /** - * @brief Сохранить текущие настройки RGB-подсветки + * @brief Save Current RGB Lighting Settings */ void rgb_backlight_save_settings(); @@ -86,9 +87,9 @@ void rgb_backlight_set_rainbow_interval(uint32_t rainbow_interval); uint32_t rgb_backlight_get_rainbow_interval(); /** - * @brief Применить текущие настройки RGB-подсветки + * @brief Apply current RGB lighting settings * - * @param brightness Яркость свечения (0-255) + * @param brightness Backlight intensity (0-255) * @param tick Whether this update was a tick (for rainbow) */ void rgb_backlight_update(uint8_t brightness, bool tick); From 81b6a86084eb384e084054926467807e5dd968af Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 04:01:08 +0200 Subject: [PATCH 17/17] Add rgb backlight rainbow saturation option --- .../scenes/xtreme_app_scene_misc_screen.c | 30 +++++++++++++++++-- firmware/targets/f7/api_symbols.csv | 2 ++ lib/drivers/rgb_backlight.c | 18 +++++++++++ lib/drivers/rgb_backlight.h | 9 ++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c index 936694aaa..92b24daeb 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c @@ -10,6 +10,7 @@ enum VarItemListIndex { VarItemListIndexRainbowLcd, VarItemListIndexRainbowSpeed, VarItemListIndexRainbowInterval, + VarItemListIndexRainbowSaturation, }; void xtreme_app_scene_misc_screen_var_item_list_callback(void* context, uint32_t index) { @@ -138,6 +139,16 @@ static void xtreme_app_scene_misc_screen_rainbow_interval_changed(VariableItem* app->save_backlight = true; } +static void xtreme_app_scene_misc_screen_rainbow_saturation_changed(VariableItem* item) { + XtremeApp* app = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item) + 1; + char str[4]; + snprintf(str, sizeof(str), "%d", index); + variable_item_set_current_value_text(item, str); + rgb_backlight_set_rainbow_saturation(index); + app->save_backlight = true; +} + void xtreme_app_scene_misc_screen_on_enter(void* context) { XtremeApp* app = context; XtremeSettings* xtreme_settings = XTREME_SETTINGS(); @@ -210,9 +221,9 @@ void xtreme_app_scene_misc_screen_on_enter(void* context) { app); value_index = rgb_backlight_get_rainbow_speed(); variable_item_set_current_value_index(item, value_index - 1); - char str[4]; - snprintf(str, sizeof(str), "%d", value_index); - variable_item_set_current_value_text(item, str); + char speed_str[4]; + snprintf(speed_str, sizeof(speed_str), "%d", value_index); + variable_item_set_current_value_text(item, speed_str); variable_item_set_locked(item, !xtreme_settings->rgb_backlight, "Needs RGB\nBacklight!"); item = variable_item_list_add( @@ -229,6 +240,19 @@ void xtreme_app_scene_misc_screen_on_enter(void* context) { variable_item_set_current_value_text(item, rainbow_interval_names[value_index]); variable_item_set_locked(item, !xtreme_settings->rgb_backlight, "Needs RGB\nBacklight!"); + item = variable_item_list_add( + var_item_list, + "Rainbow Saturation", + 25, + xtreme_app_scene_misc_screen_rainbow_saturation_changed, + app); + value_index = rgb_backlight_get_rainbow_saturation(); + variable_item_set_current_value_index(item, value_index - 1); + char saturation_str[4]; + snprintf(saturation_str, sizeof(saturation_str), "%d", value_index); + variable_item_set_current_value_text(item, saturation_str); + variable_item_set_locked(item, !xtreme_settings->rgb_backlight, "Needs RGB\nBacklight!"); + variable_item_list_set_enter_callback( var_item_list, xtreme_app_scene_misc_screen_var_item_list_callback, app); diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 0fe163927..00bc36fa0 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -2561,6 +2561,7 @@ Function,+,rgb2hsv,HsvColor,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_saturation,uint8_t, Function,+,rgb_backlight_get_rainbow_speed,uint8_t, Function,-,rgb_backlight_load_settings,void, Function,+,rgb_backlight_reconfigure,void,_Bool @@ -2568,6 +2569,7 @@ Function,+,rgb_backlight_save_settings,void, 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_saturation,void,uint8_t Function,+,rgb_backlight_set_rainbow_speed,void,uint8_t Function,-,rgb_backlight_update,void,"uint8_t, _Bool" Function,+,rgbcmp,int,"const RgbColor*, const RgbColor*" diff --git a/lib/drivers/rgb_backlight.c b/lib/drivers/rgb_backlight.c index 8806801ac..5a19ce0ca 100644 --- a/lib/drivers/rgb_backlight.c +++ b/lib/drivers/rgb_backlight.c @@ -31,6 +31,7 @@ static struct { RGBBacklightRainbowMode rainbow_mode; uint8_t rainbow_speed; uint32_t rainbow_interval; + uint32_t rainbow_saturation; } rgb_settings = { .colors = { @@ -41,6 +42,7 @@ static struct { .rainbow_mode = RGBBacklightRainbowModeOff, .rainbow_speed = 5, .rainbow_interval = 250, + .rainbow_saturation = 255, }; static struct { @@ -89,6 +91,7 @@ void rgb_backlight_reconfigure(bool enabled) { furi_timer_free(rgb_state.rainbow_timer); rgb_state.rainbow_timer = NULL; } + rgb_state.rainbow_hsv.s = rgb_settings.rainbow_saturation; rgb_backlight_update(rgb_state.last_brightness, false); } @@ -183,6 +186,21 @@ uint32_t rgb_backlight_get_rainbow_interval() { return rgb_settings.rainbow_interval; } +void rgb_backlight_set_rainbow_saturation(uint8_t rainbow_saturation) { + if(!rgb_state.settings_loaded) { + rgb_backlight_load_settings(); + } + rgb_settings.rainbow_saturation = rainbow_saturation; + rgb_backlight_reconfigure(rgb_state.enabled); +} + +uint8_t rgb_backlight_get_rainbow_saturation() { + if(!rgb_state.settings_loaded) { + rgb_backlight_load_settings(); + } + return rgb_settings.rainbow_saturation; +} + void rgb_backlight_update(uint8_t brightness, bool tick) { if(!rgb_state.enabled) return; if(!rgb_state.settings_loaded) { diff --git a/lib/drivers/rgb_backlight.h b/lib/drivers/rgb_backlight.h index d436bec4c..b289520fd 100644 --- a/lib/drivers/rgb_backlight.h +++ b/lib/drivers/rgb_backlight.h @@ -86,6 +86,15 @@ void rgb_backlight_set_rainbow_interval(uint32_t rainbow_interval); uint32_t rgb_backlight_get_rainbow_interval(); +/** + * @brief Change rainbow saturation + * + * @param rainbow_saturation What saturation to use (0 - 255) + */ +void rgb_backlight_set_rainbow_saturation(uint8_t rainbow_saturation); + +uint8_t rgb_backlight_get_rainbow_saturation(); + /** * @brief Apply current RGB lighting settings *