Skip to content

Commit

Permalink
first poc works
Browse files Browse the repository at this point in the history
  • Loading branch information
HaxSam committed Mar 29, 2024
1 parent dba42cc commit 51563ff
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 101 deletions.
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 @@ -40,13 +40,13 @@ static const struct {
char* name;
RgbColor color;
} lcd_colors[] = {
{"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}}},
};
static const size_t lcd_sz = COUNT_OF(lcd_colors);
static void momentum_app_scene_misc_screen_lcd_color_changed(VariableItem* item, uint8_t led) {
Expand Down
38 changes: 15 additions & 23 deletions applications/main/momentum_app/scenes/momentum_app_scene_misc_vgm.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ 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[] = {
{"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}}}, {"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}}},
};
static const size_t vgm_colors_count = COUNT_OF(vgm_colors);
static void momentum_app_scene_misc_vgm_foreground_changed(VariableItem* item) {
Expand All @@ -52,21 +52,13 @@ static void momentum_app_scene_misc_vgm_foreground_changed(VariableItem* 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) {
Expand All @@ -91,10 +83,10 @@ 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;
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;
Expand All @@ -103,8 +95,8 @@ void momentum_app_scene_misc_vgm_on_enter(void* context) {
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 @@ -119,7 +111,7 @@ void momentum_app_scene_misc_vgm_on_enter(void* context) {
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;
if(rgbcmp(&color, &vgm_colors[i].color) != 0) continue;
value_index = i;
found = true;
break;
Expand All @@ -128,8 +120,8 @@ void momentum_app_scene_misc_vgm_on_enter(void* context) {
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ bool momentum_app_scene_misc_vgm_color_on_event(void* context, SceneManagerEvent
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:
Expand Down
7 changes: 7 additions & 0 deletions applications/services/rpc/rpc_gui.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "rpc_i.h"
#include <gui/gui_i.h>
#include <assets_icons.h>
#include <momentum/momentum.h>
#include "colors.h"

#include <flipper.pb.h>
#include <gui.pb.h>
Expand Down Expand Up @@ -97,6 +99,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
4 changes: 2 additions & 2 deletions lib/momentum/momentum.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ typedef struct {
FuriHalSerialId uart_nmea_channel;
bool file_naming_prefix_after;
VgmColorMode vgm_color_mode;
Rgb565Color vgm_color_fg;
Rgb565Color vgm_color_bg;
RgbColor vgm_color_fg;
RgbColor vgm_color_bg;
} MomentumSettings;

typedef struct {
Expand Down
3 changes: 3 additions & 0 deletions lib/toolbox/colors.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "colors.h"

_Static_assert(sizeof(RgbColor) == 3, "RGB color must be 24-bit");
_Static_assert(sizeof(HsvColor) == 3, "HSV color must be 24-bit");

inline int rgbcmp(const RgbColor* a, const RgbColor* b) {
return memcmp(a, b, sizeof(RgbColor));
}
Expand Down
22 changes: 14 additions & 8 deletions lib/toolbox/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@
extern "C" {
#endif

typedef struct {
uint8_t r;
uint8_t g;
uint8_t b;
typedef union __attribute__((packed)) {
struct {
uint8_t r;
uint8_t g;
uint8_t b;
};
uint32_t value : 24;
} RgbColor;

typedef struct {
uint8_t h;
uint8_t s;
uint8_t v;
typedef union __attribute__((packed)) {
struct {
uint8_t h;
uint8_t s;
uint8_t v;
};
uint32_t value : 24;
} HsvColor;

int rgbcmp(const RgbColor* a, const RgbColor* b);
Expand Down
51 changes: 0 additions & 51 deletions targets/f7/furi_hal/furi_hal_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,57 +70,6 @@ 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,
Expand Down

0 comments on commit 51563ff

Please sign in to comment.