From 622f04acf1159e90ab72a5b59f6e258b1b848a8e Mon Sep 17 00:00:00 2001 From: Ben Blazak Date: Sat, 13 Oct 2012 22:54:12 -0700 Subject: [PATCH] small improvements to gen-ui-info.py --- build-scripts/gen-ui-info.py | 166 +++++++++++++++++++++++------------ 1 file changed, 112 insertions(+), 54 deletions(-) diff --git a/build-scripts/gen-ui-info.py b/build-scripts/gen-ui-info.py index 30dd2f1..2690e2c 100755 --- a/build-scripts/gen-ui-info.py +++ b/build-scripts/gen-ui-info.py @@ -1,67 +1,119 @@ #! /usr/bin/env python3 # ----------------------------------------------------------------------------- +# Copyright (c) 2012 Ben Blazak +# Released under The MIT License (MIT) (see "license.md") +# Project located at +# ----------------------------------------------------------------------------- """ -Generate UI info file (in JSON) (format version: 0) - -The file will contain: -{ - ".meta-data": { - "version": , - "date-generated": , - }, - "keyboard-functions": { - <(function name)>: { - "position": , - "length": , - "comments": { - "name": , - "description": , - "notes": [ - , - ... - ], - ... - } - }, - ... - }, - "layout-matrices": { - <(matrix name)>: { - "position": , - "length": - }, - ... - }, - "mappings": { - "physical-positions": [ - , ... - ], - "matrix-positions": [ - , ... - ], - "matrix-layout": [ - [ [ , , ], ... ], - ... - ] - }, - "miscellaneous": { - "git-commit-date": , - "git-commit-id": , - "number-of-layers": - } -} +Generate UI info file (in JSON) Depends on: - the project source code - the project '.map' file (generated by the compiler) ------------------------------------------------------------------------------ -Copyright (c) 2012 Ben Blazak -Released under The MIT License (MIT) (see "license.md") -Project located at ------------------------------------------------------------------------------ """ +_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": "", + "date-generated": "", // format: RFC 3339 + }, + "keyboard-functions": { + "<(function name)>": { + "position": "", // as given by the .map file + "length": "", // as given by the .map file + "comments": { + "name": "", // more user friendly name + "description": "", + "notes": [ + "", + "..." + ], + "..." + } + }, + "..." + }, + "layout-matrices": { + "<(matrix name)>": { + "position": "", // as given by the .map file + "length": "" // 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 + "", "..." + ], + "matrix-positions": [ // list of key-ids + "", "..." + ], + "matrix-layout": [ + [ // begin layer + [ // begin key + "", // keycode + "", // press function name (ex: 'kbfun_...') + "" // release function name (ex: 'NULL') + ], + "..." // more keys + ], + "..." // more layers + ] + }, + "miscellaneous": { + "git-commit-date": "", // format: RFC 3339 + "git-commit-id": "", + "number-of-layers": "" + } +} +""")[1:-1] + # ----------------------------------------------------------------------------- import argparse @@ -80,6 +132,7 @@ def gen_static(current_date=None, git_commit_date=None, git_commit_id=None): '.meta-data': { 'version': 0, # the format version number 'date-generated': current_date, + 'description': _FORMAT_DESCRIPTION, }, 'miscellaneous': { '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 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 { "mappings": {