Finalized calibration. Fixed a bug in screen module.

This commit is contained in:
t-moe
2015-06-01 23:28:31 +02:00
parent 3155f42646
commit eb573bc589
8 changed files with 92 additions and 76 deletions

View File

@@ -10,7 +10,7 @@ static CHECKBOX_STRUCT c_cbox;
static NUMUPDOWN_STRUCT n_updown; static NUMUPDOWN_STRUCT n_updown;
static void checkboxCB(void *checkbox, bool checked) { static void checkboxCB(void *checkbox, bool checked) {
printf("Checkbox %s\n",(checked?"checked":"unchecked")); // printf("Checkbox %s\n",(checked?"checked":"unchecked"));
} }
static void b_back_cb(void* button) { static void b_back_cb(void* button) {
@@ -18,7 +18,7 @@ static void b_back_cb(void* button) {
} }
static void n_updown_cb(void* numupdown, int16_t value) { static void n_updown_cb(void* numupdown, int16_t value) {
printf("New NumUpDown Value %d\n",value); //printf("New NumUpDown Value %d\n",value);
} }
static void touchCB(void* touchArea, TOUCH_ACTION triggeredAction) { static void touchCB(void* touchArea, TOUCH_ACTION triggeredAction) {

View File

@@ -45,7 +45,7 @@ void gui_screen_update() {
bool gui_screen_navigate(SCREEN_STRUCT* screen) { bool gui_screen_navigate(SCREEN_STRUCT* screen) {
if(screen==NULL) { //invalid argument passed if(screen==NULL || screen==screen_current || screen==screen_goto) { //invalid argument passed
return false; return false;
} }
screen->next = NULL; //this will become the new tail of the list, so the next pointer must be NULL screen->next = NULL; //this will become the new tail of the list, so the next pointer must be NULL

View File

@@ -3,30 +3,31 @@
#include "touch.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 extern volatile bool calibration; //from touch.c
static void enter(void* screen) { static void enter(void* screen) {
int _x1,_y1,_x2,_y2,dx,dy;
tft_clear(BLACK); tft_clear(BLACK);
}
tft_print_line(50,50,WHITE,BLACK,0,"Hit the markers exactly!"); static void leave(void* screen) {
}
static void update(void* screen) {
int x1,y1,x2,y2,dx,dy;
tft_print_line(50,50,WHITE,BLACK,1,"Calibration:");
tft_print_line(50,120,WHITE,BLACK,0,"Hit the markers exactly!");
//-----------------First Point-------------------- //-----------------First Point--------------------
tft_draw_line(CCENTER,CBEGIN,CCENTER,CEND,WHITE); //Draw Cross tft_draw_line(CCENTER,CBEGIN,CCENTER,CEND,WHITE); //Draw Cross
tft_draw_line(CBEGIN,CCENTER,CEND,CCENTER,WHITE); //Draw Cross tft_draw_line(CBEGIN,CCENTER,CEND,CCENTER,WHITE); //Draw Cross
calibration=1; //TouchX + TouchY Values will not be converted to Pixels calibration=1; //TouchX + TouchY Values will not be converted to Pixels
while(calibration); //Wait on PenUp while(calibration); //Wait on PenUp
POINT_STRUCT p1 = touch_get_last_point(); POINT_STRUCT p1 = touch_get_last_point();
_x1=p1.x; x1=p1.x;
_y1=p1.y; y1=p1.y;
tft_fill_rectangle(CBEGIN,CBEGIN,CEND,CEND,BLACK); //Clear Cross tft_fill_rectangle(CBEGIN,CBEGIN,CEND,CEND,BLACK); //Clear Cross
//-----------------Second Point------------------- //-----------------Second Point-------------------
@@ -35,8 +36,8 @@ static void enter(void* screen) {
calibration=1; calibration=1;
while(calibration); while(calibration);
POINT_STRUCT p2 = touch_get_last_point(); POINT_STRUCT p2 = touch_get_last_point();
_x2=p2.x; x2=p2.x;
_y2=p2.y; y2=p2.y;
tft_fill_rectangle(DWIDTH-CBEGIN,DHEIGHT-CBEGIN,DWIDTH-CEND,DHEIGHT-CEND,BLACK); tft_fill_rectangle(DWIDTH-CBEGIN,DHEIGHT-CBEGIN,DWIDTH-CEND,DHEIGHT-CEND,BLACK);
//-----------------Third Point-------------------- //-----------------Third Point--------------------
@@ -45,8 +46,8 @@ static void enter(void* screen) {
calibration=1; calibration=1;
while(calibration); while(calibration);
POINT_STRUCT p3 = touch_get_last_point(); POINT_STRUCT p3 = touch_get_last_point();
_x1+=p3.x; //Add(!) values. We'll build the average later x1+=p3.x; //Add(!) values. We'll build the average later
_y2+=p3.y; y2+=p3.y;
tft_fill_rectangle(CBEGIN,DHEIGHT-CBEGIN,CEND,DHEIGHT-CEND,BLACK); tft_fill_rectangle(CBEGIN,DHEIGHT-CBEGIN,CEND,DHEIGHT-CEND,BLACK);
//------------------4. Point--------------------- //------------------4. Point---------------------
@@ -55,23 +56,23 @@ static void enter(void* screen) {
calibration=1; calibration=1;
while(calibration); while(calibration);
POINT_STRUCT p4 = touch_get_last_point(); POINT_STRUCT p4 = touch_get_last_point();
_x2+=p4.x; x2+=p4.x;
_y1+=p4.y; y1+=p4.y;
tft_fill_rectangle(DWIDTH-CBEGIN,CBEGIN,DWIDTH-CEND,CEND,BLACK); tft_fill_rectangle(DWIDTH-CBEGIN,CBEGIN,DWIDTH-CEND,CEND,BLACK);
//-------------------Calculation--------------------- //-------------------Calculation---------------------
_x1++; //Add 1 and divide by 2 later = +0.5 (for correct rounding) x1++; //Add 1 and divide by 2 later = +0.5 (for correct rounding)
_y1++; y1++;
_x2++; x2++;
_y2++; y2++;
_x1>>=1; //Divide by 2 x1>>=1; //Divide by 2
_y1>>=1; y1>>=1;
_x2>>=1; x2>>=1;
_y2>>=1; y2>>=1;
dx = (_x2-_x1); //Build the Difference dx = (x2-x1); //Build the Difference
dy = (_y2-_y1); dy = (y2-y1);
touch_set_calibration_valules(_x1,dx,_y1,dy); touch_set_calibration_values(x1,dx,y1,dy);
tft_print_line(50,50,WHITE,BLACK,0,"Calibration Done. Press anywhere"); tft_print_line(50,120,WHITE,BLACK,0,"Calibration Done. Press anywhere");
calibration=1; calibration=1;
while(calibration); while(calibration);
@@ -79,14 +80,6 @@ static void enter(void* screen) {
} }
static void leave(void* screen) {
}
static void update(void* screen) {
}
static SCREEN_STRUCT screen = { static SCREEN_STRUCT screen = {
enter, enter,

View File

@@ -22,3 +22,12 @@ SCREEN_STRUCT* get_screen_calibrate();
/*@}*/ /*@}*/
/*@}*/ /*@}*/
//TODO: Move this define to a common accessible, but private header file (they are used by screen_calibrate.c and touch.c)
#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 //TODO: move define to tft module or make a function out of it
#define DHEIGHT 240 //TODO: move define to tft module or make a function out of it

View File

@@ -1,5 +1,6 @@
#include "touch.h" #include "touch.h"
#include "ll_touch.h" #include "ll_touch.h"
#include "screen_calibrate.h"
#include <stdio.h> #include <stdio.h>
/* The idea is as follows: /* The idea is as follows:
@@ -21,18 +22,16 @@ volatile POINT_STRUCT pos; //the last touch point
volatile TOUCH_STATE oldState=TOUCH_UP; //the last touch state volatile TOUCH_STATE oldState=TOUCH_UP; //the last touch state
volatile bool calibration = false; //whether or not we're currently calibrating volatile bool calibration = false; //whether or not we're currently calibrating
//Calibration Constants(Defaults= Timo's 3.2") bool use_calibration=false; //Whether or not the current platform needs calibration and recalc of the values
/*int cal_xs=0x0231;
int cal_dx=0x0C08;
int cal_ys=0x0287;
int cal_dy=0x0B56;*/
int cal_xs=20; //Calibration parameters (dummy values).
int cal_dx=20; int cal_xs=10;
int cal_ys=20; int cal_dx=100;
int cal_dy=20; int cal_ys=10;
int cal_dy=100;
void touch_set_calibration_valules(int xs, int dx, int ys, int dy) {
void touch_set_calibration_values(int xs, int dx, int ys, int dy) {
cal_xs = xs; cal_xs = xs;
cal_ys = ys; cal_ys = ys;
cal_dx = dx; cal_dx = dx;
@@ -45,6 +44,10 @@ bool touch_init() {
return ll_touch_init(); return ll_touch_init();
} }
void touch_set_value_convert_mode(bool uc) {
use_calibration=uc;
}
bool touch_add_raw_event(uint16_t touchX, uint16_t touchY, TOUCH_STATE state) { bool touch_add_raw_event(uint16_t touchX, uint16_t touchY, TOUCH_STATE state) {
//Update current and old position/state //Update current and old position/state
@@ -54,7 +57,6 @@ bool touch_add_raw_event(uint16_t touchX, uint16_t touchY, TOUCH_STATE state) {
if(calibration) //If in Calibration mode if(calibration) //If in Calibration mode
{ {
if(penDown) if(penDown)
{ {
pos.x=touchX; pos.x=touchX;
@@ -68,9 +70,16 @@ bool touch_add_raw_event(uint16_t touchX, uint16_t touchY, TOUCH_STATE state) {
return true; return true;
} }
//If we reach this point we're not in calibration mode and we need to process the event and call the registred handlers..
pos.x=touchX; if(use_calibration) { //the underlying touch hardware uses calibration
pos.y=touchY; //Calculate the real touch position out of the passed ones, and the calibration values
pos.x=touchX=(((long)(DWIDTH-2*CCENTER)*2*(long)((long)touchX-cal_xs)/cal_dx+1)>>1)+CCENTER;
pos.y=touchY=(((long)(DHEIGHT-2*CCENTER)*2*(long)((long)touchY-cal_ys)/cal_dy+1)>>1)+CCENTER;
} else { //no conversion needed for the underlying hardware
pos.x=touchX;
pos.y=touchY;
}
if(penDown) //pen is down now if(penDown) //pen is down now
{ {

View File

@@ -117,9 +117,15 @@ POINT_STRUCT touch_get_last_point();
* @param ys y offset (to calibration point 1) * @param ys y offset (to calibration point 1)
* @param dy y difference (between calibration point 1 and 2) * @param dy y difference (between calibration point 1 and 2)
*/ */
void touch_set_calibration_valules(int xs, int dx, int ys, int dy); void touch_set_calibration_values(int xs, int dx, int ys, int dy);
/**
* Set's the new value convert mode. Per default use_calibration is false.
* @param use_calibration whether or not the current platform needs display calibration
*/
void touch_set_value_convert_mode(bool use_calibration);
/*@}*/ /*@}*/
#endif /* TOUCH_H */ #endif /* TOUCH_H */

View File

@@ -1,14 +1,14 @@
#include"ll_touch.h" #include "ll_touch.h"
#include"screen.h" #include "screen.h"
#include"screen_calibrate.h" #include "screen_calibrate.h"
#include<stm32f4xx_spi.h> #include <stm32f4xx_spi.h>
#include<stm32f4xx_rcc.h> #include <stm32f4xx_rcc.h>
#include<stm32f4xx_exti.h> #include <stm32f4xx_exti.h>
#include<stm32f4xx_syscfg.h> #include <stm32f4xx_syscfg.h>
#include<tft.h> #include "tft.h"
#include<touch.h> #include "touch.h"
#include<stdio.h> #include <stdio.h>
#include<stdlib.h> #include <stdlib.h>
/* Defines ---------------------------------------------------------- */ /* Defines ---------------------------------------------------------- */
#define CLEAR_CS GPIO_ResetBits(GPIOB,GPIO_Pin_9) #define CLEAR_CS GPIO_ResetBits(GPIOB,GPIO_Pin_9)
@@ -17,13 +17,6 @@
#define REQ_X_COORD 0x90 // Request x coordinate #define REQ_X_COORD 0x90 // Request x coordinate
#define REQ_Y_COORD 0xD0 // Request y coordinate #define REQ_Y_COORD 0xD0 // Request y coordinate
#define REQ_1_DATAB 0x00 // Request one databyte #define REQ_1_DATAB 0x00 // Request one databyte
#define DWIDTH 320
#define DHEIGHT 240
#define CCENTER 20
#define x1 0x0231
#define dx 0x0C08
#define y1 0x0287
#define dy 0x0B56
#define NSAMPLE 16 #define NSAMPLE 16
/* Globals ----------------------------------------------------------- */ /* Globals ----------------------------------------------------------- */
@@ -109,6 +102,10 @@ void touch_test(uint16_t x, uint16_t y)
bool ll_touch_init() bool ll_touch_init()
{ {
touch_set_value_convert_mode(true); //Tell the touch module that we need converted values and display calibration
touch_set_calibration_values(0x0231, 0x0C08, 0x0287, 0x0B56); //set calibration values (copied from memory using the debugger)
//We have a ADS7843 Touch controller //We have a ADS7843 Touch controller
//Datasheet: http://www.ti.com/lit/ds/symlink/ads7843.pdf //Datasheet: http://www.ti.com/lit/ds/symlink/ads7843.pdf
@@ -271,9 +268,9 @@ void TIM7_IRQHandler()
TIM_Cmd(TIM7, DISABLE); // Disable the timer during the measuring TIM_Cmd(TIM7, DISABLE); // Disable the timer during the measuring
if(PENIRQ){ // Only do this if the PENIRQ line is still low if(PENIRQ){ // Only do this if the PENIRQ line is still low
for(i = 0; i < (NSAMPLE-1); i++){ // Sample 16 times and apply some calibration for(i = 0; i < (NSAMPLE-1); i++){ // Sample 16 times
x_samples[i] = (((long)(DWIDTH - 2 * CCENTER) * 2 * (long)((long)touch_get_x_coord() - x1) / dx + 1) >> 1) + CCENTER; x_samples[i] = touch_get_x_coord();
y_samples[i] = (((long)(DHEIGHT -2 * CCENTER) * 2 * (long)((long)touch_get_y_coord() - y1) / dy + 1) >> 1) + CCENTER; y_samples[i] = touch_get_y_coord();
} }
touch_add_raw_event(avg_vals(x_samples, NSAMPLE), avg_vals(y_samples, NSAMPLE), TOUCH_DOWN); // Update position touch_add_raw_event(avg_vals(x_samples, NSAMPLE), avg_vals(y_samples, NSAMPLE), TOUCH_DOWN); // Update position

View File

@@ -1,8 +1,10 @@
extern "C" { extern "C" {
#include "ll_touch.h" #include "ll_touch.h"
#include "touch.h"
} }
bool ll_touch_init() { bool ll_touch_init() {
touch_set_value_convert_mode(false); //tell the touch module that we don't need calibration or value conversion
return true; return true;
} }