Merge pull request #15 from Next-Flip/rgb_rpc_property

VGM: Custom color options
This commit is contained in:
WillyJL
2024-03-08 02:38:20 +00:00
committed by GitHub
15 changed files with 374 additions and 24 deletions
@@ -163,6 +163,7 @@ MomentumApp* momentum_app_alloc() {
MomentumApp* app = malloc(sizeof(MomentumApp));
app->gui = furi_record_open(RECORD_GUI);
app->dialogs = furi_record_open(RECORD_DIALOGS);
app->expansion = furi_record_open(RECORD_EXPANSION);
app->notification = furi_record_open(RECORD_NOTIFICATION);
// View Dispatcher and Scene Manager
@@ -361,6 +362,7 @@ void momentum_app_free(MomentumApp* app) {
// Records
furi_record_close(RECORD_NOTIFICATION);
furi_record_close(RECORD_EXPANSION);
furi_record_close(RECORD_DIALOGS);
furi_record_close(RECORD_GUI);
free(app);
@@ -25,6 +25,7 @@
#include <flipper_application/flipper_application.h>
#include <notification/notification_app.h>
#include <power/power_service/power.h>
#include <expansion/expansion.h>
#include <rgb_backlight.h>
#include <m-array.h>
#include <momentum/namespoof.h>
@@ -35,6 +36,7 @@ ARRAY_DEF(CharList, char*)
typedef struct {
Gui* gui;
DialogsApp* dialogs;
Expansion* expansion;
NotificationApp* notification;
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
@@ -58,6 +60,7 @@ typedef struct {
char subghz_freq_buffer[7];
bool subghz_extend;
RgbColor lcd_color;
Rgb565Color vgm_color;
char device_name[FURI_HAL_VERSION_ARRAY_NAME_LENGTH];
int32_t dolphin_level;
int32_t dolphin_angry;
@@ -18,4 +18,6 @@ ADD_SCENE(momentum_app, misc, Misc)
ADD_SCENE(momentum_app, misc_screen, MiscScreen)
ADD_SCENE(momentum_app, misc_screen_color, MiscScreenColor)
ADD_SCENE(momentum_app, misc_dolphin, MiscDolphin)
ADD_SCENE(momentum_app, misc_vgm, MiscVgm)
ADD_SCENE(momentum_app, misc_vgm_color, MiscVgmColor)
ADD_SCENE(momentum_app, misc_rename, MiscRename)
@@ -3,6 +3,7 @@
enum VarItemListIndex {
VarItemListIndexScreen,
VarItemListIndexDolphin,
VarItemListIndexVgm,
VarItemListIndexChangeDeviceName,
VarItemListIndexChargeCap,
VarItemListIndexShowMomentumIntro,
@@ -36,6 +37,9 @@ void momentum_app_scene_misc_on_enter(void* context) {
item = variable_item_list_add(var_item_list, "Dolphin", 0, NULL, app);
variable_item_set_current_value_text(item, ">");
item = variable_item_list_add(var_item_list, "VGM Options", 0, NULL, app);
variable_item_set_current_value_text(item, ">");
variable_item_list_add(var_item_list, "Change Device Name", 0, NULL, app);
char cap_str[6];
@@ -77,6 +81,10 @@ bool momentum_app_scene_misc_on_event(void* context, SceneManagerEvent event) {
scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscDolphin, 0);
scene_manager_next_scene(app->scene_manager, MomentumAppSceneMiscDolphin);
break;
case VarItemListIndexVgm:
scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscVgm, 0);
scene_manager_next_scene(app->scene_manager, MomentumAppSceneMiscVgm);
break;
case VarItemListIndexChangeDeviceName:
scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscRename, 0);
scene_manager_next_scene(app->scene_manager, MomentumAppSceneMiscRename);
@@ -55,6 +55,10 @@ static void momentum_app_scene_misc_screen_lcd_color_changed(VariableItem* item,
variable_item_set_current_value_text(item, lcd_colors[index].name);
rgb_backlight_set_color(led, &lcd_colors[index].color);
app->save_backlight = true;
if(momentum_settings.vgm_color_mode == VgmColorModeRgbBacklight) {
expansion_disable(app->expansion);
expansion_enable(app->expansion);
}
}
static void momentum_app_scene_misc_screen_lcd_color_0_changed(VariableItem* item) {
momentum_app_scene_misc_screen_lcd_color_changed(item, 0);
@@ -43,6 +43,10 @@ bool momentum_app_scene_misc_screen_color_on_event(void* context, SceneManagerEv
scene_manager_get_scene_state(app->scene_manager, MomentumAppSceneMiscScreenColor),
&app->lcd_color);
app->save_backlight = true;
if(momentum_settings.vgm_color_mode == VgmColorModeRgbBacklight) {
expansion_disable(app->expansion);
expansion_enable(app->expansion);
}
scene_manager_previous_scene(app->scene_manager);
break;
default:
@@ -0,0 +1,173 @@
#include "../momentum_app.h"
enum VarItemListIndex {
VarItemListIndexColors,
VarItemListIndexForeground,
VarItemListIndexBackground,
};
void momentum_app_scene_misc_vgm_var_item_list_callback(void* context, uint32_t index) {
MomentumApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
}
const char* const colors_names[VgmColorModeCount] = {
"Default",
"Custom",
"RGB Backlight",
};
static void momentum_app_scene_misc_vgm_colors_changed(VariableItem* item) {
MomentumApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, colors_names[index]);
momentum_settings.vgm_color_mode = index;
app->save_settings = true;
variable_item_set_locked(
variable_item_list_get(app->var_item_list, VarItemListIndexForeground),
index != VgmColorModeCustom,
NULL);
variable_item_set_locked(
variable_item_list_get(app->var_item_list, VarItemListIndexBackground),
index != VgmColorModeCustom,
NULL);
expansion_disable(app->expansion);
expansion_enable(app->expansion);
}
static const struct {
char* name;
Rgb565Color color;
} vgm_colors[] = {
{"Orange", {0xFC00}}, {"Black", {0x0000}}, {"Red", {0xF800}}, {"Maroon", {0x8000}},
{"Yellow", {0xFFE0}}, {"Olive", {0x8400}}, {"Lime", {0x07E0}}, {"Green", {0x0400}},
{"Aqua", {0x07EF}}, {"Cyan", {0x069A}}, {"Azure", {0x03FF}}, {"Teal", {0x0410}},
{"Blue", {0x001F}}, {"Navy", {0x0010}}, {"Purple", {0x8010}}, {"Fuchsia", {0xF81F}},
{"Pink", {0xA8F5}}, {"Brown", {0xA145}}, {"White", {0xFFFF}},
};
static const size_t vgm_colors_count = COUNT_OF(vgm_colors);
static void momentum_app_scene_misc_vgm_foreground_changed(VariableItem* item) {
MomentumApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, vgm_colors[index].name);
momentum_settings.vgm_color_fg = vgm_colors[index].color;
app->save_settings = true;
if(momentum_settings.vgm_color_mode == VgmColorModeCustom) {
expansion_disable(app->expansion);
expansion_enable(app->expansion);
}
}
static void momentum_app_scene_misc_vgm_background_changed(VariableItem* item) {
MomentumApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, vgm_colors[index].name);
momentum_settings.vgm_color_bg = vgm_colors[index].color;
app->save_settings = true;
if(momentum_settings.vgm_color_mode == VgmColorModeCustom) {
expansion_disable(app->expansion);
expansion_enable(app->expansion);
}
}
void momentum_app_scene_misc_vgm_on_enter(void* context) {
MomentumApp* app = context;
VariableItemList* var_item_list = app->var_item_list;
VariableItem* item;
uint8_t value_index;
item = variable_item_list_add(
var_item_list,
"VGM Colors",
VgmColorModeCount,
momentum_app_scene_misc_vgm_colors_changed,
app);
value_index = momentum_settings.vgm_color_mode;
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, colors_names[value_index]);
item = variable_item_list_add(
var_item_list,
"Foreground",
vgm_colors_count,
momentum_app_scene_misc_vgm_foreground_changed,
app);
Rgb565Color color = momentum_settings.vgm_color_fg;
bool found = false;
for(size_t i = 0; i < vgm_colors_count; i++) {
if(rgb565cmp(&color, &vgm_colors[i].color) != 0) continue;
value_index = i;
found = true;
break;
}
variable_item_set_current_value_index(item, found ? value_index : vgm_colors_count);
if(found) {
variable_item_set_current_value_text(item, vgm_colors[value_index].name);
} else {
char str[5];
snprintf(str, sizeof(str), "%04X", color.value);
variable_item_set_current_value_text(item, str);
}
variable_item_set_locked(
item, momentum_settings.vgm_color_mode != VgmColorModeCustom, "Need Custom\nColors!");
item = variable_item_list_add(
var_item_list,
"Background",
vgm_colors_count,
momentum_app_scene_misc_vgm_background_changed,
app);
color = momentum_settings.vgm_color_bg;
found = false;
for(size_t i = 0; i < vgm_colors_count; i++) {
if(rgb565cmp(&color, &vgm_colors[i].color) != 0) continue;
value_index = i;
found = true;
break;
}
variable_item_set_current_value_index(item, found ? value_index : vgm_colors_count);
if(found) {
variable_item_set_current_value_text(item, vgm_colors[value_index].name);
} else {
char str[5];
snprintf(str, sizeof(str), "%04X", color.value);
variable_item_set_current_value_text(item, str);
}
variable_item_set_locked(
item, momentum_settings.vgm_color_mode != VgmColorModeCustom, "Need Custom\nColors!");
variable_item_list_set_enter_callback(
var_item_list, momentum_app_scene_misc_vgm_var_item_list_callback, app);
variable_item_list_set_selected_item(
var_item_list, scene_manager_get_scene_state(app->scene_manager, MomentumAppSceneMiscVgm));
view_dispatcher_switch_to_view(app->view_dispatcher, MomentumAppViewVarItemList);
}
bool momentum_app_scene_misc_vgm_on_event(void* context, SceneManagerEvent event) {
MomentumApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscVgm, event.event);
consumed = true;
switch(event.event) {
case VarItemListIndexForeground:
case VarItemListIndexBackground:
scene_manager_set_scene_state(
app->scene_manager,
MomentumAppSceneMiscVgmColor,
event.event - VarItemListIndexForeground);
scene_manager_next_scene(app->scene_manager, MomentumAppSceneMiscVgmColor);
break;
default:
break;
}
}
return consumed;
}
void momentum_app_scene_misc_vgm_on_exit(void* context) {
MomentumApp* app = context;
variable_item_list_reset(app->var_item_list);
}
@@ -0,0 +1,70 @@
#include "../momentum_app.h"
enum ByteInputResult {
ByteInputResultOk,
};
void momentum_app_scene_misc_vgm_color_byte_input_callback(void* context) {
MomentumApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, ByteInputResultOk);
}
void momentum_app_scene_misc_vgm_color_on_enter(void* context) {
MomentumApp* app = context;
ByteInput* byte_input = app->byte_input;
byte_input_set_header_text(byte_input, "Set VGM Color (RGB565)");
if(scene_manager_get_scene_state(app->scene_manager, MomentumAppSceneMiscVgmColor)) {
app->vgm_color = momentum_settings.vgm_color_bg;
} else {
app->vgm_color = momentum_settings.vgm_color_fg;
}
app->vgm_color.value = __REVSH(app->vgm_color.value);
byte_input_set_result_callback(
byte_input,
momentum_app_scene_misc_vgm_color_byte_input_callback,
NULL,
app,
(void*)&app->vgm_color,
sizeof(app->vgm_color));
view_dispatcher_switch_to_view(app->view_dispatcher, MomentumAppViewByteInput);
}
bool momentum_app_scene_misc_vgm_color_on_event(void* context, SceneManagerEvent event) {
MomentumApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case ByteInputResultOk:
app->vgm_color.value = __REVSH(app->vgm_color.value);
if(scene_manager_get_scene_state(app->scene_manager, MomentumAppSceneMiscVgmColor)) {
momentum_settings.vgm_color_bg = app->vgm_color;
} else {
momentum_settings.vgm_color_fg = app->vgm_color;
}
app->save_settings = true;
if(momentum_settings.vgm_color_mode == VgmColorModeCustom) {
expansion_disable(app->expansion);
expansion_enable(app->expansion);
}
scene_manager_previous_scene(app->scene_manager);
break;
default:
break;
}
}
return consumed;
}
void momentum_app_scene_misc_vgm_color_on_exit(void* context) {
MomentumApp* app = context;
byte_input_set_result_callback(app->byte_input, NULL, NULL, NULL, NULL, 0);
byte_input_set_header_text(app->byte_input, "");
}
+10 -4
View File
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <furi_hal_serial_types.h>
#include <toolbox/colors.h>
#include <gui/canvas.h>
#ifdef __cplusplus
@@ -43,10 +44,12 @@ typedef enum {
SpiCount,
} SpiHandle;
_Static_assert(sizeof(MenuStyle) == sizeof(uint8_t), "enum too big, fix load/save");
_Static_assert(sizeof(BatteryIcon) == sizeof(uint8_t), "enum too big, fix load/save");
_Static_assert(sizeof(SpiHandle) == sizeof(uint8_t), "enum too big, fix load/save");
_Static_assert(sizeof(FuriHalSerialId) == sizeof(uint8_t), "enum too big, fix load/save");
typedef enum {
VgmColorModeDefault,
VgmColorModeCustom,
VgmColorModeRgbBacklight,
VgmColorModeCount,
} VgmColorMode;
typedef struct {
char asset_pack[ASSET_PACKS_NAME_LEN];
@@ -84,6 +87,9 @@ typedef struct {
FuriHalSerialId uart_esp_channel;
FuriHalSerialId uart_nmea_channel;
bool file_naming_prefix_after;
VgmColorMode vgm_color_mode;
Rgb565Color vgm_color_fg;
Rgb565Color vgm_color_bg;
} MomentumSettings;
typedef struct {
+24 -19
View File
@@ -41,13 +41,15 @@ MomentumSettings momentum_settings = {
.uart_esp_channel = FuriHalSerialIdUsart, // pin 13,14
.uart_nmea_channel = FuriHalSerialIdUsart, // pin 13,14
.file_naming_prefix_after = false, // Before
.vgm_color_mode = VgmColorModeDefault, // Default
.vgm_color_fg.value = 0x0000, // Default Black
.vgm_color_bg.value = 0xFC00, // Default Orange
};
typedef enum {
momentum_settings_type_str,
momentum_settings_type_int,
momentum_settings_type_uint,
momentum_settings_type_enum,
momentum_settings_type_bool,
} momentum_settings_type;
@@ -60,19 +62,20 @@ static const struct {
struct {
int32_t i_min;
int32_t i_max;
uint8_t i_sz;
};
struct {
uint32_t u_min;
uint32_t u_max;
uint8_t u_sz;
};
uint8_t e_cnt;
};
#define clamp(t, min, max) .t##_min = min, .t##_max = max
#define setting(t, n) .type = momentum_settings_type##t, .key = #n, .val = &momentum_settings.n
#define setting_str(n) setting(_str, n), .str_len = sizeof(momentum_settings.n)
#define setting_int(n, min, max) setting(_int, n), clamp(i, min, max)
#define setting_uint(n, min, max) setting(_uint, n), clamp(u, min, max)
#define setting_enum(n, cnt) setting(_enum, n), .e_cnt = cnt
#define num(t, n, min, max) .t##_min = min, .t##_max = max, .t##_sz = sizeof(momentum_settings.n)
#define setting_int(n, min, max) setting(_int, n), num(i, n, min, max)
#define setting_uint(n, min, max) setting(_uint, n), num(u, n, min, max)
#define setting_enum(n, cnt) setting_uint(n, 0, cnt - 1)
#define setting_bool(n) setting(_bool, n)
} momentum_settings_entries[] = {
{setting_str(asset_pack)},
@@ -110,6 +113,9 @@ static const struct {
{setting_enum(uart_esp_channel, FuriHalSerialIdMax)},
{setting_enum(uart_nmea_channel, FuriHalSerialIdMax)},
{setting_bool(file_naming_prefix_after)},
{setting_enum(vgm_color_mode, VgmColorModeCount)},
{setting_uint(vgm_color_fg, 0x0000, 0xFFFF)},
{setting_uint(vgm_color_bg, 0x0000, 0xFFFF)},
};
void momentum_settings_load() {
@@ -131,15 +137,13 @@ void momentum_settings_load() {
break;
case momentum_settings_type_int:
ok = flipper_format_read_int32(file, entry.key, &val_int, 1);
if(ok) *(int32_t*)entry.val = CLAMP(val_int, entry.i_max, entry.i_min);
val_int = CLAMP(val_int, entry.i_max, entry.i_min);
if(ok) memcpy(entry.val, &val_int, entry.i_sz);
break;
case momentum_settings_type_uint:
ok = flipper_format_read_uint32(file, entry.key, &val_uint, 1);
if(ok) *(uint32_t*)entry.val = CLAMP(val_uint, entry.u_max, entry.u_min);
break;
case momentum_settings_type_enum:
ok = flipper_format_read_uint32(file, entry.key, &val_uint, 1);
if(ok) *(uint8_t*)entry.val = CLAMP(val_uint, entry.e_cnt - 1U, 0U);
val_uint = CLAMP(val_uint, entry.u_max, entry.u_min);
if(ok) memcpy(entry.val, &val_uint, entry.u_sz);
break;
case momentum_settings_type_bool:
ok = flipper_format_read_bool(file, entry.key, &val_bool, 1);
@@ -164,7 +168,8 @@ void momentum_settings_save() {
FlipperFormat* file = flipper_format_file_alloc(storage);
if(flipper_format_file_open_always(file, MOMENTUM_SETTINGS_PATH)) {
uint32_t tmp_enum;
int32_t tmp_int;
uint32_t tmp_uint;
for(size_t entry_i = 0; entry_i < COUNT_OF(momentum_settings_entries); entry_i++) {
#define entry momentum_settings_entries[entry_i]
switch(entry.type) {
@@ -172,14 +177,14 @@ void momentum_settings_save() {
flipper_format_write_string_cstr(file, entry.key, (char*)entry.val);
break;
case momentum_settings_type_int:
flipper_format_write_int32(file, entry.key, (int32_t*)entry.val, 1);
tmp_int = 0;
memcpy(&tmp_int, entry.val, entry.i_sz);
flipper_format_write_int32(file, entry.key, &tmp_int, 1);
break;
case momentum_settings_type_uint:
flipper_format_write_uint32(file, entry.key, (uint32_t*)entry.val, 1);
break;
case momentum_settings_type_enum:
tmp_enum = *(uint8_t*)entry.val;
flipper_format_write_uint32(file, entry.key, &tmp_enum, 1);
tmp_uint = 0;
memcpy(&tmp_uint, entry.val, entry.u_sz);
flipper_format_write_uint32(file, entry.key, &tmp_uint, 1);
break;
case momentum_settings_type_bool:
flipper_format_write_bool(file, entry.key, (bool*)entry.val, 1);
+4
View File
@@ -86,3 +86,7 @@ void rgb2hsv(const RgbColor* rgb, HsvColor* hsv) {
hsv->h = 171 + 43 * (rgb->r - rgb->g) / (rgbMax - rgbMin);
}
}
inline int rgb565cmp(const Rgb565Color* a, const Rgb565Color* b) {
return memcmp(a, b, sizeof(Rgb565Color));
}
+11
View File
@@ -25,6 +25,17 @@ int hsvcmp(const HsvColor* a, const HsvColor* b);
void hsv2rgb(const HsvColor* hsv, RgbColor* rgb);
void rgb2hsv(const RgbColor* rgb, HsvColor* hsv);
typedef union {
uint16_t value;
struct {
uint16_t r : 5;
uint16_t g : 6;
uint16_t b : 5;
} FURI_PACKED;
} Rgb565Color;
int rgb565cmp(const Rgb565Color* a, const Rgb565Color* b);
#ifdef __cplusplus
}
#endif
+1
View File
@@ -2958,6 +2958,7 @@ Function,-,rename,int,"const char*, const char*"
Function,-,renameat,int,"int, const char*, int, const char*"
Function,-,rewind,void,FILE*
Function,+,rgb2hsv,void,"const RgbColor*, HsvColor*"
Function,+,rgb565cmp,int,"const Rgb565Color*, const Rgb565Color*"
Function,+,rgb_backlight_get_color,void,"uint8_t, RgbColor*"
Function,+,rgb_backlight_get_rainbow_interval,uint32_t,
Function,+,rgb_backlight_get_rainbow_mode,RGBBacklightRainbowMode,
1 entry status name type params
2958 Function - renameat int int, const char*, int, const char*
2959 Function - rewind void FILE*
2960 Function + rgb2hsv void const RgbColor*, HsvColor*
2961 Function + rgb565cmp int const Rgb565Color*, const Rgb565Color*
2962 Function + rgb_backlight_get_color void uint8_t, RgbColor*
2963 Function + rgb_backlight_get_rainbow_interval uint32_t
2964 Function + rgb_backlight_get_rainbow_mode RGBBacklightRainbowMode
+57
View File
@@ -9,6 +9,12 @@
#include <furi.h>
#include <protobuf_version.h>
#include <momentum/momentum.h>
#include <rgb_backlight.h>
#include <SK6805.h>
#include <colors.h>
#include <stdint.h>
FURI_WEAK void furi_hal_info_get_api_version(uint16_t* major, uint16_t* minor) {
*major = 0;
*minor = 0;
@@ -64,6 +70,57 @@ void furi_hal_info_get(PropertyValueCallback out, char sep, void* context) {
property_value_out(
&property_context, "%d", 2, "hardware", "color", furi_hal_version_get_hw_color());
// RGB Settings
property_value_out(
&property_context,
"%d",
4,
"hardware",
"screen",
"rgb",
"enabled",
momentum_settings.rgb_backlight);
for(int i = 0; i < SK6805_get_led_count(); i++) {
RgbColor rgb;
rgb_backlight_get_color(i, &rgb);
uint32_t led_value = 0;
memcpy(((void*)&led_value) + 1, &rgb, sizeof(RgbColor));
char led_string[5] = {'l', 'e', 'd', '0' + i, '\0'};
property_value_out(
&property_context, "%06X", 4, "hardware", "screen", "rgb", led_string, __REV(led_value));
}
// VGM Settings
property_value_out(
&property_context,
"%d",
4,
"hardware",
"vgm",
"color",
"mode",
momentum_settings.vgm_color_mode);
property_value_out(
&property_context,
"%04X",
4,
"hardware",
"vgm",
"color",
"fg",
momentum_settings.vgm_color_fg.value);
property_value_out(
&property_context,
"%04X",
4,
"hardware",
"vgm",
"color",
"bg",
momentum_settings.vgm_color_bg.value);
if(sep == '.') {
property_value_out(
&property_context,