Button and touch screen on stm32F4

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

  • Button and touch screen on stm32F4

    Hi, i'm trying to create my own app since the basic example "Hello word" on stm32F429I discovery (give with the firmware pack for this card). I'm using guiBuilder to design a little window with just 2 buttons for the moment. I create the C file and include it to my project. The screen show the window with the 2 buttons. For the moment all works fine, but when i touch the button 1 for example (this card is equipped with a touch sreen), this one stay pressed ! i need to touch another area on the screen to unpressed the button (or another widget). Do you know how i can proceed to unpressed the button directly after i touch the screen (like a click with a mouse) ?

    below the code i use,

    FramewinDLG.c :

    C Source Code

    1. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    2. { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 240, 320, 0, 0x64, 0 },
    3. { BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 5, 250, 100, 40, 0, 0x0, 0 },
    4. { BUTTON_CreateIndirect, "Button", ID_BUTTON_1, 125, 250, 100, 40, 0, 0x0, 0 },
    5. // USER START (Optionally insert additional widgets)
    6. // USER END
    7. };
    8. /*********************************************************************
    9. *
    10. * Static code
    11. *
    12. **********************************************************************
    13. */
    14. // USER START (Optionally insert additional static code)
    15. // USER END
    16. /*********************************************************************
    17. *
    18. * _cbDialog
    19. */
    20. static void _cbDialog(WM_MESSAGE * pMsg) {
    21. WM_HWIN hItem;
    22. int NCode;
    23. int Id;
    24. // USER START (Optionally insert additional variables)
    25. // USER END
    26. switch (pMsg->MsgId) {
    27. case WM_INIT_DIALOG:
    28. //
    29. // Initialization of 'Framewin'
    30. //
    31. hItem = pMsg->hWin;
    32. FRAMEWIN_SetText(hItem, "Test");
    33. FRAMEWIN_SetTitleHeight(hItem, 20);
    34. FRAMEWIN_SetFont(hItem, GUI_FONT_20_1);
    35. //
    36. // Initialization of 'Button'
    37. //
    38. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
    39. BUTTON_SetText(hItem, "Button 1");
    40. //
    41. // Initialization of 'Button'
    42. //
    43. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
    44. BUTTON_SetText(hItem, "Button 2");
    45. // USER START (Optionally insert additional code for further widget initialization)
    46. // USER END
    47. break;
    48. case WM_NOTIFY_PARENT:
    49. Id = WM_GetId(pMsg->hWinSrc);
    50. NCode = pMsg->Data.v;
    51. switch(Id) {
    52. case ID_BUTTON_0: // Notifications sent by 'Button'
    53. switch(NCode) {
    54. case WM_NOTIFICATION_CLICKED:
    55. // USER START (Optionally insert code for reacting on notification message)
    56. // USER END
    57. break;
    58. case WM_NOTIFICATION_RELEASED:
    59. // USER START (Optionally insert code for reacting on notification message)
    60. // USER END
    61. break;
    62. // USER START (Optionally insert additional code for further notification handling)
    63. // USER END
    64. }
    65. break;
    66. case ID_BUTTON_1: // Notifications sent by 'Button'
    67. switch(NCode) {
    68. case WM_NOTIFICATION_CLICKED:
    69. // USER START (Optionally insert code for reacting on notification message)
    70. // USER END
    71. break;
    72. case WM_NOTIFICATION_RELEASED:
    73. // USER START (Optionally insert code for reacting on notification message)
    74. // USER END
    75. break;
    76. // USER START (Optionally insert additional code for further notification handling)
    77. // USER END
    78. }
    79. break;
    80. // USER START (Optionally insert additional code for further Ids)
    81. // USER END
    82. }
    83. break;
    84. // USER START (Optionally insert additional message handling)
    85. // USER END
    86. default:
    87. WM_DefaultProc(pMsg);
    88. break;
    89. }
    90. }
    91. /*********************************************************************
    92. *
    93. * Public code
    94. *
    95. **********************************************************************
    96. */
    97. /*********************************************************************
    98. *
    99. * CreateFramewin
    100. */
    101. WM_HWIN CreateFramewin(void);
    102. WM_HWIN CreateFramewin(void) {
    103. WM_HWIN hWin;
    104. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    105. return hWin;
    106. }
    Display All


    and main.c (GUI STATE) :

    C Source Code

    1. void BSP_Pointer_Update(void)
    2. {
    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.X > ts.X) ? (prev_state.X - ts.X) : (ts.X - prev_state.X);
    10. yDiff = (prev_state.Y > ts.Y) ? (prev_state.Y - ts.Y) : (ts.Y - prev_state.Y);
    11. if(ts.TouchDetected)
    12. {
    13. if((prev_state.TouchDetected != ts.TouchDetected )||
    14. (xDiff > 3 )||
    15. (yDiff > 3))
    16. {
    17. prev_state = ts;
    18. TS_State.Layer = 0;
    19. TS_State.x = ts.X;
    20. TS_State.y = ts.Y;
    21. GUI_TOUCH_StoreStateEx(&TS_State);
    22. }
    23. }
    24. }
    Display All

    The post was edited 2 times, last by modjo ().

  • Hello,

    Please note that the function BSP_Pointer_Update() only sends touch messages to emWin in case a touch was "detected". The function GUI_TOUCH_StoreStateEx() should also be called in case the touch screen is not pressed anymore.

    Could you please tell me if this implementation is part of the package you downloaded? Was the package provided by ST or Segger? I feel that somebody already asked that question.

    Thank you.

    Best regards,
    Adrian
  • At first thanks for your answer. I downloaded this package from st (stm32 cube F4). It's based from hello word exemple (just show a string on the screen, like the documentation of emwin). If i understand, i just need to implement in BSP_Pointer_Update() a test like this

    C Source Code

    1. if(ts.TouchNoDetected)
  • Hello,

    From your already existing code I would recommend something like the following:

    C Source Code

    1. if (ts.TouchDetected) {
    2. ...
    3. TS_State.Layer = 0;
    4. TS_State.x = ts.X;
    5. TS_State.y = ts.Y;
    6. GUI_TOUCH_StoreStateEx(&TS_State);
    7. } else {
    8. TS_State.Layer = 0;
    9. TS_State.x = -1;
    10. TS_State.y = -1;
    11. GUI_TOUCH_StoreStateEx(&TS_State);
    12. }
    Display All

    Best regards,
    Adrian