diff options
author | Zach White <skullydazed@gmail.com> | 2021-07-11 09:43:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-11 09:43:58 -0700 |
commit | 0b06452d00dcd967bfcaffe89e88a4758c878e74 (patch) | |
tree | 7fb602ad2fe6c3be373f8d962e88635c9c75131d /lib/python/qmk/info.py | |
parent | fd284c43a598061afeb30e8edb4fb239f0196ac3 (diff) |
Matrix consistency check (#13470)
* Add a check to make sure the matrix sizes match the actual matrix size
* make flake8 happy
Diffstat (limited to 'lib/python/qmk/info.py')
-rw-r--r-- | lib/python/qmk/info.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index 5525f0fe6b..bcb4d81ef2 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -64,6 +64,9 @@ def info_json(keyboard): info_data = _extract_config_h(info_data) info_data = _extract_rules_mk(info_data) + # Ensure that we have matrix row and column counts + info_data = _matrix_size(info_data) + # Validate against the jsonschema try: validate(info_data, 'qmk.api.keyboard.v1') @@ -90,6 +93,9 @@ def info_json(keyboard): if layout_name not in info_data.get('layouts', {}) and layout_name not in info_data.get('layout_aliases', {}): _log_error(info_data, 'Claims to support community layout %s but no %s() macro found' % (layout, layout_name)) + # Check that the reported matrix size is consistent with the actual matrix size + _check_matrix(info_data) + return info_data @@ -338,6 +344,46 @@ def _extract_rules_mk(info_data): return info_data +def _matrix_size(info_data): + """Add info_data['matrix_size'] if it doesn't exist. + """ + if 'matrix_size' not in info_data and 'matrix_pins' in info_data: + info_data['matrix_size'] = {} + + if 'direct' in info_data['matrix_pins']: + info_data['matrix_size']['cols'] = len(info_data['matrix_pins']['direct'][0]) + info_data['matrix_size']['rows'] = len(info_data['matrix_pins']['direct']) + elif 'cols' in info_data['matrix_pins'] and 'rows' in info_data['matrix_pins']: + info_data['matrix_size']['cols'] = len(info_data['matrix_pins']['cols']) + info_data['matrix_size']['rows'] = len(info_data['matrix_pins']['rows']) + + return info_data + + +def _check_matrix(info_data): + """Check the matrix to ensure that row/column count is consistent. + """ + if 'matrix_pins' in info_data and 'matrix_size' in info_data: + actual_col_count = info_data['matrix_size'].get('cols', 0) + actual_row_count = info_data['matrix_size'].get('rows', 0) + col_count = row_count = 0 + + if 'direct' in info_data['matrix_pins']: + col_count = len(info_data['matrix_pins']['direct'][0]) + row_count = len(info_data['matrix_pins']['direct']) + elif 'cols' in info_data['matrix_pins'] and 'rows' in info_data['matrix_pins']: + col_count = len(info_data['matrix_pins']['cols']) + row_count = len(info_data['matrix_pins']['rows']) + + if col_count != actual_col_count and col_count != (actual_col_count / 2): + # FIXME: once we can we should detect if split is enabled to do the actual_col_count/2 check. + _log_error(info_data, f'MATRIX_COLS is inconsistent with the size of MATRIX_COL_PINS: {col_count} != {actual_col_count}') + + if row_count != actual_row_count and row_count != (actual_row_count / 2): + # FIXME: once we can we should detect if split is enabled to do the actual_row_count/2 check. + _log_error(info_data, f'MATRIX_ROWS is inconsistent with the size of MATRIX_ROW_PINS: {row_count} != {actual_row_count}') + + def _merge_layouts(info_data, new_info_data): """Merge new_info_data into info_data in an intelligent way. """ |