Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VGM/RPC: Rework custom colors, smoother config, better rainbow support #53

Merged
merged 18 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion applications/main/momentum_app/momentum_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef struct {
bool subghz_extend;
bool subghz_bypass;
RgbColor lcd_color;
Rgb565Color vgm_color;
RgbColor 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 @@ -46,25 +46,25 @@ static const struct {
RgbColor color;
} lcd_colors[] = {
// clang-format off
{"Off", {0, 0, 0}},
{"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}},
{"Off", {{0, 0, 0}}},
{"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}}},
// clang-format on
};
static const size_t lcd_sz = COUNT_OF(lcd_colors);
Expand Down
107 changes: 67 additions & 40 deletions applications/main/momentum_app/scenes/momentum_app_scene_misc_vgm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ const char* const colors_names[VgmColorModeCount] = {
"Rainbow",
"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;

if(index == VgmColorModeDefault) {
momentum_settings.vgm_color_fg.mode = VgmColorModeDefault;
momentum_settings.vgm_color_bg.mode = VgmColorModeDefault;
}

app->save_settings = true;
variable_item_set_locked(
variable_item_list_get(app->var_item_list, VarItemListIndexForeground),
Expand All @@ -31,58 +38,73 @@ static void momentum_app_scene_misc_vgm_colors_changed(VariableItem* item) {
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;
RgbColor color;
} vgm_colors[] = {
// clang-format off
{"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}},
{"Off", {{0, 0, 0}}},
{"Rainbow", {{0, 0, 0}}},
{"RgbMod", {{0, 0, 0}}},
{"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}}},
// clang-format on
};

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);
momentum_settings.vgm_color_fg.rgb = vgm_colors[index].color;
momentum_settings.vgm_color_fg.mode = VgmColorModeCustom;

if(strcmp("Rainbow", vgm_colors[index].name) == 0) {
momentum_settings.vgm_color_fg.mode = VgmColorModeRainbow;
}
if(strcmp("RgbMod", vgm_colors[index].name) == 0) {
momentum_settings.vgm_color_fg.mode = VgmColorModeRgbBacklight;
rgb_backlight_get_color(0, &momentum_settings.vgm_color_fg.rgb);
}

app->save_settings = true;
}

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);
momentum_settings.vgm_color_bg.rgb = vgm_colors[index].color;
momentum_settings.vgm_color_bg.mode = VgmColorModeCustom;

if(strcmp("Rainbow", vgm_colors[index].name) == 0) {
momentum_settings.vgm_color_bg.mode = VgmColorModeRainbow;
}
if(strcmp("RgbMod", vgm_colors[index].name) == 0) {
momentum_settings.vgm_color_bg.mode = VgmColorModeRgbBacklight;
rgb_backlight_get_color(0, &momentum_settings.vgm_color_bg.rgb);
}

app->save_settings = true;
}

void momentum_app_scene_misc_vgm_on_enter(void* context) {
Expand All @@ -107,20 +129,22 @@ void momentum_app_scene_misc_vgm_on_enter(void* context) {
vgm_colors_count,
momentum_app_scene_misc_vgm_foreground_changed,
app);
Rgb565Color color = momentum_settings.vgm_color_fg;
RgbColor color = momentum_settings.vgm_color_fg.rgb;
bool found = false;

for(size_t i = 0; i < vgm_colors_count; i++) {
if(rgb565cmp(&color, &vgm_colors[i].color) != 0) continue;
if(rgbcmp(&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);
char str[7];
snprintf(str, sizeof(str), "%06X", color.value);
variable_item_set_current_value_text(item, str);
}
variable_item_set_locked(
Expand All @@ -132,20 +156,22 @@ void momentum_app_scene_misc_vgm_on_enter(void* context) {
vgm_colors_count,
momentum_app_scene_misc_vgm_background_changed,
app);
color = momentum_settings.vgm_color_bg;
color = momentum_settings.vgm_color_bg.rgb;
found = false;

for(size_t i = 0; i < vgm_colors_count; i++) {
if(rgb565cmp(&color, &vgm_colors[i].color) != 0) continue;
if(rgbcmp(&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);
char str[7];
snprintf(str, sizeof(str), "%06X", color.value);
variable_item_set_current_value_text(item, str);
}
variable_item_set_locked(
Expand All @@ -167,6 +193,7 @@ bool momentum_app_scene_misc_vgm_on_event(void* context, SceneManagerEvent event
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscVgm, event.event);
consumed = true;

switch(event.event) {
case VarItemListIndexForeground:
case VarItemListIndexBackground:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ 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)");
byte_input_set_header_text(byte_input, "Set VGM Color");

if(scene_manager_get_scene_state(app->scene_manager, MomentumAppSceneMiscVgmColor)) {
app->vgm_color = momentum_settings.vgm_color_bg;
app->vgm_color = momentum_settings.vgm_color_bg.rgb;
} else {
app->vgm_color = momentum_settings.vgm_color_fg;
app->vgm_color = momentum_settings.vgm_color_fg.rgb;
}
app->vgm_color.value = __REVSH(app->vgm_color.value);

Expand All @@ -44,15 +44,11 @@ bool momentum_app_scene_misc_vgm_color_on_event(void* context, SceneManagerEvent
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;
momentum_settings.vgm_color_bg.rgb = app->vgm_color;
} else {
momentum_settings.vgm_color_fg = app->vgm_color;
momentum_settings.vgm_color_fg.rgb = 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:
Expand Down
6 changes: 6 additions & 0 deletions applications/services/rpc/rpc_gui.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "rpc_i.h"
#include <gui/gui_i.h>
#include <assets_icons.h>
#include <momentum/rpc_rgb.h>

#include <flipper.pb.h>
#include <gui.pb.h>
Expand Down Expand Up @@ -97,6 +98,11 @@ static void rpc_system_gui_screen_stream_frame_callback(
rpc_gui->transmit_frame->content.gui_screen_frame.orientation =
rpc_system_gui_screen_orientation_map[orientation];

rpc_gui->transmit_frame->content.gui_screen_frame.fg_color =
momentum_settings.vgm_color_fg.value;
rpc_gui->transmit_frame->content.gui_screen_frame.bg_color =
momentum_settings.vgm_color_bg.value;

furi_thread_flags_set(furi_thread_get_id(rpc_gui->transmit_thread), RpcGuiWorkerFlagTransmit);
}

Expand Down
2 changes: 1 addition & 1 deletion assets/protobuf
Submodule protobuf updated 1 files
+29 −27 gui.proto
8 changes: 4 additions & 4 deletions lib/drivers/rgb_backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ static struct {
} rgb_settings = {
.colors =
{
{255, 69, 0},
{255, 69, 0},
{255, 69, 0},
{{255, 69, 0}},
{{255, 69, 0}},
{{255, 69, 0}},
},
.rainbow_mode = RGBBacklightRainbowModeOff,
.rainbow_speed = 5,
Expand All @@ -58,7 +58,7 @@ static struct {
.enabled = false,
.last_brightness = 0,
.rainbow_timer = NULL,
.rainbow_hsv = {0, 255, 255},
.rainbow_hsv = {{0, 255, 255}},
};

void rgb_backlight_load_settings(bool enabled) {
Expand Down
12 changes: 10 additions & 2 deletions lib/momentum/momentum.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ typedef enum {
VgmColorModeCount,
} VgmColorMode;

typedef union __attribute__((packed)) {
struct {
VgmColorMode mode;
RgbColor rgb;
};
uint32_t value;
} RgbColorTransmit;

typedef struct {
char asset_pack[ASSET_PACKS_NAME_LEN];
uint32_t anim_speed;
Expand Down Expand Up @@ -88,9 +96,9 @@ typedef struct {
FuriHalSerialId uart_nmea_channel;
bool file_naming_prefix_after;
VgmColorMode vgm_color_mode;
Rgb565Color vgm_color_fg;
Rgb565Color vgm_color_bg;
FuriHalVersionColor spoof_color;
RgbColorTransmit vgm_color_fg;
RgbColorTransmit vgm_color_bg;
} MomentumSettings;

typedef struct {
Expand Down
1 change: 1 addition & 0 deletions lib/momentum/rpc_rgb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "rpc_rgb.h"
11 changes: 11 additions & 0 deletions lib/momentum/rpc_rgb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "momentum.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif
Loading
Loading