summaryrefslogtreecommitdiff
path: root/lib/python/qmk/info.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/info.py')
-rw-r--r--lib/python/qmk/info.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index 340969f415..72424f390e 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -218,6 +218,66 @@ def _extract_audio(info_data, config_c):
info_data['audio'] = {'pins': audio_pins}
+def _extract_encoders_values(config_c, postfix=''):
+ """Common encoder extraction logic
+ """
+ a_pad = config_c.get(f'ENCODERS_PAD_A{postfix}', '').replace(' ', '')[1:-1]
+ b_pad = config_c.get(f'ENCODERS_PAD_B{postfix}', '').replace(' ', '')[1:-1]
+ resolutions = config_c.get(f'ENCODER_RESOLUTIONS{postfix}', '').replace(' ', '')[1:-1]
+
+ default_resolution = config_c.get('ENCODER_RESOLUTION', None)
+
+ if a_pad and b_pad:
+ a_pad = list(filter(None, a_pad.split(',')))
+ b_pad = list(filter(None, b_pad.split(',')))
+ resolutions = list(filter(None, resolutions.split(',')))
+ if default_resolution:
+ resolutions += [default_resolution] * (len(a_pad) - len(resolutions))
+
+ encoders = []
+ for index in range(len(a_pad)):
+ encoder = {'pin_a': a_pad[index], 'pin_b': b_pad[index]}
+ if index < len(resolutions):
+ encoder['resolution'] = int(resolutions[index])
+ encoders.append(encoder)
+
+ return encoders
+
+
+def _extract_encoders(info_data, config_c):
+ """Populate data about encoder pins
+ """
+ encoders = _extract_encoders_values(config_c)
+ if encoders:
+ if 'encoder' not in info_data:
+ info_data['encoder'] = {}
+
+ if 'rotary' in info_data['encoder']:
+ _log_warning(info_data, 'Encoder config is specified in both config.h and info.json (encoder.rotary) (Value: %s), the config.h value wins.' % info_data['encoder']['rotary'])
+
+ info_data['encoder']['rotary'] = encoders
+
+
+def _extract_split_encoders(info_data, config_c):
+ """Populate data about split encoder pins
+ """
+ encoders = _extract_encoders_values(config_c, '_RIGHT')
+ if encoders:
+ if 'split' not in info_data:
+ info_data['split'] = {}
+
+ if 'encoder' not in info_data['split']:
+ info_data['split']['encoder'] = {}
+
+ if 'right' not in info_data['split']['encoder']:
+ info_data['split']['encoder']['right'] = {}
+
+ if 'rotary' in info_data['split']['encoder']['right']:
+ _log_warning(info_data, 'Encoder config is specified in both config.h and info.json (encoder.rotary) (Value: %s), the config.h value wins.' % info_data['split']['encoder']['right']['rotary'])
+
+ info_data['split']['encoder']['right']['rotary'] = encoders
+
+
def _extract_secure_unlock(info_data, config_c):
"""Populate data about the secure unlock sequence
"""
@@ -486,6 +546,8 @@ def _extract_config_h(info_data, config_c):
_extract_split_main(info_data, config_c)
_extract_split_transport(info_data, config_c)
_extract_split_right_pins(info_data, config_c)
+ _extract_encoders(info_data, config_c)
+ _extract_split_encoders(info_data, config_c)
_extract_device_version(info_data)
return info_data