keychron_qmk_firmware/keyboards/ferris/keymaps/json2crab.py
Pierre Chevalier 704934c427
Ferris reorganization (#10564)
* Add my own keymap

* Layer 0: Workman
* Layer 1: RSTHD (my own take on it)
* Layer 2: Mouse
* Layer 3: Navigation
* Layer 4: Symbols right
* Layer 5: Symbols left
* Layer 6: Fn keys
* Layer 7: Numbers
* Layer 8: Vim and misceallaneaous accessible from any other layer

* Move the current code to a 0.1 folder in preparation for upcoming changes

Version 0.2 is currently being prototyped and uses an arm chip which
will need its own firmware.

There is also the Ferris sweep which uses a pro-micro compatible board
which will need its own directory.

* Move Ferris out of handwired and into the light

The keyboard is now well out of the prototype phase as tens of them have
been produced and acquired by various people.

With 0.2 coming out, adoption is going to increase again as the board
will be available for sale at some recognized vendors.

Now is probably a good time to recognize its status as more than a
prototype :)

* Add code for the Ferris Sweep (a.k.a cradio)

The Ferris Sweep is a creation of the talented @davidphilipbarr, a.k.a DPB.
It has the key layout of a Ferris and uses a pro-micro connected to the
switches via direct pins so that diodes are not needed and the soldering
is minimal.

With their blessing, I took the code for it from DPB's own repo:
https://github.com/davidphilipbarr/36keys/tree/master/qmk/cradio
and did some adaptations such as removing commented out code, enabling
EE_HANDS and mouse keys for consistency with my existing Ferris code.

* Fix indentation in rules.mk

* Fix indentation in sweep's config

* Remove unnecessary lines from sweep's rules.mk

* Remove unnecessary lines from sweep's rules.mk

* Rename 0.1 to 0_1

This avoids the dot looking like the separation between a filename and
its extension.

In the same commit, bring matrix.c to the 0_1 folder as this was needed
for the code to compile properly (matrix.c is referred to in the readme
under `0_1` and is specific to that revision of the firmware).

* Update copyright statements for Sweep
2020-10-17 12:20:34 -07:00

77 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import sys
import json
indent_level=4
def parse_cli():
parser = argparse.ArgumentParser(description='Ferris keymap formatter')
parser.add_argument("--input", type=argparse.FileType('r'),
default=sys.stdin, help="Input keymap (json file produced by qmk configurator)")
return parser.parse_args()
def col_index(key_index):
if key_index < 30:
col = key_index % 5
else:
col = key_index % 2
return col
def format_layers(layers):
formatted = indent_level * " " + "\"layers\": [\n"
max_key_length = {}
for layer in layers:
for (index, keycode) in enumerate(layer):
col = col_index(index)
max_length = max_key_length.get(col)
if (not max_length) or len(keycode) > max_length:
max_key_length.update({col: len(keycode)})
for (layer_index, layer) in enumerate(layers):
formatted += 2 * indent_level * " "
formatted += "["
for (index, keycode) in enumerate(layer):
if index > 30 and index % 2 == 0 or index % 5 == 0 and index != 0:
formatted += (1 + 2 * indent_level) * " "
formatted += json.dumps(keycode)
if index == 33:
formatted += "\n"
elif index > 30 and index % 2 == 1 or index % 5 == 4:
formatted += ",\n"
else:
n_spaces = max_key_length[col_index(index)] - len(keycode)
formatted += n_spaces * " "
formatted += ", "
if index % 10 == 9:
formatted += "\n"
formatted += 2 * indent_level * " "
if layer_index < len(layers) - 1:
formatted += "],\n"
else:
formatted += "]\n"
formatted += indent_level * " "
formatted += "]"
return formatted
def format_keymap(keymap_json):
formatted = "{"
for (index, k) in enumerate(keymap_json):
if k == "layers":
formatted += format_layers(keymap_json[k])
else:
formatted += f"{indent_level * ' '}{json.dumps(k)}: {json.dumps(keymap_json[k])}"
if index < len(keymap_json) - 1:
formatted += ","
formatted += "\n"
formatted += "}"
return formatted
def main():
args=parse_cli()
keymap_json = json.loads(args.input.read())
print(format_keymap(keymap_json))
main()