Disbale Windows Manager

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

    • Disbale Windows Manager

      Hi,

      I am using the touch calibrate sample emWin has provided. It works perfectly fine the first time I call touchCalibrate function. Once the touch is calibrated, I use Windows Manager to create a window with couple buttons.
      When a button on this screen is touched, I would like to calibrate the touchscreen again. So I am trying to use the same touchCalibrate function I used before, except now that I have a window dialog, things have to be rearranged to work with a window.

      Question: Is there a way to disable windows manager and be able to enable it once the touchscreen calibration is completed?

      Any help is really appreciated.

      Thanks and regards,
      BMD
    • Hi,

      you can activate/deactivate the Window Manager using WM_Activate() and WM_Deactivate(). However, this is not a very elegant solution.

      It would be best to do the calibration in a separate window that has the size of the screen. In the attachments you find a modified version of the sample that uses the Window Manager.

      Best regards,

      Florian
      Files
    • New

      Florian,

      Apologies for not being able to respond to you for so long. Had to work on other things meanwhile.

      Thank you so much for the sample code. I tired it. I have a problem now. Once I complete calibration, I display a different screen with buttons but touch doesn't seem to be active on this screen. I am not sure why that's happening. Could you please help me understand what could be causing this.

      Thanks and regards,
      BMD
    • New

      Hi,

      I cannot really say what is going wrong without knowing which hardware you are using or what you are doing after the calibration in your application.

      Can you provide me some information and code to reproduce the behavior?

      Thanks and best regards,

      Florian
    • New

      Florian,

      Appreciate your quick response.

      I am using the WM_TOUCH_Calibrate code you sent me. But modified it to below. tools1Screen() is just a window with a couple buttons.

      C Source Code

      1. /*********************************************************************
      2. * SEGGER MICROCONTROLLER SYSTEME GmbH *
      3. * Solutions for real time microcontroller applications *
      4. **********************************************************************
      5. * *
      6. * (c) 1996 - 2004 SEGGER Microcontroller Systeme GmbH *
      7. * *
      8. * Internet: www.segger.com Support: support@segger.com *
      9. * *
      10. **********************************************************************
      11. ***** emWin - Graphical user interface for embedded applications *****
      12. emWin is protected by international copyright laws. Knowledge of the
      13. source code may not be used to write a similar product. This file may
      14. only be used in accordance with a license and should not be re-
      15. distributed in any way. We appreciate your understanding and fairness.
      16. ----------------------------------------------------------------------
      17. File : WM_TOUCH_Calibrate.c
      18. Purpose : Demonstrates how a touch screen can be calibrated at run time
      19. Requirements: WindowManager - (X)
      20. MemoryDevices - ( )
      21. AntiAliasing - ( )
      22. VNC-Server - ( )
      23. PNG-Library - ( )
      24. TrueTypeFonts - ( )
      25. ---------------------------END-OF-HEADER------------------------------
      26. */
      27. #include "BUTTON.h"
      28. #include "DIALOG.h"
      29. #include "FS.h"
      30. #include "GlobalVariables.h"
      31. #include "GUI.h"
      32. #include "IMAGE.h"
      33. #include "Images.h"
      34. #include "Messages.h"
      35. #include "project.h"
      36. #include "Prototypes.h"
      37. #include "Screens.h"
      38. #include <stddef.h>
      39. #include <string.h>
      40. #include "TEXT.h"
      41. #include "WIDGET.h"
      42. #include "WM.h"
      43. #include "EEPROM.h"
      44. #include "GlobalDefines.h"
      45. /*********************************************************************
      46. *
      47. * Defines
      48. *
      49. **********************************************************************
      50. */
      51. #define RECOMMENDED_MEMORY (1024L * 5)
      52. unsigned char CalibrationComplete = FALSE;
      53. /*********************************************************************
      54. *
      55. * Static code
      56. *
      57. **********************************************************************
      58. */
      59. /*********************************************************************
      60. *
      61. * _cbBk
      62. */
      63. static void _cbCalibrate(WM_MESSAGE * pMsg)
      64. {
      65. static unsigned char CalibrationPoint = 0;
      66. unsigned int EEPROM_Address;
      67. unsigned char EEPROM_Byte;
      68. GUI_PID_STATE *pState;
      69. static int ReferenceX[NUM_TOUCHSCREEN_CAL_POINTS];
      70. static int ReferenceY[NUM_TOUCHSCREEN_CAL_POINTS];
      71. static int SampleX[NUM_TOUCHSCREEN_CAL_POINTS];
      72. static int SampleY[NUM_TOUCHSCREEN_CAL_POINTS];
      73. int X_Size;
      74. int Y_Size;
      75. static int Pressed;
      76. WM_HWIN hItem;
      77. hItem = pMsg->hWin;
      78. switch(pMsg->MsgId)
      79. {
      80. case WM_CREATE:
      81. X_Size = LCD_GetXSize();
      82. Y_Size = LCD_GetYSize();
      83. //
      84. // Calculate reference points depending on LCD size
      85. //
      86. ReferenceX[0] = (X_Size * 5) / 100;
      87. ReferenceY[0] = (Y_Size * 5) / 100;
      88. ReferenceX[1] = X_Size - (X_Size * 5) / 100;
      89. ReferenceY[1] = ReferenceY[0];
      90. ReferenceX[2] = ReferenceX[1];
      91. ReferenceY[2] = Y_Size - (Y_Size * 5) / 100;
      92. ReferenceX[3] = ReferenceX[0];
      93. ReferenceY[3] = ReferenceY[2];
      94. ReferenceX[4] = X_Size / 2;
      95. ReferenceY[4] = Y_Size / 2;
      96. break;
      97. case WM_PAINT:
      98. GUI_SetBkColor(GUI_BLACK);
      99. GUI_Clear();
      100. GUI_SetColor(GUI_WHITE);
      101. GUI_SetPenSize(3);
      102. GUI_DispStringHCenterAt("Please touch the point", X_Size / 2, Y_Size / 2 - 60);
      103. GUI_DrawCircle(ReferenceX[CalibrationPoint], ReferenceY[CalibrationPoint], 5);
      104. break;
      105. case WM_TOUCH:
      106. GUI_TOUCH_Exec();
      107. pState = (GUI_PID_STATE *)pMsg->Data.p;
      108. if(pState->Pressed)
      109. {
      110. Pressed = 1;
      111. }
      112. else if (Pressed)
      113. {
      114. // Store sample points
      115. SampleX[CalibrationPoint] = GUI_TOUCH_GetxPhys();
      116. SampleY[CalibrationPoint] = GUI_TOUCH_GetyPhys();
      117. CalibrationPoint++;
      118. WM_InvalidateWindow(hItem);
      119. CalibrationComplete = TRUE;
      120. if (CalibrationPoint == NUM_TOUCHSCREEN_CAL_POINTS)
      121. {
      122. EEPROM_Start();
      123. EEPROM_UpdateTemperature();
      124. EEPROM_Address = TOUCHSCREEN_CAL_UL_X_ADDR;
      125. // Pass measured points to emWin
      126. GUI_TOUCH_CalcCoefficients(NUM_TOUCHSCREEN_CAL_POINTS, ReferenceX, ReferenceY,
      127. SampleX, SampleY, X_Size, Y_Size);
      128. GUI_Clear();
      129. for(CalibrationPoint = 0; CalibrationPoint < NUM_TOUCHSCREEN_CAL_POINTS;
      130. CalibrationPoint++)
      131. {
      132. // Store the low byte of the X component of the calibration point.
      133. EEPROM_Byte = LO8(SampleX[CalibrationPoint]);
      134. EEPROM_WriteByte(EEPROM_Byte, EEPROM_Address);
      135. EEPROM_Address++;
      136. // Store the high byte of the X component of the calibration point.
      137. EEPROM_Byte = HI8(SampleX[CalibrationPoint]);
      138. EEPROM_WriteByte(EEPROM_Byte, EEPROM_Address);
      139. EEPROM_Address++;
      140. // Store the low byte of the Y component of the calibration point.
      141. EEPROM_Byte = LO8(SampleY[CalibrationPoint]);
      142. EEPROM_WriteByte(EEPROM_Byte, EEPROM_Address);
      143. EEPROM_Address++;
      144. // Store the high byte of the Y component of the calibration point.
      145. EEPROM_Byte = HI8(SampleY[CalibrationPoint]);
      146. EEPROM_WriteByte(EEPROM_Byte, EEPROM_Address);
      147. EEPROM_Address++;
      148. }// end for
      149. EEPROM_Stop();
      150. WM_DeleteWindow(hItem);
      151. tools1Screen();
      152. }
      153. }
      154. break;
      155. }
      156. }
      157. void MainTask(void)
      158. {
      159. // Check if recommended memory for the sample is available.
      160. if(GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY)
      161. {
      162. return;
      163. }// end if
      164. // Use memory devices for all windows.
      165. #if GUI_SUPPORT_MEMDEV
      166. WM_SetCreateFlags(WM_CF_MEMDEV);
      167. WM_EnableMemdev(WM_HBKWIN);
      168. #endif
      169. WM_SetDesktopColor(GUI_BLACK);
      170. WM_MULTIBUF_Enable(TRUE); // Enable multibuffering prior to drawing the screen.
      171. WM_CreateWindow(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_CF_SHOW, &_cbCalibrate, 0);
      172. }
      Display All
      Thanks and regards,
      BMD
    • New

      Florian,

      I am using resistive touchscreen.

      Source Code

      1. GUI_TOUCH_CalcCoefficients(NUM_TOUCHSCREEN_CAL_POINTS, ReferenceX, ReferenceY,
      2. SampleX, SampleY, X_Size, Y_Size);
      This is how I pass the data sent by the touch controller to emWin.


      Thanks and regards,
      BMD
    • New

      Hi,

      bio_med wrote:

      GUI_TOUCH_CalcCoefficients(NUM_TOUCHSCREEN_CAL_POINTS, ReferenceX, ReferenceY,
      SampleX, SampleY, X_Size, Y_Size);
      this routine is used for calibration. Before you can do that, the touch points have to be retrieved from the controller and sent to emWin. This is done by the routine GUI_TOUCH_StoreStateEx().

      Below you can find a (simplified) example configuration for the STM32F746G-Disco. Note that this is only an example, you have to adapt it according to your hardware. But the method of doing this is the same, you simply have to send the coordinates and pressed state to emWin based on the touch controller output using GUI_TOUCH_StoreStateEx().


      C Source Code

      1. /*********************************************************************
      2. * SEGGER Microcontroller GmbH *
      3. * The Embedded Experts *
      4. **********************************************************************
      5. * *
      6. * (c) 2003 - 2019 SEGGER Microcontroller GmbH *
      7. * *
      8. * www.segger.com Support: support@segger.com *
      9. * *
      10. **********************************************************************
      11. ----------------------------------------------------------------------
      12. File : PIDConf.c
      13. Purpose : Touch screen controller configuration
      14. ---------------------------END-OF-HEADER------------------------------
      15. */
      16. #include "GUI.h"
      17. #include "PIDConf.h"
      18. #include "RTOS.h"
      19. #include "TaskPrio.h"
      20. /*********************************************************************
      21. *
      22. * Defines
      23. *
      24. **********************************************************************
      25. */
      26. /*********************************************************************
      27. *
      28. * Static data
      29. *
      30. **********************************************************************
      31. */
      32. static U8 _IsInitialized;
      33. static int _LayerIndex;
      34. static OS_STACKPTR int Stack_Touch[128];
      35. static OS_TASK TCB_TOUCH;
      36. static void PID_X_Exec(void);
      37. static void TouchTask(void);
      38. /*********************************************************************
      39. *
      40. * Static code
      41. *
      42. **********************************************************************
      43. */
      44. /*********************************************************************
      45. *
      46. * TouchTask
      47. */
      48. static void TouchTask(void) {
      49. while(1) {
      50. PID_X_Exec();
      51. OS_Delay(25);
      52. }
      53. }
      54. /*********************************************************************
      55. *
      56. * PID_X_Exec
      57. */
      58. static void PID_X_Exec(void) {
      59. TS_StateTypeDef TS_State = {0};
      60. static GUI_PID_STATE StatePID;
      61. static int IsTouched;
      62. if (_IsInitialized) {
      63. BSP_TS_GetState(&TS_State); // Read touch input
      64. StatePID.Layer = _LayerIndex;
      65. if (TS_State.touchDetected) { // If touch detected, set up pid state structure
      66. IsTouched = 1; // Remember that last even has been touch down
      67. StatePID.Pressed = 1; // Pressed, "down event"
      68. StatePID.x = TS_State.touchX[0];
      69. StatePID.y = TS_State.touchY[0];
      70. GUI_TOUCH_StoreStateEx(&StatePID); // Pass information to emWin
      71. } else {
      72. if (IsTouched == 1) { // No touch detected but last event was touch down
      73. IsTouched = 0; // Restore IsTouched variable
      74. StatePID.Pressed = 0; // Unpressed, "up event"
      75. GUI_TOUCH_StoreStateEx(&StatePID); // Since StatePID is declared as static we use the x/y coordinate
      76. // from the down event to create an up event.
      77. }
      78. }
      79. }
      80. }
      81. /*********************************************************************
      82. *
      83. * Public code
      84. *
      85. **********************************************************************
      86. */
      87. /*********************************************************************
      88. *
      89. * PID_X_SetLayerIndex
      90. */
      91. void PID_X_SetLayerIndex(int LayerIndex) {
      92. _LayerIndex = LayerIndex;
      93. }
      94. /*********************************************************************
      95. *
      96. * PID_X_Init
      97. */
      98. void PID_X_Init(void) {
      99. int xSize, ySize;
      100. if (_IsInitialized == 0) {
      101. xSize = LCD_GetXSize();
      102. ySize = LCD_GetYSize();
      103. BSP_TS_Init(xSize, ySize);
      104. OS_CREATETASK(&TCB_TOUCH, "TouchTask", TouchTask, TASKPRIO_TOUCH, Stack_Touch);
      105. _IsInitialized = 1;
      106. }
      107. }
      108. /*************************** End of file ****************************/
      Display All
      Best regards,

      Florian