Skip to content

Commit

Permalink
rainbow mode now works over rpc
Browse files Browse the repository at this point in the history
still not done refrash rate from flipper change and is slow so the rainbow mode doesnt look good
  • Loading branch information
HaxSam committed Mar 29, 2024
1 parent 51563ff commit 113ed1f
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ static const struct {
char* name;
RgbColor color;
} vgm_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}}},
{"Off", {{0, 0, 0}}}, {"Orange", {{255, 130, 0}}}, {"Red", {{255, 0, 0}}},
{"Maroon", {{176, 48, 96}}}, {"Yellow", {{255, 255, 0}}}, {"Olive", {{128, 128, 0}}},
{"Lime", {{0, 255, 0}}}, {"Green", {{74, 255, 0}}}, {"Aqua", {{0, 255, 255}}},
{"Cyan", {{0, 255, 255}}}, {"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}}},
{"Fuchsia", {{255, 0, 255}}}, {"Pink", {{173, 31, 173}}}, {"Brown", {{150, 75, 0}}},
{"White", {{255, 255, 255}}},
};
static const size_t vgm_colors_count = COUNT_OF(vgm_colors);
static void momentum_app_scene_misc_vgm_foreground_changed(VariableItem* item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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;
Expand Down
9 changes: 3 additions & 6 deletions applications/services/rpc/rpc_gui.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "rpc_i.h"
#include <gui/gui_i.h>
#include <assets_icons.h>
#include <momentum/momentum.h>
#include "colors.h"
#include <momentum/rpc_rgb.h>

#include <flipper.pb.h>
#include <gui.pb.h>
Expand Down Expand Up @@ -99,10 +98,8 @@ 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;
rpc_gui->transmit_frame->content.gui_screen_frame.fg_color = get_screen_color_fg().value;
rpc_gui->transmit_frame->content.gui_screen_frame.bg_color = get_screen_color_bg().value;

furi_thread_flags_set(furi_thread_get_id(rpc_gui->transmit_thread), RpcGuiWorkerFlagTransmit);
}
Expand Down
80 changes: 80 additions & 0 deletions lib/momentum/rpc_rgb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "rpc_rgb.h"

#include "colors.h"
#include "momentum.h"
#include "drivers/rgb_backlight.h"

static const RgbColor rainbow_colors[] = {
{{255, 0, 0}}, // Red
{{255, 130, 0}}, // Orange
{{255, 255, 0}}, // Yellow
{{0, 255, 0}}, // Green
{{0, 0, 255}}, // Blue
{{123, 0, 255}}, // Indigo
{{255, 0, 255}} // Violet
};

typedef struct {
uint8_t color;
uint8_t step;
} rgb_trans;

static struct {
rgb_trans fg;
rgb_trans bg;
} state = {
.fg = {0, 0},
.bg = {0, 0},
};

RgbColor rainbow_step(rgb_trans* rgb) {
if(rgb->step >= 20) {
rgb->color = (rgb->color + 1) % 7;
rgb->step = 0;
}

RgbColor color = interpolate_color(
&rainbow_colors[rgb->color], &rainbow_colors[(rgb->color + 1) % 7], rgb->step, 20);
rgb->step++;

return color;
}

RgbColor get_screen_color_fg() {
RgbColor color = {{0, 0, 0}};

switch(momentum_settings.vgm_color_mode) {
case VgmColorModeCustom:
color = momentum_settings.vgm_color_fg;
break;
case VgmColorModeRainbow:
//color = rainbow_step(&state.fg);
break;
case VgmColorModeRgbBacklight:
//rgb_backlight_get_color(0, &color);
break;
default:
break;
}

return color;
}

RgbColor get_screen_color_bg() {
RgbColor color = {{255, 130, 0}};
switch(momentum_settings.vgm_color_mode) {
case VgmColorModeCustom:
color = momentum_settings.vgm_color_bg;
break;
case VgmColorModeRainbow:
color = rainbow_step(&state.bg);
break;
case VgmColorModeRgbBacklight:
rgb_backlight_get_color(0, &color);
break;
default:
break;
}

return color;
}
18 changes: 18 additions & 0 deletions lib/momentum/rpc_rgb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "colors.h"

#ifdef __cplusplus
extern "C" {
#endif

void rpc_rgb_init();

RgbColor get_screen_color_fg();
RgbColor get_screen_color_bg();

void rpc_rgb_deinit();

#ifdef __cplusplus
}
#endif
29 changes: 27 additions & 2 deletions lib/toolbox/colors.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ void rgb2hsv(const RgbColor* rgb, HsvColor* hsv) {
}
}

inline int rgb565cmp(const Rgb565Color* a, const Rgb565Color* b) {
return memcmp(a, b, sizeof(Rgb565Color));
RgbColor interpolate_color(
const RgbColor* colorStart,
const RgbColor* colorEnd,
uint8_t step,
uint8_t maxSteps) {
RgbColor color;

if(step >= maxSteps) {
memcpy(&color, colorEnd, sizeof(RgbColor));
return color;
}

color.r = colorStart->r + (colorEnd->r - colorStart->r) * step / maxSteps;
color.g = colorStart->g + (colorEnd->g - colorStart->g) * step / maxSteps;
color.b = colorStart->b + (colorEnd->b - colorStart->b) * step / maxSteps;

return color;
}

RgbColor lerp_color(const RgbColor* colorStart, const RgbColor* colorEnd, double t) {
RgbColor color;

color.r = colorStart->r * ((double)1.0 - t) + colorEnd->r * t;
color.g = colorStart->g * ((double)1.0 - t) + colorEnd->g * t;
color.b = colorStart->b * ((double)1.0 - t) + colorEnd->b * t;

return color;
}
15 changes: 6 additions & 9 deletions lib/toolbox/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ 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;
RgbColor interpolate_color(
const RgbColor* colorStart,
const RgbColor* colorEnd,
uint8_t step,
uint8_t maxSteps);

int rgb565cmp(const Rgb565Color* a, const Rgb565Color* b);
RgbColor lerp_color(const RgbColor* colorStart, const RgbColor* colorEnd, double t);

#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,7 @@ Function,+,infrared_worker_tx_stop,void,InfraredWorker*
Function,-,initstate,char*,"unsigned, char*, size_t"
Function,+,input_get_key_name,const char*,InputKey
Function,+,input_get_type_name,const char*,InputType
Function,+,interpolate_color,RgbColor,"const RgbColor*, const RgbColor*, uint8_t, uint8_t"
Function,-,iprintf,int,"const char*, ..."
Function,-,isalnum,int,int
Function,-,isalnum_l,int,"int, locale_t"
Expand Down Expand Up @@ -2188,6 +2189,7 @@ Function,-,ldexp,double,"double, int"
Function,-,ldexpf,float,"float, int"
Function,-,ldexpl,long double,"long double, int"
Function,-,ldiv,ldiv_t,"long, long"
Function,+,lerp_color,RgbColor,"const RgbColor*, const RgbColor*, double"
Function,+,lfrfid_dict_file_load,ProtocolId,"ProtocolDict*, const char*"
Function,+,lfrfid_dict_file_save,_Bool,"ProtocolDict*, ProtocolId, const char*"
Function,+,lfrfid_raw_file_alloc,LFRFIDRawFile*,Storage*
Expand Down Expand Up @@ -2960,7 +2962,6 @@ 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,
Expand Down

0 comments on commit 113ed1f

Please sign in to comment.