|
发表于 2014-6-28 22:44:28
|
显示全部楼层
不好意思啊,我用了下,怎么a[7]DE 数据 是 00 00 00 00 00 00 80 00 00 00 00 00 00 00 ,这么个啊,是否可以给个工程文件啊,谢谢
#include "Simulate_I2C.h"
#include"stm32f10x.h"
#include "GUI.h"
#include "GUI_X.h"
#include "tsc2046.h"
//Ìæ»»µô GUI_TOUCH_Exec±äΪ My_GUI_TOUCH_Exec
#define LCD_XSIZE (320) /* X-resolution of LCD, Logical coor. */
#define LCD_YSIZE (240) /* Y-resolution of LCD, Logical coor. */
#define MIN_AD_X 0
#define MAX_AD_X 4096
#define MIN_AD_Y 0
#define MAX_AD_Y 4096
#define ABS(v) ((v>0) ? v : -v)
typedef struct {
int x[5];
int y[5];
int xfb[5];
int yfb[5];
int a[7];
} CALIBRATION_t;
CALIBRATION_t mCurrentSettings;
extern unsigned char TOUCH_Calibrate_ok;
//--------------------------------------------------------
static BOOL perform_calibration(CALIBRATION_t *cal)
{
int j;
float n, x, y, x2, y2, xy, z, zx, zy;
float det, a, b, c, e, f, i;
float scaling = 65536.0;
// Get sums for matrix
n = x = y = x2 = y2 = xy = 0;
for (j = 0; j < 5; j++)
{
n += 1.0;
x += (float)cal->x[j];
y += (float)cal->y[j];
x2 += (float)(cal->x[j] * cal->x[j]);
y2 += (float)(cal->y[j] * cal->y[j]);
xy += (float)(cal->x[j] * cal->y[j]);
}
// Get determinant of matrix -- check if determinant is too small
det = n * (x2 * y2 - xy * xy) + x * (xy * y - x * y2) + y * (x * xy - y * x2);
if (det < 0.1 && det > -0.1)
{
return (FALSE);
}
// Get elements of inverse matrix
a = (x2 * y2 - xy * xy) / det;
b = (xy * y - x * y2) / det;
c = (x * xy - y * x2) / det;
e = (n * y2 - y * y) / det;
f = (x * y - n * xy) / det;
i = (n * x2 - x * x) / det;
// Get sums for x calibration
z = zx = zy = 0;
for (j = 0; j < 5; j++)
{
z += (float)cal->xfb[j];
zx += (float)(cal->xfb[j] * cal->x[j]);
zy += (float)(cal->xfb[j] * cal->y[j]);
}
// Now multiply out to get the calibration for framebuffer x coord
cal->a[0] = (int)((a * z + b * zx + c * zy) * (scaling));
cal->a[1] = (int)((b * z + e * zx + f * zy) * (scaling));
cal->a[2] = (int)((c * z + f * zx + i * zy) * (scaling));
// Get sums for y calibration
z = zx = zy = 0;
for (j = 0; j < 5; j++)
{
z += (float)cal->yfb[j];
zx += (float)(cal->yfb[j] * cal->x[j]);
zy += (float)(cal->yfb[j] * cal->y[j]);
}
// Now multiply out to get the calibration for framebuffer y coord
cal->a[3] = (int)((a * z + b * zx + c * zy) * (scaling));
cal->a[4] = (int)((b * z + e * zx + f * zy) * (scaling));
cal->a[5] = (int)((c * z + f * zx + i * zy) * (scaling));
// If we got here, we're OK, so assign scaling to a[6] and return
cal->a[6] = (int)scaling;
return (TRUE);
}
//-----------------------------------------------------
//¶ÁÈ¡´¥ÃþÆÁ×ø±ê£¬Î´×ö×ø±êת»»£¬²»ÄÜÖ±½ÓʹÓÃ
//Á¬Ðø¶Á2´Î£¬½á¹û+-5ÒÔÄÚÓÐЧ
static BOOL TOUCH_MeasureXY(int *x, int *y)
{
int x1, y1;
int x2, y2;
int i;
x1 = TOUCH_X_MeasureX();
y1 = TOUCH_X_MeasureY();
for (i = 0; i < 1000; i++);
x2 = TOUCH_X_MeasureX();
y2 = TOUCH_X_MeasureY();
if (ABS(x1 - x2) < 50 && ABS(y1 - y2) < 50)
{
*x = (x1 + x2) / 2;
*y = (y1 + y2) / 2;
return TRUE;
}
else
{
return FALSE;
}
}
static BOOL check_touch_pressed(int xPhys,
int yPhys)
{
if ((xPhys < MIN_AD_X) ||
(xPhys > MAX_AD_X) ||
(yPhys < MIN_AD_Y) ||
(yPhys > MAX_AD_Y))
{
return (FALSE);
}
return (TRUE);
}
static void get_sample(CALIBRATION_t *cal,
int index,
int x,
int y,
BOOL isRight)
{
int xPhys, yPhys;
GUI_SetColor(GUI_WHITE);
GUI_FillCircle(x, y, 10);
GUI_SetColor(GUI_RED);
GUI_FillCircle(x, y, 5);
GUI_SetColor(GUI_WHITE);
if (isRight)
GUI_DispStringAt("MSG_PRESS_HERE", x - 80, y - 8);
else
GUI_DispStringAt("MSG_PRESS_HERE", x + 20, y - 8);
// Wait touch to release
while (1)
{
if (TOUCH_MeasureXY(&xPhys, &yPhys))
{
if (!check_touch_pressed(xPhys, yPhys))
break;
}
// OSTimeDlyHMSM(0, 0, 0, 100);
}
// Wait touch pressed
while(1)
{
if (TOUCH_MeasureXY(&xPhys, &yPhys))
{
if (check_touch_pressed(xPhys, yPhys))
{
if (TOUCH_MeasureXY(&cal->x[index], &cal->y[index]))
break;
}
}
// OSTimeDlyHMSM(0, 0, 0, 100);
};
// Tell user to release
GUI_Clear();
if (isRight)
GUI_DispStringAt("MSG_COMPLETE", x - 80, y - 8);
else
GUI_DispStringAt("MSG_COMPLETE", x + 20, y - 8);
cal->xfb[index] = x;
cal->yfb[index] = y;
}
//*********************************************************************
// _ExecCalibration
//**********************************************************************
//
BOOL ExecCalibration(CALIBRATION_t *cal)
{
BOOL result;
GUI_RECT rect;
int xPhys;
int yPhys;
GUI_Init();
//_Calibrate upper left
GUI_SetBkColor(GUI_RED);
GUI_Clear();
// GUI_SetFont(&GUI_FontHZ_SimSun_16);
// Top Left
get_sample(cal, 0, 50, 50, FALSE);
// Top Right
get_sample(cal, 1, LCD_XSIZE - 50, 50, TRUE);
// Bottom Right
get_sample(cal, 2, LCD_XSIZE - 50, LCD_YSIZE - 50, TRUE);
// Bottom Left
get_sample(cal, 3, 50, LCD_YSIZE - 50, FALSE);
// Center
get_sample(cal, 4, LCD_XSIZE / 2, LCD_YSIZE / 2, FALSE);
rect.x0 = 0;
rect.x1 = LCD_XSIZE;
rect.y0 = 50;
rect.y1 = rect.y0 + 20;
GUI_Clear();
result = perform_calibration(cal);
if (result)
GUI_DispStringInRect("MSG_CALIBRATION_SUCCESSFUL",
&rect, GUI_TA_CENTER | GUI_TA_VCENTER);
else
GUI_DispStringInRect("MSG_CALIBRATION_SUCCESSFUL",
&rect, GUI_TA_CENTER | GUI_TA_VCENTER);
rect.y0 = 80;
rect.y1 = rect.y0 + 20;
GUI_DispNextLine();
GUI_DispStringInRect("MSG_PRESS_TOUCH_TO_CONTINUE",
&rect, GUI_TA_CENTER | GUI_TA_VCENTER);
// OSTimeDlyHMSM(0, 0, 0, 200);
// Wait the touch to continue
while (1)
{
if (TOUCH_MeasureXY(&xPhys, &yPhys))
{
if (check_touch_pressed(xPhys, yPhys))
break;
}
// OSTimeDlyHMSM(0, 0, 0, 10);
}
return (result);
}
//--------------------------------------------------------
//
// _StoreUnstable
//--------------------------------------------------------
static void _StoreUnstable1(int x, int y)
{
static int _xLast = -1;
static int _yLast = -1;
int xOut, yOut;
if ((x != -1) &&
(y != -1) &&
(_xLast != -1) &&
(_yLast != -1))
{
xOut = _xLast;
yOut = _yLast;
}
else
{
xOut = -1;
yOut = -1;
}
_xLast = x;
_yLast = y;
GUI_TOUCH_StoreUnstable(xOut, yOut);
}
//---------------------------------------------------------------------
// My_GUI_TOUCH_Exec
//
//---------------------------------------------------------------------
void My_GUI_TOUCH_Exec1()
{
int xPhys, yPhys;
int x, y;
if (TOUCH_MeasureXY(&xPhys, &yPhys))
{
// Convert values into logical values
x = (int)((mCurrentSettings.a[0] + mCurrentSettings.a[1] * xPhys +
mCurrentSettings.a[2] * yPhys) / mCurrentSettings.a[6]);
y = (int)((mCurrentSettings.a[3] + mCurrentSettings.a[4] * xPhys +
mCurrentSettings.a[5] * yPhys) / mCurrentSettings.a[6]);
if ((x < 0) || (x > LCD_XSIZE) || (y < 0) || (y > LCD_YSIZE))
{
_StoreUnstable1(-1, -1);
}
else
{
_StoreUnstable1(x, y);
}
}
}
void MainTask3(void)
{
unsigned char i;
if(ExecCalibration(&mCurrentSettings)==1)
{
USART_SendData(USART1, (unsigned char)(0xaa));
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
for(i=0;i<7;i++)
{
USART_SendData(USART1, (unsigned char)(mCurrentSettings.a>>8));
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
USART_SendData(USART1, (unsigned char)(mCurrentSettings.a));
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}
TOUCH_Calibrate_ok=1;
}
}
//-----------------------------------------------------------------------
|
|