Browse Source

Add suggested changes

xmkb
Nick 4 years ago
parent
commit
564f787280
  1. 1
      app/CMakeLists.txt
  2. 2
      app/dts/behaviors/rgb_underglow.dtsi
  3. 18
      app/include/zmk/rgb_underglow.h
  4. 44
      app/src/behaviors/behavior_rgb_underglow.c
  5. 44
      app/src/rgb_underglow.c

1
app/CMakeLists.txt

@ -54,7 +54,6 @@ target_sources_ifdef(CONFIG_ZMK_KSCAN_COMPOSITE_DRIVER app PRIVATE src/kscan_com @@ -54,7 +54,6 @@ target_sources_ifdef(CONFIG_ZMK_KSCAN_COMPOSITE_DRIVER app PRIVATE src/kscan_com
target_sources_ifdef(CONFIG_ZMK_USB app PRIVATE src/usb_hid.c)
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c)
target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c)
target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/behaviors/behavior_rgb_underglow.c)
target_sources(app PRIVATE src/endpoints.c)
target_sources(app PRIVATE src/main.c)

2
app/dts/behaviors/rgb_underglow.dtsi

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

18
app/include/zmk/rgb_underglow.h

@ -1,8 +1,14 @@ @@ -1,8 +1,14 @@
/*
* Copyright (c) 2020 Nick Winans <nick@winans.codes>
*
* SPDX-License-Identifier: MIT
*/
#pragma once
void zmk_rgb_underglow_toggle();
void zmk_rgb_underglow_cycle_effect(int direction);
void zmk_rgb_underglow_change_hue(int direction);
void zmk_rgb_underglow_change_sat(int direction);
void zmk_rgb_underglow_change_brt(int direction);
void zmk_rgb_underglow_change_spd(int direction);
int zmk_rgb_underglow_toggle();
int zmk_rgb_underglow_cycle_effect(int direction);
int zmk_rgb_underglow_change_hue(int direction);
int zmk_rgb_underglow_change_sat(int direction);
int zmk_rgb_underglow_change_brt(int direction);
int zmk_rgb_underglow_change_spd(int direction);

44
app/src/behaviors/behavior_rgb_underglow.c

@ -15,9 +15,6 @@ @@ -15,9 +15,6 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
struct behavior_rgb_underglow_config { };
struct behavior_rgb_underglow_data { };
static int behavior_rgb_underglow_init(struct device *dev)
{
return 0;
@ -28,53 +25,38 @@ static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t a @@ -28,53 +25,38 @@ static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t a
switch (action)
{
case RGB_TOG:
zmk_rgb_underglow_toggle();
break;
return zmk_rgb_underglow_toggle();
case RGB_HUI:
zmk_rgb_underglow_change_hue(1);
break;
return zmk_rgb_underglow_change_hue(1);
case RGB_HUD:
zmk_rgb_underglow_change_hue(-1);
break;
return zmk_rgb_underglow_change_hue(-1);
case RGB_SAI:
zmk_rgb_underglow_change_sat(1);
break;
return zmk_rgb_underglow_change_sat(1);
case RGB_SAD:
zmk_rgb_underglow_change_sat(-1);
break;
return zmk_rgb_underglow_change_sat(-1);
case RGB_BRI:
zmk_rgb_underglow_change_brt(1);
break;
case RGB_BRD:
zmk_rgb_underglow_change_brt(-1);
break;
return zmk_rgb_underglow_change_brt(-1);
case RGB_SPI:
zmk_rgb_underglow_change_spd(1);
break;
return zmk_rgb_underglow_change_spd(1);
case RGB_SPD:
zmk_rgb_underglow_change_spd(-1);
break;
return zmk_rgb_underglow_change_spd(-1);
case RGB_EFF:
zmk_rgb_underglow_cycle_effect(1);
break;
return zmk_rgb_underglow_cycle_effect(1);
case RGB_EFR:
zmk_rgb_underglow_cycle_effect(-1);
break;
return zmk_rgb_underglow_cycle_effect(-1);
}
return 0;
return -ENOTSUP;
}
static const struct behavior_driver_api behavior_rgb_underglow_driver_api = {
.binding_pressed = on_keymap_binding_pressed,
};
static const struct behavior_rgb_underglow_config behavior_rgb_underglow_config = {};
static struct behavior_rgb_underglow_data behavior_rgb_underglow_data;
DEVICE_AND_API_INIT(behavior_rgb_underglow, DT_INST_LABEL(0), behavior_rgb_underglow_init,
&behavior_rgb_underglow_data,
&behavior_rgb_underglow_config,
NULL,
NULL,
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
&behavior_rgb_underglow_driver_api);

