Generate keymap dd keycodes to header (#20273)
This commit is contained in:
parent
59a3098139
commit
938badc3b0
4 changed files with 61 additions and 32 deletions
|
@ -19,6 +19,9 @@ from qmk.info import info_json
|
|||
|
||||
# The `keymap.c` template to use when a keyboard doesn't have its own
|
||||
DEFAULT_KEYMAP_C = """#include QMK_KEYBOARD_H
|
||||
#if __has_include("keymap.h")
|
||||
# include "keymap.h"
|
||||
#endif
|
||||
__INCLUDES__
|
||||
|
||||
/* THIS FILE WAS GENERATED!
|
||||
|
@ -26,8 +29,6 @@ __INCLUDES__
|
|||
* This file was generated by qmk json2c. You may or may not want to
|
||||
* edit it directly.
|
||||
*/
|
||||
__KEYCODE_OUTPUT_GOES_HERE__
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
__KEYMAP_GOES_HERE__
|
||||
};
|
||||
|
@ -125,29 +126,6 @@ def _generate_macros_function(keymap_json):
|
|||
return macro_txt
|
||||
|
||||
|
||||
def _generate_keycodes_function(keymap_json):
|
||||
"""Generates keymap level keycodes.
|
||||
"""
|
||||
lines = []
|
||||
lines.append('enum keymap_keycodes {')
|
||||
|
||||
for index, item in enumerate(keymap_json.get('keycodes', [])):
|
||||
key = item["key"]
|
||||
if index == 0:
|
||||
lines.append(f' {key} = QK_USER_0,')
|
||||
else:
|
||||
lines.append(f' {key},')
|
||||
|
||||
lines.append('};')
|
||||
|
||||
for item in keymap_json.get('keycodes', []):
|
||||
key = item["key"]
|
||||
for alias in item.get("aliases", []):
|
||||
lines.append(f'#define {alias} {key}')
|
||||
|
||||
return lines
|
||||
|
||||
|
||||
def template_json(keyboard):
|
||||
"""Returns a `keymap.json` template for a keyboard.
|
||||
|
||||
|
@ -350,12 +328,6 @@ def generate_c(keymap_json):
|
|||
hostlang = f'#include "keymap_{keymap_json["host_language"]}.h"\n#include "sendstring_{keymap_json["host_language"]}.h"\n'
|
||||
new_keymap = new_keymap.replace('__INCLUDES__', hostlang)
|
||||
|
||||
keycodes = ''
|
||||
if 'keycodes' in keymap_json and keymap_json['keycodes'] is not None:
|
||||
keycodes_txt = _generate_keycodes_function(keymap_json)
|
||||
keycodes = '\n'.join(keycodes_txt)
|
||||
new_keymap = new_keymap.replace('__KEYCODE_OUTPUT_GOES_HERE__', keycodes)
|
||||
|
||||
return new_keymap
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue