diff options
Diffstat (limited to 'keyboards/gmmk/pro/ansi/keymaps/mike1808/utils.c')
-rw-r--r-- | keyboards/gmmk/pro/ansi/keymaps/mike1808/utils.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/keyboards/gmmk/pro/ansi/keymaps/mike1808/utils.c b/keyboards/gmmk/pro/ansi/keymaps/mike1808/utils.c new file mode 100644 index 000000000..35ae20b12 --- /dev/null +++ b/keyboards/gmmk/pro/ansi/keymaps/mike1808/utils.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* Copyright 2021 Mikael Manukyan <arm.localhost@gmail.com> | ||
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 | #include "utils.h" | ||
17 | |||
18 | void store_rgb_state_to_eeprom() { | ||
19 | uint8_t mode = rgb_matrix_get_mode(); | ||
20 | uint8_t speed = rgb_matrix_get_speed(); | ||
21 | HSV color = rgb_matrix_get_hsv(); | ||
22 | |||
23 | rgb_matrix_mode(mode); | ||
24 | rgb_matrix_set_speed(speed); | ||
25 | rgb_matrix_sethsv(color.h, color.s, color.v); | ||
26 | } | ||
27 | |||
28 | void press(KeyPressState *self) { | ||
29 | self->_count++; | ||
30 | |||
31 | dprintf("KPS: press: %d\n", self->_count); | ||
32 | |||
33 | // pressed the first time | ||
34 | if (self->_count == 1) { | ||
35 | self->hander(true); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | void release(KeyPressState *self) { | ||
40 | self->_count--; | ||
41 | |||
42 | dprintf("KPS: release: %d\n", self->_count); | ||
43 | |||
44 | // all keys are relased | ||
45 | if (self->_count == 0) { | ||
46 | self->hander(false); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | void reset(KeyPressState *self) { | ||
51 | self->_count = 0; | ||
52 | } | ||
53 | |||
54 | KeyPressState *NewKeyPressState(key_press_handler handler) { | ||
55 | KeyPressState *kps = (KeyPressState *)(malloc(sizeof(KeyPressState))); | ||
56 | |||
57 | kps->_count = 0; | ||
58 | kps->press = press; | ||
59 | kps->release = release; | ||
60 | kps->reset = reset; | ||
61 | kps->hander = handler; | ||
62 | |||
63 | return kps; | ||
64 | } | ||