|
楼主 |
发表于 2018-9-28 13:44:51
|
显示全部楼层
本帖最后由 zidone 于 2018-9-28 14:15 编辑
video_20180928_140204.mp4
(25.87 MB, 下载次数: 15)
video_20180928_133725.mp4
(44 MB, 下载次数: 13)
1.箭头只在屏幕的上三分之一的部分内移动,且与手指移动方向相反
2.执行触摸校正程序的时候,屏幕左上以及右上坐标点是可以正确校正的,下半部分两个点无法正确校正
3.我手指移动屏幕最左边,箭头基本上是移到屏幕的最右边;我手指移动到屏幕最右边,箭头基本上是移动到屏幕最左边;我手指移动到屏幕最下边,箭头移动到屏幕最上边;
但是我手指移动到屏幕最上边,箭头不能移动到屏幕最下边,基本在屏幕的上三分之一处。
4.且箭头不与手指紧密跟随- /*********************************************************************
- * SEGGER Microcontroller GmbH & Co. KG *
- * Solutions for real time microcontroller applications *
- **********************************************************************
- * *
- * (c) 1996 - 2015 SEGGER Microcontroller GmbH & Co. KG *
- * *
- * Internet: www.segger.com Support: support@segger.com *
- * *
- **********************************************************************
- ** emWin V5.30 - Graphical user interface for embedded applications **
- All Intellectual Property rights in the Software belongs to SEGGER.
- emWin is protected by international copyright laws. Knowledge of the
- source code may not be used to write a similar product. This file may
- only be used in accordance with the following terms:
- The software has been licensed to ARM LIMITED whose registered office
- is situated at 110 Fulbourn Road, Cambridge CB1 9NJ, England solely
- for the purposes of creating libraries for ARM7, ARM9, Cortex-M
- series, and Cortex-R4 processor-based devices, sublicensed and
- distributed as part of the MDK-ARM Professional under the terms and
- conditions of the End User License supplied with the MDK-ARM
- Professional.
- Full source code is available at: www.segger.com
- We appreciate your understanding and fairness.
- ----------------------------------------------------------------------
- Licensing information
- Licensor: SEGGER Software GmbH
- Licensed to: ARM Ltd
- Licensed SEGGER software: emWin
- License number: GUI-00181
- License model: LES-SLA-20007, Agreement, effective since October 1st 2011
- Licensed product: MDK-ARM Professional
- Licensed platform: ARM7/9, Cortex-M/R4
- Licensed number of seats: -
- ----------------------------------------------------------------------
- File : GUI_TOUCH_X.C
- Purpose : Config / System dependent externals for GUI
- ---------------------------END-OF-HEADER------------------------------
- */
- #include "GUI.h"
- #include "touch/bsp_touch.h"
- void GUI_TOUCH_X_ActivateX(void) {
- }
- void GUI_TOUCH_X_ActivateY(void) {
- }
- int GUI_TOUCH_X_MeasureX(void) {
- return XPT2046_ReadAdc_Fliter(XPT2046_CHANNEL_Y);
- }
- int GUI_TOUCH_X_MeasureY(void) {
- return XPT2046_ReadAdc_Fliter(XPT2046_CHANNEL_X);
- }
复制代码- #define SAMP_CNT 4 // 定义采集次数
- #define SAMP_CNT_DIV2 2 // 采集次数/2
- /**
- * 函数功能: 选择一个模拟通道,启动ADC,并返回ADC采样结果
- * 输入参数: channel :通道选择
- * 参数值:0x90 :通道Y
- * 参数值:0xd0 :通道X
- * 返 回 值: 滤波后的12位ADC值
- * 说 明:无
- */
- uint16_t XPT2046_ReadAdc_Fliter(uint8_t channel)
- {
- uint8_t i, j, min;
- uint16_t temp;
- uint16_t tempXY[SAMP_CNT];
-
- static uint16_t adc_x = 0,adc_y = 0;
- /* 如果检查到触摸屏被按下,才进行触摸屏通道采集,否则直接退出函数 */
- /* 通过触摸屏IRQ引脚可以判断触摸屏是否被触摸,有被触摸时为低电平,否则为高电平 */
- if(XPT2046_EXTI_Read()== XPT2046_EXTI_ActiveLevel)
- {
- /* 连续采样SAMP_CNT次数的数据 */
- for(i = 0;i < SAMP_CNT;i++)
- {
- XPT2046_WriteCMD(channel);
- tempXY[i] = XPT2046_ReadCMD();
- }
- /* 降序排列 */
- for(i=0; i<SAMP_CNT-1; i++)
- {
- min=i;
- for (j=i+1; j<SAMP_CNT; j++)
- {
- if (tempXY[min] > tempXY[j]) min=j;
- }
- temp = tempXY[i];
- tempXY[i] = tempXY[min];
- tempXY[min] = temp;
- }
-
- // 设定阈值
- if((tempXY[SAMP_CNT_DIV2]-tempXY[SAMP_CNT_DIV2-1]) > 5)
- {
- /* 若两个中间值相差太远,则舍弃这个新数据,返回上一次的触摸数据*/
- if(channel == XPT2046_CHANNEL_Y )
- return adc_x; //x通道
- else
- return adc_y; //y通道
- }
-
- // 求中间值的均值
- if(channel == XPT2046_CHANNEL_Y)
- {
- adc_x = (tempXY[SAMP_CNT_DIV2]+tempXY[SAMP_CNT_DIV2-1]) / 2;
- //printf("x->%d \n",adc_x);
- return adc_x;
- }
- else
- {
- adc_y = (tempXY[SAMP_CNT_DIV2]+tempXY[SAMP_CNT_DIV2-1]) / 2;
- //printf("y->%d ",adc_y);
- return adc_y;
- }
- }
- else
- {
- return 0; //没有触摸,返回0
- }
- }
复制代码- /**
- * 函数功能: 触摸校准计算
- * 输入参数: 无
- * 返 回 值: 无
- * 说 明: 无
- */
- void TOUCH_Calibrate(void)
- {
- uint16_t Calibrate_data[10];
- int aPhysX[2], aPhysY[2], aLogX[2], aLogY[2], i;
- GUI_SetBkColor(GUI_WHITE);
- GUI_Clear();
- GUI_SetColor(GUI_BLACK);
- GUI_SetFont(&GUI_Font13B_ASCII);
- _Explain();
- /* Set the logical values */
- aLogX[0] = 15;
- aLogY[0] = 15;
- aLogX[1] = LCD_GetXSize() - 20;
- aLogY[1] = LCD_GetYSize() - 20;
- /* Get the physical values of the AD converter for 2 positions */
- for (i = 0; i < 2; i++) {
- _GetPhysValues(aLogX[i], aLogY[i], &aPhysX[i], &aPhysY[i], _acPos[i]);
- }
-
-
- Calibrate_data[0]=0xAA55;
- Calibrate_data[1]=aLogX[0];
- Calibrate_data[2]=aLogX[1];
- Calibrate_data[3]=aPhysX[0];
- Calibrate_data[4]=aPhysX[1];
-
- Calibrate_data[5]=aLogY[0];
- Calibrate_data[6]=aLogY[1];
- Calibrate_data[7]=aPhysY[0];
- Calibrate_data[8]=aPhysY[1];
- Calibrate_data[9]=0x55AA;
-
- if((Calibrate_data[3]<490&&Calibrate_data[3]>260)&&(Calibrate_data[4]<3780&&Calibrate_data[4]>3490)
- &&(Calibrate_data[7]<3920&&Calibrate_data[7]>3660)&&(Calibrate_data[8]<500&&Calibrate_data[8]>270))
- {
- SPI_FLASH_SectorErase(CALIBRATE_DATA_ADDR);
- SPI_FLASH_BufferWrite((uint8_t *)Calibrate_data,CALIBRATE_DATA_ADDR, sizeof(Calibrate_data));
- /* Use the physical values to calibrate the touch screen */
- GUI_TOUCH_Calibrate(GUI_COORD_X, aLogX[0], aLogX[1], aPhysX[0], aPhysX[1]); /* Calibrate X-axis */
- GUI_TOUCH_Calibrate(GUI_COORD_Y, aLogY[0], aLogY[1], aPhysY[0], aPhysY[1]); /* Calibrate Y-axis */
-
- printf("\nGUI_COORD_X:aLogX[0]=%d,aLogX[1]=%d,aPhysX[0]=%d,aPhysX[1]=%d\n",aLogX[0], aLogX[1], aPhysX[0], aPhysX[1]);
- printf("\nGUI_COORD_Y:aLogY[0]=%d,aLogY[1]=%d,aPhysY[1]=%d,aPhysY[1]=%d\n",aLogY[0], aLogY[1], aPhysY[0], aPhysY[1]);
- }
- else
- {
- printf("触摸屏校验失败,触摸误差太大。\n");
- GUI_Clear();
- GUI_Delay(10);
- GUI_SetColor(GUI_RED);
- GUI_SetFont(GUI_FONT_20B_ASCII);
- GUI_DispStringAt("Touch Calibrate Failure!!!\n The System will Reboot",10,100);
- GUI_Delay(3000);
- Soft_Reset();
- }
-
- SPI_FLASH_BufferRead((uint8_t *)Calibrate_data,CALIBRATE_DATA_ADDR, sizeof(Calibrate_data));
- printf("Calibrate_data:\n [0]->0x%X\n [1]->%d\n [2]->%d\n [3]->%d\n [4]->%d\n",
- Calibrate_data[0],Calibrate_data[1],Calibrate_data[2],Calibrate_data[3],Calibrate_data[4]);
- printf(" [5]->%d\n [6]->%d\n [7]->%d\n [8]->%d\n [9]->0x%X\n",
- Calibrate_data[5],Calibrate_data[6],Calibrate_data[7],Calibrate_data[8],Calibrate_data[9]);
- /* Display the result */
- GUI_CURSOR_Show();
- GUI_Clear();
- _DispStringCentered("Congratulation, your\n"
- "touch screen has been\n"
- "calibrated. Please use\n"
- "the cursor to test\n"
- "the calibration...");
- /* Let the user play */
- while(1) {
- GUI_PID_STATE State;
- GUI_TOUCH_GetState(&State);
- if (State.Pressed == 1) {
- GUI_FillCircle(State.x, State.y, 3);
- }
- GUI_Delay(10);
- }
- }
复制代码
|
|