From 5d1c083959967b6f55ce7cff3c83442bc71d23cb Mon Sep 17 00:00:00 2001 From: Mega Mind <68985133+megamind4089@users.noreply.github.com> Date: Mon, 12 Oct 2020 00:30:51 +0800 Subject: [PATCH] Added toggle and removed a param --- app/include/dt-bindings/zmk/ext_power.h | 11 ++++------- app/src/behaviors/behavior_ext_power.c | 5 +++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/include/dt-bindings/zmk/ext_power.h b/app/include/dt-bindings/zmk/ext_power.h index a72b6571..2a3e8460 100644 --- a/app/include/dt-bindings/zmk/ext_power.h +++ b/app/include/dt-bindings/zmk/ext_power.h @@ -6,11 +6,8 @@ #define EXT_POWER_OFF_CMD 0 #define EXT_POWER_ON_CMD 1 +#define EXT_POWER_TOGGLE_CMD 2 -/* - * Note: Some future commands might include additional parameters, so we - * defines these aliases up front. - */ - -#define EP_ON EXT_POWER_ON_CMD 0 -#define EP_OFF EXT_POWER_OFF_CMD 0 +#define EP_ON EXT_POWER_ON_CMD +#define EP_OFF EXT_POWER_OFF_CMD +#define EP_TOG EXT_POWER_TOGGLE_CMD diff --git a/app/src/behaviors/behavior_ext_power.c b/app/src/behaviors/behavior_ext_power.c index 2bd93ee0..7f06e1dd 100644 --- a/app/src/behaviors/behavior_ext_power.c +++ b/app/src/behaviors/behavior_ext_power.c @@ -30,6 +30,11 @@ static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t c return ext_power_api->disable(ext_power); case EXT_POWER_ON_CMD: return ext_power_api->enable(ext_power); + case EXT_POWER_TOGGLE_CMD: + if(ext_power_api->get(ext_power) > 0) + return ext_power_api->disable(ext_power); + else + return ext_power_api->enable(ext_power); default: LOG_ERR("Unknown ext_power command: %d", command); }