Author Topic: My Ergodox Layout  (Read 23801 times)

0 Members and 1 Guest are viewing this topic.

Offline frew

  • Thread Starter
  • Posts: 39
  • Location: dallas
    • blog
My Ergodox Layout
« on: Thu, 27 June 2013, 08:05:32 »
Hey all,

I have a somewhat different layout on my ergodox that I think might be worth sharing.  It has some multikey macro's so I can't exactly link to it in the web configurator.  It's basically qwerty (moreso than the standard layout because moving = and esc were killing me): https://www.massdrop.com/ext/ergodox/?referer=4Y5A3K&hash=5671abb74b38c8a43323c46902b064f7.  If any of you are vi users you'll notice that hjkl map to arrow keys in the second layer.  I'm also going to map w/b to ctrl right/ctrl left respectively, and y/p to ctrl-c/ctrl-v.  The other thing I have done, which as I say isn't represented in that link, is add multikey macros on the very bottom row of the left hand.  Right hand still unassigned.  I program in perl so that's why I chose these specific key macros.  The keys are as follows, from left to right:

  • Pause (for pausing music)
  • ->
  • ::
  • =>

I had to compile my own version of the firmware but that was actually not hard at all.  For those interested, here is the code for my layout: https://github.com/frioux/ergodox-firmware/blob/frew/firmware/keyboard/ergodox/layout/qwerty-kinesis-mod.c

Here is the commit that added the => key: https://github.com/frioux/ergodox-firmware/commit/ec29390c880c9bb2af17d9cc1ecbd9276f612dbf  As you can hopefully see, it's REALLY easy to add macros like this with the new codebase.

To compile your own firmware like this (in ubuntu) just check out the code (git clone git://github.com/benblazak/ergodox-firmware; cd ergodox-firmware; git checkout partial-rewrite) install the deps needed to compile (sudo apt-get install gcc-avr binutils-avr avr-libc) and then build your firmware! (cd firmware; make)

Hope this helps someone else!  I'm interested if others have interesting ideas in this same area...

Offline frew

  • Thread Starter
  • Posts: 39
  • Location: dallas
    • blog
Re: My Ergodox Layout
« Reply #1 on: Thu, 27 June 2013, 08:52:00 »
I went ahead and added the copy/paste/word/bword keys too, so that code is in the repo now as well.

Offline flc

  • Posts: 24
Re: My Ergodox Layout
« Reply #2 on: Thu, 27 June 2013, 08:53:06 »
After seeing your work it seems that even thought the web configurator does not support characters such as áàéèíìóòúù, they can be added in code. Is this correct?

Offline frew

  • Thread Starter
  • Posts: 39
  • Location: dallas
    • blog
Re: My Ergodox Layout
« Reply #3 on: Thu, 27 June 2013, 09:03:55 »
Actually no.  Keyboards are stupid and only certain keycodes can be sent.  If you could send those keys by typing, say Alt+1234 then yes, but not by just typing ú into one of those little strings.  Though it wouldn't be too hard to make a macro I think that would be unicode aware...

Offline flc

  • Posts: 24
Re: My Ergodox Layout
« Reply #4 on: Thu, 27 June 2013, 09:49:03 »
If you don't mind, could you help me with an example or just point me in the right direction?

I noticed the following lines in your code...
void P(m_sep)(void) { KF(type_string)( PSTR("::") ); }
void R(m_sep)(void) {}

What changes would I have to make to replace your current "::" with ALT+0225 key combination?

Offline frew

  • Thread Starter
  • Posts: 39
  • Location: dallas
    • blog
Re: My Ergodox Layout
« Reply #5 on: Thu, 27 June 2013, 10:18:50 »
Sure!  So with special keys like alt and ctrl you can't use PSTR.  Here's a commit that does something like what you want: https://github.com/frioux/ergodox-firmware/commit/90139f96d66e6808c147b21f3dd34aaa7ff261d9#firmware/keyboard/ergodox/layout/qwerty-kinesis-mod.c

So Alt + 0225 is really Alt+0 Alt + 2 Alt + 2 Alt + 5, which expands to this (I think):
(note that constants used for keys are in firmware/lib/usb/usage-page/keyboard.h)

void keys__press__m_u0225(void) {
    usb__kb__set_key(true, KEYBOARD__LeftAlt)   

    usb__kb__set_key(true, KEYBOARD__0_RightParenthesis);
    usb__kb__send_report();
    usb__kb__set_key(false, KEYBOARD__0_RightParenthesis);

    usb__kb__set_key(true, KEYBOARD__2_At);
    usb__kb__send_report();
    usb__kb__set_key(false, KEYBOARD__2_At);

    usb__kb__set_key(true, KEYBOARD__2_At);
    usb__kb__send_report();
    usb__kb__set_key(false, KEYBOARD__2_At);

    usb__kb__set_key(true, KEYBOARD__5_Percent);
    usb__kb__send_report();
    usb__kb__set_key(false, KEYBOARD__5_Percent);

    usb__kb__set_key(false, KEYBOARD__LeftAlt);
}
void R(m_u0225)(void) {}


Then in the layout you'd put m_u0225.  Let me know if this works, I'm interested.

Offline frew

  • Thread Starter
  • Posts: 39
  • Location: dallas
    • blog
Re: My Ergodox Layout
« Reply #6 on: Thu, 27 June 2013, 10:33:38 »
Oh and I'm not totally sure but I think I recall back in the day when I used windows that it had to be the keypad numbers, so if that's the case you'd have to change these from KEYBOARD__0_RightParenthesis to KEYPAD__0_Insert, and I guess you may need to make sure the Numlock flag is set if you need to use the keypad.  I'll rewrite the function if you do end up needing to use the keypad numbers

Offline flc

  • Posts: 24
Re: My Ergodox Layout
« Reply #7 on: Thu, 27 June 2013, 10:49:01 »
Thank you so much. Unfortunately, I can't try it as I don't currently have the ErgoDox. But one of the questions I had before getting in on this group buy was the ability to program it for those special characters - and it is looking more and more like its possible. I also love the idea of being able to map any string to a key.

BTW, I just checked and one does have to use the numbers on the keypad.

Offline daerid

  • Posts: 4276
  • Location: Denver, CO
    • Rossipedia
Re: My Ergodox Layout
« Reply #8 on: Thu, 27 June 2013, 12:31:52 »
@frew: Yes, that's correct. Using the top row of numbers won't work when keying in unicode characters, it has to be the numpad.

Offline ic07

  • Posts: 190
Re: My Ergodox Layout
« Reply #9 on: Thu, 27 June 2013, 14:54:27 »
Really?  Grr... using the top row of numbers works in OS X.  I'll have to try messing with that function a little more next time I'm in that part of the code.

About writing special characters directly, it is possible using the function frew described originally :-) .  `key_functions__type_string( PSTR( ... ) )` should be able to handle most any null-terminated UTF-8 string, including those containing multi-byte characters, as long as each character fits inside a `uint16_t`.  Please keep in mind though that these macros will behave a little weirdly if you happen to be holding down any of the keys they need to press when they are activated, and that they will not auto-repeat like normal keys (even if the macro represents a single character, like "á", which may be something better done on the OS side if that is of concern).

