discoverpixy
screen_calibrate.c
Go to the documentation of this file.
1 /**************************************************************************************************************************************
2 * Project: discoverpixy
3 * Website: https://github.com/t-moe/discoverpixy
4 * Authors: Aaron Schmocker, Timo Lang
5 * Institution: BFH Bern University of Applied Sciences
6 * File: common/touch/screen_calibrate.c
7 *
8 * Version History:
9 * Date Autor Email SHA Changes
10 * 2015-06-01 timolang@gmail.com 06227da Added calibrate screen (WIP). fixed bug in emulator drawing.
11 * 2015-06-01 timolang@gmail.com eb573bc Finalized calibration. Fixed a bug in screen module.
12 *
13 **************************************************************************************************************************************/
14 
15 #include "screen_calibrate.h"
16 #include "tft.h"
17 #include "touch.h"
18 
19 
20 extern volatile bool calibration; //from touch.c
21 
22 
23 static void enter(void* screen)
24 {
26 }
27 
28 static void leave(void* screen)
29 {
30 
31 }
32 
33 static void update(void* screen)
34 {
35  int x1, y1, x2, y2, dx, dy;
36 
37 
38  tft_print_line(50, 50, WHITE, BLACK, 1, "Calibration:");
39  tft_print_line(50, 120, WHITE, BLACK, 0, "Hit the markers exactly!");
40  //-----------------First Point--------------------
41  tft_draw_line(CCENTER, CBEGIN, CCENTER, CEND, WHITE); //Draw Cross
42  tft_draw_line(CBEGIN, CCENTER, CEND, CCENTER, WHITE); //Draw Cross
43  calibration = 1; //TouchX + TouchY Values will not be converted to Pixels
44 
45  while (calibration); //Wait on PenUp
46 
48  x1 = p1.x;
49  y1 = p1.y;
50  tft_fill_rectangle(CBEGIN, CBEGIN, CEND, CEND, BLACK); //Clear Cross
51 
52  //-----------------Second Point-------------------
55  calibration = 1;
56 
57  while (calibration);
58 
60  x2 = p2.x;
61  y2 = p2.y;
63 
64  //-----------------Third Point--------------------
67  calibration = 1;
68 
69  while (calibration);
70 
72  x1 += p3.x; //Add(!) values. We'll build the average later
73  y2 += p3.y;
75 
76  //------------------4. Point---------------------
79  calibration = 1;
80 
81  while (calibration);
82 
84  x2 += p4.x;
85  y1 += p4.y;
87  //-------------------Calculation---------------------
88  x1++; //Add 1 and divide by 2 later = +0.5 (for correct rounding)
89  y1++;
90  x2++;
91  y2++;
92  x1 >>= 1; //Divide by 2
93  y1 >>= 1;
94  x2 >>= 1;
95  y2 >>= 1;
96  dx = (x2 - x1); //Build the Difference
97  dy = (y2 - y1);
98 
99  touch_set_calibration_values(x1, dx, y1, dy);
100  tft_print_line(50, 120, WHITE, BLACK, 0, "Calibration Done. Press anywhere");
101 
102  calibration = 1;
103 
104  while (calibration);
105 
106  gui_screen_back();
107 
108 }
109 
110 
112  enter,
113  leave,
114  update
115 };
116 
117 
119 {
120  return &screen;
121 }
#define CCENTER
void tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:50
uint16_t y
The Y-Coordinate of the point.
Definition: touch.h:88
void tft_print_line(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char *text)
Definition: tft.c:98
uint16_t x
The X-Coordinate of the point.
Definition: touch.h:87
SCREEN_STRUCT * get_screen_calibrate()
#define DHEIGHT
static void enter(void *screen)
void tft_clear(uint16_t color)
Definition: tft.c:45
#define CBEGIN
#define WHITE
Definition: tft.h:53
static void update(void *screen)
POINT_STRUCT touch_get_last_point()
Definition: touch.c:211
void tft_fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:67
static void leave(void *screen)
static SCREEN_STRUCT screen
#define DWIDTH
#define CEND
bool gui_screen_back()
Definition: screen.c:85
void touch_set_calibration_values(int xs, int dx, int ys, int dy)
Definition: touch.c:51
#define BLACK
Definition: tft.h:54
volatile bool calibration
Definition: touch.c:40