How to use a Button, created by the GUI-Builder

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

  • How to use a Button, created by the GUI-Builder

    Hey everyone,

    Since a few days I am working with the STM32F746G-Discovery Board from ST.

    For my application, I would like to use the GUI Builder and create some Windows
    with Buttons and Images.

    I successfully implemented the GUI library from ST and created a nice starting
    screen with only one button.

    The problem is, I am struggling with the handling of touch events.

    The only thing I changed so far is, that inside of the WindowDLG.c file
    (created by the GUI Builder) I added one line of code.



    C Source Code

    1. case
    2. WM_NOTIFICATION_RELEASED:
    3. //USER START (Optionally insert code for reacting on notification message)
    4. switch (Id) {
    5. case ID_BUTTON_0:
    6. WINDOW_SetBkColor(pMsg->hWin, GUI_BLUE); //<------------------------------------------
    7. break;
    8. }




    When I start the GUI and press the Button, nothing happens...
    Inside of my main.c I initialize the Touch Screen like this:


    C Source Code

    1. static void BSP_Config(void) {
    2. /* Initializes the SDRAM device */
    3. BSP_SDRAM_Init();
    4. /* Initialize the Touch screen */
    5. BSP_TS_Init(480, 272);
    6. /* Enable the CRC Module */
    7. __CRC_CLK_ENABLE()
    8. ;
    9. }
    Display All




    In addition to that, I call the following function every 50ms:


    C Source Code

    1. void BSP_Pointer_Update(void) {
    2. uint8_t text[20] = "Hello World!\n\r";
    3. GUI_PID_STATE TS_State;
    4. static TS_StateTypeDef prev_state;
    5. TS_StateTypeDef ts;
    6. uint16_t xDiff, yDiff;
    7. BSP_TS_GetState(&ts);
    8. TS_State.Pressed = ts.touchDetected;
    9. xDiff = (prev_state.touchX > ts.touchX) ?
    10. (prev_state.touchX -
    11. ts.touchX) : (ts.touchX - prev_state.touchX);
    12. yDiff = (prev_state.touchY > ts.touchY) ?
    13. (prev_state.touchY -
    14. ts.touchY) : (ts.touchY - prev_state.touchY);
    15. if(prev_state.touchDetected > 0){
    16. HAL_UART_Transmit(&huart1, text, 20,
    17. 100);
    18. }
    19. if ((prev_state.touchDetected != ts.touchDetected) || (xDiff
    20. > 3)
    21. || (yDiff > 3)) {
    22. prev_state.touchDetected =
    23. ts.touchDetected;
    24. if ((ts.touchX != 0) &&
    25. (ts.touchY != 0)) {
    26. prev_state.touchX[0] =
    27. ts.touchX[0];
    28. prev_state.touchY[0] =
    29. ts.touchY[0];
    30. }
    31. GUI_TOUCH_StoreStateEx(&TS_State);
    32. }
    33. }
    Display All




    I got this code from the Internet. I figured out, that I need this to upgrade
    the Touch status and the x and y position of the touch itself.

    I also send a String to my computer every time, I touch the screen.



    #### To sum it up:

    What do I need to change inside of the main so that the added line inside my
    WindowDLG.c file gets executed?

    (Do I need to do any additional configurations of the touchscreen? Do I need to
    put the created GUI somehow in the foreground? How do I need to change the BSP_Pointer_Update Function?)

    I really hope that somebody of you could help me. I cannot find any good
    examples or tutorials about this issue which explain the WHOLE problem.



    Kind regards

    Sören
  • Hi Sören,

    This is how we have implemented the touch into one of our STM32F746 Discovery project:

    C Source Code

    1. /*********************************************************************
    2. *
    3. * PID_X_Exec
    4. */
    5. static void PID_X_Exec(void) {
    6. TS_StateTypeDef TS_State;
    7. static GUI_PID_STATE StatePID;
    8. static int IsTouched;
    9. BSP_TS_GetState(&TS_State);
    10. StatePID.Layer = 0;
    11. if (TS_State.touchDetected) {
    12. IsTouched = 1;
    13. StatePID.Pressed = 1;
    14. StatePID.x = (int)(TS_State.touchX[0]);
    15. StatePID.y = (int)(TS_State.touchY[0]);
    16. GUI_PID_StoreState(&StatePID);
    17. } else {
    18. if (IsTouched == 1) {
    19. IsTouched = 0;
    20. StatePID.Pressed = 0;
    21. GUI_PID_StoreState(&StatePID);
    22. }
    23. }
    24. }
    Display All


    Important is that you generate up events, too, at the same position as the last down event. In our project we call this function from a dedicated touch task but it should be possible to call it from within a super loop. Once the touch input is properly passed to emWin the button should react as soon as it gets pressed.

    You can also take a look into our eval package. There is a PIDConf.c,located under Start/Setup/, which contains the function above. The package is for Embedded Studio but it should work as a reference when using a different tool chain.

    The package can be found here:
    segger.com/admin/uploads/evalB…I_IP_OS_MB_USB_160708.zip

    Regards,
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.