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

qmk new-keyboard: prompt for matrix type and dimensions #24634

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
5 changes: 0 additions & 5 deletions data/templates/keyboard/keyboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
"keyboard_name": "%KEYBOARD%",
"maintainer": "%USER_NAME%",
"manufacturer": "%REAL_NAME%",
"diode_direction": "COL2ROW",
"matrix_pins": {
"cols": ["C2"],
"rows": ["D1"]
},
"usb": {
"vid": "0xFEED",
"pid": "0x0000",
Expand Down
51 changes: 41 additions & 10 deletions lib/python/qmk/cli/new/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,21 @@ def augment_community_info(config, src, dest):
# avoid assumptions on macro name by using the first available
first_layout = next(iter(info["layouts"].values()))["layout"]

# guess at width and height now its optional
width, height = (0, 0)
for item in first_layout:
width = max(width, int(item["x"]) + 1)
height = max(height, int(item["y"]) + 1)

info["matrix_pins"] = {
"cols": ["C2"] * width,
"rows": ["D1"] * height,
}
matrix_type = prompt_matrix_type()
(rows, cols) = prompt_matrix_size(len(first_layout))

if matrix_type == 'direct':
info["matrix_pins"] = {
"direct": [
["C2"] * cols,
] * rows,
}
elif matrix_type in ['COL2ROW', 'ROW2COL']:
info["diode_direction"] = matrix_type
info["matrix_pins"] = {
"cols": ["C2"] * cols,
"rows": ["D1"] * rows,
}

# assume a 1:1 mapping on matrix to electrical
for item in first_layout:
Expand Down Expand Up @@ -136,6 +141,32 @@ def prompt_heading_subheading(heading, subheading):
cli.log.info(subheading)


def prompt_matrix_type():
prompt_heading_subheading("Specify Matrix Type", "")

matrix_types = ['COL2ROW', 'ROW2COL', 'direct', 'custom']

return choice("Matrix type?", matrix_types)


def prompt_matrix_size(key_count):
prompt_heading_subheading("Specify Matrix Dimensions", "The number of rows and columns in the electrical matrix")

errmsg = 'Need at least one row or column!'

ret = True
while ret:
rows = int(_question("Rows:", reprompt=errmsg, validate=lambda x: int(x) > 0))
cols = int(_question("Cols:", reprompt=errmsg, validate=lambda x: int(x) > 0))

if rows * cols >= key_count:
ret = False
else:
cli.log.error(f"Number of rows ({rows}) * number of cols ({cols}) is not sufficient for the number of keys in the selected layout ({key_count})!")

return (rows, cols)


def prompt_keyboard():
prompt_heading_subheading("Name Your Keyboard Project", """For more information, see:
https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboard-project""")
Expand Down