Skip to content

Commit

Permalink
Merge pull request #15 from Next-Flip/rgb_rpc_property
Browse files Browse the repository at this point in the history
VGM: Custom color options
  • Loading branch information
Willy-JL authored Mar 8, 2024
2 parents a143074 + b112711 commit 8a37dab
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 24 deletions.
2 changes: 2 additions & 0 deletions applications/main/momentum_app/momentum_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions applications/main/momentum_app/momentum_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -35,6 +36,7 @@ ARRAY_DEF(CharList, char*)
typedef struct {
Gui* gui;
DialogsApp* dialogs;
Expansion* expansion;
NotificationApp* notification;
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
enum VarItemListIndex {
VarItemListIndexScreen,
VarItemListIndexDolphin,
VarItemListIndexVgm,
VarItemListIndexChangeDeviceName,
VarItemListIndexChargeCap,
VarItemListIndexShowMomentumIntro,
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
173 changes: 173 additions & 0 deletions applications/main/momentum_app/scenes/momentum_app_scene_misc_vgm.c
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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, "");
}
14 changes: 10 additions & 4 deletions lib/momentum/momentum.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 8a37dab

Please sign in to comment.