For windows users, you may want to look at this function in your fork, and try changing the three `KEYBOARD__...`macros to `KEYPAD__...` ones.  That may also be a good place to make sure "numlock" is activated...  If you like, you can try replacing the function with this (untested! sorry):

Code: [Select]
void key_functions__type_byte_hex(uint8_t byte) {
    uint8_t c[2] = { byte >> 4, byte & 0xF };

    bool numlock_on = usb__kb__read_led('N');

    if (! numlock_on ) {
        usb__kb__set_key(true, KEYPAD__NumLock_Clear);
        usb__kb__send_report();
        usb__kb__set_key(false, KEYPAD__NumLock_Clear);
    }

    for (uint8_t i=0; i<2; i++) {
        if      (c[i] == 0) c[i]  = KEYPAD__0_Insert;
        else if (c[i] < 10) c[i] += KEYPAD__1_End-1;
        else                c[i] += KEYBOARD__a_A-10;

        usb__kb__set_key(true, c[i]);
        usb__kb__send_report();
        usb__kb__set_key(false, c[i]);
    }

    if (! numlock_on ) {
        usb__kb__set_key(true, KEYPAD__NumLock_Clear);
        usb__kb__send_report();
        usb__kb__set_key(false, KEYPAD__NumLock_Clear);
    }

    usb__kb__send_report();
}

Offline sordna

  • Posts: 2248
Re: My Ergodox Layout
« Reply #10 on: Fri, 26 July 2013, 22:36:08 »
Will the new partial-rewrite firmware support layouts generated by the massdrop generator ?
Kinesis Contoured Advantage & Advantage2 LF with Cherry MX Red switches / Extra keys mod / O-ring dampening mod / Dvorak layout. ErgoDox with buzzer and LED mod.
Also: Kinesis Advantage Classic, Kinesis Advantage2, Data911 TG3, Fingerworks Touchstream LP, IBM SSK (Buckling spring), Goldtouch GTU-0077 keyboard

Offline jeffgran

  • Posts: 126
  • Location: Denver
Re: My Ergodox Layout
« Reply #11 on: Sat, 27 July 2013, 13:21:01 »
@OP, this is really cool, thanks for posting this. I program mostly in Ruby, so the only multi-character symbol I can think of is the "hash rocket" => but that would be cool to have it on a single key. But baking in multiple-key macros into the firmware seems like it could be really powerful with a little creativity.

