Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More DD encoder fixes #17615

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/python/qmk/cli/generate/config_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def generate_encoder_config(encoder_json, config_h_lines, postfix=''):
for encoder in encoder_json.get("rotary", []):
a_pads.append(encoder["pin_a"])
b_pads.append(encoder["pin_b"])
resolutions.append(str(encoder.get("resolution", 4)))
resolutions.append(encoder.get("resolution", None))

config_h_lines.append(f'#ifndef ENCODERS_PAD_A{postfix}')
config_h_lines.append(f'# define ENCODERS_PAD_A{postfix} {{ { ", ".join(a_pads) } }}')
Expand All @@ -152,13 +152,15 @@ def generate_encoder_config(encoder_json, config_h_lines, postfix=''):
config_h_lines.append(f'# define ENCODERS_PAD_B{postfix} {{ { ", ".join(b_pads) } }}')
config_h_lines.append(f'#endif // ENCODERS_PAD_B{postfix}')

if len(set(resolutions)) == 1:
if None in resolutions:
cli.log.debug("Unable to generate ENCODER_RESOLUTION configuration")
elif len(set(resolutions)) == 1:
config_h_lines.append(f'#ifndef ENCODER_RESOLUTION{postfix}')
config_h_lines.append(f'# define ENCODER_RESOLUTION{postfix} { resolutions[0] }')
config_h_lines.append(f'#endif // ENCODER_RESOLUTION{postfix}')
else:
config_h_lines.append(f'#ifndef ENCODER_RESOLUTIONS{postfix}')
config_h_lines.append(f'# define ENCODER_RESOLUTIONS{postfix} {{ { ", ".join(resolutions) } }}')
config_h_lines.append(f'# define ENCODER_RESOLUTIONS{postfix} {{ { ", ".join(map(str,resolutions)) } }}')
config_h_lines.append(f'#endif // ENCODER_RESOLUTIONS{postfix}')


Expand Down
10 changes: 7 additions & 3 deletions lib/python/qmk/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,21 @@ def _extract_encoders_values(config_c, postfix=''):
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', '4')
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(',')))
resolutions += [default_resolution] * (len(a_pad) - len(resolutions))
if default_resolution:
resolutions += [default_resolution] * (len(a_pad) - len(resolutions))

encoders = []
for index in range(len(a_pad)):
encoders.append({'pin_a': a_pad[index], 'pin_b': b_pad[index], "resolution": int(resolutions[index])})
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

Expand Down