Skip to content

Commit

Permalink
Add VGM color settings section
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Mar 8, 2024
1 parent 3ba5198 commit 4c347fc
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 0 deletions.
1 change: 1 addition & 0 deletions applications/main/momentum_app/momentum_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,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
170 changes: 170 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,170 @@
#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}},
};
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, "");
}

0 comments on commit 4c347fc

Please sign in to comment.