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.
90 lines
2.6 KiB
90 lines
2.6 KiB
6 years ago
|
/* Kaleidoscope-Macros - Macro keys for Kaleidoscope.
|
||
|
* Copyright (C) 2017-2018 Keyboard.io, Inc.
|
||
|
*
|
||
|
* 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.
|
||
|
*
|
||
|
* 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.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License along with
|
||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#pragma once
|
||
|
|
||
5 years ago
|
#include "kaleidoscope/Runtime.h"
|
||
6 years ago
|
|
||
6 years ago
|
#include "kaleidoscope/plugin/Macros/MacroKeyDefs.h"
|
||
|
#include "kaleidoscope/plugin/Macros/MacroSteps.h"
|
||
5 years ago
|
#include "kaleidoscope/keyswitch_state.h"
|
||
|
#include "kaleidoscope/key_events.h"
|
||
6 years ago
|
|
||
|
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState);
|
||
|
|
||
|
#if !defined(MAX_CONCURRENT_MACROS)
|
||
|
#define MAX_CONCURRENT_MACROS 8
|
||
|
#endif
|
||
|
|
||
|
struct MacroKeyEvent {
|
||
|
byte key_code;
|
||
|
byte key_id;
|
||
|
byte key_state;
|
||
|
};
|
||
|
|
||
|
namespace kaleidoscope {
|
||
|
namespace plugin {
|
||
|
|
||
|
class Macros_ : public kaleidoscope::Plugin {
|
||
|
public:
|
||
|
Macros_(void) {}
|
||
|
|
||
|
static MacroKeyEvent active_macros[MAX_CONCURRENT_MACROS];
|
||
|
static byte active_macro_count;
|
||
|
static void addActiveMacroKey(byte key_code, byte key_id, byte key_state) {
|
||
|
// If we've got too many active macros, give up:
|
||
|
if (active_macro_count >= MAX_CONCURRENT_MACROS) {
|
||
|
return;
|
||
|
}
|
||
|
active_macros[active_macro_count].key_code = key_code;
|
||
|
active_macros[active_macro_count].key_id = key_id;
|
||
|
active_macros[active_macro_count].key_state = key_state;
|
||
|
++active_macro_count;
|
||
|
}
|
||
|
|
||
6 years ago
|
EventHandlerResult onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr, uint8_t keyState);
|
||
6 years ago
|
EventHandlerResult beforeReportingState();
|
||
|
EventHandlerResult afterEachCycle();
|
||
|
|
||
|
void play(const macro_t *macro_p);
|
||
|
|
||
|
/* What follows below, is a bit of template magic that allows us to use
|
||
|
Macros.type() with any number of arguments, without having to use a
|
||
5 years ago
|
sentinel. See the comments on Runtime.use() for more details - this is
|
||
6 years ago
|
the same trick.
|
||
|
*/
|
||
|
inline const macro_t *type() {
|
||
|
return MACRO_NONE;
|
||
|
}
|
||
|
const macro_t *type(const char *string);
|
||
|
template <typename... Strings>
|
||
|
const macro_t *type(const char *first, Strings&&... strings) {
|
||
|
type(first);
|
||
|
return type(strings...);
|
||
|
}
|
||
|
|
||
6 years ago
|
static KeyAddr key_addr;
|
||
6 years ago
|
|
||
|
private:
|
||
|
Key lookupAsciiCode(uint8_t ascii_code);
|
||
4 years ago
|
bool isMacroKey(Key key);
|
||
6 years ago
|
};
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
extern kaleidoscope::plugin::Macros_ Macros;
|