diff options
| author | Thomas Baart <mail@thomasbaart.nl> | 2019-02-05 19:19:56 +0100 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-02-05 10:19:56 -0800 |
| commit | 47051f506fd4888bbb55fa7981cb7b24827f3d1b (patch) | |
| tree | 88628409bc9d63bfb0999be7f5b328ff5421b365 /tmk_core | |
| parent | 7df9e584fa1ee31ab5bb35b1c7fa09845cba0a80 (diff) | |
| download | qmk_firmware-47051f506fd4888bbb55fa7981cb7b24827f3d1b.tar.gz qmk_firmware-47051f506fd4888bbb55fa7981cb7b24827f3d1b.zip | |
Add One Shot Key callbacks (#4697)
* Added callbacks to one shot modifier changes
* Altered signature of callback functions
* Reordered the callback methods, shortened brief documentation
* Added One Shot Modifier callback documentation
* First attempt at unit tests
* Revert "First attempt at unit tests"
This reverts commit 5ec21a782202c0d74cf21cb852bd319f0c8b4842.
* Simplified oneshot function implementations
* Made clear_oneshot_locked_mods to be conform action_util.h, adhering to the (void) signature
* Made used datatypes for oneshot mods consistently unsigned integers
* Corrected callback to call clear callback when clear_oneshot_locked_mods is invoked
* Simplified oneshot equals statements
* Corrected return type and signature of get and set oneshot locked mods
* Consolidated one shot callbacks, added initial layer callback version
* Fixed non-updating one shot layer variable after timeout or other clear, added code comments
* Added better one shot key docs
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/common/action_util.c | 88 | ||||
| -rw-r--r-- | tmk_core/common/action_util.h | 11 |
2 files changed, 84 insertions, 15 deletions
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index 58401ace5..365ed6a1d 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c | |||
| @@ -48,11 +48,21 @@ extern inline void del_key(uint8_t key); | |||
| 48 | extern inline void clear_keys(void); | 48 | extern inline void clear_keys(void); |
| 49 | 49 | ||
| 50 | #ifndef NO_ACTION_ONESHOT | 50 | #ifndef NO_ACTION_ONESHOT |
| 51 | static int8_t oneshot_mods = 0; | 51 | static uint8_t oneshot_mods = 0; |
| 52 | static int8_t oneshot_locked_mods = 0; | 52 | static uint8_t oneshot_locked_mods = 0; |
| 53 | int8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } | 53 | uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } |
| 54 | void set_oneshot_locked_mods(int8_t mods) { oneshot_locked_mods = mods; } | 54 | void set_oneshot_locked_mods(uint8_t mods) { |
| 55 | void clear_oneshot_locked_mods(void) { oneshot_locked_mods = 0; } | 55 | if (mods != oneshot_locked_mods) { |
| 56 | oneshot_locked_mods = mods; | ||
| 57 | oneshot_locked_mods_changed_kb(oneshot_locked_mods); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | void clear_oneshot_locked_mods(void) { | ||
| 61 | if (oneshot_locked_mods) { | ||
| 62 | oneshot_locked_mods = 0; | ||
| 63 | oneshot_locked_mods_changed_kb(oneshot_locked_mods); | ||
| 64 | } | ||
| 65 | } | ||
| 56 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 66 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
| 57 | static uint16_t oneshot_time = 0; | 67 | static uint16_t oneshot_time = 0; |
| 58 | bool has_oneshot_mods_timed_out(void) { | 68 | bool has_oneshot_mods_timed_out(void) { |
| @@ -97,6 +107,7 @@ void set_oneshot_layer(uint8_t layer, uint8_t state) | |||
| 97 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 107 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
| 98 | oneshot_layer_time = timer_read(); | 108 | oneshot_layer_time = timer_read(); |
| 99 | #endif | 109 | #endif |
| 110 | oneshot_layer_changed_kb(get_oneshot_layer()); | ||
| 100 | } | 111 | } |
| 101 | /** \brief Reset oneshot layer | 112 | /** \brief Reset oneshot layer |
| 102 | * | 113 | * |
| @@ -107,6 +118,7 @@ void reset_oneshot_layer(void) { | |||
| 107 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 118 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
| 108 | oneshot_layer_time = 0; | 119 | oneshot_layer_time = 0; |
| 109 | #endif | 120 | #endif |
| 121 | oneshot_layer_changed_kb(get_oneshot_layer()); | ||
| 110 | } | 122 | } |
| 111 | /** \brief Clear oneshot layer | 123 | /** \brief Clear oneshot layer |
| 112 | * | 124 | * |
| @@ -118,9 +130,7 @@ void clear_oneshot_layer_state(oneshot_fullfillment_t state) | |||
| 118 | oneshot_layer_data &= ~state; | 130 | oneshot_layer_data &= ~state; |
| 119 | if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) { | 131 | if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) { |
| 120 | layer_off(get_oneshot_layer()); | 132 | layer_off(get_oneshot_layer()); |
| 121 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 133 | reset_oneshot_layer(); |
| 122 | oneshot_layer_time = 0; | ||
| 123 | #endif | ||
| 124 | } | 134 | } |
| 125 | } | 135 | } |
| 126 | /** \brief Is oneshot layer active | 136 | /** \brief Is oneshot layer active |
| @@ -243,23 +253,27 @@ void clear_macro_mods(void) { macro_mods = 0; } | |||
| 243 | * | 253 | * |
| 244 | * FIXME: needs doc | 254 | * FIXME: needs doc |
| 245 | */ | 255 | */ |
| 246 | void set_oneshot_mods(uint8_t mods) | 256 | void set_oneshot_mods(uint8_t mods) { |
| 247 | { | 257 | if (oneshot_mods != mods) { |
| 248 | oneshot_mods = mods; | ||
| 249 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 258 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
| 250 | oneshot_time = timer_read(); | 259 | oneshot_time = timer_read(); |
| 251 | #endif | 260 | #endif |
| 261 | oneshot_mods = mods; | ||
| 262 | oneshot_mods_changed_kb(mods); | ||
| 263 | } | ||
| 252 | } | 264 | } |
| 253 | /** \brief clear oneshot mods | 265 | /** \brief clear oneshot mods |
| 254 | * | 266 | * |
| 255 | * FIXME: needs doc | 267 | * FIXME: needs doc |
| 256 | */ | 268 | */ |
| 257 | void clear_oneshot_mods(void) | 269 | void clear_oneshot_mods(void) { |
| 258 | { | 270 | if (oneshot_mods) { |
| 259 | oneshot_mods = 0; | 271 | oneshot_mods = 0; |
| 260 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 272 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
| 261 | oneshot_time = 0; | 273 | oneshot_time = 0; |
| 262 | #endif | 274 | #endif |
| 275 | oneshot_mods_changed_kb(oneshot_mods); | ||
| 276 | } | ||
| 263 | } | 277 | } |
| 264 | /** \brief get oneshot mods | 278 | /** \brief get oneshot mods |
| 265 | * | 279 | * |
| @@ -271,6 +285,54 @@ uint8_t get_oneshot_mods(void) | |||
| 271 | } | 285 | } |
| 272 | #endif | 286 | #endif |
| 273 | 287 | ||
| 288 | /** \brief Called when the one shot modifiers have been changed. | ||
| 289 | * | ||
| 290 | * \param mods Contains the active modifiers active after the change. | ||
| 291 | */ | ||
| 292 | __attribute__((weak)) | ||
| 293 | void oneshot_locked_mods_changed_user(uint8_t mods) { } | ||
| 294 | |||
| 295 | /** \brief Called when the locked one shot modifiers have been changed. | ||
| 296 | * | ||
| 297 | * \param mods Contains the active modifiers active after the change. | ||
| 298 | */ | ||
| 299 | __attribute__((weak)) | ||
| 300 | void oneshot_locked_mods_changed_kb(uint8_t mods) { | ||
| 301 | oneshot_locked_mods_changed_user(mods); | ||
| 302 | } | ||
| 303 | |||
| 304 | /** \brief Called when the one shot modifiers have been changed. | ||
| 305 | * | ||
| 306 | * \param mods Contains the active modifiers active after the change. | ||
| 307 | */ | ||
| 308 | __attribute__((weak)) | ||
| 309 | void oneshot_mods_changed_user(uint8_t mods) { } | ||
| 310 | |||
| 311 | /** \brief Called when the one shot modifiers have been changed. | ||
| 312 | * | ||
| 313 | * \param mods Contains the active modifiers active after the change. | ||
| 314 | */ | ||
| 315 | __attribute__((weak)) | ||
| 316 | void oneshot_mods_changed_kb(uint8_t mods) { | ||
| 317 | oneshot_mods_changed_user(mods); | ||
| 318 | } | ||
| 319 | |||
| 320 | /** \brief Called when the one shot layers have been changed. | ||
| 321 | * | ||
| 322 | * \param layer Contains the layer that is toggled on, or zero when toggled off. | ||
| 323 | */ | ||
| 324 | __attribute__((weak)) | ||
| 325 | void oneshot_layer_changed_user(uint8_t layer) { } | ||
| 326 | |||
| 327 | /** \brief Called when the one shot layers have been changed. | ||
| 328 | * | ||
| 329 | * \param layer Contains the layer that is toggled on, or zero when toggled off. | ||
| 330 | */ | ||
| 331 | __attribute__((weak)) | ||
| 332 | void oneshot_layer_changed_kb(uint8_t layer) { | ||
| 333 | oneshot_layer_changed_user(layer); | ||
| 334 | } | ||
| 335 | |||
| 274 | /** \brief inspect keyboard state | 336 | /** \brief inspect keyboard state |
| 275 | * | 337 | * |
| 276 | * FIXME: needs doc | 338 | * FIXME: needs doc |
diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h index 345893151..d03f5682a 100644 --- a/tmk_core/common/action_util.h +++ b/tmk_core/common/action_util.h | |||
| @@ -71,8 +71,8 @@ void oneshot_enable(void); | |||
| 71 | void oneshot_disable(void); | 71 | void oneshot_disable(void); |
| 72 | bool has_oneshot_mods_timed_out(void); | 72 | bool has_oneshot_mods_timed_out(void); |
| 73 | 73 | ||
| 74 | int8_t get_oneshot_locked_mods(void); | 74 | uint8_t get_oneshot_locked_mods(void); |
| 75 | void set_oneshot_locked_mods(int8_t mods); | 75 | void set_oneshot_locked_mods(uint8_t mods); |
| 76 | void clear_oneshot_locked_mods(void); | 76 | void clear_oneshot_locked_mods(void); |
| 77 | 77 | ||
| 78 | typedef enum { | 78 | typedef enum { |
| @@ -89,6 +89,13 @@ bool is_oneshot_layer_active(void); | |||
| 89 | uint8_t get_oneshot_layer_state(void); | 89 | uint8_t get_oneshot_layer_state(void); |
| 90 | bool has_oneshot_layer_timed_out(void); | 90 | bool has_oneshot_layer_timed_out(void); |
| 91 | 91 | ||
| 92 | void oneshot_locked_mods_changed_user(uint8_t mods); | ||
| 93 | void oneshot_locked_mods_changed_kb(uint8_t mods); | ||
| 94 | void oneshot_mods_changed_user(uint8_t mods); | ||
| 95 | void oneshot_mods_changed_kb(uint8_t mods); | ||
| 96 | void oneshot_layer_changed_user(uint8_t layer); | ||
| 97 | void oneshot_layer_changed_kb(uint8_t layer); | ||
| 98 | |||
| 92 | /* inspect */ | 99 | /* inspect */ |
| 93 | uint8_t has_anymod(void); | 100 | uint8_t has_anymod(void); |
| 94 | 101 | ||
