Merge remote-tracking branch 'origin/emulator' into dev_aaron
This commit is contained in:
102
common/touch/screen_calibrate.c
Normal file
102
common/touch/screen_calibrate.c
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "screen_calibrate.h"
|
||||
#include "tft.h"
|
||||
#include "touch.h"
|
||||
|
||||
|
||||
#define CCENTER 20 //Pixel Distance from Sides for Calibration Cross
|
||||
#define CLENGTH 10 //Length of the Calibration Cross Lines
|
||||
#define CBEGIN (CCENTER-CLENGTH/2)
|
||||
#define CEND (CCENTER + CLENGTH/2)
|
||||
#define DWIDTH 320
|
||||
#define DHEIGHT 240
|
||||
|
||||
extern volatile bool calibration; //from touch.c
|
||||
|
||||
|
||||
static void enter(void* screen) {
|
||||
int _x1,_y1,_x2,_y2,dx,dy;
|
||||
|
||||
tft_clear(BLACK);
|
||||
|
||||
tft_print_line(50,50,WHITE,BLACK,0,"Hit the markers exactly!");
|
||||
//-----------------First Point--------------------
|
||||
tft_draw_line(CCENTER,CBEGIN,CCENTER,CEND,WHITE); //Draw Cross
|
||||
tft_draw_line(CBEGIN,CCENTER,CEND,CCENTER,WHITE); //Draw Cross
|
||||
calibration=1; //TouchX + TouchY Values will not be converted to Pixels
|
||||
while(calibration); //Wait on PenUp
|
||||
POINT_STRUCT p1 = touch_get_last_point();
|
||||
_x1=p1.x;
|
||||
_y1=p1.y;
|
||||
tft_fill_rectangle(CBEGIN,CBEGIN,CEND,CEND,BLACK); //Clear Cross
|
||||
|
||||
//-----------------Second Point-------------------
|
||||
tft_draw_line(DWIDTH-CCENTER,DHEIGHT-CBEGIN,DWIDTH-CCENTER,DHEIGHT-CEND,WHITE);
|
||||
tft_draw_line(DWIDTH-CBEGIN,DHEIGHT-CCENTER,DWIDTH-CEND,DHEIGHT-CCENTER,WHITE);
|
||||
calibration=1;
|
||||
while(calibration);
|
||||
POINT_STRUCT p2 = touch_get_last_point();
|
||||
_x2=p2.x;
|
||||
_y2=p2.y;
|
||||
tft_fill_rectangle(DWIDTH-CBEGIN,DHEIGHT-CBEGIN,DWIDTH-CEND,DHEIGHT-CEND,BLACK);
|
||||
|
||||
//-----------------Third Point--------------------
|
||||
tft_draw_line(CCENTER,DHEIGHT-CBEGIN,CCENTER,DHEIGHT-CEND,WHITE);
|
||||
tft_draw_line(CBEGIN,DHEIGHT-CCENTER,CEND,DHEIGHT-CCENTER,WHITE);
|
||||
calibration=1;
|
||||
while(calibration);
|
||||
POINT_STRUCT p3 = touch_get_last_point();
|
||||
_x1+=p3.x; //Add(!) values. We'll build the average later
|
||||
_y2+=p3.y;
|
||||
tft_fill_rectangle(CBEGIN,DHEIGHT-CBEGIN,CEND,DHEIGHT-CEND,BLACK);
|
||||
|
||||
//------------------4. Point---------------------
|
||||
tft_draw_line(DWIDTH-CCENTER,CBEGIN,DWIDTH-CCENTER,CEND,WHITE);
|
||||
tft_draw_line(DWIDTH-CBEGIN,CCENTER,DWIDTH-CEND,CCENTER,WHITE);
|
||||
calibration=1;
|
||||
while(calibration);
|
||||
POINT_STRUCT p4 = touch_get_last_point();
|
||||
_x2+=p4.x;
|
||||
_y1+=p4.y;
|
||||
tft_fill_rectangle(DWIDTH-CBEGIN,CBEGIN,DWIDTH-CEND,CEND,BLACK);
|
||||
//-------------------Calculation---------------------
|
||||
_x1++; //Add 1 and divide by 2 later = +0.5 (for correct rounding)
|
||||
_y1++;
|
||||
_x2++;
|
||||
_y2++;
|
||||
_x1>>=1; //Divide by 2
|
||||
_y1>>=1;
|
||||
_x2>>=1;
|
||||
_y2>>=1;
|
||||
dx = (_x2-_x1); //Build the Difference
|
||||
dy = (_y2-_y1);
|
||||
|
||||
touch_set_calibration_valules(_x1,dx,_y1,dy);
|
||||
tft_print_line(50,50,WHITE,BLACK,0,"Calibration Done. Press anywhere");
|
||||
|
||||
calibration=1;
|
||||
while(calibration);
|
||||
gui_screen_back();
|
||||
|
||||
}
|
||||
|
||||
static void leave(void* screen) {
|
||||
|
||||
}
|
||||
|
||||
static void update(void* screen) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
static SCREEN_STRUCT screen = {
|
||||
enter,
|
||||
leave,
|
||||
update
|
||||
};
|
||||
|
||||
|
||||
SCREEN_STRUCT* get_screen_calibrate() {
|
||||
return &screen;
|
||||
}
|
||||
|
||||
|
||||
24
common/touch/screen_calibrate.h
Normal file
24
common/touch/screen_calibrate.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "screen.h"
|
||||
|
||||
/**
|
||||
* @addtogroup touch
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup calibrate Calibrate (Screen)
|
||||
* The calibrate screen for the touch module
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
|
||||
/**
|
||||
* Returns a pointer to the calibrate screen
|
||||
* \sa gui_screen_navigate
|
||||
* @return
|
||||
*/
|
||||
SCREEN_STRUCT* get_screen_calibrate();
|
||||
|
||||
/*@}*/
|
||||
/*@}*/
|
||||
@@ -19,6 +19,27 @@ TOUCH_AREA_STRUCT* areas[NUM_AREAS] = {NULL}; //list with pointers to all manage
|
||||
|
||||
volatile POINT_STRUCT pos; //the last touch point
|
||||
volatile TOUCH_STATE oldState=TOUCH_UP; //the last touch state
|
||||
volatile bool calibration = false; //whether or not we're currently calibrating
|
||||
|
||||
//Calibration Constants(Defaults= Timo's 3.2")
|
||||
/*int cal_xs=0x0231;
|
||||
int cal_dx=0x0C08;
|
||||
int cal_ys=0x0287;
|
||||
int cal_dy=0x0B56;*/
|
||||
|
||||
int cal_xs=20;
|
||||
int cal_dx=20;
|
||||
int cal_ys=20;
|
||||
int cal_dy=20;
|
||||
|
||||
void touch_set_calibration_valules(int xs, int dx, int ys, int dy) {
|
||||
cal_xs = xs;
|
||||
cal_ys = ys;
|
||||
cal_dx = dx;
|
||||
cal_dy = dy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool touch_init() {
|
||||
return ll_touch_init();
|
||||
@@ -30,6 +51,24 @@ bool touch_add_raw_event(uint16_t touchX, uint16_t touchY, TOUCH_STATE state) {
|
||||
bool penDown = (state==TOUCH_DOWN);
|
||||
bool oldPenDown = (oldState==TOUCH_DOWN);
|
||||
oldState=state;
|
||||
|
||||
if(calibration) //If in Calibration mode
|
||||
{
|
||||
|
||||
if(penDown)
|
||||
{
|
||||
pos.x=touchX;
|
||||
pos.y=touchY;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(oldPenDown) //Run only if we got at least one pen down
|
||||
calibration=0; //Calibration finish (Touch X and Y are the values from the last measure, where the pen was down)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
pos.x=touchX;
|
||||
pos.y=touchY;
|
||||
|
||||
|
||||
@@ -110,6 +110,15 @@ void touch_unregister_area(TOUCH_AREA_STRUCT* area);
|
||||
*/
|
||||
POINT_STRUCT touch_get_last_point();
|
||||
|
||||
/**
|
||||
* Set's the new calibration values
|
||||
* @param xs x offset (to calibration point 1)
|
||||
* @param dx x difference (between calibration point 1 and 2)
|
||||
* @param ys y offset (to calibration point 1)
|
||||
* @param dy y difference (between calibration point 1 and 2)
|
||||
*/
|
||||
void touch_set_calibration_valules(int xs, int dx, int ys, int dy);
|
||||
|
||||
|
||||
/*@}*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user