Skip to content

Commit

Permalink
usb_comm: Support full control on RGB underglow
Browse files Browse the repository at this point in the history
  • Loading branch information
xingrz committed Feb 7, 2023
1 parent f524a7f commit 8892ecd
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config/app/usb_comm/handler/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ bool handle_rgb_control(const usb_comm_MessageH2D *h2d, usb_comm_MessageD2H *d2h
uint32_t bytes_len);
bool handle_rgb_get_state(const usb_comm_MessageH2D *h2d, usb_comm_MessageD2H *d2h,
const void *bytes, uint32_t bytes_len);
bool handle_rgb_set_state(const usb_comm_MessageH2D *h2d, usb_comm_MessageD2H *d2h,
const void *bytes, uint32_t bytes_len);

bool handle_eink_set_image(const usb_comm_MessageH2D *h2d, usb_comm_MessageD2H *d2h,
const void *bytes, uint32_t bytes_len);
38 changes: 35 additions & 3 deletions config/app/usb_comm/handler/handler_rgb.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,44 @@ bool handle_rgb_get_state(const usb_comm_MessageH2D *h2d, usb_comm_MessageD2H *d
{
usb_comm_RgbState *res = &d2h->payload.rgb_state;

bool on;
if (zmk_rgb_underglow_get_state(&on) != 0) {
if (zmk_rgb_underglow_get_state(&res->on) != 0) {
return false;
}

res->on = on;
struct zmk_led_hsb color = zmk_rgb_underglow_calc_hue(0);
res->color.h = color.h;
res->color.s = color.s;
res->color.b = color.b;
res->has_color = true;

res->effect = zmk_rgb_underglow_calc_effect(0);
res->has_effect = true;

return true;
}

bool handle_rgb_set_state(const usb_comm_MessageH2D *h2d, usb_comm_MessageD2H *d2h,
const void *bytes, uint32_t bytes_len)
{
const usb_comm_RgbState *req = &h2d->payload.rgb_state;

if (req->on) {
zmk_rgb_underglow_on();
} else {
zmk_rgb_underglow_off();
}

if (req->has_color) {
zmk_rgb_underglow_set_hsb((struct zmk_led_hsb){
.h = req->color.h,
.s = req->color.s,
.b = req->color.b,
});
}

if (req->has_effect) {
zmk_rgb_underglow_select_effect((int)req->effect);
}

return handle_rgb_get_state(h2d, d2h, bytes, bytes_len);
}
1 change: 1 addition & 0 deletions config/app/usb_comm/handler/handler_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ bool handle_version(const usb_comm_MessageH2D *h2d, usb_comm_MessageD2H *d2h, co

#ifdef CONFIG_HW75_USB_COMM_FEATURE_RGB
res->features.has_rgb = res->features.rgb = true;
res->features.has_rgb_full_control = res->features.rgb_full_control = true;
#endif // CONFIG_HW75_USB_COMM_FEATURE_RGB

#ifdef CONFIG_HW75_USB_COMM_FEATURE_EINK
Expand Down
1 change: 1 addition & 0 deletions config/app/usb_comm/usb_comm_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static struct {
#ifdef CONFIG_HW75_USB_COMM_FEATURE_RGB
{ usb_comm_Action_RGB_CONTROL, usb_comm_MessageD2H_rgb_state_tag, handle_rgb_control },
{ usb_comm_Action_RGB_GET_STATE, usb_comm_MessageD2H_rgb_state_tag, handle_rgb_get_state },
{ usb_comm_Action_RGB_SET_STATE, usb_comm_MessageD2H_rgb_state_tag, handle_rgb_set_state },
#endif // CONFIG_HW75_USB_COMM_FEATURE_RGB

#ifdef CONFIG_HW75_USB_COMM_FEATURE_EINK
Expand Down
20 changes: 20 additions & 0 deletions config/proto/usb_comm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum Action {
KNOB_SET_CONFIG = 4;
RGB_CONTROL = 5;
RGB_GET_STATE = 6;
RGB_SET_STATE = 8;
EINK_SET_IMAGE = 7;
}

Expand All @@ -30,6 +31,7 @@ message MessageH2D
Nop nop = 2;
KnobConfig knob_config = 3;
RgbControl rgb_control = 4;
RgbState rgb_state = 7;
EinkImage eink_image = 5;
}
}
Expand Down Expand Up @@ -62,6 +64,7 @@ message Version
message Features
{
optional bool rgb = 1;
optional bool rgb_full_control = 5;
optional bool eink = 2;
optional bool knob = 3;
}
Expand Down Expand Up @@ -123,6 +126,23 @@ message RgbControl
message RgbState
{
required bool on = 1;
optional HSB color = 2;
optional Effect effect = 3;
optional uint32 speed = 4;

message HSB
{
required uint32 h = 1;
required uint32 s = 2;
required uint32 b = 3;
}

enum Effect {
SOLID = 0;
BREATHE = 1;
SPECTRUM = 2;
SWIRL = 3;
}
}

message EinkImage
Expand Down

0 comments on commit 8892ecd

Please sign in to comment.