Source Code
- static void _Calibrate(void) {
- GUI_PID_STATE State;
- int i;
- int xSize, ySize;
- xSize = LCD_GetXSize();
- ySize = LCD_GetYSize();
- //
- // Calculate reference points depending on LCD size
- //
- _aRefX[0] = (xSize * 5) / 100;
- _aRefY[0] = (ySize * 5) / 100;
- _aRefX[1] = xSize - (xSize * 5) / 100;
- _aRefY[1] = _aRefY[0];
- _aRefX[2] = _aRefX[1];
- _aRefY[2] = ySize - (ySize * 5) / 100;
- _aRefX[3] = _aRefX[0];
- _aRefY[3] = _aRefY[2];
- _aRefX[4] = xSize / 2;
- _aRefY[4] = ySize / 2;
- //
- // Draw reference points on LCD
- //
- GUI_TOUCH_GetState(&State);
- State.Pressed = 0;
- GUI_SetPenSize(3);
- for (i = 0; i < NUM_CALIB_POINTS; i++) {
- GUI_Clear();
- GUI_DispStringHCenterAt("Please touch the point", LCD_GetXSize() / 2, LCD_GetYSize() / 2 - 60);
- GUI_DrawCircle(_aRefX[i], _aRefY[i], 5);
- while (State.Pressed != 1) {
- GUI_Delay(250);
- GUI_TOUCH_GetState(&State);
- }
- if (State.Pressed == 1) {
- //
- // Store sample points
- //
- _aSamX[i] = GUI_TOUCH_GetxPhys();
- _aSamY[i] = GUI_TOUCH_GetyPhys();
- }
- State.Pressed = 0;
- GUI_Delay(250);
- }
- //
- // Pass measured points to emWin
- //
- GUI_TOUCH_CalcCoefficients(NUM_CALIB_POINTS, _aRefX, _aRefY, _aSamX, _aSamY, xSize, ySize);
- }
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * MainTask
- */
- void MainTask(void) {
- GUI_Init();
- //
- // Calibrate touch ...
- //
- _Calibrate();
- //
- // ... and play with it
- //
- GUI_CURSOR_Show();
- BUTTON_Create(100, 100, 200, 50, 1234, WM_CF_SHOW); // A button to be touched
- while (1) {
- GUI_Delay(100);
- }
- }
I am currently working to calibrate resistive touchscreen using emWin library. I see a sample code provided in the library Touch_calibrate.c
As I am working on this, I can see that the code seems to be stuck at while (State.Pressed != 1) .
Also, I was able to implement Touch_sample.c and detect touch to see values changing for both analog inputs and positions.
If someone came across the same problem could you please advise.
Please see the code I am currently using.
Thank you in advance for all your help.
The post was edited 1 time, last by bio_med ().