Add suggested changes
This commit is contained in:
parent
295af93289
commit
564f787280
5 changed files with 57 additions and 58 deletions
|
@ -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_USB app PRIVATE src/usb_hid.c)
|
||||||
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.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/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/endpoints.c)
|
||||||
target_sources(app PRIVATE src/main.c)
|
target_sources(app PRIVATE src/main.c)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
behaviors {
|
behaviors {
|
||||||
rgb_ug: behavior_rgb_underglow {
|
rgb_ug: behavior_rgb_underglow {
|
||||||
compatible = "zmk,behavior-rgb-underglow";
|
compatible = "zmk,behavior-rgb-underglow";
|
||||||
label = "RGB_UNDERGLOW_ACTION";
|
label = "RGB_UNDERGLOW";
|
||||||
#binding-cells = <1>;
|
#binding-cells = <1>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Nick Winans <nick@winans.codes>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void zmk_rgb_underglow_toggle();
|
int zmk_rgb_underglow_toggle();
|
||||||
void zmk_rgb_underglow_cycle_effect(int direction);
|
int zmk_rgb_underglow_cycle_effect(int direction);
|
||||||
void zmk_rgb_underglow_change_hue(int direction);
|
int zmk_rgb_underglow_change_hue(int direction);
|
||||||
void zmk_rgb_underglow_change_sat(int direction);
|
int zmk_rgb_underglow_change_sat(int direction);
|
||||||
void zmk_rgb_underglow_change_brt(int direction);
|
int zmk_rgb_underglow_change_brt(int direction);
|
||||||
void zmk_rgb_underglow_change_spd(int direction);
|
int zmk_rgb_underglow_change_spd(int direction);
|
||||||
|
|
|
@ -15,9 +15,6 @@
|
||||||
|
|
||||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
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)
|
static int behavior_rgb_underglow_init(struct device *dev)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -28,53 +25,38 @@ static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t a
|
||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case RGB_TOG:
|
case RGB_TOG:
|
||||||
zmk_rgb_underglow_toggle();
|
return zmk_rgb_underglow_toggle();
|
||||||
break;
|
|
||||||
case RGB_HUI:
|
case RGB_HUI:
|
||||||
zmk_rgb_underglow_change_hue(1);
|
return zmk_rgb_underglow_change_hue(1);
|
||||||
break;
|
|
||||||
case RGB_HUD:
|
case RGB_HUD:
|
||||||
zmk_rgb_underglow_change_hue(-1);
|
return zmk_rgb_underglow_change_hue(-1);
|
||||||
break;
|
|
||||||
case RGB_SAI:
|
case RGB_SAI:
|
||||||
zmk_rgb_underglow_change_sat(1);
|
return zmk_rgb_underglow_change_sat(1);
|
||||||
break;
|
|
||||||
case RGB_SAD:
|
case RGB_SAD:
|
||||||
zmk_rgb_underglow_change_sat(-1);
|
return zmk_rgb_underglow_change_sat(-1);
|
||||||
break;
|
|
||||||
case RGB_BRI:
|
case RGB_BRI:
|
||||||
zmk_rgb_underglow_change_brt(1);
|
zmk_rgb_underglow_change_brt(1);
|
||||||
break;
|
|
||||||
case RGB_BRD:
|
case RGB_BRD:
|
||||||
zmk_rgb_underglow_change_brt(-1);
|
return zmk_rgb_underglow_change_brt(-1);
|
||||||
break;
|
|
||||||
case RGB_SPI:
|
case RGB_SPI:
|
||||||
zmk_rgb_underglow_change_spd(1);
|
return zmk_rgb_underglow_change_spd(1);
|
||||||
break;
|
|
||||||
case RGB_SPD:
|
case RGB_SPD:
|
||||||
zmk_rgb_underglow_change_spd(-1);
|
return zmk_rgb_underglow_change_spd(-1);
|
||||||
break;
|
|
||||||
case RGB_EFF:
|
case RGB_EFF:
|
||||||
zmk_rgb_underglow_cycle_effect(1);
|
return zmk_rgb_underglow_cycle_effect(1);
|
||||||
break;
|
|
||||||
case RGB_EFR:
|
case RGB_EFR:
|
||||||
zmk_rgb_underglow_cycle_effect(-1);
|
return zmk_rgb_underglow_cycle_effect(-1);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct behavior_driver_api behavior_rgb_underglow_driver_api = {
|
static const struct behavior_driver_api behavior_rgb_underglow_driver_api = {
|
||||||
.binding_pressed = on_keymap_binding_pressed,
|
.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,
|
DEVICE_AND_API_INIT(behavior_rgb_underglow, DT_INST_LABEL(0), behavior_rgb_underglow_init,
|
||||||
&behavior_rgb_underglow_data,
|
NULL,
|
||||||
&behavior_rgb_underglow_config,
|
NULL,
|
||||||
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
||||||
&behavior_rgb_underglow_driver_api);
|
&behavior_rgb_underglow_driver_api);
|
|
@ -15,12 +15,11 @@
|
||||||
|
|
||||||
#include <drivers/led_strip.h>
|
#include <drivers/led_strip.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
#include <drivers/spi.h>
|
|
||||||
|
|
||||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
|
||||||
#define STRIP_LABEL DT_LABEL(DT_ALIAS(led_strip))
|
#define STRIP_LABEL DT_LABEL(DT_CHOSEN(zmk_underglow))
|
||||||
#define STRIP_NUM_PIXELS DT_PROP(DT_ALIAS(led_strip), chain_length)
|
#define STRIP_NUM_PIXELS DT_PROP(DT_CHOSEN(zmk_underglow), chain_length)
|
||||||
|
|
||||||
enum rgb_underglow_effect {
|
enum rgb_underglow_effect {
|
||||||
UNDERGLOW_EFFECT_SOLID,
|
UNDERGLOW_EFFECT_SOLID,
|
||||||
|
@ -184,7 +183,7 @@ static int zmk_rgb_underglow_init(struct device *_arg)
|
||||||
LOG_INF("Found LED strip device %s", STRIP_LABEL);
|
LOG_INF("Found LED strip device %s", STRIP_LABEL);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERR("LED strip device %s not found", STRIP_LABEL);
|
LOG_ERR("LED strip device %s not found", STRIP_LABEL);
|
||||||
return 1;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = (struct rgb_underglow_state){
|
state = (struct rgb_underglow_state){
|
||||||
|
@ -202,22 +201,25 @@ static int zmk_rgb_underglow_init(struct device *_arg)
|
||||||
return 0;
|
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) {
|
if (state.current_effect == 0 && direction < 0) {
|
||||||
state.current_effect = UNDERGLOW_EFFECT_NUMBER - 1;
|
state.current_effect = UNDERGLOW_EFFECT_NUMBER - 1;
|
||||||
} else {
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
state.current_effect += direction;
|
state.current_effect += direction;
|
||||||
|
|
||||||
if (state.current_effect >= UNDERGLOW_EFFECT_NUMBER) {
|
if (state.current_effect >= UNDERGLOW_EFFECT_NUMBER) {
|
||||||
state.current_effect = 0;
|
state.current_effect = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
state.animation_step = 0;
|
state.animation_step = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmk_rgb_underglow_toggle()
|
int zmk_rgb_underglow_toggle()
|
||||||
{
|
{
|
||||||
state.on = !state.on;
|
state.on = !state.on;
|
||||||
|
|
||||||
|
@ -235,13 +237,15 @@ void zmk_rgb_underglow_toggle()
|
||||||
|
|
||||||
k_timer_stop(&underglow_tick);
|
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) {
|
if (state.hue == 0 && direction < 0) {
|
||||||
state.hue = 350;
|
state.hue = 350;
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.hue += direction * CONFIG_ZMK_RGB_UNDERGLOW_HUE_STEP;
|
state.hue += direction * CONFIG_ZMK_RGB_UNDERGLOW_HUE_STEP;
|
||||||
|
@ -249,12 +253,14 @@ void zmk_rgb_underglow_change_hue(int direction)
|
||||||
if (state.hue > 350) {
|
if (state.hue > 350) {
|
||||||
state.hue = 0;
|
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) {
|
if (state.saturation == 0 && direction < 0) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.saturation += direction * CONFIG_ZMK_RGB_UNDERGLOW_SAT_STEP;
|
state.saturation += direction * CONFIG_ZMK_RGB_UNDERGLOW_SAT_STEP;
|
||||||
|
@ -262,12 +268,14 @@ void zmk_rgb_underglow_change_sat(int direction)
|
||||||
if (state.saturation > 100) {
|
if (state.saturation > 100) {
|
||||||
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) {
|
if (state.brightness == 0 && direction < 0) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.brightness += direction * CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP;
|
state.brightness += direction * CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP;
|
||||||
|
@ -275,12 +283,14 @@ void zmk_rgb_underglow_change_brt(int direction)
|
||||||
if (state.brightness > 100) {
|
if (state.brightness > 100) {
|
||||||
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) {
|
if (state.animation_speed == 1 && direction < 0) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.animation_speed += direction;
|
state.animation_speed += direction;
|
||||||
|
@ -288,6 +298,8 @@ void zmk_rgb_underglow_change_spd(int direction)
|
||||||
if (state.animation_speed > 5) {
|
if (state.animation_speed > 5) {
|
||||||
state.animation_speed = 5;
|
state.animation_speed = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_INIT(zmk_rgb_underglow_init,
|
SYS_INIT(zmk_rgb_underglow_init,
|
||||||
|
|
Loading…
Reference in a new issue