generated from zmkfirmware/unified-zmk-config-template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add behaviors to show indicators on demand
- Loading branch information
Showing
8 changed files
with
151 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
target_sources_ifdef(CONFIG_RGBLED_WIDGET app PRIVATE src/widget.c) | ||
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_RGBLED_WIDGET app PRIVATE src/behaviors/behavior_rgbled_widget.c) | ||
|
||
zephyr_include_directories(include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/ { | ||
behaviors { | ||
/omit-if-no-ref/ ind_bat: ind_bat { | ||
compatible = "zmk,behavior-rgbled-widget"; | ||
#binding-cells = <0>; | ||
indicate-battery; | ||
}; | ||
/omit-if-no-ref/ ind_con: ind_con { | ||
compatible = "zmk,behavior-rgbled-widget"; | ||
#binding-cells = <0>; | ||
indicate-connectivity; | ||
}; | ||
/omit-if-no-ref/ ind_lyr: ind_lyr { | ||
compatible = "zmk,behavior-rgbled-widget"; | ||
#binding-cells = <0>; | ||
indicate-layer; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
description: RGB LED widget indicator behavior | ||
|
||
compatible: "zmk,behavior-rgbled-widget" | ||
|
||
include: zero_param.yaml | ||
|
||
properties: | ||
indicate-battery: | ||
type: boolean | ||
indicate-connectivity: | ||
type: boolean | ||
indicate-layer: | ||
type: boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#define DT_DRV_COMPAT zmk_behavior_rgbled_widget | ||
|
||
#include <zephyr/device.h> | ||
#include <drivers/behavior.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
#include <zmk/behavior.h> | ||
|
||
#include <zmk_rgbled_widget/widget.h> | ||
|
||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
struct behavior_rgb_wdg_config { | ||
bool indicate_battery; | ||
bool indicate_connectivity; | ||
bool indicate_layer; | ||
}; | ||
|
||
static int behavior_rgb_wdg_init(const struct device *dev) { return 0; } | ||
|
||
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev); | ||
const struct behavior_rgb_wdg_config *cfg = dev->config; | ||
|
||
#if IS_ENABLED(CONFIG_ZMK_BATTERY_REPORTING) | ||
if (cfg->indicate_battery) { | ||
indicate_battery(); | ||
} | ||
#endif | ||
#if IS_ENABLED(CONFIG_ZMK_BLE) | ||
if (cfg->indicate_connectivity) { | ||
indicate_connectivity(); | ||
} | ||
#endif | ||
#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) | ||
if (cfg->indicate_layer) { | ||
indicate_layer(); | ||
} | ||
#endif | ||
|
||
return ZMK_BEHAVIOR_OPAQUE; | ||
} | ||
|
||
static int on_keymap_binding_released(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
return ZMK_BEHAVIOR_OPAQUE; | ||
} | ||
|
||
static const struct behavior_driver_api behavior_rgb_wdg_driver_api = { | ||
.binding_pressed = on_keymap_binding_pressed, | ||
.binding_released = on_keymap_binding_released, | ||
.locality = BEHAVIOR_LOCALITY_GLOBAL, | ||
#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) | ||
.get_parameter_metadata = zmk_behavior_get_empty_param_metadata, | ||
#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) | ||
}; | ||
|
||
#define RGBIND_INST(n) \ | ||
static struct behavior_rgb_wdg_config behavior_rgb_wdg_config_##n = { \ | ||
.indicate_battery = DT_INST_PROP(n, indicate_battery), \ | ||
.indicate_connectivity = DT_INST_PROP(n, indicate_connectivity), \ | ||
.indicate_layer = DT_INST_PROP(n, indicate_layer), \ | ||
}; \ | ||
BEHAVIOR_DT_INST_DEFINE(n, behavior_rgb_wdg_init, NULL, NULL, &behavior_rgb_wdg_config_##n, \ | ||
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ | ||
&behavior_rgb_wdg_driver_api); | ||
|
||
DT_INST_FOREACH_STATUS_OKAY(RGBIND_INST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters