Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Changes in USB keyboard support on Teensy 2.0

  1. #1
    Junior Member
    Join Date
    Dec 2019
    Location
    Ferney-Voltaire
    Posts
    5

    Changes in USB keyboard support on Teensy 2.0

    Hi,

    I'm trying to tweak some code written five years ago for the Teensy 2.0. Back then, KEYCODE_TYPE and the KEY_xxx codes were an unsigned chars, and the code worked fine.

    Now, with the changes to enable media keys on Teensy 2.0, the KEY_xxx keys are either unsigned char or unsigned int (for unicode) and I cannot see what I have to define to make it unsigned char. It is defaulting to unsigned int (for unicode) rather than unsigned chart (for ASCII).

    I just want to compile my code and make an unrelated tweak (this code is reading an Infra-red remote control and generating USB keyboard keypresses).

    Does anyone know how I can ask the USB keyboard support to either make KEYCODE_TYPE be a 16 bit int or that the KEY_xxx codes generate an 8 bit char?

    Thanks,

    Paul
    Last edited by makegeneve; 12-04-2019 at 08:08 AM.

  2. #2
    Junior Member
    Join Date
    Dec 2019
    Location
    Ferney-Voltaire
    Posts
    5
    Code is trivially simple:

    typedef struct
    {
    unsigned char ir_code;
    KEYCODE_TYPE keyboard_code;
    KEYCODE_TYPE keyboard_modifier;
    } keyboard_entry_t;

    keyboard_entry_t nec_key_translation[] = {
    { 0x15, KEY_ENTER, 0 }, /*OK*/
    { 0x1B, KEY_LEFT, 0 }, /*LEFT*/
    { 0x1C, KEY_RIGHT, 0 }, /*RIGHT*/
    { 0x0B, KEY_UP, 0 }, /*UP*/
    and the error is (repeated umpteen times for all the keys):
    IR_Keyboard:114: error: narrowing conversion of '61480' from 'unsigned int' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing]
    };

  3. #3
    Junior Member
    Join Date
    Dec 2019
    Location
    Ferney-Voltaire
    Posts
    5

    Unhappy

    So it looks like KEYBOARD_TYPE is being defined somewhere as 8 bit, but the KEY_xxx codes are generating 16 bit values...

    I'm running the latest teensyduino and Arduino 1.8.10
    Last edited by makegeneve; 12-04-2019 at 08:08 AM.

  4. #4
    Junior Member
    Join Date
    Dec 2019
    Location
    Ferney-Voltaire
    Posts
    5
    I suppose I could make it compile by simply changing the struct to use unsigned int instead of KEYCODE_TYPE but that feels like the sort of hack that will bite me later.

  5. #5
    Junior Member
    Join Date
    Dec 2019
    Location
    Ferney-Voltaire
    Posts
    5
    Finally made it compile by setting the Keyboard Layout to "US International" instead of "US English"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •