Skip to content
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

Allow sketches to change the keyboard language layout config without editing source files in the library itself #176

Merged
merged 6 commits into from
Jul 13, 2019

Conversation

blahlicus
Copy link
Contributor

@blahlicus blahlicus commented Jun 28, 2019

As per #175, NicoHood/HID currently requires the user to change the flags in HID-Settings.h to switch from US to German keyboard layout and etc.

This is really bad because it requires the user to edit source files in the HID-Project library.

This PR allows sketches to set flags to define which layout it would like to use without messing with source files in the library, below is an example using the German layout:

#define HID_CUSTOM_LAYOUT // set this flag to indicate that a custom layout is selected
// if the above flag is not defined, then the default US layout is used instead

#define LAYOUT_GERMAN // set this flag after the above flag to indicate the custom input method is German
// for more layouts, see /src/KeyboardLayouts/ImprovedKeylayouts.h

// you must set the above flags before including HID-Project
#include "HID-Project.h"


void setup() {
  BootKeyboard.begin();
  delay(300);
  BootKeyboard.write(KEY_7|MOD_LEFT_SHIFT); // this outputs the / symbol as per the german input method
}


void loop() {

}

To use a non-US English layout, the user only has to #define HID_CUSTOM_LAYOUT followed by #define LAYOUT_[Your layout here] before #including the HID-Project.h file.

if HID_CUSTOM_LAYOUT is undefined, then it defaults to the original US ASCII table, which means this PR is reverse compatible with older sketches.

@wladimir-computin
Copy link
Contributor

How do you compile it? Are you using the Arduino IDE?

@blahlicus
Copy link
Contributor Author

Yeah.

@NicoHood
Copy link
Owner

NicoHood commented Jul 5, 2019

Oh nice. This works, because I did not use .cpp files, right? The .cpp files do not require the keyboard layout. This should work - I am surprised that it is that easy. Did you test this carefully?

@blahlicus
Copy link
Contributor Author

I tested the above code on both the Pro Micro and an SAMD21 device.

I also tested it in my complicated firmware which depends on this library and it worked fine. Previous version of my complicated firmware which depends on older versions of this library also works with this so it shows reverse-compatibility is working.

Perhaps we could have a second opinion from @wladimir-computin and then decide on the merge?

@wladimir-computin
Copy link
Contributor

In my opinion @blahlicus did a great job, no complaints from my side.
@NicoHood, are you ok with merging his commit?

@NicoHood NicoHood merged commit 0b3d6dc into NicoHood:master Jul 13, 2019
@bitboy85
Copy link

Not working for me #208
Arduino IDE 1.8.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants