New To STemWin

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

  • New To STemWin

    Hellow I am new to GUI builder I have managed to create a sample Framewin with a button, how do I make the button responsive to touch


    C Source Code

    1. /*********************************************************************
    2. * *
    3. * SEGGER Microcontroller GmbH & Co. KG *
    4. * Solutions for real time microcontroller applications *
    5. * *
    6. **********************************************************************
    7. * *
    8. * C-file generated by: *
    9. * *
    10. * GUI_Builder for emWin version 5.28 *
    11. * Compiled Jan 30 2015, 16:41:06 *
    12. * (c) 2015 Segger Microcontroller GmbH & Co. KG *
    13. * *
    14. **********************************************************************
    15. * *
    16. * Internet: www.segger.com Support: support@segger.com *
    17. * *
    18. **********************************************************************
    19. */
    20. // USER START (Optionally insert additional includes)
    21. // USER END
    22. #include "DIALOG.h"
    23. /*********************************************************************
    24. *
    25. * Defines
    26. *
    27. **********************************************************************
    28. */
    29. #define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
    30. #define ID_BUTTON_0 (GUI_ID_USER + 0x01)
    31. // USER START (Optionally insert additional defines)
    32. // USER END
    33. /*********************************************************************
    34. *
    35. * Static data
    36. *
    37. **********************************************************************
    38. */
    39. // USER START (Optionally insert additional static data)
    40. // USER END
    41. /*********************************************************************
    42. *
    43. * _aDialogCreate
    44. */
    45. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    46. { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 320, 240, 0, 0x64, 0 },
    47. { BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 67, 54, 150, 77, 0, 0x0, 0 },
    48. // USER START (Optionally insert additional widgets)
    49. void BUTTON_SetReactOnTouch(void);
    50. // USER END
    51. };
    52. /*********************************************************************
    53. *
    54. * Static code
    55. *
    56. **********************************************************************
    57. */
    58. // USER START (Optionally insert additional static code)
    59. // USER END
    60. /*********************************************************************
    61. *
    62. * _cbDialog
    63. */
    64. static void _cbDialog(WM_MESSAGE * pMsg) {
    65. WM_HWIN hItem;
    66. int NCode;
    67. int Id;
    68. // USER START (Optionally insert additional variables)
    69. // USER END
    70. switch (pMsg->MsgId) {
    71. case WM_INIT_DIALOG:
    72. //
    73. // Initialization of 'Framewin'
    74. //
    75. hItem = pMsg->hWin;
    76. FRAMEWIN_SetTitleHeight(hItem, 14);
    77. FRAMEWIN_SetText(hItem, "Smart GTI");
    78. FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_TOP);
    79. //
    80. // Initialization of 'Button'
    81. //
    82. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
    83. BUTTON_SetText(hItem, "This is me testing");
    84. // USER START (Optionally insert additional code for further widget initialization)
    85. // USER END
    86. break;
    87. case WM_NOTIFY_PARENT:
    88. Id = WM_GetId(pMsg->hWinSrc);
    89. NCode = pMsg->Data.v;
    90. switch(Id) {
    91. case ID_BUTTON_0: // Notifications sent by 'Button'
    92. switch(NCode) {
    93. case WM_NOTIFICATION_CLICKED:
    94. // USER START (Optionally insert code for reacting on notification message)
    95. // USER END
    96. break;
    97. case WM_NOTIFICATION_RELEASED:
    98. // USER START (Optionally insert code for reacting on notification message)
    99. // USER END
    100. break;
    101. // USER START (Optionally insert additional code for further notification handling)
    102. // USER END
    103. }
    104. break;
    105. // USER START (Optionally insert additional code for further Ids)
    106. // USER END
    107. }
    108. break;
    109. // USER START (Optionally insert additional message handling)
    110. // USER END
    111. default:
    112. WM_DefaultProc(pMsg);
    113. break;
    114. }
    115. }
    116. /*********************************************************************
    117. *
    118. * Public code
    119. *
    120. **********************************************************************
    121. */
    122. /*********************************************************************
    123. *
    124. * CreateFramewin
    125. */
    126. WM_HWIN CreateFramewin(void);
    127. WM_HWIN CreateFramewin(void) {
    128. WM_HWIN hWin;
    129. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    130. return hWin;
    131. }
    132. // USER START (Optionally insert additional public code)
    133. // USER END
    134. /*************************** End of file ****************************/
    Display All
  • Hi,

    Welcome to emWin.

    You have to read the touch coordinates from your touch screen and pass them to emWin.
    The touch screen initialization and how the data from the touch screen are getting received is up the user.

    In most cases we create a dedicated touch task and fill a GUI_PID_STATE structure which gets passed to the function GUI_TOUCH_StoreStateEx().
    GUI_TOUCH_StoreStateEx() fills a touch buffer in emWin.

    Here is an example of a function for touch handling it gets called periodically from a touch task (like every 25ms):

    C Source Code

    1. /*********************************************************************
    2. *
    3. * PID_X_Exec
    4. */
    5. static void PID_X_Exec(void) {
    6. TS_STATE * pStateTS;
    7. static GUI_PID_STATE StatePID;
    8. static int IsTouched;
    9. if (_IsInitialized) {
    10. pStateTS = IOE_TS_GetState(); // Read data from TC
    11. StatePID.Layer = _LayerIndex; // Set the currently selected layer
    12. if (pStateTS->TouchDetected) { // If TC reports a touch
    13. IsTouched = 1; // Remember that we had a touch
    14. StatePID.Pressed = 1; // Set Pressed state
    15. StatePID.x = XPOS(pStateTS->X); // Set x
    16. StatePID.y = YPOS(pStateTS->Y); // and y values
    17. GUI_PID_StoreState(&StatePID); // Write touch event to emWin
    18. } else {
    19. //
    20. // Create up event
    21. //
    22. if (IsTouched == 1) { // No touch detected but but there was a touch
    23. IsTouched = 0; // No touch any longer
    24. StatePID.Pressed = 0; // Set Pressed state to 0, since this is a static variable the x and y values are those from the last touch event
    25. GUI_PID_StoreState(&StatePID); // Write touch event to emWin
    26. }
    27. }
    28. }
    29. }
    Display All


    If you don't have an OS you might also call the function above from within a super loop.

    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.
  • Hey guys,
    I'm new to emWin as well. I am using a STM32 MCU and tried the 2 code snippets above. However the touch is not working :(

    The button is properly displayed however there is no reaction when i'm touching the button. I'm displaying the current touched coordinates in one corner of the screen, therefore i can see that my touch driver is working.
    SO the problem must be somewhere in my emwin routine


    Source Code

    1. /*********************************************************************
    2. *
    3. * PID_X_Exec
    4. */
    5. /*********************************************************************
    6. *
    7. * PID_X_Exec
    8. */
    9. static void PID_X_Exec(void)
    10. {
    11. static GUI_PID_STATE StatePID;
    12. static int IsTouched;
    13. if (osOK != osMutexWait(current_coordinates.mutex, 200))
    14. {
    15. //Mutex nicht erhalten
    16. }
    17. else
    18. {
    19. //Mutex erhalten
    20. StatePID.Layer = 1; // Set the currently selected layer
    21. if (current_coordinates.touch_detected)
    22. { // If TC reports a touch
    23. IsTouched = 1; // Remember that we had a touch
    24. StatePID.Pressed = 1; // Set Pressed state
    25. StatePID.x = current_coordinates.touchX; // Set x
    26. StatePID.y = current_coordinates.touchY; // and y values
    27. GUI_PID_StoreState(&StatePID); // Write touch event to emWin
    28. current_coordinates.touch_detected = 0;
    29. }
    30. else
    31. {
    32. //
    33. // Create up event
    34. //
    35. if (IsTouched == 1)
    36. { // No touch detected but but there was a touch
    37. IsTouched = 0; // No touch any longer
    38. current_coordinates.touch_detected = 0;
    39. StatePID.Pressed = 0; // Set Pressed state to 0, since this is a static variable the x and y values are those from the last touch event
    40. GUI_PID_StoreState(&StatePID); // Write touch event to emWin
    41. }
    42. }
    43. osMutexRelease(current_coordinates.mutex);
    44. }
    45. }
    Display All


    as recommended this function is running in a separate task with gets called ever 25ms. I could check in the debugger, the mutex is granted as well every time

    this is my display task

    Source Code

    1. void DisplayThread(void const * argument)
    2. {
    3. //Display Init.
    4. GUI_Init();
    5. Create_Framewindow();
    6. const size_t nMax = 32;
    7. uint8_t * touchcoords[nMax];
    8. for (;;)
    9. {
    10. snprintf((char *) touchcoords, nMax, "X: d, Y: d", touchX, touchY);
    11. GUI_DispStringAt((char *) touchcoords, 0, 0);
    12. WM_Exec();
    13. osDelay(500);
    14. }
    15. }
    Display All



    when a touch is detected the display background colour is supposed to turn red, therefore i took the code posted by BrianTaku94 and added a

    Source Code

    1. case WM_NOTIFICATION_CLICKED:
    2. // USER START (Optionally insert code for reacting on notification message)
    3. GUI_SetBkColor(GUI_RED);
    4. // USER END
    5. break;


    however the colour is not changing, do i have to redraw the display somewhere after the callback?

    Could you have a look at my problem? that would be great :)
  • Hi,

    Yes, the touch needs to be passed to the same layer as the window (or button) is created in. This is 0 per default. If you had a window in layer 1 which should receive touch input you would have to change the layer inddex for the touch to 1.

    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.