44
app/src/rgb_underglow.c

@ -15,12 +15,11 @@ @@ -15,12 +15,11 @@
#include <drivers/led_strip.h>
#include <device.h>
#include <drivers/spi.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#define STRIP_LABEL DT_LABEL(DT_ALIAS(led_strip))
#define STRIP_NUM_PIXELS DT_PROP(DT_ALIAS(led_strip), chain_length)
#define STRIP_LABEL DT_LABEL(DT_CHOSEN(zmk_underglow))
#define STRIP_NUM_PIXELS DT_PROP(DT_CHOSEN(zmk_underglow), chain_length)
enum rgb_underglow_effect {
UNDERGLOW_EFFECT_SOLID,
@ -184,7 +183,7 @@ static int zmk_rgb_underglow_init(struct device *_arg) @@ -184,7 +183,7 @@ static int zmk_rgb_underglow_init(struct device *_arg)
LOG_INF("Found LED strip device %s", STRIP_LABEL);
} else {
LOG_ERR("LED strip device %s not found", STRIP_LABEL);
return 1;
return -EINVAL;
}
state = (struct rgb_underglow_state){
@ -202,22 +201,25 @@ static int zmk_rgb_underglow_init(struct device *_arg) @@ -202,22 +201,25 @@ static int zmk_rgb_underglow_init(struct device *_arg)
return 0;
}
void zmk_rgb_underglow_cycle_effect(int direction)
int zmk_rgb_underglow_cycle_effect(int direction)
{
if (state.current_effect == 0 && direction < 0) {
state.current_effect = UNDERGLOW_EFFECT_NUMBER - 1;
} else {
return 0;
}
state.current_effect += direction;
if (state.current_effect >= UNDERGLOW_EFFECT_NUMBER) {
state.current_effect = 0;
}
}
state.animation_step = 0;
return 0;
}
void zmk_rgb_underglow_toggle()
int zmk_rgb_underglow_toggle()
{
state.on = !state.on;
@ -235,13 +237,15 @@ void zmk_rgb_underglow_toggle() @@ -235,13 +237,15 @@ void zmk_rgb_underglow_toggle()
k_timer_stop(&underglow_tick);
}
return 0;
}
void zmk_rgb_underglow_change_hue(int direction)
int zmk_rgb_underglow_change_hue(int direction)
{
if (state.hue == 0 && direction < 0) {
state.hue = 350;
return;
return 0;
}
state.hue += direction * CONFIG_ZMK_RGB_UNDERGLOW_HUE_STEP;
@ -249,12 +253,14 @@ void zmk_rgb_underglow_change_hue(int direction) @@ -249,12 +253,14 @@ void zmk_rgb_underglow_change_hue(int direction)
if (state.hue > 350) {
state.hue = 0;
}
return 0;
}
void zmk_rgb_underglow_change_sat(int direction)
int zmk_rgb_underglow_change_sat(int direction)
{
if (state.saturation == 0 && direction < 0) {
return;
return 0;
}
state.saturation += direction * CONFIG_ZMK_RGB_UNDERGLOW_SAT_STEP;
@ -262,12 +268,14 @@ void zmk_rgb_underglow_change_sat(int direction) @@ -262,12 +268,14 @@ void zmk_rgb_underglow_change_sat(int direction)
if (state.saturation > 100) {
state.saturation = 100;
}
return 0;
}
void zmk_rgb_underglow_change_brt(int direction)
int zmk_rgb_underglow_change_brt(int direction)
{
if (state.brightness == 0 && direction < 0) {
return;
return 0;
}
state.brightness += direction * CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP;
@ -275,12 +283,14 @@ void zmk_rgb_underglow_change_brt(int direction) @@ -275,12 +283,14 @@ void zmk_rgb_underglow_change_brt(int direction)
if (state.brightness > 100) {
state.brightness = 100;
}
return 0;
}
void zmk_rgb_underglow_change_spd(int direction)
int zmk_rgb_underglow_change_spd(int direction)
{
if (state.animation_speed == 1 && direction < 0) {
return;
return 0;
}
state.animation_speed += direction;
@ -288,6 +298,8 @@ void zmk_rgb_underglow_change_spd(int direction) @@ -288,6 +298,8 @@ void zmk_rgb_underglow_change_spd(int direction)
if (state.animation_speed > 5) {
state.animation_speed = 5;
}
return 0;
}
SYS_INIT(zmk_rgb_underglow_init,

Loading…
Cancel
Save