Skip to content

Commit

Permalink
Sync QWERTY and Colemak layouts
Browse files Browse the repository at this point in the history
* Initial shield

Change caps word to shell launch

add a README and update BT config

test new values for track ball

test new values for track ball

adjust automouse timeout

shift around some keys

Test Hyper

Working Meh & Hyper

add tap-preferred flavor to keymap home row

add tap-preferred to number keys

update thumb button

Update num keys and thumb key

Change scrolling speed

add <> to numbers in keymap

try adjusting mouse keys scroll speed

try adjusting mouse keys scroll speed with numbers in <>

try adjusting mouse keys scroll speed with numbers in <>

remove scroll numbers

add layer one to the mouse scroll layers

test ac scrolling

change cpi values

change cpi values

add trackball snipe layer

adjust cpi to use dividor

add slow mouse layer for sniping

remove dividor on snipe and attach it to layer 8

make top thumb key only layer 8 and move middle click to another slot

add mouse keys and L8 toggle to L8

adjust the speed of the trackball down

adjust the speed of the trackball down

adjust the speed of the trackball down

added layer 1 back into the scroll layers

change all right meta buttons to left meta

update symbols layer

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh and add back in build conditions

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

combine the build jobs for qwerty and colemak dh

adjusted the path to the keymap files

added the board and shield to the matrix variables

added the board and shield to the matrix variables

combine the build jobs for qwerty and colemak dh

add board back into the matrix

add board back into the matrix

add board back into the matrix

add board back into the matrix

add board back into the matrix

add colemak hd and qwerty to the same build

add colemak hd and qwerty to the same build

add colemak hd and qwerty to the same build

add colemak hd and qwerty to the same build

add colemak hd and qwerty to the same build

add colemak hd and qwerty to the same build

add colemak hd and qwerty to the same build

add colemak hd and qwerty to the same build

add colemak hd and qwerty to the same build

try just two boards

try just default keymap

change build.yaml

change build.yaml

change build.yaml

change build.yaml

change build.yaml

change build.yaml

change build.yaml

change build.yaml

change build.yaml

change build.yaml

separate the artifacts by layout

separate the artifacts by layout

separate the artifacts by layout

working with separate artifacts

* create a scrpit to generate qwerty keymaps

* added formatting to the output

* removed extra job in build.yaml

* move the path selection out of the script and into the pipeline

* move the path selection back into the script

* move the path selection back into the script

* move the path selection back into the script

* move the path selection back into the script

* modified path configuration

* moved code to the build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* updated build.yml

* moved code to the build.yml

* moved code to the build.yml

* moved code to the build.yml

* moved code to the build.yml

* moved code to the build.yml

* moved code to the build.yml

* moved code to the build.yml

* moved code to the build.yml

* moved code to the build.yml

* moved code to the build.yml

* moved code to the build.yml

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* remove extra artifacts after merge

* remove extra artifacts after merge
  • Loading branch information
280Zo authored Aug 4, 2024
1 parent 9db608f commit 7e396d1
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 1 deletion.
25 changes: 24 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
on: [push, pull_request, workflow_dispatch]

jobs:
create-qwerty-keymap:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# Add any dependencies here
- name: Generate QWERTY keymap
run: |
python scripts/generate_qwerty.py
- uses: actions/upload-artifact@master
with:
name: charybdis_qwerty.keymap
path: "${{ github.workspace }}/charybdis_qwerty.keymap"

build:
uses: zmkfirmware/zmk/.github/workflows/build-user-config.yml@main
needs: create-qwerty-keymap
uses: ./.github/workflows/user_config_build.yaml
# uses: zmkfirmware/zmk/.github/workflows/build-user-config.yml@main
208 changes: 208 additions & 0 deletions .github/workflows/user_config_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
name: Reusable user config build