Offline tp4tissue

  • * Destiny Supporter
  • Posts: 13551
  • Location: Official Geekhack Public Defender..
  • OmniExpert of: Rice, Top-Ramen, Ergodox, n Females
Re: My Ergodox Layout
« Reply #12 on: Mon, 29 July 2013, 04:38:52 »
any chance of getting the media keys to work?

Offline frew

  • Thread Starter
  • Posts: 39
  • Location: dallas
    • blog
Re: My Ergodox Layout
« Reply #13 on: Wed, 14 August 2013, 11:07:03 »
Not yet.  All I care about is play/pause so I just used pause for that, but it should be doable, I just am not great with C.  The original author of the code (ic07) has some notes on how it might be done.

Offline ic07

  • Posts: 190
Re: My Ergodox Layout
« Reply #14 on: Wed, 14 August 2013, 19:42:15 »
Sorry, just saw this thread had new posts.  Sometimes Geekhack stops sending emails...

@sordna: No... Support really needs to be the other way around.  There probably isn't a huge reason for that though, as far as I can tell, since layouts in rev-2 are much easier to deal with in source.

@tp4tissue: You can see the top of the github read me if you like.  There are 3 media keys implemented in rev-1 (by judascleric), and NKRO and mouse keys are in a separate branch of rev-2 (by dyuri).  I plan to implement all those features myself in rev-2 at some point, but it might be a while.

Offline sordna

  • Posts: 2248
Re: My Ergodox Layout
« Reply #15 on: Fri, 16 August 2013, 01:33:55 »
@sordna: ... layouts in rev-2 are much easier to deal with in source.

That's good news!  The other things we need to make sure rev-2 supports (or is easily hacked to support):
- lighting the teensy LED to indicate you left the main layer
- clicking a buzzer
(both of the above in this old patch you helped me with)

Ok, I just compiled partial-rewrite for the first time. I changed firmware/keyboard/ergodox/options.h to the settings for switches with internal diodes, and then compiled with: make KEYBOARD_LAYOUT=dvorak--kinesis-mod

