Integrate RGB backlight into API + add to xfw app

This commit is contained in:
Willy-JL
2023-03-20 23:09:41 +00:00
parent 2a834bedeb
commit d05a3b7ec9
10 changed files with 71 additions and 31 deletions

View File

@@ -12,15 +12,6 @@ void xtreme_app_scene_misc_var_item_list_callback(void* context, uint32_t index)
view_dispatcher_send_custom_event(app->view_dispatcher, index); view_dispatcher_send_custom_event(app->view_dispatcher, index);
} }
static void xtreme_app_scene_misc_rgb_backlight_changed(VariableItem* item) {
XtremeApp* app = variable_item_get_context(item);
bool value = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
XTREME_SETTINGS()->rgb_backlight = value;
app->save_settings = true;
app->require_reboot = true;
}
static void xtreme_app_scene_misc_xp_level_changed(VariableItem* item) { static void xtreme_app_scene_misc_xp_level_changed(VariableItem* item) {
XtremeApp* app = variable_item_get_context(item); XtremeApp* app = variable_item_get_context(item);
app->xp_level = variable_item_get_current_value_index(item) + 1; app->xp_level = variable_item_get_current_value_index(item) + 1;
@@ -30,6 +21,23 @@ static void xtreme_app_scene_misc_xp_level_changed(VariableItem* item) {
app->save_level = true; app->save_level = true;
} }
static void xtreme_app_scene_misc_rgb_backlight_changed(VariableItem* item) {
XtremeApp* app = variable_item_get_context(item);
bool value = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
XTREME_SETTINGS()->rgb_backlight = value;
app->save_settings = true;
notification_message(app->notification, &sequence_display_backlight_on);
}
static void xtreme_app_scene_misc_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);
notification_message(app->notification, &sequence_display_backlight_on);
}
const char* const butthurt_timer_names[] = 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"}; {"OFF", "30 M", "1 H", "2 H", "4 H", "6 H", "8 H", "12 H", "24 H", "48 H"};
const int32_t butthurt_timer_values[COUNT_OF(butthurt_timer_names)] = const int32_t butthurt_timer_values[COUNT_OF(butthurt_timer_names)] =
@@ -52,11 +60,6 @@ void xtreme_app_scene_misc_on_enter(void* context) {
variable_item_list_add(var_item_list, "Change Device Name", 0, NULL, app); variable_item_list_add(var_item_list, "Change Device Name", 0, NULL, app);
item = variable_item_list_add(
var_item_list, "RGB Backlight", 2, xtreme_app_scene_misc_rgb_backlight_changed, app);
variable_item_set_current_value_index(item, xtreme_settings->rgb_backlight);
variable_item_set_current_value_text(item, xtreme_settings->rgb_backlight ? "ON" : "OFF");
char level_str[4]; char level_str[4];
snprintf(level_str, 4, "%li", app->xp_level); snprintf(level_str, 4, "%li", app->xp_level);
item = variable_item_list_add( item = variable_item_list_add(
@@ -79,6 +82,18 @@ void xtreme_app_scene_misc_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, butthurt_timer_names[value_index]); variable_item_set_current_value_text(item, butthurt_timer_names[value_index]);
item = variable_item_list_add(
var_item_list, "RGB Backlight", 2, xtreme_app_scene_misc_rgb_backlight_changed, app);
variable_item_set_current_value_index(item, xtreme_settings->rgb_backlight);
variable_item_set_current_value_text(item, xtreme_settings->rgb_backlight ? "ON" : "OFF");
item = variable_item_list_add(
var_item_list, "LCD Color", rgb_backlight_get_color_count(), xtreme_app_scene_misc_lcd_color_changed, app);
value_index = rgb_backlight_get_settings()->display_color_index;
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!");
variable_item_list_set_enter_callback( variable_item_list_set_enter_callback(
var_item_list, xtreme_app_scene_misc_var_item_list_callback, app); var_item_list, xtreme_app_scene_misc_var_item_list_callback, app);

View File

@@ -139,6 +139,7 @@ XtremeApp* xtreme_app_alloc() {
XtremeApp* app = malloc(sizeof(XtremeApp)); XtremeApp* app = malloc(sizeof(XtremeApp));
app->gui = furi_record_open(RECORD_GUI); app->gui = furi_record_open(RECORD_GUI);
app->dialogs = furi_record_open(RECORD_DIALOGS); app->dialogs = furi_record_open(RECORD_DIALOGS);
app->notification = furi_record_open(RECORD_NOTIFICATION);
// View Dispatcher and Scene Manager // View Dispatcher and Scene Manager
app->view_dispatcher = view_dispatcher_alloc(); app->view_dispatcher = view_dispatcher_alloc();
@@ -301,6 +302,7 @@ void xtreme_app_free(XtremeApp* app) {
furi_string_free(app->version_tag); furi_string_free(app->version_tag);
// Records // Records
furi_record_close(RECORD_NOTIFICATION);
furi_record_close(RECORD_DIALOGS); furi_record_close(RECORD_DIALOGS);
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
free(app); free(app);

View File

@@ -20,6 +20,8 @@
#include <lib/flipper_format/flipper_format.h> #include <lib/flipper_format/flipper_format.h>
#include <lib/subghz/subghz_setting.h> #include <lib/subghz/subghz_setting.h>
#include <applications/main/fap_loader/fap_loader_app.h> #include <applications/main/fap_loader/fap_loader_app.h>
#include <notification/notification_app.h>
#include <rgb_backlight/rgb_backlight.h>
#include <m-array.h> #include <m-array.h>
#include "xtreme/settings.h" #include "xtreme/settings.h"
#include "xtreme/assets.h" #include "xtreme/assets.h"
@@ -31,6 +33,7 @@ ARRAY_DEF(CharList, char*)
typedef struct { typedef struct {
Gui* gui; Gui* gui;
DialogsApp* dialogs; DialogsApp* dialogs;
NotificationApp* notification;
SceneManager* scene_manager; SceneManager* scene_manager;
ViewDispatcher* view_dispatcher; ViewDispatcher* view_dispatcher;
VariableItemList* var_item_list; VariableItemList* var_item_list;

View File

@@ -10,6 +10,7 @@ App(
"desktop", "desktop",
"loader", "loader",
"power", "power",
"rgb_backlight",
"namechangersrv", "namechangersrv",
], ],
) )

View File

@@ -0,0 +1,9 @@
App(
appid="rgb_backlight",
name="RGB Backlight",
apptype=FlipperAppType.SERVICE,
entry_point="rgb_backlight_srv",
sdk_headers=[
"rgb_backlight.h",
],
)

View File

@@ -174,3 +174,8 @@ void rgb_backlight_update(uint8_t brightness) {
SK6805_update(); SK6805_update();
} }
int32_t rgb_backlight_srv(void* p) {
UNUSED(p);
return 0;
}

View File

@@ -19,6 +19,10 @@
#include <furi.h> #include <furi.h>
#include "SK6805.h" #include "SK6805.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct { typedef struct {
char* name; char* name;
uint8_t red; uint8_t red;
@@ -76,4 +80,8 @@ uint8_t rgb_backlight_get_color_count(void);
* @param index Индекс из доступных вариантов цвета * @param index Индекс из доступных вариантов цвета
* @return Указатель на строку с названием цвета * @return Указатель на строку с названием цвета
*/ */
const char* rgb_backlight_get_color_text(uint8_t index); const char* rgb_backlight_get_color_text(uint8_t index);
#ifdef __cplusplus
}
#endif

View File

@@ -3,7 +3,6 @@
#include <gui/modules/variable_item_list.h> #include <gui/modules/variable_item_list.h>
#include <gui/view_dispatcher.h> #include <gui/view_dispatcher.h>
#include <lib/toolbox/value_index.h> #include <lib/toolbox/value_index.h>
#include "rgb_backlight.h"
#define MAX_NOTIFICATION_SETTINGS 4 #define MAX_NOTIFICATION_SETTINGS 4
@@ -120,14 +119,6 @@ static void vibro_changed(VariableItem* item) {
notification_message(app->notification, &sequence_single_vibro); notification_message(app->notification, &sequence_single_vibro);
} }
static void color_changed(VariableItem* item) {
NotificationAppSettings* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
rgb_backlight_set_color(index);
variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index));
notification_message(app->notification, &sequence_display_backlight_on);
}
static uint32_t notification_app_settings_exit(void* context) { static uint32_t notification_app_settings_exit(void* context) {
UNUSED(context); UNUSED(context);
return VIEW_NONE; return VIEW_NONE;
@@ -145,12 +136,6 @@ static NotificationAppSettings* alloc_settings() {
VariableItem* item; VariableItem* item;
uint8_t value_index; uint8_t value_index;
item = variable_item_list_add(
app->variable_item_list, "LCD Color", rgb_backlight_get_color_count(), color_changed, app);
value_index = rgb_backlight_get_settings()->display_color_index;
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, rgb_backlight_get_color_text(value_index));
item = variable_item_list_add( item = variable_item_list_add(
app->variable_item_list, "LCD Brightness", BACKLIGHT_COUNT, backlight_changed, app); app->variable_item_list, "LCD Brightness", BACKLIGHT_COUNT, backlight_changed, app);
value_index = value_index_float( value_index = value_index_float(

View File

@@ -37,6 +37,7 @@ Header,+,applications/services/locale/locale.h,,
Header,+,applications/services/notification/notification.h,, Header,+,applications/services/notification/notification.h,,
Header,+,applications/services/notification/notification_messages.h,, Header,+,applications/services/notification/notification_messages.h,,
Header,+,applications/services/power/power_service/power.h,, Header,+,applications/services/power/power_service/power.h,,
Header,+,applications/services/rgb_backlight/rgb_backlight.h,,
Header,+,applications/services/rpc/rpc_app.h,, Header,+,applications/services/rpc/rpc_app.h,,
Header,+,applications/services/storage/storage.h,, Header,+,applications/services/storage/storage.h,,
Header,+,applications/services/xtreme/assets.h,, Header,+,applications/services/xtreme/assets.h,,
@@ -314,6 +315,10 @@ Function,-,LL_USART_DeInit,ErrorStatus,USART_TypeDef*
Function,+,LL_USART_Init,ErrorStatus,"USART_TypeDef*, LL_USART_InitTypeDef*" Function,+,LL_USART_Init,ErrorStatus,"USART_TypeDef*, LL_USART_InitTypeDef*"
Function,-,LL_USART_StructInit,void,LL_USART_InitTypeDef* Function,-,LL_USART_StructInit,void,LL_USART_InitTypeDef*
Function,-,LL_mDelay,void,uint32_t Function,-,LL_mDelay,void,uint32_t
Function,-,SK6805_get_led_count,uint8_t,
Function,-,SK6805_init,void,
Function,-,SK6805_set_led_color,void,"uint8_t, uint8_t, uint8_t, uint8_t"
Function,-,SK6805_update,void,
Function,-,SystemCoreClockUpdate,void, Function,-,SystemCoreClockUpdate,void,
Function,-,SystemInit,void, Function,-,SystemInit,void,
Function,+,XTREME_ASSETS,XtremeAssets*, Function,+,XTREME_ASSETS,XtremeAssets*,
@@ -2516,6 +2521,13 @@ Function,-,rfal_platform_spi_acquire,void,
Function,-,rfal_platform_spi_release,void, Function,-,rfal_platform_spi_release,void,
Function,-,rfal_set_callback_context,void,void* Function,-,rfal_set_callback_context,void,void*
Function,-,rfal_set_state_changed_callback,void,RfalStateChangedCallback Function,-,rfal_set_state_changed_callback,void,RfalStateChangedCallback
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_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,-,rindex,char*,"const char*, int" Function,-,rindex,char*,"const char*, int"
Function,-,rint,double,double Function,-,rint,double,double
Function,-,rintf,float,float Function,-,rintf,float,float
1 entry status name type params
37 Header + applications/services/notification/notification.h
38 Header + applications/services/notification/notification_messages.h
39 Header + applications/services/power/power_service/power.h
40 Header + applications/services/rgb_backlight/rgb_backlight.h
41 Header + applications/services/rpc/rpc_app.h
42 Header + applications/services/storage/storage.h
43 Header + applications/services/xtreme/assets.h
315 Function + LL_USART_Init ErrorStatus USART_TypeDef*, LL_USART_InitTypeDef*
316 Function - LL_USART_StructInit void LL_USART_InitTypeDef*
317 Function - LL_mDelay void uint32_t
318 Function - SK6805_get_led_count uint8_t
319 Function - SK6805_init void
320 Function - SK6805_set_led_color void uint8_t, uint8_t, uint8_t, uint8_t
321 Function - SK6805_update void
322 Function - SystemCoreClockUpdate void
323 Function - SystemInit void
324 Function + XTREME_ASSETS XtremeAssets*
2521 Function - rfal_platform_spi_release void
2522 Function - rfal_set_callback_context void void*
2523 Function - rfal_set_state_changed_callback void RfalStateChangedCallback
2524 Function + rgb_backlight_get_color_count uint8_t
2525 Function + rgb_backlight_get_color_text const char* uint8_t
2526 Function + rgb_backlight_get_settings RGBBacklightSettings*
2527 Function - rgb_backlight_load_settings void
2528 Function - rgb_backlight_save_settings void
2529 Function + rgb_backlight_set_color void uint8_t
2530 Function - rgb_backlight_update void uint8_t
2531 Function - rindex char* const char*, int
2532 Function - rint double double
2533 Function - rintf float float

View File

@@ -4,7 +4,7 @@
#include <lp5562.h> #include <lp5562.h>
#include <stdint.h> #include <stdint.h>
#include <xtreme/settings.h> #include <xtreme/settings.h>
#include <applications/settings/notification_settings/rgb_backlight.h> #include <rgb_backlight/rgb_backlight.h>
#define LED_CURRENT_RED 50 #define LED_CURRENT_RED 50
#define LED_CURRENT_GREEN 50 #define LED_CURRENT_GREEN 50