Warning caused by hid::pressKey(LSHIFT(mapped_key));


(tiltowaitt) #1

In my WIP AutoShift plugin, I have a line that reads:

hid::pressKey(LSHIFT(mapped_key));

While the compiled code works, I get a very verbose warning:

In file included from /Users/tiltowait/Programming/Keyboardio/Model01-Firmware/lib/hardware/keyboardio/avr/libraries/Kaleidoscope/src/kaleidoscope/key_events.h:21:0,
                 from /Users/tiltowait/Programming/Keyboardio/Model01-Firmware/lib/hardware/keyboardio/avr/libraries/Kaleidoscope/src/kaleidoscope/Kaleidoscope.h:47,
                 from /Users/tiltowait/Programming/Keyboardio/Model01-Firmware/lib/hardware/keyboardio/avr/libraries/Kaleidoscope/src/Kaleidoscope.h:19,
                 from /Users/tiltowait/Programming/Keyboardio/Model01-Firmware/lib/plugins/Kaleidoscope-AutoShift/src/Kaleidoscope/AutoShift.h:20,
                 from /Users/tiltowait/Programming/Keyboardio/Model01-Firmware/lib/plugins/Kaleidoscope-AutoShift/src/Kaleidoscope-AutoShift.h:20,
                 from /Users/tiltowait/Programming/Keyboardio/Model01-Firmware/lib/plugins/Kaleidoscope-AutoShift/src/Kaleidoscope/AutoShift.cpp:18:
/Users/tiltowait/Programming/Keyboardio/Model01-Firmware/lib/plugins/Kaleidoscope-AutoShift/src/Kaleidoscope/AutoShift.cpp: In member function 'kaleidoscope::EventHandlerResult kaleidoscope::plugin::AutoShift::onKeyswitchEvent(kaleidoscope::Key&, byte, byte, uint8_t)':
/Users/tiltowait/Programming/Keyboardio/Model01-Firmware/lib/hardware/keyboardio/avr/libraries/Kaleidoscope/src/kaleidoscope/key_defs.h:105:47: warning: narrowing conversion of '(int)(mapped_key.kaleidoscope::Key::<anonymous>.kaleidoscope::Key::<anonymous struct>::flags | 8u)' from 'int' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing]
 #define LSHIFT(k) ((Key) { k.keyCode, k.flags | SHIFT_HELD })
                                               ^
/Users/tiltowait/Programming/Keyboardio/Model01-Firmware/lib/plugins/Kaleidoscope-AutoShift/src/Kaleidoscope/AutoShift.cpp:108:21: note: in expansion of macro 'LSHIFT'
       hid::pressKey(LSHIFT(mapped_key));

What is the proper way to force the firmware to output a shifted key?


(Gergely Nagy) #2

Hm… hid::pressKey shouldn’t warn there, I think. Will look into it. Meanwhile, you can try handleKeyswitchEvent(LSHIFT(mapped_key), UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED);


(tiltowaitt) #3

Thanks, but I get the same warning with handleKeyswitchEvent.


(Gergely Nagy) #4

Interesting, I don’t get warning locally. What version of Arduino and avr-gcc are you using?


(Gergely Nagy) #5

Aha! You’re likely running into #272. Try this:

Key k = LSHIFT(mapped_key);
hid::pressKey(k);

(tiltowaitt) #6

Same error! It’s just moved to the assignment like instead.

I’m using Arduino 1.8.8. avr-gcc is v5.4.0.

If it matters, I build from the command line rather than using the Arduino IDE, and I’m on a Mac.


(Gergely Nagy) #7

Just shooting in the dark now… perhaps:

Key k = mapped_key;
k.flags |= SHIFT_HELD;
hid::pressKey(k);

(We’re usually building with avr-gcc 4.9, which is less picky it seems)


(tiltowaitt) #8

Yes, that fixes it. Thanks.

The strange thing is that I use LSHIFT() on one of the keys in my keymap without getting any warning there. Is it possibly using different compiler flags for the sketch compared to the plugin files?


(Gergely Nagy) #9

It’s a bit different there, because it ends up being optimized differently, I guess.

Nope, same flags.