That works, but I'm a bit lost now, since I've been used to the MD configurator :-)
What is the minimum I have to do to use the dvorak layout as a starting point, and remap some keys, like bring the kinesis up/down arrows in their proper place (normally its the 2 leftmost keys of the right hand bottom row, it's very confusing that you moved them away!).

Is there a doc that explains to mere mortals how to do a customized layout by dealing with the sources ?

Also, what is the symbolic name for the key that flashes the teensy?

thanks!
Kinesis Contoured Advantage & Advantage2 LF with Cherry MX Red switches / Extra keys mod / O-ring dampening mod / Dvorak layout. ErgoDox with buzzer and LED mod.
Also: Kinesis Advantage Classic, Kinesis Advantage2, Data911 TG3, Fingerworks Touchstream LP, IBM SSK (Buckling spring), Goldtouch GTU-0077 keyboard

Offline dyuri

  • Posts: 10
  • Location: Budapest, Hungary
Re: My Ergodox Layout
« Reply #16 on: Fri, 16 August 2013, 03:43:50 »
That's good news!  The other things we need to make sure rev-2 supports (or is easily hacked to support):
- lighting the teensy LED to indicate you left the main layer
- clicking a buzzer
(both of the above in this old patch you helped me with)
This should be easy, I've already enabled the teensy led in my branch ( https://github.com/dyuri/ergodox-firmware/blob/repa/firmware/keyboard/ergodox/led.c#L38 )

What is the minimum I have to do to use the dvorak layout as a starting point, and remap some keys, like bring the kinesis up/down arrows in their proper place (normally its the 2 leftmost keys of the right hand bottom row, it's very confusing that you moved them away!).

Is there a doc that explains to mere mortals how to do a customized layout by dealing with the sources ?
I don't know about such doc, but it's quite easy to create completely custom layouts based on  firmware/keyboard/ergodox/layout/templates/kinesis-mod.c.h. The key macros are defined under the firmware/keyboard/ergodox/layout/common folder, but the keypress/release functions (referred by these macros) are under firmware/lib/layout/ i.e. the basic keys in firmware/lib/layout/keys.h.

Also, what is the symbolic name for the key that flashes the teensy?
It's "btldr". (macro, function)
Ergodox (MX Clears) | HPE 87 (MX Blacks)

Offline sordna

  • Posts: 2248
Re: My Ergodox Layout
« Reply #17 on: Fri, 16 August 2013, 12:21:38 »
Thanks so much, I'll give it a try!
Kinesis Contoured Advantage & Advantage2 LF with Cherry MX Red switches / Extra keys mod / O-ring dampening mod / Dvorak layout. ErgoDox with buzzer and LED mod.
Also: Kinesis Advantage Classic, Kinesis Advantage2, Data911 TG3, Fingerworks Touchstream LP, IBM SSK (Buckling spring), Goldtouch GTU-0077 keyboard

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #18 on: Sat, 31 August 2013, 15:18:45 »
Could one of you give me a hand? I've been trying to use frew's code to make a layer with custom macro keys:
https://github.com/fisofo/ergodox-firmware/compare, similar to what he did here:
https://github.com/frioux/ergodox-firmware/blob/frew/firmware/keyboard/ergodox/layout/qwerty-kinesis-mod.c

It compiles fine, but when I dump it on the teensy, the all 3 lights turn on, and it is unresponsive. Am I missing something obvious here? I'm sure I am; I am brand new to C and to Git, just trying to make some obvious modifications to get this working.

Thanks guys.

Offline ic07

  • Posts: 190
Re: My Ergodox Layout
« Reply #19 on: Sat, 31 August 2013, 15:38:32 »
It doesn't *look* like anything you did...  Have you tried flashing your Teensy with dyuri's code, unmodified (since your branch is forked from his)?  I went over his changes again (very) briefly, and didn't see anything that would cause that to happen - but my branch doesn't do that, so if it's not your changes, you might want to ask him.

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #20 on: Sat, 31 August 2013, 16:19:28 »
It doesn't *look* like anything you did...  Have you tried flashing your Teensy with dyuri's code, unmodified (since your branch is forked from his)?  I went over his changes again (very) briefly, and didn't see anything that would cause that to happen - but my branch doesn't do that, so if it's not your changes, you might want to ask him.

Ah, good point! I just tried dyuri's, and it does the same thing to me. Doh! So I merged my changes into your main partial-rewrite, and then it worked. Brilliant! Thanks ic07!

Out of curiosity, would it be easy (if not "proper") to get media keys working using this same method? And if so, could you give me an example to get me started? I'm one of those Windows users that this isn't working for :/ 
I looked at the rev-1 code that Ryan Prince created to see if I could get it up to rev-2, but after messing with it for a couple hours I finally gave up. Over my head I'm afraid.

Back to coding!
« Last Edit: Sat, 31 August 2013, 18:12:33 by fisofo »

Offline ic07

  • Posts: 190
Re: My Ergodox Layout
« Reply #21 on: Sat, 31 August 2013, 19:16:14 »
:)

About media keys... sorry... I honestly don't understand the USB code that well either right now.  Implementing all that stuff is on my todo list, but delayed at the moment because of school.  If you think it's worth it, you might consider switching to rev-1 for now, and implementing your macros there.  The functions would look essentially the same (though a few of the function names have changed) - that would require working with the rev-1 layout format though, which is kind of a pain in source.  No easy solution, I'm afraid :/

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #22 on: Sat, 31 August 2013, 23:13:12 »
Media keys are not that high on my list at this point as I can always implement through hotkeys using F13-F24 function keys. Or maybe I'll check rev-1 out again.

Anyway, no worries, school is important! And thanks for the help :thumb:

Offline dyuri

  • Posts: 10
  • Location: Budapest, Hungary
Re: My Ergodox Layout
« Reply #23 on: Mon, 02 September 2013, 04:46:28 »
It doesn't *look* like anything you did...  Have you tried flashing your Teensy with dyuri's code, unmodified (since your branch is forked from his)?  I went over his changes again (very) briefly, and didn't see anything that would cause that to happen - but my branch doesn't do that, so if it's not your changes, you might want to ask him.

Ah, good point! I just tried dyuri's, and it does the same thing to me. Doh! So I merged my changes into your main partial-rewrite, and then it worked.

This is strange, I'm using my branch for a long time, and used to tweek my layout (and recompile the fw) once/twice a week and never had suck kind of issues. It would be interesting if you could find out why my branch doesn't work for you.

It should be not too difficult to extend the usb descriptors with one for the media keys - as I did with the mouse and the second keyboard interface for nkro -, but since my desktop environment does not support them I cannot not test them, so I didn't want to mess with them.
Ergodox (MX Clears) | HPE 87 (MX Blacks)

Offline ic07

  • Posts: 190
Re: My Ergodox Layout
« Reply #24 on: Mon, 02 September 2013, 09:35:22 »
@dyuri: If it's not your code either, perhaps you caught a bad (testing) commit of mine last time you merged? I try not to have those at HEAD when I push, but I think it's happened a few times.

Edit: On my phone at the moment, so, hard to check myself, sorry.
« Last Edit: Mon, 02 September 2013, 09:37:21 by ic07 »

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #25 on: Mon, 02 September 2013, 09:39:06 »
@dyuri: I wish I knew what to tell you! I just downloaded yours again and compiled it (we're talking the "repa" branch, right?) there are no problems in that step, and it looks identical to when I compile my branch. (Note: I am on windows using WinAVR). But still when I load it to teensy, I just get the 3 lights on and it is non-responsive.

Are you familiar with http://winmerge.org/? I used that to compare the files and it lets me see all of the differences, but I'm honestly not adept enough in C to know what I'd need to troubleshoot next. Here's a report generated by Winmerge that shows which files have differences, but you'd need to run winmerge yourself to see the differences in each file: https://github.com/fisofo/ergodox-firmware/blob/partial-rewrite/doc/Compare_dyuri.html. I tried doing this using Git, but it didn't seem to list everything? I could be doing it wrong.

It'd be great to get the media keys working, but I'm not sure where I'd start :/

Offline dyuri

  • Posts: 10
  • Location: Budapest, Hungary
Re: My Ergodox Layout
« Reply #26 on: Tue, 03 September 2013, 03:12:00 »
Could you try to compile my branch (repa), with disabled mouse and/or nkro support (https://github.com/dyuri/ergodox-firmware/blob/repa/firmware/keyboard/ergodox/options.mk#L34 comment out these lines)? In this way we might see which part has the bug.
Ergodox (MX Clears) | HPE 87 (MX Blacks)

Offline dyuri

  • Posts: 10
  • Location: Budapest, Hungary
Re: My Ergodox Layout
« Reply #27 on: Tue, 03 September 2013, 10:56:17 »
I had the opportunity to test my firmware with a Macbook (OS X 10.8, Mountain Lion), and everything worked as it should (mouse and nkro as well).
Ergodox (MX Clears) | HPE 87 (MX Blacks)

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #28 on: Tue, 03 September 2013, 20:15:32 »
I just gave that a whirl: with both mouse and nkro disabled, repa works fine, but if I re-compile with either the mouse OR nkro enabled, I get the three lights stuck on and unresponsive keyboard.

So... that's strange! What if you post the hash of your firmware.hex file and I can compare with what I get? It would be interesting to see if WinAVR is compiling differently or something. Or if you have a Win7 x64 system you could plug into you could see if your keyboard does the same thing as mine.

Offline dyuri

  • Posts: 10
  • Location: Budapest, Hungary
Re: My Ergodox Layout
« Reply #29 on: Wed, 04 September 2013, 03:03:27 »
MD5 hash of my firmware.hex (very latest, mouse and nkro enabled): 612783ec7c7c81efdda9628cd3ded61e
You can download it here: http://dyuri.horak.hu/alma/repa.hex

I'll try to get close to a Win7 to test it.
Ergodox (MX Clears) | HPE 87 (MX Blacks)

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #30 on: Wed, 04 September 2013, 19:33:50 »
The plot thickens! When I compile it, I get the attached, with an MD5 of: 2795b1aa7cb37677988a85e3e5f5bfee

However, I downloaded and loaded your firmware, and it does the same thing for me anyway, so I guess it's not the compiler. Weird, not sure what's up!

Did you guys see that tmk is now available for ErgoDox? I'm going to check it out this evening: https://github.com/cub-uanic/tmk_keyboard/tree/cub_layout

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #31 on: Sat, 07 September 2013, 09:02:12 »
cub-uanic's TMK firmware compiles and loads onto my ergodox, but the keyboard is very slow to respond. There's a post going over here for it: http://geekhack.org/index.php?topic=48106.0, I'm still waiting to hear if anyone else has the same issues I've had with it. Very strange.

The "killer" feature I really want to get is the dual shot modifier keys (tap does one thing, holding key does another). Do any of you see an easy way to add this to Ben's firmware?

Offline ic07

  • Posts: 190
Re: My Ergodox Layout
« Reply #32 on: Sat, 07 September 2013, 10:03:57 »
On rev 2 it's very possible, albeit undocumented :( .  Take a look around for the timer functions. I haven't tried using them for tap/hold differentiation yet, but my initial thoughts are that one could have a global var (with a sufficiently long name...) that belongs to a pair of press and release functions. Perhaps the press function sets it, and schedules a function to run that clears it after a few cycles, and the release function changes its behavior based on the state of the var. Or perhaps the press function sets it and the release function clears it, and the function that is scheduled does something different based on what state the var is in. The only badish thing is that my scheduler resolution (in order to avoid all the fun that comes with executing within an interrupt) has only cycle (~5ms) resolution.

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #33 on: Sat, 07 September 2013, 11:00:32 »
I was thinking something like this in keys.c.h, but I haven't nailed down the timer portion. What do you think?

Code: [Select]
void KF(Space_Tap_Key)(bool pressed, uint8_t keycode) {
    static uint8_t whichkey = 0;
    if (pressed && Timer > 200) {
        whichkey = 1
        KF(press)(keys__press__lpu2l2);
    } else if (!pressed && Timer > 200) {
whichkey = 1
        KF(press)(keycode);
}
    if (!pressed && whickkey == 1) {
        KF(release)(keys__press__lpo2l2);
    }
if (!pressed && whickkey == 0) {
        KF(release)(keycode);
    }
}

void P(spc2layer) (void) { KF(Space_Tap_Key)(true, KEYBOARD__Spacebar); }
void R(spc2layer) (void) { KF(Space_Tap_Key)(false, KEYBOARD__Spacebar); }

Offline ic07

  • Posts: 190
Re: My Ergodox Layout
« Reply #34 on: Sat, 07 September 2013, 16:16:56 »
The only problem with doing it that way is that whichever key function is assigned will get called immediately (i.e. when the key has been "pressed" for 0 units of time) - but what you want to do is delay somehow until you get to 200 (milliseconds? which would be ~40 scan cycles) before doing anything - unless the key is released before then, in which case you know to execute the "tapped" function instead of the "held" one.

There are different ways to do it, and you could definitely use absolute times and compare them, but what I'd probably do is something like

Code: [Select]
bool space_tap_key__held;
bool space_tap_key__has_been_released;

// this happens first
P(space_tap_key)(void){
    space_tap_key__held = false;
    space_tap_key__has_been_released = false;
    timer__schedule_cycles(40, &KF(space_tap_key));
}

// this happens after 40 cycles ~= 200 milliseconds
// (whether the key has been released or not)
KF(space_tap_key)(void){
    if (!space_tap_key__has_been_released) {
        space_tap_key__held = true;
        // perform the "held" press function
        P(lpu2l2);
    }
}

// this happens when the key is released
// (whether the scheduled function has run or not)
// (but the scheduled function is not occurring within an interrupt, so we
//  don't have to worry about race conditions inside this one)
R(space_tap_key)(void){
    if (space_tap_key__held) {
        // release the "held" function
        R(lpu2l2);
    } else {
        // press the "tapped" function
        KF(press)(KEYBOARD__Spacebar);
        // (send the report)
        usb__kb__send_report();
        // then release it
        KF(release)(KEYBOARD__Spacebar);
    }
    space_tap_key__has_been_released = true;
}

Untested, and my logic or some details may be off, sorry... Really crazy week at school (like I mentioned on the massdrop thread).  Should give you an idea though :)

Oh ya!  And the header for the timer library is here.

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #35 on: Sat, 07 September 2013, 17:00:09 »
That does make sense, thanks! Totally understand about school, thanks for helping as much as you have. If/when you get another few moments to look at this, I think your code is really close, but the lines for "P(lpu2l2);" and "R(lpu2l2);" both return "warning: statement with no effect" when I build it.

If it helps, I've committed these changes to my fork here: https://github.com/fisofo/ergodox-firmware/blob/partial-rewrite/firmware/keyboard/ergodox/layout/common/keys.c.h

Offline ic07

  • Posts: 190
Re: My Ergodox Layout
« Reply #36 on: Sat, 07 September 2013, 19:58:34 »
Ooh!  They should be "P(lpu2l2)();" and "R(lpu2l2)();".  I thought those macros would confuse someone someday... lol.  IIRC "P(lpu2l2)" expands to "keys__push__lpu2l2", which, if not followed by "()" is interpreted as a function pointer instead of a function.  In some places in the layout code we do want to refer to the function pointer (though, in those cases it's better to use "&P(lpu2l2)"), but in this case we're trying to actually call the function.

np :) hope you get it working!

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #37 on: Sat, 07 September 2013, 22:19:22 »
THANK YOU!  :D

So that totally worked, but the lag on the space key was pretty unbearable, and changing the timing didn't work that great, but it gave me the idea to implement double tap activation instead with the ctrl key.

After messing around for awhile I got it nailed down, and man does it work nice! Here's the code:

Code: [Select]
// counts the number of times the ctrl key was hit
uint8_t ctrl_key__counter = 0;

 // this happens 40 cycles ~= 200 milliseconds after ctrl key is released first time
 // resets the counter to prevent activating the layer after a longer period of time
void KF(ctrl_tap_key)(void){
ctrl_key__counter = 0;
}

// this fires when ctrl key is pressed
void P(ctrl_tap_key)(void){
    ctrl_key__counter++;
if (ctrl_key__counter == 1) { // ctrl key works on first press
KF(press)(KEYBOARD__LeftControl);
} else { // on any subsequent press within the scheduled cycles, the layer key is activated
P(lpupo1l1)();
}
}

// this happens when the key is released
void R(ctrl_tap_key)(void){
if (ctrl_key__counter == 1) { // ctrl was hit just once, so release it
KF(release)(KEYBOARD__LeftControl);
timer__schedule_cycles(40, &KF(ctrl_tap_key)); // start the timer; if ctrl not hit again within these cycles, the counter is reset
} else { // ctrl key was hit more than once and was not released; release the layer key and reset the counter
R(lpupo1l1)();
ctrl_key__counter = 0;
}
}

I'm going to tweak my setup and will commit these changes to my fork in the next day or so. Thanks for the help Ben!

Offline ic07

  • Posts: 190
Re: My Ergodox Layout
« Reply #38 on: Sun, 08 September 2013, 01:25:19 »
Glad I could :)

Offline sordna

  • Posts: 2248
Re: My Ergodox Layout
« Reply #39 on: Mon, 09 September 2013, 13:13:53 »
Are you guys going to converge into a common release ?
Kinesis Contoured Advantage & Advantage2 LF with Cherry MX Red switches / Extra keys mod / O-ring dampening mod / Dvorak layout. ErgoDox with buzzer and LED mod.
Also: Kinesis Advantage Classic, Kinesis Advantage2, Data911 TG3, Fingerworks Touchstream LP, IBM SSK (Buckling spring), Goldtouch GTU-0077 keyboard

Offline fisofo

  • Posts: 65
Re: My Ergodox Layout
« Reply #40 on: Mon, 09 September 2013, 17:26:27 »
Are you guys going to converge into a common release ?

Ben isn't doing that at this point with school in full swing. I've updated my fork if you are interested and am going to take a break for a few days to give my hands a rest from the coding, which has caused my wrists to flair up :/

Offline sordna

  • Posts: 2248
Re: My Ergodox Layout
« Reply #41 on: Wed, 11 September 2013, 22:12:42 »
I have trouble with choice. I don't want to have to choose!  I want one firmware that makes it ridiculously easy to do your layout by editing a file. Until then I'll probably use the massdrop generator, since I'm now spoiled by it :-)
Kinesis Contoured Advantage & Advantage2 LF with Cherry MX Red switches / Extra keys mod / O-ring dampening mod / Dvorak layout. ErgoDox with buzzer and LED mod.
Also: Kinesis Advantage Classic, Kinesis Advantage2, Data911 TG3, Fingerworks Touchstream LP, IBM SSK (Buckling spring), Goldtouch GTU-0077 keyboard

Offline jalli

  • Posts: 101
  • Location: Toronto, Canada
Re: My Ergodox Layout
« Reply #42 on: Wed, 11 September 2013, 23:12:36 »
While waiting for my parts to arrive I've been designing my layout and thinking about some custom firmware options that I think would be cool, thoughts comments encouraged!

Some of these are good reasons why using the Massdrop configuration utility is limiting, what I'm currently thinking:

Make the shift keys into  dead keys in addition to modifiers, once you get above 100 WPM using a modifier becomes unreliable and uncomfortable, would be much easier to just tap shift knowing that the next character would become upper case.

Make right alt, left alt, right ctrl and left ctrl available as dead keys in addition to modifiers, if no other key is pressed between down state and up state we can assume they are being used as dead keys instead of modifiers and we can assign a new role (I'm thinking Diacritics for foreign languages but it could be anything that a dead key is useful for.

Put the teensy in the left panel, enable one handed keyboard with mouse. The biggest trouble I find with one handed typing is that some sort of modifier is needed to "flip" between the "right" and "left layouts and it's really hard to use your left hand to do this since you need to be able to type normally with all fingers.

Ideally I would use an extra button on my mouse to switch, now we need a way for the mouse to communicate with the teensy/Ergodox to tell it to "flip sides". As far as I know the only signals that could be used to signal something like this to the teensy are the "Lock keys", and fortunately one of them is largely unused; Scroll Lock.
It should be possible to modify the firmware to enable it to use "Scroll Lock" as a programmable input, from that point it's easy to program a mouse to turn scroll lock on/off with a button.
Antonia

Offline ic07

  • Posts: 190
Re: My Ergodox Layout
« Reply #43 on: Thu, 12 September 2013, 11:41:05 »
I never thought of using scroll lock as an input signal to the keyboard. That's a good idea though :).

Offline jalli

  • Posts: 101
  • Location: Toronto, Canada
Re: My Ergodox Layout
« Reply #44 on: Thu, 12 September 2013, 12:39:13 »
I'm still waiting for my Ergodox to arrive, once I get it I'll start experimenting.

I'm sure there are other ways to pass signals but this might be really easy and requires minimal integration from the device sending the signal.


I never thought of using scroll lock as an input signal to the keyboard. That's a good idea though :).
Antonia

Offline jalli

  • Posts: 101
  • Location: Toronto, Canada
Re: My Ergodox Layout
« Reply #45 on: Sun, 15 September 2013, 21:40:07 »
Just thought I would let you know that the Ergodox keyboard layout is now available as an option in
http://patorjk.com/keyboard-layout-analyzer, it's a tool to optimize keyboard layouts and is really cool,
I highly recommend you try it out if you are building your own layout or to compare existing layouts.
Antonia

Offline Oobly

  • * Esteemed Elder
  • Posts: 3929
  • Location: Finland
Re: My Ergodox Layout
« Reply #46 on: Mon, 16 September 2013, 06:12:32 »
Just thought I would let you know that the Ergodox keyboard layout is now available as an option in
http://patorjk.com/keyboard-layout-analyzer, it's a tool to optimize keyboard layouts and is really cool,
I highly recommend you try it out if you are building your own layout or to compare existing layouts.

I notice that the left and right thumbs are reversed in the layouts. Not sure it affects the metrics, but it certainly affects my mental image of using the layout ;)
Buying more keycaps,
it really hacks my wallet,
but I must have them.

Offline jalli

  • Posts: 101
  • Location: Toronto, Canada
Re: My Ergodox Layout
« Reply #47 on: Mon, 16 September 2013, 06:44:03 »
Just thought I would let you know that the Ergodox keyboard layout is now available as an option in
http://patorjk.com/keyboard-layout-analyzer, it's a tool to optimize keyboard layouts and is really cool,
I highly recommend you try it out if you are building your own layout or to compare existing layouts.

I notice that the left and right thumbs are reversed in the layouts. Not sure it affects the metrics, but it certainly affects my mental image of using the layout ;)

