Browse Source

(feat) Allow setting underglow color by key press

xmkb
KemoNine 4 years ago committed by Pete Johanson
parent
commit
99f932a47d
  1. 2
      app/dts/behaviors/rgb_underglow.dtsi
  2. 2
      app/dts/bindings/behaviors/zmk,behavior-rgb-underglow.yaml
  3. 37
      app/include/dt-bindings/zmk/rgb.h
  4. 1
      app/include/zmk/rgb_underglow.h
  5. 25
      app/src/behaviors/behavior_rgb_underglow.c
  6. 13
      app/src/rgb_underglow.c

2
app/dts/behaviors/rgb_underglow.dtsi

@ -9,7 +9,7 @@
rgb_ug: behavior_rgb_underglow { rgb_ug: behavior_rgb_underglow {
compatible = "zmk,behavior-rgb-underglow"; compatible = "zmk,behavior-rgb-underglow";
label = "RGB_UNDERGLOW"; label = "RGB_UNDERGLOW";
#binding-cells = <1>; #binding-cells = <2>;
}; };
}; };
}; };

2
app/dts/bindings/behaviors/zmk,behavior-rgb-underglow.yaml

@ -5,4 +5,4 @@ description: RGB Underglow Action
compatible: "zmk,behavior-rgb-underglow" compatible: "zmk,behavior-rgb-underglow"
include: one_param.yaml include: two_param.yaml

37
app/include/dt-bindings/zmk/rgb.h

@ -4,14 +4,29 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#define RGB_TOG 0 #define RGB_TOG_CMD 0
#define RGB_HUI 1 #define RGB_HUI_CMD 1
#define RGB_HUD 2 #define RGB_HUD_CMD 2
#define RGB_SAI 3 #define RGB_SAI_CMD 3
#define RGB_SAD 4 #define RGB_SAD_CMD 4
#define RGB_BRI 5 #define RGB_BRI_CMD 5
#define RGB_BRD 6 #define RGB_BRD_CMD 6
#define RGB_SPI 7 #define RGB_SPI_CMD 7
#define RGB_SPD 8 #define RGB_SPD_CMD 8
#define RGB_EFF 9 #define RGB_EFF_CMD 9
#define RGB_EFR 10 #define RGB_EFR_CMD 10
#define RGB_COLOR_HSB_CMD 11
#define RGB_TOG RGB_TOG_CMD 0
#define RGB_HUI RGB_HUI_CMD 0
#define RGB_HUD RGB_HUD_CMD 0
#define RGB_SAI RGB_SAI_CMD 0
#define RGB_SAD RGB_SAD_CMD 0
#define RGB_BRI RGB_BRI_CMD 0
#define RGB_BRD RGB_BRD_CMD 0
#define RGB_SPI RGB_SPI_CMD 0
#define RGB_SPD RGB_SPD_CMD 0
#define RGB_EFF RGB_EFF_CMD 0
#define RGB_EFR RGB_EFR_CMD 0
#define RGB_COLOR_HSB(h, s, v) RGB_COLOR_HSB_CMD(((h) << 16) + ((s) << 8) + (v))
#define RGB_COLOR_HSV RGB_COLOR_HSB

1
app/include/zmk/rgb_underglow.h

@ -12,3 +12,4 @@ int zmk_rgb_underglow_change_hue(int direction);
int zmk_rgb_underglow_change_sat(int direction); int zmk_rgb_underglow_change_sat(int direction);
int zmk_rgb_underglow_change_brt(int direction); int zmk_rgb_underglow_change_brt(int direction);
int zmk_rgb_underglow_change_spd(int direction); int zmk_rgb_underglow_change_spd(int direction);
int zmk_rgb_underglow_set_hsb(uint16_t hue, uint8_t saturation, uint8_t brightness);

25
app/src/behaviors/behavior_rgb_underglow.c

@ -21,28 +21,31 @@ static int behavior_rgb_underglow_init(const struct device *dev) { return 0; }
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) { struct zmk_behavior_binding_event event) {
switch (binding->param1) { switch (binding->param1) {
case RGB_TOG: case RGB_TOG_CMD:
return zmk_rgb_underglow_toggle(); return zmk_rgb_underglow_toggle();
case RGB_HUI: case RGB_HUI_CMD:
return zmk_rgb_underglow_change_hue(1); return zmk_rgb_underglow_change_hue(1);
case RGB_HUD: case RGB_HUD_CMD:
return zmk_rgb_underglow_change_hue(-1); return zmk_rgb_underglow_change_hue(-1);
case RGB_SAI: case RGB_SAI_CMD:
return zmk_rgb_underglow_change_sat(1); return zmk_rgb_underglow_change_sat(1);
case RGB_SAD: case RGB_SAD_CMD:
return zmk_rgb_underglow_change_sat(-1); return zmk_rgb_underglow_change_sat(-1);
case RGB_BRI: case RGB_BRI_CMD:
return zmk_rgb_underglow_change_brt(1); return zmk_rgb_underglow_change_brt(1);
case RGB_BRD: case RGB_BRD_CMD:
return zmk_rgb_underglow_change_brt(-1); return zmk_rgb_underglow_change_brt(-1);
case RGB_SPI: case RGB_SPI_CMD:
return zmk_rgb_underglow_change_spd(1); return zmk_rgb_underglow_change_spd(1);
case RGB_SPD: case RGB_SPD_CMD:
return zmk_rgb_underglow_change_spd(-1); return zmk_rgb_underglow_change_spd(-1);
case RGB_EFF: case RGB_EFF_CMD:
return zmk_rgb_underglow_cycle_effect(1); return zmk_rgb_underglow_cycle_effect(1);
case RGB_EFR: case RGB_EFR_CMD:
return zmk_rgb_underglow_cycle_effect(-1); return zmk_rgb_underglow_cycle_effect(-1);
case RGB_COLOR_HSB_CMD:
return zmk_rgb_underglow_set_hsb((binding->param2 >> 16) & 0xFFFF,
(binding->param2 >> 8) & 0xFF, binding->param2 & 0xFF);
} }
return -ENOTSUP; return -ENOTSUP;

13
app/src/rgb_underglow.c

@ -346,6 +346,19 @@ int zmk_rgb_underglow_toggle() {
return zmk_rgb_underglow_save_state(); return zmk_rgb_underglow_save_state();
} }
int zmk_rgb_underglow_set_hsb(uint16_t hue, uint8_t saturation, uint8_t brightness) {
if (hue > 360 || saturation > 100 || brightness > 100) {
return -ENOTSUP;
}
state.hue = hue;
state.saturation = saturation;
state.brightness = brightness;
state.current_effect = UNDERGLOW_EFFECT_SOLID;
return 0;
}
int zmk_rgb_underglow_change_hue(int direction) { int zmk_rgb_underglow_change_hue(int direction) {
if (!led_strip) if (!led_strip)
return -ENODEV; return -ENODEV;

Loading…
Cancel
Save