00001
00002
00003
00004 #include <stdint.h>
00005 #include <stdlib.h>
00006 #include "compiler.h"
00007 #include "assert.h"
00008 #include "rtouch.h"
00009 #include "rtouch_calibrate.h"
00010
00011 #include "et024006dhu.h"
00012
00013
00014
00015
00017
00018
00019
00020
00021
00022
00023
00024 #define tft_print_string(x, y, string, color) \
00025 et024006_PrintString((string), (FONT8x8), (x), (y), (color), -1)
00026 #define tft_draw_pixel(x, y, color) \
00027 et024006_DrawPixel((x), (y), (color))
00028 #define tft_draw_filled_circle(x, y, radius, color, quadrant) \
00029 et024006_DrawFilledCircle((x), (y), (radius), (color), (quadrant))
00030
00031 #define RTOUCH_COLOR 0x0000
00032 #define TFT_WHOLE 0xff
00033
00034
00035
00036
00037
00038
00039
00040
00041 void calibratehandler( rtouch_event_t const * event );
00042
00043
00044
00045
00046
00047 static rtouch_calibration_points_t points;
00048 static rtouch_calibration_matrix_t matrix;
00049
00050 static int calibstate;
00051
00052
00053
00054
00055
00056
00057
00058 bool APP_Recalibrate( void )
00059 {
00060 calibstate = 0;
00061
00062
00063
00064 return true;
00065
00066
00067
00068 }
00069
00070
00071
00072
00073
00074 void calibratehandler( rtouch_event_t const * event )
00075 {
00076
00077
00078 }
00079
00080
00081 bool rtouch_calibrate(void)
00082 {
00083
00084 rtouch_event_t event;
00085 bool in_progress = true;
00086 static int state = 0;
00087 static rtouch_event_handler_t oldHandler;
00088
00089 switch (state) {
00090
00091 case 0:
00092
00093
00094
00095
00096 tft_print_string( 10, 10, "Touch screen calibration...",
00097 RTOUCH_COLOR);
00098
00099 points.point1.panelX = 30;
00100 points.point1.panelY = 30;
00101 points.point2.panelX = 170;
00102 points.point2.panelY = 220;
00103 points.point3.panelX = 300;
00104 points.point3.panelY = 120;
00105 tft_draw_filled_circle( points.point1.panelX,
00106 points.point1.panelY, 2, RTOUCH_COLOR, TFT_WHOLE );
00107 state = 1;
00108
00109 oldHandler = rtouch_get_event_handler();
00110 rtouch_set_event_handler( calibratehandler );
00111
00112 break;
00113
00114 case 1:
00115 if (rtouch_is_touched() == false) { break; }
00116 tft_draw_filled_circle( points.point1.panelX,
00117 points.point1.panelY, 2, RTOUCH_COLOR, TFT_WHOLE );
00118 rtouch_get_event(&event);
00119 points.point1.rawX = event.rawX;
00120 points.point1.rawY = event.rawY;
00121 state = 2;
00122
00123 break;
00124
00125 case 2:
00126 if (rtouch_is_touched() == true) { break; }
00127 tft_draw_filled_circle( points.point2.panelX,
00128 points.point2.panelY, 2, RTOUCH_COLOR, TFT_WHOLE );
00129 state = 3;
00130 break;
00131
00132 case 3:
00133 if (rtouch_is_touched() == false) { break; }
00134 tft_draw_filled_circle( points.point2.panelX,
00135 points.point2.panelY, 2, RTOUCH_COLOR, TFT_WHOLE );
00136 rtouch_get_event(&event);
00137 points.point2.rawX = event.rawX;
00138 points.point2.rawY = event.rawY;
00139 state = 4;
00140 break;
00141
00142 case 4:
00143 if (rtouch_is_touched() == true) { break; }
00144 tft_draw_filled_circle( points.point3.panelX,
00145 points.point3.panelY, 2, RTOUCH_COLOR, TFT_WHOLE );
00146 state = 5;
00147 break;
00148
00149 case 5:
00150 if (rtouch_is_touched() == false) { break; }
00151 tft_draw_filled_circle( points.point3.panelX,
00152 points.point3.panelY, 2, RTOUCH_COLOR, TFT_WHOLE );
00153 rtouch_get_event(&event);
00154 points.point3.rawX = event.rawX;
00155 points.point3.rawY = event.rawY;
00156 state = 6;
00157 break;
00158
00159 case 6:
00160 if (rtouch_is_touched() == true) { break; }
00161 rtouch_compute_calibration_matrix(&points, &matrix);
00162 rtouch_set_calibration_matrix(&matrix);
00163 state = 7;
00164
00165 rtouch_set_event_handler(oldHandler);
00166 in_progress = false;
00167 state = 0;
00168
00169 break;
00170
00171 default:
00172 break;
00173 }
00174 return in_progress;
00175 }
00176
00177
00178
00179
00180