small improvements to gen-ui-info.py
parent
467886299b
commit
622f04acf1
|
@ -1,67 +1,119 @@
|
||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
|
||||||
|
# Released under The MIT License (MIT) (see "license.md")
|
||||||
|
# Project located at <https://github.com/benblazak/ergodox-firmware>
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Generate UI info file (in JSON) (format version: 0)
|
Generate UI info file (in JSON)
|
||||||
|
|
||||||
The file will contain:
|
|
||||||
{
|
|
||||||
".meta-data": {
|
|
||||||
"version": <number>,
|
|
||||||
"date-generated": <string>,
|
|
||||||
},
|
|
||||||
"keyboard-functions": {
|
|
||||||
<(function name)>: {
|
|
||||||
"position": <number>,
|
|
||||||
"length": <number>,
|
|
||||||
"comments": {
|
|
||||||
"name": <string>,
|
|
||||||
"description": <string>,
|
|
||||||
"notes": [
|
|
||||||
<string>,
|
|
||||||
...
|
|
||||||
],
|
|
||||||
...
|
|
||||||
}
|
|
||||||
},
|
|
||||||
...
|
|
||||||
},
|
|
||||||
"layout-matrices": {
|
|
||||||
<(matrix name)>: {
|
|
||||||
"position": <number>,
|
|
||||||
"length": <number>
|
|
||||||
},
|
|
||||||
...
|
|
||||||
},
|
|
||||||
"mappings": {
|
|
||||||
"physical-positions": [
|
|
||||||
<string>, ...
|
|
||||||
],
|
|
||||||
"matrix-positions": [
|
|
||||||
<string>, ...
|
|
||||||
],
|
|
||||||
"matrix-layout": [
|
|
||||||
[ [ <number>, <string>, <string> ], ... ],
|
|
||||||
...
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"miscellaneous": {
|
|
||||||
"git-commit-date": <string>,
|
|
||||||
"git-commit-id": <string>,
|
|
||||||
"number-of-layers": <number>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Depends on:
|
Depends on:
|
||||||
- the project source code
|
- the project source code
|
||||||
- the project '.map' file (generated by the compiler)
|
- the project '.map' file (generated by the compiler)
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
|
|
||||||
Released under The MIT License (MIT) (see "license.md")
|
|
||||||
Project located at <https://github.com/benblazak/ergodox-firmware>
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_FORMAT_DESCRIPTION = ("""
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Version 0
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* Hopefully the add-hoc conventions are clear enough... I didn't feel like
|
||||||
|
* investing the time in making it a real JSON Schema when there aren't many
|
||||||
|
* validators, and the most current completed draft at the moment (draft 3) is
|
||||||
|
* expired...
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* Please note that in general, fields may be added without changing the
|
||||||
|
* version number, and that programs using this format are not required to fill
|
||||||
|
* (or read) any of the given fields.
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
var ui_info = {
|
||||||
|
".meta-data": { // for the JSON file
|
||||||
|
"version": "<number>",
|
||||||
|
"date-generated": "<string>", // format: RFC 3339
|
||||||
|
},
|
||||||
|
"keyboard-functions": {
|
||||||
|
"<(function name)>": {
|
||||||
|
"position": "<number>", // as given by the .map file
|
||||||
|
"length": "<number>", // as given by the .map file
|
||||||
|
"comments": {
|
||||||
|
"name": "<string>", // more user friendly name
|
||||||
|
"description": "<string>",
|
||||||
|
"notes": [
|
||||||
|
"<string>",
|
||||||
|
"..."
|
||||||
|
],
|
||||||
|
"..."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"..."
|
||||||
|
},
|
||||||
|
"layout-matrices": {
|
||||||
|
"<(matrix name)>": {
|
||||||
|
"position": "<number>", // as given by the .map file
|
||||||
|
"length": "<number>" // as given by the .map file
|
||||||
|
},
|
||||||
|
"..."
|
||||||
|
},
|
||||||
|
"mappings": {
|
||||||
|
/*
|
||||||
|
* The mappings prefixed with 'matrix' have their elements in the same
|
||||||
|
* order as the .hex file (whatever order that is). The mappings
|
||||||
|
* prefixed with 'physical' will have their elements in an order
|
||||||
|
* corresponding to thier physical position on the keyboard. You can
|
||||||
|
* convert between the two using the relative positions of the key-ids
|
||||||
|
* in 'physical-positions' and 'matrix-positions'.
|
||||||
|
*
|
||||||
|
* The current order of 'physical' mappings is:
|
||||||
|
* --------------------------------------------
|
||||||
|
* // left hand, spatial positions
|
||||||
|
* 00, 01, 02, 03, 04, 05, 06,
|
||||||
|
* 07, 08, 09, 10, 11, 12, 13,
|
||||||
|
* 14, 15, 16, 17, 18, 19,
|
||||||
|
* 20, 21, 22, 23, 24, 25, 26,
|
||||||
|
* 27, 28, 29, 30, 31,
|
||||||
|
* 32, 33,
|
||||||
|
* 34, 35, 36,
|
||||||
|
* 37, 38, 39,
|
||||||
|
|
||||||
|
* // right hand, spatial positions
|
||||||
|
* 40, 41, 42, 43, 44, 45, 46,
|
||||||
|
* 47, 48, 49, 50, 51, 52, 53,
|
||||||
|
* 54, 55, 56, 57, 58, 59,
|
||||||
|
* 60, 61, 62, 63, 64, 65, 66,
|
||||||
|
* 67, 68, 69, 70, 71,
|
||||||
|
* 72, 73,
|
||||||
|
* 74, 75, 76,
|
||||||
|
* 77, 78, 79,
|
||||||
|
* --------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
"physical-positions": [ // list of key-ids
|
||||||
|
"<string>", "..."
|
||||||
|
],
|
||||||
|
"matrix-positions": [ // list of key-ids
|
||||||
|
"<string>", "..."
|
||||||
|
],
|
||||||
|
"matrix-layout": [
|
||||||
|
[ // begin layer
|
||||||
|
[ // begin key
|
||||||
|
"<number>", // keycode
|
||||||
|
"<string>", // press function name (ex: 'kbfun_...')
|
||||||
|
"<string>" // release function name (ex: 'NULL')
|
||||||
|
],
|
||||||
|
"..." // more keys
|
||||||
|
],
|
||||||
|
"..." // more layers
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"miscellaneous": {
|
||||||
|
"git-commit-date": "<string>", // format: RFC 3339
|
||||||
|
"git-commit-id": "<string>",
|
||||||
|
"number-of-layers": "<number>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""")[1:-1]
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -80,6 +132,7 @@ def gen_static(current_date=None, git_commit_date=None, git_commit_id=None):
|
||||||
'.meta-data': {
|
'.meta-data': {
|
||||||
'version': 0, # the format version number
|
'version': 0, # the format version number
|
||||||
'date-generated': current_date,
|
'date-generated': current_date,
|
||||||
|
'description': _FORMAT_DESCRIPTION,
|
||||||
},
|
},
|
||||||
'miscellaneous': {
|
'miscellaneous': {
|
||||||
'git-commit-date': git_commit_date, # should be passed by makefile
|
'git-commit-date': git_commit_date, # should be passed by makefile
|
||||||
|
@ -318,6 +371,11 @@ def gen_mappings(matrix_file_path, layout_file_path):
|
||||||
# make the numbers into actual numbers
|
# make the numbers into actual numbers
|
||||||
layout['_kb_layout'] = \
|
layout['_kb_layout'] = \
|
||||||
[[eval(el) for el in layer] for layer in layout['_kb_layout']]
|
[[eval(el) for el in layer] for layer in layout['_kb_layout']]
|
||||||
|
# remove the preceeding '&' from function pointers
|
||||||
|
for matrix in ('_kb_layout_press', '_kb_layout_release'):
|
||||||
|
layout[matrix] = \
|
||||||
|
[ [re.sub(r'&', '', el) for el in layer]
|
||||||
|
for layer in layout[matrix] ]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"mappings": {
|
"mappings": {
|
||||||
|
|
Loading…
Reference in New Issue