Add KeyEvent data type

The `KeyEvent` type will encapsulate all of the data that will be passed to the
new generation of event handler functions.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1024/head
Michael Richters 4 years ago
parent b8025a94f3
commit 3be1ea6531
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -80,6 +80,7 @@ void setup();
#endif #endif
#include "kaleidoscope/KeyAddr.h" #include "kaleidoscope/KeyAddr.h"
#include "kaleidoscope/KeyEvent.h"
#include "kaleidoscope/key_events.h" #include "kaleidoscope/key_events.h"
#include "kaleidoscope/layers.h" #include "kaleidoscope/layers.h"
#include "kaleidoscope_internal/sketch_exploration/sketch_exploration.h" #include "kaleidoscope_internal/sketch_exploration/sketch_exploration.h"

@ -0,0 +1,23 @@
/* Kaleidoscope - Firmware for computer input devices
* Copyright (C) 2020 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/>.
*/
#include "kaleidoscope/KeyEvent.h"
namespace kaleidoscope {
KeyEventId KeyEvent::last_id_ = 0;
} // namespace kaleidoscope

@ -0,0 +1,68 @@
/* Kaleidoscope - Firmware for computer input devices
* Copyright (C) 2021 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
#include <stdint.h> // for uint8_t, int8_t
#include "kaleidoscope/key_defs.h" // for Key, Key_NoKey
#include "kaleidoscope/KeyAddr.h" // for KeyAddr
namespace kaleidoscope {
// It's important that this is a signed integer, not unsigned. It should be
// `int8_t`, but I changed it to 32 for debugging purposes.
typedef int8_t KeyEventId;
struct KeyEvent {
public:
// Constructor for plugin use when regenerating an event with specific ID:
KeyEvent(KeyAddr addr, uint8_t state,
Key key = Key_NoKey, KeyEventId id = last_id_)
: addr(addr), state(state), key(key), id_(id) {}
KeyEvent() : id_(last_id_) {}
// For use by keyscanner creating a new event from a physical keyswitch toggle
// on or off.
static KeyEvent next(KeyAddr addr, uint8_t state) {
return KeyEvent(addr, state, Key_NoKey, ++last_id_);
}
KeyEventId id() const {
return id_;
}
void swapId(KeyEvent &other) {
KeyEventId tmp_id = id_;
id_ = other.id_;
other.id_ = tmp_id;
}
KeyAddr addr = KeyAddr::none();
uint8_t state = 0;
Key key = Key_NoKey;
private:
// serial number of the event:
static KeyEventId last_id_;
KeyEventId id_;
};
} // namespace kaleidoscope
typedef kaleidoscope::KeyEventId KeyEventId;
typedef kaleidoscope::KeyEvent KeyEvent;
Loading…
Cancel
Save