on:
workflow_call:
inputs:
build_matrix_path:
description: "Path to the build matrix file"
default: "build.yaml"
required: false
type: string
config_path:
description: "Path to the config directory"
default: "config"
required: false
type: string
keymap_path:
description: "Path to the keymap directory"
default: "config/boards/shields/charybdis-mini-wireless/keymaps"
required: false
type: string
fallback_binary:
description: "Fallback binary format, if no *.uf2 file was built"
default: "bin"
required: false
type: string

jobs:
matrix:
runs-on: ubuntu-latest
name: Fetch Build Keyboards
outputs:
build_matrix: ${{ env.build_matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install yaml2json
run: python3 -m pip install remarshal

- name: Fetch Build Matrix
run: |
echo "build_matrix=$(yaml2json '${{ inputs.build_matrix_path }}' | jq -c .)" >> $GITHUB_ENV
yaml2json "${{ inputs.build_matrix_path }}" | jq
build:
runs-on: ubuntu-latest
container:
image: zmkfirmware/zmk-build-arm:stable
needs: matrix
name: Build
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.build_matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create build directory
run: |
echo "build_dir=$(mktemp -d)" >> $GITHUB_ENV
- name: Prepare variables
shell: sh -x {0}
env:
board: ${{ matrix.board }}
shield: ${{ matrix.shield }}
keymap: ${{ matrix.keymap }}
artifact_name: ${{ matrix.artifact-name }}
snippet: ${{ matrix.snippet }}
run: |
if [ -e zephyr/module.yml ]; then
export zmk_load_arg=" -DZMK_EXTRA_MODULES='${GITHUB_WORKSPACE}'"
new_tmp_dir="${TMPDIR:-/tmp}/zmk-config"
mkdir -p "${new_tmp_dir}"
echo "base_dir=${new_tmp_dir}" >> $GITHUB_ENV
else
echo "base_dir=${GITHUB_WORKSPACE}" >> $GITHUB_ENV
fi
if [ -n "${snippet}" ]; then
extra_west_args="-S \"${snippet}\""
fi
echo "zephyr_version=${ZEPHYR_VERSION}" >> $GITHUB_ENV
echo "extra_west_args=${extra_west_args}" >> $GITHUB_ENV
echo "extra_cmake_args=${shield:+-DSHIELD=\"$shield\"}${zmk_load_arg}" >> $GITHUB_ENV
echo "display_name=${shield:+$shield - }${board} - ${keymap}" >> $GITHUB_ENV
echo "artifact_name=${artifact_name:-${shield:+$shield-}${board}-zmk-${keymap}}" >> $GITHUB_ENV
- name: Copy qwerty keymap to keymap directory
uses: actions/download-artifact@master
with:
name: charybdis_qwerty.keymap
path: ${{ inputs.keymap_path }}

- name: Copy config files to isolated temporary directory
run: |
if [ "${{ env.base_dir }}" != "${GITHUB_WORKSPACE}" ]; then
mkdir "${{ env.base_dir }}/${{ inputs.config_path }}"
cp -R ${{ inputs.config_path }}/* "${{ env.base_dir }}/${{ inputs.config_path }}/"
cp -R "${{ env.base_dir }}/${{ inputs.keymap_path }}/${{ matrix.keymap }}.keymap" \
"${{ env.base_dir }}/${{ inputs.config_path }}/boards/shields/charybdis-mini-wireless/charybdis.keymap"
fi
echo "Build files list:"
ls -R "${{ env.base_dir }}"
- name: Cache west modules
uses: actions/cache@v4
continue-on-error: true
env:
cache_name: cache-zephyr-${{ env.zephyr_version }}-modules
with:
path: |
${{ env.base_dir }}/modules/
${{ env.base_dir }}/tools/
${{ env.base_dir }}/zephyr/
${{ env.base_dir }}/bootloader/
${{ env.base_dir }}/zmk/
key: ${{ runner.os }}-build-${{ env.cache_name }}-${{ hashFiles('**/west.yml', '**/build.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache_name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: West Init
working-directory: ${{ env.base_dir }}
run: west init -l "${{ env.base_dir }}/${{ inputs.config_path }}"

- name: West Update
working-directory: ${{ env.base_dir }}
run: west update

- name: West Zephyr export
working-directory: ${{ env.base_dir }}
run: west zephyr-export

- name: West Build (${{ env.display_name }})
working-directory: ${{ env.base_dir }}
shell: sh -x {0}
run: west build -s zmk/app -d "${{ env.build_dir }}" -b "${{ matrix.board }}" ${{ env.extra_west_args }} -- -DZMK_CONFIG=${{ env.base_dir }}/${{ inputs.config_path }} ${{ env.extra_cmake_args }} ${{ matrix.cmake-args }}

- name: ${{ env.display_name }} Kconfig file
run: |
if [ -f "${{ env.build_dir }}/zephyr/.config" ]
then
grep -v -e "^#" -e "^$" "${{ env.build_dir }}/zephyr/.config" | sort
else
echo "No Kconfig output"
fi
if: ${{ !cancelled() }}

- name: ${{ env.display_name }} Devicetree file
run: |
if [ -f "${{ env.build_dir }}/zephyr/zephyr.dts" ]
then
cat "${{ env.build_dir }}/zephyr/zephyr.dts"
elif [ -f "${{ env.build_dir }}/zephyr/zephyr.dts.pre" ]
then
cat -s "${{ env.build_dir }}/zephyr/zephyr.dts.pre"
else
echo "No Devicetree output"
fi
if: ${{ !cancelled() }}

- name: Rename artifacts
shell: sh -x {0}
run: |
mkdir "${{ env.build_dir }}/artifacts"
if [ -f "${{ env.build_dir }}/zephyr/zmk.uf2" ]
then
cp "${{ env.build_dir }}/zephyr/zmk.uf2" "${{ env.build_dir }}/artifacts/${{ env.artifact_name }}.uf2"
elif [ -f "${{ env.build_dir }}/zephyr/zmk.${{ inputs.fallback_binary }}" ]
then
cp "${{ env.build_dir }}/zephyr/zmk.${{ inputs.fallback_binary }}" "${{ env.build_dir }}/artifacts/${{ env.artifact_name }}.${{ inputs.fallback_binary }}"
fi
- name: Archive (${{ env.display_name }})
uses: actions/upload-artifact@v4
with:
name: artifact-${{ env.artifact_name }}
path: ${{ env.build_dir }}/artifacts

merge:
runs-on: ubuntu-latest
needs: build
name: Merge Output Artifacts
steps:
- name: Merge QWERTY Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: "qwerty-firmware"
pattern: artifact-charybdis_QWERTY*
delete-merged: true
- name: Merge Colemak DH Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: "colemak-dh-firmware"
pattern: artifact-charybdis_colemak*
delete-merged: true
cleanup:
runs-on: ubuntu-latest
needs: merge
name: Delete unneeded artifacts
steps:
- uses: geekyeggo/delete-artifact@v5
with:
name: charybdis_qwerty.keymap
failOnError: false
12 changes: 12 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,17 @@
include:
- board: nice_nano_v2
shield: charybdis_left
keymap: charybdis_colemak_dh
artifact-name: charybdis_colemak_left
- board: nice_nano_v2
shield: charybdis_right
keymap: charybdis_colemak_dh
artifact-name: charybdis_colemak_right
- board: nice_nano_v2
shield: charybdis_left
keymap: charybdis_qwerty
artifact-name: charybdis_QWERTY_left
- board: nice_nano_v2
shield: charybdis_right
keymap: charybdis_qwerty
artifact-name: charybdis_QWERTY_right
File renamed without changes.
116 changes: 116 additions & 0 deletions scripts/generate_qwerty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import re
import os

# Define the file paths
colemak_file = 'charybdis_colemak_dh.keymap'
qwerty_file = 'charybdis_qwerty.keymap'

# Define the Colemak DH to QWERTY mapping
colemak_to_qwerty = {
# Top row (numbers and symbols are not included in this example)
'Q': 'Q', 'W': 'W', 'F': 'E', 'P': 'R', 'B': 'T', 'J': 'Y', 'L': 'U', 'U': 'I', 'Y': 'O', 'APOS': 'P',
# Home row
'A': 'A', 'R': 'S', 'S': 'D', 'D': 'F', 'G': 'G', 'M': 'H', 'N': 'J', 'E': 'K', 'I': 'L', 'O': 'SEMICOLON',
# Bottom row
'Z': 'Z', 'X': 'X', 'C': 'C', 'V': 'V', 'K': 'B', 'H': 'N',
# Special keys (not row-specific)
'TAB': 'TAB', 'DEL': 'DEL', 'BACKSPACE': 'BACKSPACE', 'ESCAPE': 'ESCAPE', 'RETURN': 'RETURN', 'SPACE': 'SPACE'
}

def format_columns(text):
zmk_behavior = r'(&\w{2})'

# Split the input text into lines
lines = text.strip().split('\n')

# Split each line into columns
split_lines = [re.split(zmk_behavior,line) for line in lines]

# Determine the number of columns
num_columns = max(len(line) for line in split_lines)

# Calculate the maximum width for each column
column_widths = [0] * num_columns
for line in split_lines:
for i, item in enumerate(line):
column_widths[i] = max(column_widths[i], len(item))

# Format each line with the calculated column widths
formatted_lines = []
for line in split_lines:
formatted_line = ''.join(f"{item:<{column_widths[i] + 1}}" for i, item in enumerate(line))
formatted_lines.append(formatted_line)

# Join all formatted lines
formatted_text = '\n'.join(formatted_lines)
return formatted_text

# Read the content of the input file
gh_workspace = os.getenv('GITHUB_WORKSPACE')
relative_path = 'config/boards/shields/charybdis-mini-wireless/keymaps'
absolute_path = os.path.join(gh_workspace, relative_path)
os.chdir(absolute_path)
with open(colemak_file, 'r') as file:
content = file.read()

# Find and replace the 'Base' keymap layout
def convert_colemak_to_qwerty(keymap_content):
# Define regex pattern to find the 'Base' keymap section
base_keymap_pattern = re.compile(r'(Base\s*\{\s*bindings\s*=\s*<\s*)(.*?)(\s*>;)', re.DOTALL)

def replace_keymap(match):
before_keymap = match.group(1)
old_keymap = match.group(2)
after_keymap = match.group(3)

print(f"Found Base keymap \n{old_keymap}")

# Split the old keymap by lines
lines = old_keymap.strip().split('\n')

# Process each line
new_lines = []
print("Processing keys")
for line in lines:
# Split the line by spaces or other delimiters
parts = line.split()
new_parts = []

for part in parts:
if not part.startswith('&'):
# Extract key (removing ZMK behavior commands)
key = part.split()[1] if len(part.split()) > 1 else part
# Map the key to QWERTY if applicable
if key.upper() in colemak_to_qwerty:
print(key.upper(),end=":")
new_key = colemak_to_qwerty[key]
print(new_key)
new_parts.append(part.replace(key, new_key))
else:
new_parts.append(part)
else:
new_parts.append(part)

# Join new parts for the line and add to new_lines
new_lines.append(' '.join(new_parts))

# Join new lines to form the new keymap content
new_keymap = '\n'.join(new_lines)
print("")
print(f"Generated QWERTY map \n{format_columns(new_keymap)}")
return before_keymap + format_columns(new_keymap) + after_keymap

# Apply regex substitution to convert keymap
new_content = base_keymap_pattern.sub(replace_keymap, keymap_content)

return new_content

# Replace the 'Base' keymap with the QWERTY layout
qwerty_map = convert_colemak_to_qwerty(content)

# Write the new content to the output file
os.chdir(os.getenv('GITHUB_WORKSPACE'))
with open(qwerty_file, 'w') as file:
file.write(qwerty_map)

print(f"\nUpdated keymap written to {os.getcwd()+'/'+qwerty_file}")

0 comments on commit 7e396d1

Please sign in to comment.