-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
46 lines (36 loc) · 1.21 KB
/
main.c
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
#include <stdio.h>
#include <string.h>
#include "pico/stdlib.h"
#include "key_matrix.h"
#include "keyboard.h"
#include "scancodes.h"
const int keymap[] = {
KEY_NUM_LOCK, KEY_KP_SLASH, KEY_KP_ASTERISK, KEY_KP_MINUS,
KEY_KP_7, KEY_KP_8, KEY_KP_9, KEY_NULL,
KEY_KP_4, KEY_KP_5, KEY_KP_6, KEY_KP_PLUS,
KEY_KP_1, KEY_KP_2, KEY_KP_3, KEY_NULL,
KEY_KP_0, KEY_KP_0, KEY_KP_DOT, KEY_KP_ENTER
};
const int output_pins[4] = {2, 3, 4, 5};
const int input_pins[5] = {28, 27, 21, 20, 19};
bool is_keycodes_changed(const int* prev, const int* curr){
for (int i=0; i<6; i++){
if (prev[i]!=curr[i]) return true;
}
return false;
}
int main(void){
stdio_init_all();
init_key_matrix(keymap, output_pins, ARRAY_SIZE(output_pins), input_pins, ARRAY_SIZE(input_pins));
keyboard_start();
int keycodes_prev[6] = {0, };
while(1){
int keycodes[6] = {0, };
int modifier = 0;
scan_key_matrix(&modifier, keycodes);
if (is_keycodes_changed(keycodes_prev, keycodes)){
send_keys(modifier, keycodes);
memcpy(keycodes_prev, keycodes, sizeof(keycodes_prev));
}
}
}