How right you are, it does affect the metrics due to hand alternation patterns, I'll report to Patrick, thanks for pointing that out.

R.

Jarl
Antonia

Offline cub-uanic

  • Posts: 72
  • Location: Ukraine, Kharkov
Re: My Ergodox Layout
« Reply #48 on: Mon, 16 September 2013, 17:32:29 »
As I see, my port of TMK was already mentioned in this thread, but I'd like to remind about it once more :)

It have all TMK features (NKRO, media keys, mouse keys, dual-role keys and so on), and also have support for layer indication and even for LeftLed's  ;D
(see http://geekhack.org/index.php?topic=22780.msg873819#msg873819 for more details)

All Ergodox-specific problems were successfully solved - big thanks to Ben and his firmware, which was used as working example.

Check it out here: https://github.com/cub-uanic/tmk_keyboard/tree/cub_layout
And here: http://geekhack.org/index.php?topic=48106.0

I have my own modification of "Workman for Programmers" for XOrg, optimized for Perl and Vim:
https://github.com/cub-uanic/tmk_keyboard/blob/cub_layout/keyboard/ergodox/addons/etc/layout/xkb/workman

And my layout were added to http://patorjk.com/keyboard-layout-analyzer/#/config
Try to analyze some real Perl code, for example from here:
https://raw.github.com/miyagawa/cpanminus/devel/lib/App/cpanminus/script.pm

Happy ErgoPerl-ing!  :thumb:

ErgoDox Classic - Stock Clears
Teenesis - Kinesis Advantage powered by Teensy

Offline wasabah

  • Posts: 156
  • Location: Germany
Re: My Ergodox Layout
« Reply #49 on: Tue, 05 November 2013, 06:28:00 »
While waiting for my parts to arrive I've been designing my layout and thinking about some custom firmware options that I think would be cool, thoughts comments encouraged!

Some of these are good reasons why using the Massdrop configuration utility is limiting, what I'm currently thinking:

Make the shift keys into  dead keys in addition to modifiers, once you get above 100 WPM using a modifier becomes unreliable and uncomfortable, would be much easier to just tap shift knowing that the next character would become upper case.

Make right alt, left alt, right ctrl and left ctrl available as dead keys in addition to modifiers, if no other key is pressed between down state and up state we can assume they are being used as dead keys instead of modifiers and we can assign a new role (I'm thinking Diacritics for foreign languages but it could be anything that a dead key is useful for.

Put the teensy in the left panel, enable one handed keyboard with mouse. The biggest trouble I find with one handed typing is that some sort of modifier is needed to "flip" between the "right" and "left layouts and it's really hard to use your left hand to do this since you need to be able to type normally with all fingers.

Ideally I would use an extra button on my mouse to switch, now we need a way for the mouse to communicate with the teensy/Ergodox to tell it to "flip sides". As far as I know the only signals that could be used to signal something like this to the teensy are the "Lock keys", and fortunately one of them is largely unused; Scroll Lock.
It should be possible to modify the firmware to enable it to use "Scroll Lock" as a programmable input, from that point it's easy to program a mouse to turn scroll lock on/off with a button.


I'm looking for options to get a left-handed keyboard myself at the moment.
As I already own an Ergodox, I'm really interested to see what you come up with!
I guess my biggest problem converting to a left-handed keyboard is the case from Massdrop which I would somehow need to alter.
ErgoDox Classic | Logitech G400 | Logitech Marble | Logitech M570 | Logitech M235 | Logitech M305