Kaleidoscope
TapDance.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*-
2  * Kaleidoscope-TapDance -- Tap-dance keys
3  * Copyright (C) 2016, 2017 Gergely Nagy
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include <Kaleidoscope.h>
22 #include <Kaleidoscope-Ranges.h>
23 
24 #define TD(n) (Key) {.raw = kaleidoscope::ranges::TD_FIRST + n }
25 
26 #define tapDanceActionKeys(tap_count, tap_dance_action, ...) ({ \
27  static const Key __k[] PROGMEM = { __VA_ARGS__ }; \
28  TapDance.actionKeys(tap_count, tap_dance_action, \
29  sizeof (__k) / sizeof (Key), &__k[0]); \
30  })
31 
32 namespace kaleidoscope {
33 class TapDance : public KaleidoscopePlugin {
34  public:
35  typedef enum {
36  Tap,
41  } ActionType;
42 
43  TapDance(void);
44 
45  void begin(void) final;
46  static uint16_t time_out;
47 
48  void actionKeys(uint8_t tap_count, ActionType tap_dance_action, uint8_t max_keys, const Key tap_keys[]);
49 
50  private:
51  static uint32_t end_time_;
52  static uint8_t tap_count_[16];
53  static uint16_t pressed_state_;
54  static uint16_t triggered_state_;
55  static uint16_t release_next_state_;
56  static Key last_tap_dance_key_;
57  static byte last_tap_dance_row_;
58  static byte last_tap_dance_col_;
59 
60  static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
61  static void loopHook(bool is_post_clear);
62 
63  static Key tap(void);
64  static void interrupt(byte row, byte col);
65  static void timeout(void);
66  static Key release(uint8_t tap_dance_index);
67 };
68 
69 }
70 
71 void tapDanceAction(uint8_t tap_dance_index, byte row, byte col, uint8_t tap_count,
73 
ActionType
Definition: TapDance.h:35
void tapDanceAction(uint8_t tap_dance_index, byte row, byte col, uint8_t tap_count, kaleidoscope::TapDance::ActionType tap_dance_action)
void begin(void) final
Definition: TapDance.cpp:102
Definition: TapDance.h:38
TapDance(void)
Definition: TapDance.cpp:99
Definition: hid.cpp:4
byte byte uint8_t tap_count
Definition: TapDance.cpp:229
byte byte col
Definition: TapDance.cpp:229
Definition: key_defs.h:13
Definition: TapDance.h:39
Definition: TapDance.h:37
Definition: TapDance.h:40
Definition: TapDance.h:33
Definition: TapDance.h:36
byte byte uint8_t kaleidoscope::TapDance::ActionType tap_dance_action
Definition: TapDance.cpp:230
Definition: Kaleidoscope.h:40
byte row
Definition: TapDance.cpp:229
static uint16_t time_out
Definition: TapDance.h:46
void actionKeys(uint8_t tap_count, ActionType tap_dance_action, uint8_t max_keys, const Key tap_keys[])
Definition: TapDance.cpp:107