1.1k views
in GUI Development by

Hello,

I'm developing a new display, where I need to handle menu navigation with the switch in the image below.

 

In EW the Keyboard keys, already have a template ("Key Press handler"). I need something similar to this, but with the switch inputs.

Can someone help me please?

 

Best Regards

1 Answer

+2 votes
by

Hello,

unlike its name indicates, the Key Press handler is not restricted to handle events generated by the real keyboard only. You can also connect hardware buttons, like the switch from the image above, and use it as the input device. Every time the user presses a button on the switch, you simply feed the corresponding keyboard event to the application. For example, when the user presses the left button, you could feed an event with the key code Left. To handle the event within the application you use then a Key Press handler configured to react to the Left key code.

To use the switch as an alternative (or additional) keyboard input device you will need to adapt the main loop. The main loop is the glue part between the GUI application and your target device. Just evaluate in the loop whether the user has pressed a button on the switch and if this is the case generate the corresponding keyboard event.

Hope it helps you.

Best regards

Paul Banach

by
Hello Paul,

Thank you for your answer.

 

Can you give me an example code to implement in main.c to use my input as an OK Key?

 

Thank you again.

 

Best Regards

Ricky
by

Hi Ricky!

Please have a look into one of the main.c files that we provide within our Build Environments. There you will find the following function:

static XEnum GetKeyCommand( void )
{
  #ifdef USE_TERMINAL_INPUT
    switch ( EwBspGetCharacter())
    {
      case 0x65 : EwPrint("Key 'Exit' pressed\n");  return CoreKeyCodeExit;
      case 0x38 : EwPrint("Key 'Up' pressed\n");    return CoreKeyCodeUp;
      case 0x32 : EwPrint("Key 'Down' pressed\n");  return CoreKeyCodeDown;
      case 0x36 : EwPrint("Key 'Right' pressed\n"); return CoreKeyCodeRight;
      case 0x34 : EwPrint("Key 'Left' pressed\n");  return CoreKeyCodeLeft;
      case 0x35 : EwPrint("Key 'OK' pressed\n");    return CoreKeyCodeOk;
      case 0x6D : EwPrint("Key 'Menu' pressed\n");  return CoreKeyCodeMenu;
      case 0x70 : EwPrint("Key 'Power' pressed\n"); return CoreKeyCodePower;
    }
  #endif

  return CoreKeyCodeNoKey;
}

As you can see, this function is prepared to get key codes from the terminal - just adpat this implementation to convert your key events instead of the received key code. Instead of getting some key code from EwBspGetCharacter() call your driver to detect key hits.

I hope this helps...

Best regards,

Manfred

by
Hello,

 

Thank you so much for the help! It's working!

 

Best Regards

Ricky

Embedded Wizard Website | Privacy Policy | Imprint

...