fix bugs triggered by certain boards

master
Zach White 2021-01-08 00:00:15 -08:00 committed by Zach White
parent a828a82d59
commit 30331b383f
4 changed files with 59 additions and 20 deletions

View File

@ -166,6 +166,10 @@
"type": "string", "type": "string",
"pattern": "^[A-K]\\d{1,2}$" "pattern": "^[A-K]\\d{1,2}$"
}, },
{
"type": "number",
"multipleOf": 1
},
{ {
"type": "null" "type": "null"
} }
@ -176,15 +180,37 @@
"cols": { "cols": {
"type": "array", "type": "array",
"items": { "items": {
"type": "string", "oneOf": [
"pattern": "^[A-K]\\d{1,2}$" {
"type": "string",
"pattern": "^[A-K]\\d{1,2}$"
},
{
"type": "number",
"multipleOf": 1
},
{
"type": "null"
}
]
} }
}, },
"rows": { "rows": {
"type": "array", "type": "array",
"items": { "items": {
"type": "string", "oneOf": [
"pattern": "^[A-K]\\d{1,2}$" {
"type": "string",
"pattern": "^[A-K]\\d{1,2}$"
},
{
"type": "number",
"multipleOf": 1
},
{
"type": "null"
}
]
} }
} }
} }

View File

@ -9,7 +9,7 @@ from qmk.comment_remover import comment_remover
default_key_entry = {'x': -1, 'y': 0, 'w': 1} default_key_entry = {'x': -1, 'y': 0, 'w': 1}
single_comment_regex = re.compile(r' */[/*].*$') single_comment_regex = re.compile(r' */[/*].*$')
multi_comment_regex = re.compile(r'/\*(.|\n)*\*/', re.MULTILINE) multi_comment_regex = re.compile(r'/\*(.|\n)*?\*/', re.MULTILINE)
def strip_line_comment(string): def strip_line_comment(string):
@ -103,7 +103,7 @@ def parse_config_h_file(config_h_file, config_h=None):
if config_h_file.exists(): if config_h_file.exists():
config_h_text = config_h_file.read_text() config_h_text = config_h_file.read_text()
config_h_text = config_h_text.replace('\\\n', '') config_h_text = config_h_text.replace('\\\n', '') # Why are you here?
config_h_text = strip_multiline_comment(config_h_text) config_h_text = strip_multiline_comment(config_h_text)
for linenum, line in enumerate(config_h_text.split('\n')): for linenum, line in enumerate(config_h_text.split('\n')):

View File

@ -64,7 +64,7 @@ def direct_pins(direct_pins):
rows = [] rows = []
for row in direct_pins: for row in direct_pins:
cols = ','.join([col or 'NO_PIN' for col in row]) cols = ','.join(map(str, [col or 'NO_PIN' for col in row]))
rows.append('{' + cols + '}') rows.append('{' + cols + '}')
col_count = len(direct_pins[0]) col_count = len(direct_pins[0])
@ -88,7 +88,7 @@ def direct_pins(direct_pins):
def col_pins(col_pins): def col_pins(col_pins):
"""Return the config.h lines that set the column pins. """Return the config.h lines that set the column pins.
""" """
cols = ','.join(col_pins) cols = ','.join(map(str, [pin or 'NO_PIN' for pin in col_pins]))
col_num = len(col_pins) col_num = len(col_pins)
return """ return """
@ -105,7 +105,7 @@ def col_pins(col_pins):
def row_pins(row_pins): def row_pins(row_pins):
"""Return the config.h lines that set the row pins. """Return the config.h lines that set the row pins.
""" """
rows = ','.join(row_pins) rows = ','.join(map(str, [pin or 'NO_PIN' for pin in row_pins]))
row_num = len(row_pins) row_num = len(row_pins)
return """ return """

View File

@ -315,11 +315,10 @@ def _extract_rgblight(info_data, config_c):
cli.log.error('%s: config.h: Could not convert "%s" to %s: %s', info_data['keyboard_folder'], config_c[config_key], config_type.__name__, e) cli.log.error('%s: config.h: Could not convert "%s" to %s: %s', info_data['keyboard_folder'], config_c[config_key], config_type.__name__, e)
for json_key, config_key in rgblight_toggles.items(): for json_key, config_key in rgblight_toggles.items():
if config_key in config_c: if config_key in config_c and json_key in rgblight:
if json_key in rgblight: _log_warning(info_data, 'RGB Light: %s is specified in both info.json and config.h, the config.h value wins.', json_key)
_log_warning(info_data, 'RGB Light: %s is specified in both info.json and config.h, the config.h value wins.', json_key)
rgblight[json_key] = config_c[config_key] rgblight[json_key] = config_key in config_c
for json_key, config_key in rgblight_animations.items(): for json_key, config_key in rgblight_animations.items():
if config_key in config_c: if config_key in config_c:
@ -337,16 +336,30 @@ def _extract_rgblight(info_data, config_c):
return info_data return info_data
def _pin_name(pin):
"""Returns the proper representation for a pin.
"""
pin = pin.strip()
if not pin:
return None
elif pin.isdigit():
return int(pin)
elif pin == 'NO_PIN':
return None
elif pin[0] in 'ABCDEFGHIJK' and pin[1].isdigit():
return pin
raise ValueError(f'Invalid pin: {pin}')
def _extract_pins(pins): def _extract_pins(pins):
"""Returns a list of pins from a comma separated string of pins. """Returns a list of pins from a comma separated string of pins.
""" """
pins = [pin.strip() for pin in pins.split(',') if pin] return [_pin_name(pin) for pin in pins.split(',')]
for pin in pins:
if pin[0] not in 'ABCDEFGHIJK' or not pin[1].isdigit():
raise ValueError(f'Invalid pin: {pin}')
return pins
def _extract_direct_matrix(info_data, direct_pins): def _extract_direct_matrix(info_data, direct_pins):