Context sensitive buttons? "Soft-keys"

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Context sensitive buttons? "Soft-keys"

    What is the best way to implement soft-keys in emWin? I'd like to have five button widgets along the bottom of the screen that respond to dedicated hardware tactile switches.
  • Hello Strobot,

    I would recommend the following in order to implement soft-keys (see according emWin manual sections parenthesized):

    - Define one custom message for every set of soft-keys which you are going to use in your application. (15.5 "Messages")
    - Use a custom callback function for every soft-key and make it react (e.g. change the displayed text on the soft-key) to the custom messages. (15.2.3 "Overwriting callback functions")
    - Make your application send the according message every time another set of soft-keys shall be used. (WM_SendMessageNoPara() in 15.8 "WM API: Basic functions")

    Best regards,
    Adrian
  • Hi Adrian,

    Thanks for the reply - very helpful.

    Let me see if I understand:
    1. The user presses a tactile button that happens to initiate a context switch (redefine the behavior / text of the soft-keys) to move to another UI "state"
    2. The application detects the button press, then sends the corresponding custom message
    3. The callback functions of the soft-keys respond to this custom message and execute commands to change the button widget text
    One thing I'm not sure about: Will I also need a custom message for each soft-key to notify its callback function that it has been pressed? For example - I'd need five custom messages for five button widgets? Or would I just need one "pressed"-custom message and have my application send that message to the specific widget, depending on which hardware switch was pressed?
  • Hello Strobot,

    Yes, your description is correct. You can use the same message identifier in every callback function, but there might be an even better way:

    The current procedure would be sending the custom message to every soft-key, so if the UI needs to change you will need to call the function WM_SendMessage() several times in a row. Then there would be several callback function doing mostly the same.

    If you use a dialog, you can make the callback function of the dialog react to the according message and do all changes as part of one action. Instead of sending several messages to each soft-key, just send the message to the dialog and use the function WM_GetDialogItem() to retrieve the handles of the soft-keys. You will need to use Widget IDs to distinguish between the widgets.

    Best regards,
    Adrian
  • Hi Adrian,

    Thanks again for the help. I think I still need some clarification on how to get this all working...

    Here are some defines

    C Source Code

    1. /* custom message */
    2. #define MSG_SOFTKEY_PRESSED (WM_USER + 0)
    3. #define MSG_SOFTKEY_RELEASED (WM_USER + 1)
    4. #define MSG_SOFTKEY_NEXTSTATE (WM_USER + 2)
    5. /* Widget IDs */
    6. #define SOFTKEY_WIDGET_ID_A (GUI_ID_USER + 0)
    7. #define SOFTKEY_WIDGET_ID_B (GUI_ID_USER + 1)
    8. #define SOFTKEY_WIDGET_ID_C (GUI_ID_USER + 2)
    9. #define SOFTKEY_WIDGET_ID_D (GUI_ID_USER + 3)

    Here is where I create the button. I'm not sure what to pass WM_SetCallback(); - what is the window handle of the button widget that was just created? Same as the window ID of the widget, or is it "aButton"?

    C Source Code

    1. BUTTON_Handle aButton;
    2. aButton = BUTTON_CreateEx(5, /* x0 - leftmost pixel of widget */
    3. yLcdSize - 45, /* y0 - topmost pixel of widget */
    4. xLcdSize / 4 - 10, /* xsize - horizontal size */
    5. 50, /* ysize - vertical size */
    6. 0, /* hParent - handle of parent window */
    7. WM_CF_SHOW, /* WinFlags - window create flags */
    8. 0, /* ExFlags - doesn't matter */
    9. SOFTKEY_WIDGET_ID_A); /* Id - window ID of the widget */
    10. BUTTON_SetText(aButton, "Start Run");
    11. WM_SetCallback(SOFTKEY_WIDGET_ID_A, &_cbAbutton);
    Display All

    Here is its custom callback.

    C Source Code

    1. /* The MSG_SOFTEY_PRESSED message is sent from the softkey interfacing driver (ie an interrupt)
    2. using WM_SendMessageNoPara()*/
    3. void _cbAbutton(WM_MESSAGE * pMsg)
    4. {
    5. switch (pMsg -> MsgId)
    6. {
    7. case MSG_SOFTKEY_PRESSED:
    8. // make the button display the pressed state
    9. BUTTON_SetPressed(aButton, 1);
    10. break;
    11. case MSG_SOFTKEY_RELEASED:
    12. BUTTON_SetPressed(aButton, 0);
    13. break;
    14. case MSG_SOFTKEY_NEXTSTATE:
    15. BUTTON_SetText(aButton, "Next state");
    16. break;
    17. default:
    18. BUTTON_Callback(pMsg);
    19. }
    20. }
    Display All

    My hardware softkey driver will send... Not sure what the hWin windows handle is for the first parameter. Is it aButton, or SOFTKEY_WIDGET_ID_A ?

    C Source Code

    1. WM_SendMessageNoPara(???, MSG_SOFTKEY_PRESSED);

    The post was edited 4 times, last by strobot ().

  • Hello strobot,

    Please note that IDs and handles are not the same. For detailed information about the functions WM_SetCallback() and WM_SendMessageNoPara(), please refer to the according function description which can be found in the emWin user manual.

    Best regards,
    Adrian