diff options
Diffstat (limited to 'keyboards/omnikeyish/dynamic_macro.h')
| -rw-r--r-- | keyboards/omnikeyish/dynamic_macro.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/keyboards/omnikeyish/dynamic_macro.h b/keyboards/omnikeyish/dynamic_macro.h new file mode 100644 index 000000000..87665c443 --- /dev/null +++ b/keyboards/omnikeyish/dynamic_macro.h | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | /* Copyright 2016 Jack Humbert | ||
| 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 | /* Author: Wojciech Siewierski < wojciech dot siewierski at onet dot pl > */ | ||
| 18 | #pragma once | ||
| 19 | |||
| 20 | #include "action.h" | ||
| 21 | #include "action_layer.h" | ||
| 22 | |||
| 23 | #ifndef DYNAMIC_MACRO_COUNT | ||
| 24 | #define DYNAMIC_MACRO_COUNT 2 | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #ifndef DYNAMIC_MACRO_SIZE | ||
| 28 | /* May be overridden with a custom value. Be aware that the effective | ||
| 29 | * macro length is half of this value: each keypress is recorded twice | ||
| 30 | * because of the down-event and up-event. This is not a bug, it's the | ||
| 31 | * intended behavior. | ||
| 32 | * | ||
| 33 | * Usually it should be fine to set the macro size to at least 256 but | ||
| 34 | * there have been reports of it being too much in some users' cases, | ||
| 35 | * so 128 is considered a safe default. | ||
| 36 | */ | ||
| 37 | #define DYNAMIC_MACRO_SIZE 64 | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #ifndef DYNAMIC_MACRO_EEPROM_STORAGE | ||
| 41 | #define DYNAMIC_MACRO_EEPROM_STORAGE | ||
| 42 | #endif | ||
| 43 | |||
| 44 | /* DYNAMIC_MACRO_RANGE must be set as the last element of user's | ||
| 45 | * "planck_keycodes" enum prior to including this header. This allows | ||
| 46 | * us to 'extend' it. | ||
| 47 | */ | ||
| 48 | enum dynamic_macro_keycodes { | ||
| 49 | DYN_MACRO_PROG = DYNAMIC_MACRO_RANGE, | ||
| 50 | |||
| 51 | /* Requirement: DYN_MACRO_KEYs are in sequence in the enum. */ | ||
| 52 | DYN_MACRO_KEY1, | ||
| 53 | DYN_MACRO_KEY2, | ||
| 54 | DYN_MACRO_KEY3, | ||
| 55 | DYN_MACRO_KEY4, | ||
| 56 | DYN_MACRO_KEY5, | ||
| 57 | DYN_MACRO_KEY6, | ||
| 58 | DYN_MACRO_KEY7, | ||
| 59 | DYN_MACRO_KEY8, | ||
| 60 | DYN_MACRO_KEY9, | ||
| 61 | DYN_MACRO_KEY10, | ||
| 62 | DYN_MACRO_KEY11, | ||
| 63 | DYN_MACRO_KEY12 | ||
| 64 | }; | ||
| 65 | |||
| 66 | enum dynamic_macro_recording_state { STATE_NOT_RECORDING, STATE_RECORD_KEY_PRESSED, STATE_CURRENTLY_RECORDING }; | ||
| 67 | |||
| 68 | typedef struct { | ||
| 69 | keyrecord_t events[DYNAMIC_MACRO_SIZE]; | ||
| 70 | uint8_t length; | ||
| 71 | uint16_t checksum; | ||
| 72 | } dynamic_macro_t; | ||
| 73 | |||
| 74 | dynamic_macro_t dynamic_macros[DYNAMIC_MACRO_COUNT]; | ||
| 75 | |||
| 76 | void dynamic_macro_init(void); | ||
| 77 | void dynamic_macro_led_blink(void); | ||
| 78 | void dynamic_macro_record_start(uint8_t macro_id); | ||
| 79 | void dynamic_macro_play(uint8_t macro_id); | ||
| 80 | void dynamic_macro_record_key(uint8_t macro_id, keyrecord_t* record); | ||
| 81 | void dynamic_macro_record_end(uint8_t macro_id); | ||
| 82 | bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t* record); | ||
| 83 | |||
| 84 | #define DYNAMIC_MACRO_CRC_LENGTH (sizeof(dynamic_macro_t) - sizeof(uint16_t)) | ||
| 85 | |||
| 86 | #ifdef DYNAMIC_MACRO_EEPROM_STORAGE | ||
| 87 | #define DYNAMIC_MACRO_EEPROM_MAGIC (uint16_t)0xDEAD | ||
| 88 | |||
| 89 | uint16_t dynamic_macro_calc_crc(dynamic_macro_t* macro); | ||
| 90 | void dynamic_macro_load_eeprom_all(void); | ||
| 91 | void dynamic_macro_load_eeprom(uint8_t macro_id); | ||
| 92 | void dynamic_macro_save_eeprom(uint8_t macro_id); | ||
| 93 | bool dynamic_macro_header_correct(void); | ||
| 94 | #endif | ||
| 95 | |||
