You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.8 KiB
85 lines
2.8 KiB
8 years ago
|
/* -*- mode: c++ -*-
|
||
8 years ago
|
* Kaleidoscope-MagicCombo -- Magic combo framework
|
||
6 years ago
|
* Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc
|
||
8 years ago
|
*
|
||
6 years ago
|
* This program is free software: you can redistribute it and/or modify it under
|
||
|
* the terms of the GNU General Public License as published by the Free Software
|
||
|
* Foundation, version 3.
|
||
8 years ago
|
*
|
||
6 years ago
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
|
* details.
|
||
8 years ago
|
*
|
||
6 years ago
|
* You should have received a copy of the GNU General Public License along with
|
||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||
8 years ago
|
*/
|
||
|
|
||
|
#pragma once
|
||
|
|
||
8 years ago
|
#include <Kaleidoscope.h>
|
||
8 years ago
|
|
||
7 years ago
|
#define MAX_COMBO_LENGTH 5
|
||
|
|
||
|
#define USE_MAGIC_COMBOS(...) \
|
||
|
namespace kaleidoscope { \
|
||
6 years ago
|
namespace plugin { \
|
||
7 years ago
|
namespace magiccombo { \
|
||
6 years ago
|
const kaleidoscope::plugin::MagicCombo::Combo combos[] PROGMEM = \
|
||
|
{__VA_ARGS__}; \
|
||
7 years ago
|
\
|
||
|
const uint8_t combos_length = sizeof(combos) / sizeof(*combos); \
|
||
|
} \
|
||
6 years ago
|
} \
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
#define _MAGICCOMBO_API_CHANGE \
|
||
|
"The MagicCombo API changed in an incompatible way, you will need to\n" \
|
||
|
"upgrade.\n" \
|
||
|
"\n" \
|
||
|
"Please see the `UPGRADING.md` document shipped with the source:\n" \
|
||
|
" https://github.com/keyboardio/Kaleidoscope-MagicCombo/blob/master/UPGRADING.md"
|
||
|
|
||
8 years ago
|
namespace kaleidoscope {
|
||
6 years ago
|
namespace plugin {
|
||
8 years ago
|
|
||
7 years ago
|
class MagicCombo : public kaleidoscope::Plugin {
|
||
8 years ago
|
public:
|
||
7 years ago
|
typedef void (*ComboAction)(uint8_t combo_index);
|
||
8 years ago
|
typedef struct {
|
||
7 years ago
|
ComboAction action;
|
||
|
int8_t keys[MAX_COMBO_LENGTH + 1];
|
||
|
} Combo;
|
||
7 years ago
|
typedef struct combo_t {
|
||
|
uint32_t left_hand, right_hand;
|
||
|
|
||
7 years ago
|
template <typename T>
|
||
|
combo_t(T l, T r) {
|
||
7 years ago
|
static_assert(sizeof(T) < 0, _DEPRECATE(_MAGICCOMBO_API_CHANGE));
|
||
7 years ago
|
}
|
||
7 years ago
|
} combo_t;
|
||
8 years ago
|
|
||
7 years ago
|
MagicCombo(void) {}
|
||
8 years ago
|
|
||
7 years ago
|
static const combo_t *magic_combos;
|
||
8 years ago
|
static uint16_t min_interval;
|
||
8 years ago
|
|
||
7 years ago
|
EventHandlerResult beforeReportingState();
|
||
|
|
||
8 years ago
|
private:
|
||
8 years ago
|
static uint32_t end_time_;
|
||
8 years ago
|
};
|
||
|
|
||
7 years ago
|
namespace magiccombo {
|
||
|
extern const MagicCombo::Combo combos[];
|
||
|
extern const uint8_t combos_length;
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
}
|
||
8 years ago
|
|
||
6 years ago
|
// Backward compatibility
|
||
|
typedef plugin::MagicCombo MagicCombo;
|
||
|
}
|
||
|
|
||
|
extern kaleidoscope::plugin::MagicCombo MagicCombo;
|