-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathkeyboard.hpp
More file actions
112 lines (102 loc) · 2.4 KB
/
Copy pathkeyboard.hpp
File metadata and controls
112 lines (102 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef KEYBOARD_HPP
#define KEYBOARD_HPP
#include "stack.hpp"
#include "keymap.h"
#include "keycode.c"
#include "mHID-Project/HID-Project.h"
#include "mHID-Project/HID-Settings.h"
uint16_t curr_col_state[KEYBOARD_ROWS];
uint16_t prev_col_state[KEYBOARD_ROWS];
uint16_t temp_col_state[KEYBOARD_ROWS];
uint8_t key_pressed_num = 0;
uint8_t key_released_num = 0;
Stack key_press_stack;
Stack key_release_stack;
void init_keyboard () {
Consumer.begin();
NKROKeyboard.begin();
}
uint8_t debounce = 0;
void update_curr_col_state()
{
uint8_t row;
uint16_t _col_state;
for (row = 0; row < KEYBOARD_ROWS; row++)
{
// 扫描行
digitalWrite(row_pins[row], LOW);
_col_state = ~get_col_state();
if (temp_col_state[row] != _col_state)
{
// 检测到变化, 开始防抖, 延迟curr_col_state生效
temp_col_state[row] = _col_state;
debounce = DEBOUNCE;
}
digitalWrite(row_pins[row], HIGH);
}
if (debounce)
{
if (--debounce)
{
delay(1);
}
else
{
for (row = 0; row < KEYBOARD_ROWS; row++)
{
curr_col_state[row] = temp_col_state[row];
}
}
}
}
void send_key(uint8_t keycode, bool pressed)
{
// 不需要使用表, 把类分好来就可以的了
uint16_t _code;
switch (keycode)
{
case KC_A ... KC_EXSEL:
case KC_LCTRL ... KC_RGUI:
if (pressed)
NKROKeyboard.press((KeyboardKeycode)keycode);
else
NKROKeyboard.release((KeyboardKeycode)keycode);
break;
case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
_code = KEYCODE2SYSTEM(keycode);
if (pressed)
System.press((SystemKeycode)_code);
else
System.release();
break;
case KC_AUDIO_MUTE ... KC_BRIGHTNESS_DOWN:
_code = KEYCODE2CONSUMER(keycode);
#ifdef _DEBUG_
Serial.print("comsumer key triggered");
#endif
if (pressed)
Consumer.press((ConsumerKeycode)_code);
else
Consumer.release((ConsumerKeycode)_code);
break;
case KC_MS_UP ... KC_MS_ACCEL2:
if (pressed)
NKROKeyboard.press(keycode);
else
NKROKeyboard.release(keycode);
break;
case KC_TRNS:
break;
case KC_BOOTLOADER:
break;
default:
break;
}
}
void press_key (uint8_t keycode) {
send_key(keycode, true);
};
void release_key (uint8_t keycode) {
send_key(keycode, false);
}
#endif