1
0
Fork 0

Configure keyboard matrix from info.json (#10817)

* Make parameters from info.json available to the build system

* move all clueboard settings to info.json

* code formatting

* make flake8 happy

* make flake8 happy

* make qmk lint happy

* Add support for specifying led indicators in json

* move led indicators to the clueboard info.json

* Apply suggestions from code review

Co-authored-by: Erovia <Erovia@users.noreply.github.com>

* add missing docstring

Co-authored-by: Erovia <Erovia@users.noreply.github.com>
This commit is contained in:
Zach White 2020-12-30 10:27:37 -08:00 committed by GitHub
parent f231f24dda
commit 47b9b11009
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
79 changed files with 4791 additions and 3901 deletions

View file

@ -3,25 +3,12 @@
import json
import os
from pathlib import Path
from decimal import Decimal
from collections import OrderedDict
from milc import cli
from kle2xy import KLE2xy
from qmk.converter import kle2qmk
class CustomJSONEncoder(json.JSONEncoder):
def default(self, obj):
try:
if isinstance(obj, Decimal):
if obj % 2 in (Decimal(0), Decimal(1)):
return int(obj)
return float(obj)
except TypeError:
pass
return json.JSONEncoder.default(self, obj)
from qmk.info_json_encoder import InfoJSONEncoder
@cli.argument('filename', help='The KLE raw txt to convert')
@ -52,24 +39,22 @@ def kle2json(cli):
cli.log.error('Could not parse KLE raw data: %s', raw_code)
cli.log.exception(e)
return False
keyboard = OrderedDict(
keyboard_name=kle.name,
url='',
maintainer='qmk',
width=kle.columns,
height=kle.rows,
layouts={'LAYOUT': {
'layout': 'LAYOUT_JSON_HERE'
}},
)
# Initialize keyboard with json encoded from ordered dict
keyboard = json.dumps(keyboard, indent=4, separators=(', ', ': '), sort_keys=False, cls=CustomJSONEncoder)
# Initialize layout with kle2qmk from converter module
layout = json.dumps(kle2qmk(kle), separators=(', ', ':'), cls=CustomJSONEncoder)
# Replace layout in keyboard json
keyboard = keyboard.replace('"LAYOUT_JSON_HERE"', layout)
keyboard = {
'keyboard_name': kle.name,
'url': '',
'maintainer': 'qmk',
'width': kle.columns,
'height': kle.rows,
'layouts': {
'LAYOUT': {
'layout': kle2qmk(kle)
}
},
}
# Write our info.json
file = open(out_path / "info.json", "w")
file.write(keyboard)
file.close()
keyboard = json.dumps(keyboard, indent=4, separators=(', ', ': '), sort_keys=False, cls=InfoJSONEncoder)
info_json_file = out_path / 'info.json'
info_json_file.write_text(keyboard)
cli.log.info('Wrote out {fg_cyan}%s/info.json', out_path)