-
-
Notifications
You must be signed in to change notification settings - Fork 39.6k
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
[CLI] Add c2json #8817
[CLI] Add c2json #8817
Conversation
CLI CI fails because |
fffa2c4
to
83c2e39
Compare
This feature would be a huge benefit to me -- I'm fairly new to QMK and I have trouble keeping my layouts straight in my head, especially when I'm making small changes. @Erovia is there any specific task I could help out with here? I'm not super-familiar with travis / docker but if you have any more insight on what's failing I am happy to dive in as deep as I can. |
Thank you for your interest! I'll need to rebase and fix the conflicts. Also, I think this feature could benefit greatly from this PR, but I think I'd rather see this merged as is and improve it iteratively. Ultimately, this just needs testing. (and the rebasing I mentioned) |
Thanks for the fast follow-up -- I definitely understand the priority. I'll try using this branch locally with my own keymap work, to see what results I get. |
That would be great. |
4064a26
to
1b44d5a
Compare
@fastjames Rebased and fixed up the code. If you have some time to try it out, I'd appreciate the feedback. |
Thanks very much for freshening this up. I had a few minutes today so here's the test procedure I followed:
Off the bat, I got a generic alert stating
I think I hit success after that! I can see the keymap in the configurator, and the layers appear to match what I recall setting up. I hope this testing information helps, and I'm happy to take a shot at making the changes if you're busy. |
I tried c2json for my keymap for ARM target . |
Mentions #6877 here for visibility. Thank you @Erovia for creating this pull request. This is what I long for in qmk command. @skullydazed can we help anything to move this PR forward? |
Rebased and fixed the missing @elfmimi: For the time being, I'd rather not complicate the parsing with edge-cases like the missing PROGMEM. In the future me or someone else might get back to it. Sorry for the ping, but thought you guys might like to know that I'm still working on this :) |
@Erovia Thank you so much for your work, I used this to build a list of all keymaps (https://github.com/qmk-helper/qmk-database) which is used for a keyboard/keymap browser. Because of this I am hoping this PR gets merged soon so I can automate the generation of JSONs. Another issue besides the keymap field are layer modifiers with integers as identifier else:
if is_adv_kc:
layer['keycodes'][-1] += line[1]
elif line[0] is Token.Literal.Number.Integer and is_keymap:
if not layer['name']:
layer['name'] = line[1] One example keymap with this issue is thevankeyboards/minivan:default keymap.c (simplified):#define _QW 0
#define _L1 3
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_QW] = LAYOUT(
MO(_L1)
)
} keymap.c preprocessed:const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
MO(3)
)
} keymap.json, no-cpp, correct{"layers": [["MO(_L1)"]]} keymap.json, with cpp, actual result{"layers": [["MO()"]]} keymap.json, with cpp, expected result{"layers": [["MO(3)"]]} |
Buckwich noticed that if the advanced keycode / layer toggling key contains a number, it goes missing. Now we properly handle them. Thx for noticing!
Looks good to me, only the position of the keymap name moved in the json (to the correct position). Numbers are working. Thank you for the quick fix. |
woohoo!! Thank you @Erovia, @Buckwich and @skullydazed for merging this into master! |
* 'master' of https://github.com/qmk/qmk_firmware: (178 commits) Docs: fix udev rules [CLI] Add c2json (qmk#8817) Improve LAYOUT macro searching (qmk#9530) CLI: update subcommands to use return instead of exit() (qmk#10323) Fixes small typo in docs (qmk#10515) Update personal keymap for Let's Split keyboard. (qmk#10536) [Keymap] Move my custom functions and keymaps to userspace (qmk#10502) [Keyboard] add support for ymd75 rev3 (qmk#10483) [Keyboard] Add soy20 PCB (qmk#10440) Fix for MIDI sustain effect issue (qmk#10361) format code according to conventions [skip ci] [Keyboard] Add Yugo-M Controller (qmk#10389) [Keymap] Add onekey keymap for OLED testing (qmk#10380) [Keymap] Add winterNebs keymaps (qmk#10328) [Keymap] Added 333fred 5x6_5 keymap (qmk#10272) [Keyboard] Add hannah60rgb rev.2 PCB (qmk#10287) Adding VIA support to katana60 rev2 (qmk#10442) OLED driver fixes (qmk#10377) IS31FL3741 driver fixup (qmk#10519) add info.json for XD75 keyboard (qmk#10523) ...
* upstream/master: (81 commits) [Keyboard] New keyboard - eiri (qmk#10529) [Keymap] Add niu mini dye sub keymap (qmk#10525) Clean ChibiOS platform files (qmk#10505) [Keyboard] LeftyNumpad Keyboard (qmk#10500) [Keyboard] add maja capslock indicator (qmk#10151) Fix issue introduced by PR#10404 (qmk#10559) Docs: fix udev rules [CLI] Add c2json (qmk#8817) Improve LAYOUT macro searching (qmk#9530) CLI: update subcommands to use return instead of exit() (qmk#10323) Fixes small typo in docs (qmk#10515) Update personal keymap for Let's Split keyboard. (qmk#10536) [Keymap] Move my custom functions and keymaps to userspace (qmk#10502) [Keyboard] add support for ymd75 rev3 (qmk#10483) [Keyboard] Add soy20 PCB (qmk#10440) Fix for MIDI sustain effect issue (qmk#10361) format code according to conventions [skip ci] [Keyboard] Add Yugo-M Controller (qmk#10389) [Keymap] Add onekey keymap for OLED testing (qmk#10380) [Keymap] Add winterNebs keymaps (qmk#10328) ...
* Basic keymap parsing finally works * Add 'keymap.json' creation to the qmk.keymap module * Add tests and fix formatting * Fix/exclude flake8 errors * Convert keymap.c to valid keymap.json * Fix some errors * Add tests * Finalize keymap.json creation, add json template * Add docs * Move pygments to the standard requirements * Add support for nameless layers, fix tests * Fix things after rebase * Add missing 'keymap' value. * Fix missing layer numbers from advanced keycodes Buckwich noticed that if the advanced keycode / layer toggling key contains a number, it goes missing. Now we properly handle them. Thx for noticing! * Apply suggestions from code review * fixup tests Co-authored-by: Zach White <skullydazed@drpepper.org> Co-authored-by: skullY <skullydazed@gmail.com>
* Basic keymap parsing finally works * Add 'keymap.json' creation to the qmk.keymap module * Add tests and fix formatting * Fix/exclude flake8 errors * Convert keymap.c to valid keymap.json * Fix some errors * Add tests * Finalize keymap.json creation, add json template * Add docs * Move pygments to the standard requirements * Add support for nameless layers, fix tests * Fix things after rebase * Add missing 'keymap' value. * Fix missing layer numbers from advanced keycodes Buckwich noticed that if the advanced keycode / layer toggling key contains a number, it goes missing. Now we properly handle them. Thx for noticing! * Apply suggestions from code review * fixup tests Co-authored-by: Zach White <skullydazed@drpepper.org> Co-authored-by: skullY <skullydazed@gmail.com>
* Basic keymap parsing finally works * Add 'keymap.json' creation to the qmk.keymap module * Add tests and fix formatting * Fix/exclude flake8 errors * Convert keymap.c to valid keymap.json * Fix some errors * Add tests * Finalize keymap.json creation, add json template * Add docs * Move pygments to the standard requirements * Add support for nameless layers, fix tests * Fix things after rebase * Add missing 'keymap' value. * Fix missing layer numbers from advanced keycodes Buckwich noticed that if the advanced keycode / layer toggling key contains a number, it goes missing. Now we properly handle them. Thx for noticing! * Apply suggestions from code review * fixup tests Co-authored-by: Zach White <skullydazed@drpepper.org> Co-authored-by: skullY <skullydazed@gmail.com>
* Basic keymap parsing finally works * Add 'keymap.json' creation to the qmk.keymap module * Add tests and fix formatting * Fix/exclude flake8 errors * Convert keymap.c to valid keymap.json * Fix some errors * Add tests * Finalize keymap.json creation, add json template * Add docs * Move pygments to the standard requirements * Add support for nameless layers, fix tests * Fix things after rebase * Add missing 'keymap' value. * Fix missing layer numbers from advanced keycodes Buckwich noticed that if the advanced keycode / layer toggling key contains a number, it goes missing. Now we properly handle them. Thx for noticing! * Apply suggestions from code review * fixup tests Co-authored-by: Zach White <skullydazed@drpepper.org> Co-authored-by: skullY <skullydazed@gmail.com>
* Basic keymap parsing finally works * Add 'keymap.json' creation to the qmk.keymap module * Add tests and fix formatting * Fix/exclude flake8 errors * Convert keymap.c to valid keymap.json * Fix some errors * Add tests * Finalize keymap.json creation, add json template * Add docs * Move pygments to the standard requirements * Add support for nameless layers, fix tests * Fix things after rebase * Add missing 'keymap' value. * Fix missing layer numbers from advanced keycodes Buckwich noticed that if the advanced keycode / layer toggling key contains a number, it goes missing. Now we properly handle them. Thx for noticing! * Apply suggestions from code review * fixup tests Co-authored-by: Zach White <skullydazed@drpepper.org> Co-authored-by: skullY <skullydazed@gmail.com>
Description
First of all, I'd like to thank both @lf- for starting to work on this feature in #7218 and @skullydazed for suggesting a Pygments-based approach.
This submodules attemps to parse a
keymap.c
file and generate akeymap.json
for the user.Sadly this is not as easy as the other way around, so parsing is limited. Sorry drashna. :)
Types of Changes
This PR intends to supersede both
Checklist