Parent directory

test_keymap_key.hpp

1854 bytes
 1/* Copyright 2021 Stefan Kerkmann
 2 *
 3 * This program is free software: you can redistribute it and/or modify
 4 * it under the terms of the GNU General Public License as published by
 5 * the Free Software Foundation, either version 2 of the License, or
 6 * (at your option) any later version.
 7 *
 8 * This program is distributed in the hope that it will be useful,
 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include <cstddef>
20#include <string>
21#include "keycode_util.hpp"
22extern "C" {
23#include "keyboard.h"
24#include "test_matrix.h"
25}
26
27#include <cassert>
28
29typedef uint8_t layer_t;
30
31struct KeymapKey {
32    KeymapKey(layer_t layer, uint8_t col, uint8_t row, uint16_t keycode) : layer(layer), position({.col = col, .row = row}), code(keycode), report_code(keycode), name(get_keycode_identifier_or_default(keycode)) {
33        validate();
34    }
35
36    KeymapKey(layer_t layer, uint8_t col, uint8_t row, uint16_t keycode, uint16_t report_code) : layer(layer), position({.col = col, .row = row}), code(keycode), report_code(report_code), name{get_keycode_identifier_or_default(keycode)} {
37        validate();
38    }
39
40    void press();
41    void release();
42
43    const layer_t  layer;
44    const keypos_t position;
45    const uint16_t code;
46    std::string    name;
47    /* Sometimes the keycode does not match the code that is send in the usb report, so we provide it here. */
48    const uint16_t report_code;
49
50   private:
51    void validate() {
52        assert(position.col <= MATRIX_COLS);
53        assert(position.row <= MATRIX_ROWS);
54    }
55    uint32_t timestamp_pressed;
56};