Caiou
Dependents: LCD_Proj LCD_imagetest LCD_Proj_rtc
Fork of DmTftLibrary by
DmTouchCalibration.cpp@11:264e19992620, 2015-01-21 (annotated)
- Committer:
- displaymodule
- Date:
- Wed Jan 21 13:56:51 2015 +0000
- Revision:
- 11:264e19992620
- Parent:
- 9:bac5439e3c1c
- Child:
- 15:0c36e018a6cc
add DM_TFT43_108, DM_TFT50_111 based on new lib drv: DmTftRa8875
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
displaymodule | 7:6cd8c36cbdb3 | 1 | /********************************************************************************************** |
displaymodule | 7:6cd8c36cbdb3 | 2 | Copyright (c) 2014 DisplayModule. All rights reserved. |
displaymodule | 7:6cd8c36cbdb3 | 3 | |
displaymodule | 7:6cd8c36cbdb3 | 4 | Redistribution and use of this source code, part of this source code or any compiled binary |
displaymodule | 7:6cd8c36cbdb3 | 5 | based on this source code is permitted as long as the above copyright notice and following |
displaymodule | 7:6cd8c36cbdb3 | 6 | disclaimer is retained. |
displaymodule | 7:6cd8c36cbdb3 | 7 | |
displaymodule | 7:6cd8c36cbdb3 | 8 | DISCLAIMER: |
displaymodule | 7:6cd8c36cbdb3 | 9 | THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES |
displaymodule | 7:6cd8c36cbdb3 | 10 | NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. |
displaymodule | 7:6cd8c36cbdb3 | 11 | ********************************************************************************************/ |
displaymodule | 7:6cd8c36cbdb3 | 12 | |
displaymodule | 7:6cd8c36cbdb3 | 13 | #include "DmTouchCalibration.h" |
displaymodule | 7:6cd8c36cbdb3 | 14 | |
displaymodule | 7:6cd8c36cbdb3 | 15 | DmTouchCalibration::DmTouchCalibration(DmTftBase *tftBase, DmTouch *touch) { |
displaymodule | 7:6cd8c36cbdb3 | 16 | _tft = tftBase; |
displaymodule | 7:6cd8c36cbdb3 | 17 | _touch = touch; |
displaymodule | 7:6cd8c36cbdb3 | 18 | _textRow = 20; |
displaymodule | 7:6cd8c36cbdb3 | 19 | } |
displaymodule | 7:6cd8c36cbdb3 | 20 | |
displaymodule | 7:6cd8c36cbdb3 | 21 | // For best result, create a calibration for each display |
displaymodule | 7:6cd8c36cbdb3 | 22 | CalibrationMatrix DmTouchCalibration::getDefaultCalibrationData(DmTouch::Display disp) { |
displaymodule | 7:6cd8c36cbdb3 | 23 | CalibrationMatrix calibrationMatrix = {0}; |
displaymodule | 7:6cd8c36cbdb3 | 24 | switch (disp) { |
displaymodule | 7:6cd8c36cbdb3 | 25 | case DmTouch::DM_TFT28_103: |
displaymodule | 7:6cd8c36cbdb3 | 26 | calibrationMatrix.a = 67548; // 63787; |
displaymodule | 7:6cd8c36cbdb3 | 27 | calibrationMatrix.b = -625; // -138; |
displaymodule | 7:6cd8c36cbdb3 | 28 | calibrationMatrix.c = -16854644;//-15921157; |
displaymodule | 7:6cd8c36cbdb3 | 29 | calibrationMatrix.d = 362; // -244; |
displaymodule | 7:6cd8c36cbdb3 | 30 | calibrationMatrix.e = 89504; // 89313; |
displaymodule | 7:6cd8c36cbdb3 | 31 | calibrationMatrix.f = -14380636;//-10726623; |
displaymodule | 7:6cd8c36cbdb3 | 32 | break; |
displaymodule | 7:6cd8c36cbdb3 | 33 | |
displaymodule | 7:6cd8c36cbdb3 | 34 | case DmTouch::DM_TFT24_104: |
displaymodule | 7:6cd8c36cbdb3 | 35 | calibrationMatrix.a = -71855; |
displaymodule | 7:6cd8c36cbdb3 | 36 | calibrationMatrix.b = 2147; |
displaymodule | 7:6cd8c36cbdb3 | 37 | calibrationMatrix.c = 259719524; |
displaymodule | 7:6cd8c36cbdb3 | 38 | calibrationMatrix.d = -1339; |
displaymodule | 7:6cd8c36cbdb3 | 39 | calibrationMatrix.e = -91012; |
displaymodule | 7:6cd8c36cbdb3 | 40 | calibrationMatrix.f = 354268832; |
displaymodule | 7:6cd8c36cbdb3 | 41 | break; |
displaymodule | 7:6cd8c36cbdb3 | 42 | |
displaymodule | 7:6cd8c36cbdb3 | 43 | case DmTouch::DM_TFT28_105: |
displaymodule | 7:6cd8c36cbdb3 | 44 | calibrationMatrix.a = 65521; |
displaymodule | 7:6cd8c36cbdb3 | 45 | calibrationMatrix.b = -253; |
displaymodule | 7:6cd8c36cbdb3 | 46 | calibrationMatrix.c = -11813673; |
displaymodule | 7:6cd8c36cbdb3 | 47 | calibrationMatrix.d = -439; |
displaymodule | 7:6cd8c36cbdb3 | 48 | calibrationMatrix.e = 89201; |
displaymodule | 7:6cd8c36cbdb3 | 49 | calibrationMatrix.f = -10450920; |
displaymodule | 7:6cd8c36cbdb3 | 50 | break; |
displaymodule | 7:6cd8c36cbdb3 | 51 | |
displaymodule | 7:6cd8c36cbdb3 | 52 | case DmTouch::DM_TFT35_107: |
displaymodule | 7:6cd8c36cbdb3 | 53 | calibrationMatrix.a = 91302; // 85984; |
displaymodule | 7:6cd8c36cbdb3 | 54 | calibrationMatrix.b = 817; // 451; |
displaymodule | 7:6cd8c36cbdb3 | 55 | calibrationMatrix.c = -26296117;//-16494041; |
displaymodule | 7:6cd8c36cbdb3 | 56 | calibrationMatrix.d = -1877; // 2308; |
displaymodule | 7:6cd8c36cbdb3 | 57 | calibrationMatrix.e = 73762; // 65173; |
displaymodule | 7:6cd8c36cbdb3 | 58 | calibrationMatrix.f = -26384255;//-19179080; |
displaymodule | 7:6cd8c36cbdb3 | 59 | break; |
displaymodule | 11:264e19992620 | 60 | case DmTouch::DM_TFT43_108: // or DM_TFT43_110 |
displaymodule | 11:264e19992620 | 61 | calibrationMatrix.a = 541307; |
displaymodule | 11:264e19992620 | 62 | calibrationMatrix.b = -4288; |
displaymodule | 11:264e19992620 | 63 | calibrationMatrix.c = -36678732; |
displaymodule | 11:264e19992620 | 64 | calibrationMatrix.d = 2730; |
displaymodule | 11:264e19992620 | 65 | calibrationMatrix.e = 321714; |
displaymodule | 11:264e19992620 | 66 | calibrationMatrix.f = -31439472; |
displaymodule | 11:264e19992620 | 67 | break; |
displaymodule | 11:264e19992620 | 68 | case DmTouch::DM_TFT50_111: // or DM_TFT50_112 |
displaymodule | 11:264e19992620 | 69 | calibrationMatrix.a = 875894; |
displaymodule | 11:264e19992620 | 70 | calibrationMatrix.b = 1655; |
displaymodule | 11:264e19992620 | 71 | calibrationMatrix.c = -53695309; |
displaymodule | 11:264e19992620 | 72 | calibrationMatrix.d = -993; |
displaymodule | 11:264e19992620 | 73 | calibrationMatrix.e = 544421; |
displaymodule | 11:264e19992620 | 74 | calibrationMatrix.f = -41496753; |
displaymodule | 11:264e19992620 | 75 | break; |
displaymodule | 7:6cd8c36cbdb3 | 76 | default: |
displaymodule | 7:6cd8c36cbdb3 | 77 | break; |
displaymodule | 7:6cd8c36cbdb3 | 78 | } |
displaymodule | 7:6cd8c36cbdb3 | 79 | return calibrationMatrix; |
displaymodule | 7:6cd8c36cbdb3 | 80 | } |
displaymodule | 7:6cd8c36cbdb3 | 81 | |
displaymodule | 7:6cd8c36cbdb3 | 82 | |
displaymodule | 7:6cd8c36cbdb3 | 83 | bool DmTouchCalibration::getTouchReferencePoints(Point displayRefPoint[], Point touchRefPoint[], uint16_t tftWidth, uint16_t tftHeight) { |
displaymodule | 7:6cd8c36cbdb3 | 84 | _touch->setPrecison(60); |
displaymodule | 7:6cd8c36cbdb3 | 85 | displayRefPoint[0].x = (tftWidth / 2); |
displaymodule | 7:6cd8c36cbdb3 | 86 | displayRefPoint[0].y = (tftHeight / 2); |
displaymodule | 7:6cd8c36cbdb3 | 87 | displayRefPoint[1].x = 1 * (tftWidth / 5); |
displaymodule | 7:6cd8c36cbdb3 | 88 | displayRefPoint[1].y = 1 * (tftHeight / 5); |
displaymodule | 7:6cd8c36cbdb3 | 89 | displayRefPoint[2].x = 4 * (tftWidth / 5); |
displaymodule | 7:6cd8c36cbdb3 | 90 | displayRefPoint[2].y = 1 * (tftHeight / 5); |
displaymodule | 7:6cd8c36cbdb3 | 91 | displayRefPoint[3].x = 4 * (tftWidth / 5); |
displaymodule | 7:6cd8c36cbdb3 | 92 | displayRefPoint[3].y = 4 * (tftHeight / 5); |
displaymodule | 7:6cd8c36cbdb3 | 93 | displayRefPoint[4].x = 1 * (tftWidth / 5); |
displaymodule | 7:6cd8c36cbdb3 | 94 | displayRefPoint[4].y = 4 * (tftHeight / 5); |
displaymodule | 7:6cd8c36cbdb3 | 95 | |
displaymodule | 7:6cd8c36cbdb3 | 96 | for(int n = 0; n < 5; n++) { |
displaymodule | 7:6cd8c36cbdb3 | 97 | drawCalibPoint(displayRefPoint[n].x, displayRefPoint[n].y); |
displaymodule | 7:6cd8c36cbdb3 | 98 | if (!getRawTouch(touchRefPoint[n].x, touchRefPoint[n].y)) { |
displaymodule | 7:6cd8c36cbdb3 | 99 | return false; |
displaymodule | 7:6cd8c36cbdb3 | 100 | } |
displaymodule | 7:6cd8c36cbdb3 | 101 | releaseTouch(displayRefPoint[n].x, displayRefPoint[n].y); |
displaymodule | 7:6cd8c36cbdb3 | 102 | } |
displaymodule | 7:6cd8c36cbdb3 | 103 | |
displaymodule | 7:6cd8c36cbdb3 | 104 | _touch->setPrecison(3); |
displaymodule | 7:6cd8c36cbdb3 | 105 | return true; |
displaymodule | 7:6cd8c36cbdb3 | 106 | } |
displaymodule | 7:6cd8c36cbdb3 | 107 | |
displaymodule | 7:6cd8c36cbdb3 | 108 | bool DmTouchCalibration::getRawTouch(uint16_t& x, uint16_t& y) const { |
displaymodule | 7:6cd8c36cbdb3 | 109 | bool touched = false; |
displaymodule | 9:bac5439e3c1c | 110 | bool haveAllSamples = false; |
displaymodule | 7:6cd8c36cbdb3 | 111 | |
displaymodule | 7:6cd8c36cbdb3 | 112 | while(!touched) { |
displaymodule | 7:6cd8c36cbdb3 | 113 | if (_touch->isTouched()) { |
displaymodule | 7:6cd8c36cbdb3 | 114 | //Serial.println("is touched"); |
displaymodule | 9:bac5439e3c1c | 115 | haveAllSamples = _touch->getMiddleXY(x, y); |
displaymodule | 9:bac5439e3c1c | 116 | |
displaymodule | 9:bac5439e3c1c | 117 | // As many samples are take during calibration it is important to |
displaymodule | 9:bac5439e3c1c | 118 | // make sure that the screen is still touched. If the user has let |
displaymodule | 9:bac5439e3c1c | 119 | // go already then the gathered samples are not good enough. |
displaymodule | 9:bac5439e3c1c | 120 | touched = haveAllSamples && _touch->isTouched(); |
displaymodule | 7:6cd8c36cbdb3 | 121 | } |
displaymodule | 7:6cd8c36cbdb3 | 122 | } |
displaymodule | 9:bac5439e3c1c | 123 | return haveAllSamples; |
displaymodule | 7:6cd8c36cbdb3 | 124 | } |
displaymodule | 7:6cd8c36cbdb3 | 125 | |
displaymodule | 7:6cd8c36cbdb3 | 126 | void DmTouchCalibration::drawCalibPoint(uint16_t x, uint16_t y) const { |
displaymodule | 7:6cd8c36cbdb3 | 127 | const uint8_t lineSize = 5; |
displaymodule | 7:6cd8c36cbdb3 | 128 | _tft->drawHorizontalLine(x-lineSize, y, lineSize*2, RED); |
displaymodule | 7:6cd8c36cbdb3 | 129 | _tft->drawVerticalLine(x, y-lineSize, lineSize*2, RED); |
displaymodule | 7:6cd8c36cbdb3 | 130 | } |
displaymodule | 7:6cd8c36cbdb3 | 131 | |
displaymodule | 7:6cd8c36cbdb3 | 132 | void DmTouchCalibration::releaseTouch(uint16_t x, uint16_t y) const { |
displaymodule | 7:6cd8c36cbdb3 | 133 | _tft->drawCircle(x, y, 10, YELLOW); |
displaymodule | 7:6cd8c36cbdb3 | 134 | delay(100); |
displaymodule | 7:6cd8c36cbdb3 | 135 | _tft->fillCircle(x, y, 10, GREEN); |
displaymodule | 7:6cd8c36cbdb3 | 136 | delay(100); |
displaymodule | 7:6cd8c36cbdb3 | 137 | _tft->fillCircle(x, y, 10, BLACK); |
displaymodule | 7:6cd8c36cbdb3 | 138 | delay(300); |
displaymodule | 7:6cd8c36cbdb3 | 139 | _touch->waitForTouchRelease(); |
displaymodule | 7:6cd8c36cbdb3 | 140 | } |
displaymodule | 7:6cd8c36cbdb3 | 141 | |
displaymodule | 7:6cd8c36cbdb3 | 142 | CalibrationMatrix DmTouchCalibration::calculateCalibrationMatrix(Point displayRefPoint[], Point touchRefPoint[]) { |
displaymodule | 7:6cd8c36cbdb3 | 143 | double A = 0.0, B = 0.0, C = 0.0, D = 0.0, E = 0.0, F = 0.0; |
displaymodule | 7:6cd8c36cbdb3 | 144 | double d = 0.0, dx1 = 0.0, dx2 = 0.0, dx3 = 0.0, dy1 = 0.0, dy2 = 0.0, dy3 = 0.0; |
displaymodule | 7:6cd8c36cbdb3 | 145 | uint32_t X2_1 = 0, X2_2 = 0, X2_3 = 0, X2_4 = 0, X2_5 = 0; |
displaymodule | 7:6cd8c36cbdb3 | 146 | uint32_t Y2_1 = 0, Y2_2 = 0, Y2_3 = 0, Y2_4 = 0, Y2_5 = 0; |
displaymodule | 7:6cd8c36cbdb3 | 147 | uint32_t XxY_1 = 0, XxY_2 = 0, XxY_3 = 0, XxY_4 = 0, XxY_5 = 0; |
displaymodule | 7:6cd8c36cbdb3 | 148 | uint32_t XxXd_1 = 0, XxXd_2 = 0, XxXd_3 = 0, XxXd_4 = 0, XxXd_5 = 0; |
displaymodule | 7:6cd8c36cbdb3 | 149 | uint32_t YxXd_1 = 0, YxXd_2 = 0, YxXd_3 = 0, YxXd_4 = 0, YxXd_5 = 0; |
displaymodule | 7:6cd8c36cbdb3 | 150 | uint32_t XxYd_1 = 0, XxYd_2 = 0, XxYd_3 = 0, XxYd_4 = 0, XxYd_5 = 0; |
displaymodule | 7:6cd8c36cbdb3 | 151 | uint32_t YxYd_1 = 0, YxYd_2 = 0, YxYd_3 = 0, YxYd_4 = 0, YxYd_5 = 0; |
displaymodule | 7:6cd8c36cbdb3 | 152 | uint32_t alfa = 0, beta = 0, chi = 0, Kx = 0, Ky = 0, Lx = 0, Ly = 0; |
displaymodule | 7:6cd8c36cbdb3 | 153 | uint16_t epsilon = 0, fi = 0, Mx = 0, My = 0; |
displaymodule | 7:6cd8c36cbdb3 | 154 | |
displaymodule | 7:6cd8c36cbdb3 | 155 | X2_1 = ((uint32_t)touchRefPoint[0].x * touchRefPoint[0].x); |
displaymodule | 7:6cd8c36cbdb3 | 156 | X2_2 = ((uint32_t)touchRefPoint[1].x * touchRefPoint[1].x); |
displaymodule | 7:6cd8c36cbdb3 | 157 | X2_3 = ((uint32_t)touchRefPoint[2].x * touchRefPoint[2].x); |
displaymodule | 7:6cd8c36cbdb3 | 158 | X2_4 = ((uint32_t)touchRefPoint[3].x * touchRefPoint[3].x); |
displaymodule | 7:6cd8c36cbdb3 | 159 | X2_5 = ((uint32_t)touchRefPoint[4].x * touchRefPoint[4].x); |
displaymodule | 7:6cd8c36cbdb3 | 160 | |
displaymodule | 7:6cd8c36cbdb3 | 161 | Y2_1 = ((uint32_t)touchRefPoint[0].y * touchRefPoint[0].y); |
displaymodule | 7:6cd8c36cbdb3 | 162 | Y2_2 = ((uint32_t)touchRefPoint[1].y * touchRefPoint[1].y); |
displaymodule | 7:6cd8c36cbdb3 | 163 | Y2_3 = ((uint32_t)touchRefPoint[2].y * touchRefPoint[2].y); |
displaymodule | 7:6cd8c36cbdb3 | 164 | Y2_4 = ((uint32_t)touchRefPoint[3].y * touchRefPoint[3].y); |
displaymodule | 7:6cd8c36cbdb3 | 165 | Y2_5 = ((uint32_t)touchRefPoint[4].y * touchRefPoint[4].y); |
displaymodule | 7:6cd8c36cbdb3 | 166 | |
displaymodule | 7:6cd8c36cbdb3 | 167 | XxY_1 = ((uint32_t)touchRefPoint[0].x * touchRefPoint[0].y); |
displaymodule | 7:6cd8c36cbdb3 | 168 | XxY_2 = ((uint32_t)touchRefPoint[1].x * touchRefPoint[1].y); |
displaymodule | 7:6cd8c36cbdb3 | 169 | XxY_3 = ((uint32_t)touchRefPoint[2].x * touchRefPoint[2].y); |
displaymodule | 7:6cd8c36cbdb3 | 170 | XxY_4 = ((uint32_t)touchRefPoint[3].x * touchRefPoint[3].y); |
displaymodule | 7:6cd8c36cbdb3 | 171 | XxY_5 = ((uint32_t)touchRefPoint[4].x * touchRefPoint[4].y); |
displaymodule | 7:6cd8c36cbdb3 | 172 | |
displaymodule | 7:6cd8c36cbdb3 | 173 | XxXd_1 = ((uint32_t)touchRefPoint[0].x * displayRefPoint[0].x); |
displaymodule | 7:6cd8c36cbdb3 | 174 | XxXd_2 = ((uint32_t)touchRefPoint[1].x * displayRefPoint[1].x); |
displaymodule | 7:6cd8c36cbdb3 | 175 | XxXd_3 = ((uint32_t)touchRefPoint[2].x * displayRefPoint[2].x); |
displaymodule | 7:6cd8c36cbdb3 | 176 | XxXd_4 = ((uint32_t)touchRefPoint[3].x * displayRefPoint[3].x); |
displaymodule | 7:6cd8c36cbdb3 | 177 | XxXd_5 = ((uint32_t)touchRefPoint[4].x * displayRefPoint[4].x); |
displaymodule | 7:6cd8c36cbdb3 | 178 | |
displaymodule | 7:6cd8c36cbdb3 | 179 | YxXd_1 = ((uint32_t)touchRefPoint[0].y * displayRefPoint[0].x); |
displaymodule | 7:6cd8c36cbdb3 | 180 | YxXd_2 = ((uint32_t)touchRefPoint[1].y * displayRefPoint[1].x); |
displaymodule | 7:6cd8c36cbdb3 | 181 | YxXd_3 = ((uint32_t)touchRefPoint[2].y * displayRefPoint[2].x); |
displaymodule | 7:6cd8c36cbdb3 | 182 | YxXd_4 = ((uint32_t)touchRefPoint[3].y * displayRefPoint[3].x); |
displaymodule | 7:6cd8c36cbdb3 | 183 | YxXd_5 = ((uint32_t)touchRefPoint[4].y * displayRefPoint[4].x); |
displaymodule | 7:6cd8c36cbdb3 | 184 | |
displaymodule | 7:6cd8c36cbdb3 | 185 | XxYd_1 = ((uint32_t)touchRefPoint[0].x * displayRefPoint[0].y); |
displaymodule | 7:6cd8c36cbdb3 | 186 | XxYd_2 = ((uint32_t)touchRefPoint[1].x * displayRefPoint[1].y); |
displaymodule | 7:6cd8c36cbdb3 | 187 | XxYd_3 = ((uint32_t)touchRefPoint[2].x * displayRefPoint[2].y); |
displaymodule | 7:6cd8c36cbdb3 | 188 | XxYd_4 = ((uint32_t)touchRefPoint[3].x * displayRefPoint[3].y); |
displaymodule | 7:6cd8c36cbdb3 | 189 | XxYd_5 = ((uint32_t)touchRefPoint[4].x * displayRefPoint[4].y); |
displaymodule | 7:6cd8c36cbdb3 | 190 | |
displaymodule | 7:6cd8c36cbdb3 | 191 | YxYd_1 = ((uint32_t)touchRefPoint[0].y * displayRefPoint[0].y); |
displaymodule | 7:6cd8c36cbdb3 | 192 | YxYd_2 = ((uint32_t)touchRefPoint[1].y * displayRefPoint[1].y); |
displaymodule | 7:6cd8c36cbdb3 | 193 | YxYd_3 = ((uint32_t)touchRefPoint[2].y * displayRefPoint[2].y); |
displaymodule | 7:6cd8c36cbdb3 | 194 | YxYd_4 = ((uint32_t)touchRefPoint[3].y * displayRefPoint[3].y); |
displaymodule | 7:6cd8c36cbdb3 | 195 | YxYd_5 = ((uint32_t)touchRefPoint[4].y * displayRefPoint[4].y); |
displaymodule | 7:6cd8c36cbdb3 | 196 | |
displaymodule | 7:6cd8c36cbdb3 | 197 | alfa = X2_1 + X2_2 + X2_3 + X2_4 + X2_5; |
displaymodule | 7:6cd8c36cbdb3 | 198 | beta = Y2_1 + Y2_2 + Y2_3 + Y2_4 + Y2_5; |
displaymodule | 7:6cd8c36cbdb3 | 199 | chi = XxY_1 + XxY_2 + XxY_3 + XxY_4 + XxY_5; |
displaymodule | 7:6cd8c36cbdb3 | 200 | epsilon = touchRefPoint[0].x + touchRefPoint[1].x + touchRefPoint[2].x + touchRefPoint[3].x + touchRefPoint[4].x; |
displaymodule | 7:6cd8c36cbdb3 | 201 | fi = touchRefPoint[0].y + touchRefPoint[1].y + touchRefPoint[2].y + touchRefPoint[3].y + touchRefPoint[4].y; |
displaymodule | 7:6cd8c36cbdb3 | 202 | Kx = XxXd_1 + XxXd_2 + XxXd_3 + XxXd_4 + XxXd_5; |
displaymodule | 7:6cd8c36cbdb3 | 203 | Ky = XxYd_1 + XxYd_2 + XxYd_3 + XxYd_4 + XxYd_5; |
displaymodule | 7:6cd8c36cbdb3 | 204 | Lx = YxXd_1 + YxXd_2 + YxXd_3 + YxXd_4 + YxXd_5; |
displaymodule | 7:6cd8c36cbdb3 | 205 | Ly = YxYd_1 + YxYd_2 + YxYd_3 + YxYd_4 + YxYd_5; |
displaymodule | 7:6cd8c36cbdb3 | 206 | Mx = displayRefPoint[0].x + displayRefPoint[1].x + displayRefPoint[2].x + displayRefPoint[3].x + displayRefPoint[4].x; |
displaymodule | 7:6cd8c36cbdb3 | 207 | My = displayRefPoint[0].y + displayRefPoint[1].y + displayRefPoint[2].y + displayRefPoint[3].y + displayRefPoint[4].y; |
displaymodule | 7:6cd8c36cbdb3 | 208 | d = 5 * ( ((double)alfa * beta) - ((double)chi * chi) ) + 2 * ((double)chi * epsilon * fi) - ((double)alfa * fi * fi ) - ( (double)beta * epsilon * epsilon ); |
displaymodule | 7:6cd8c36cbdb3 | 209 | dx1 = 5 * ( ((double)Kx * beta) - ((double)Lx * chi) ) + ((double)fi * ( ((double)Lx * epsilon) - ((double)Kx * fi) )) + ((double)Mx * ( ((double)chi * fi) - ((double)beta * epsilon) )); |
displaymodule | 7:6cd8c36cbdb3 | 210 | dx2 = 5 * ( ((double)Lx * alfa) - ((double)Kx * chi) ) + ((double)epsilon * ( ((double)Kx * fi) - ((double)Lx * epsilon) )) + ((double)Mx * ( ((double)chi * epsilon) - ((double)alfa * fi) )); |
displaymodule | 7:6cd8c36cbdb3 | 211 | dx3 = ((double)Kx * ( ((double)chi * fi) - ((double)beta * epsilon) )) + ((double)Lx * ( ((double)chi * epsilon) - ((double)alfa * fi) )) + ((double)Mx * ( ((double)alfa * beta) - ((double)chi * chi) )); |
displaymodule | 7:6cd8c36cbdb3 | 212 | dy1 = 5 * ( ((double)Ky * beta) - ((double)Ly * chi) ) + ((double)fi * ( ((double)Ly * epsilon) - ((double)Ky * fi) )) + ((double)My * ( ((double)chi * fi) - ((double)beta * epsilon) )); |
displaymodule | 7:6cd8c36cbdb3 | 213 | dy2 = 5 * ( ((double)Ly * alfa) - ((double)Ky * chi) ) + ((double)epsilon * ( ((double)Ky * fi) - ((double)Ly * epsilon) )) + ((double)My * ( ((double)chi * epsilon) - ((double)alfa * fi) )); |
displaymodule | 7:6cd8c36cbdb3 | 214 | dy3 = ((double)Ky * ( ((double)chi * fi) - ((double)beta * epsilon) )) + ((double)Ly * ( ((double)chi * epsilon) - ((double)alfa * fi) )) + ((double)My * ( ((double)alfa * beta) - ((double)chi * chi) )); |
displaymodule | 7:6cd8c36cbdb3 | 215 | |
displaymodule | 7:6cd8c36cbdb3 | 216 | A = dx1 / d; |
displaymodule | 7:6cd8c36cbdb3 | 217 | B = dx2 / d; |
displaymodule | 7:6cd8c36cbdb3 | 218 | C = dx3 / d; |
displaymodule | 7:6cd8c36cbdb3 | 219 | D = dy1 / d; |
displaymodule | 7:6cd8c36cbdb3 | 220 | E = dy2 / d; |
displaymodule | 7:6cd8c36cbdb3 | 221 | F = dy3 / d; |
displaymodule | 7:6cd8c36cbdb3 | 222 | |
displaymodule | 7:6cd8c36cbdb3 | 223 | CalibrationMatrix calibrationData; |
displaymodule | 7:6cd8c36cbdb3 | 224 | calibrationData.a = (int32_t)(A * _touch->rescaleFactor()); |
displaymodule | 7:6cd8c36cbdb3 | 225 | calibrationData.b = (int32_t)(B * _touch->rescaleFactor()); |
displaymodule | 7:6cd8c36cbdb3 | 226 | calibrationData.c = (int32_t)(C * _touch->rescaleFactor()); |
displaymodule | 7:6cd8c36cbdb3 | 227 | calibrationData.d = (int32_t)(D * _touch->rescaleFactor()); |
displaymodule | 7:6cd8c36cbdb3 | 228 | calibrationData.e = (int32_t)(E * _touch->rescaleFactor()); |
displaymodule | 7:6cd8c36cbdb3 | 229 | calibrationData.f = (int32_t)(F * _touch->rescaleFactor()); |
displaymodule | 7:6cd8c36cbdb3 | 230 | return calibrationData; |
displaymodule | 7:6cd8c36cbdb3 | 231 | } |
displaymodule | 7:6cd8c36cbdb3 | 232 | |
displaymodule | 7:6cd8c36cbdb3 | 233 | void DmTouchCalibration::drawCalibration(CalibrationMatrix calibrationMatrix) { |
displaymodule | 7:6cd8c36cbdb3 | 234 | printHeadline("CalibrationData: "); |
displaymodule | 7:6cd8c36cbdb3 | 235 | printHeadline("a: "); |
displaymodule | 7:6cd8c36cbdb3 | 236 | printNumber(calibrationMatrix.a); |
displaymodule | 7:6cd8c36cbdb3 | 237 | printHeadline("b: "); |
displaymodule | 7:6cd8c36cbdb3 | 238 | printNumber(calibrationMatrix.b); |
displaymodule | 7:6cd8c36cbdb3 | 239 | printHeadline("c: "); |
displaymodule | 7:6cd8c36cbdb3 | 240 | printNumber(calibrationMatrix.c); |
displaymodule | 7:6cd8c36cbdb3 | 241 | printHeadline("d: "); |
displaymodule | 7:6cd8c36cbdb3 | 242 | printNumber(calibrationMatrix.d); |
displaymodule | 7:6cd8c36cbdb3 | 243 | printHeadline("e: "); |
displaymodule | 7:6cd8c36cbdb3 | 244 | printNumber(calibrationMatrix.e); |
displaymodule | 7:6cd8c36cbdb3 | 245 | printHeadline("f: "); |
displaymodule | 7:6cd8c36cbdb3 | 246 | printNumber(calibrationMatrix.f); |
displaymodule | 7:6cd8c36cbdb3 | 247 | } |
displaymodule | 7:6cd8c36cbdb3 | 248 | |
displaymodule | 7:6cd8c36cbdb3 | 249 | void DmTouchCalibration::printHeadline(char* text) { |
displaymodule | 7:6cd8c36cbdb3 | 250 | _textRow += 20; |
displaymodule | 7:6cd8c36cbdb3 | 251 | _tft->drawString(5, _textRow, text); |
displaymodule | 7:6cd8c36cbdb3 | 252 | } |
displaymodule | 7:6cd8c36cbdb3 | 253 | |
displaymodule | 7:6cd8c36cbdb3 | 254 | void DmTouchCalibration::printNumber(int32_t number) const { |
displaymodule | 7:6cd8c36cbdb3 | 255 | _tft->drawNumber(20, _textRow, number, 10, false); |
displaymodule | 7:6cd8c36cbdb3 | 256 | } |
displaymodule | 7:6cd8c36cbdb3 | 257 | |
displaymodule | 7:6cd8c36cbdb3 | 258 | void DmTouchCalibration::printCalibration(CalibrationMatrix calibrationMatrix) const { |
displaymodule | 7:6cd8c36cbdb3 | 259 | #if defined (DM_TOOLCHAIN_ARDUINO) |
displaymodule | 7:6cd8c36cbdb3 | 260 | Serial.println(F("-------- Calibration data ------")); |
displaymodule | 7:6cd8c36cbdb3 | 261 | Serial.println(F("CalibrationMatrix calibrationMatrix;")); |
displaymodule | 7:6cd8c36cbdb3 | 262 | Serial.print(F("calibrationMatrix.a = ")); |
displaymodule | 7:6cd8c36cbdb3 | 263 | Serial.print(calibrationMatrix.a); |
displaymodule | 7:6cd8c36cbdb3 | 264 | Serial.println(F(";")); |
displaymodule | 7:6cd8c36cbdb3 | 265 | Serial.print(F("calibrationMatrix.b = ")); |
displaymodule | 7:6cd8c36cbdb3 | 266 | Serial.print(calibrationMatrix.b); |
displaymodule | 7:6cd8c36cbdb3 | 267 | Serial.println(F(";")); |
displaymodule | 7:6cd8c36cbdb3 | 268 | Serial.print(F("calibrationMatrix.c = ")); |
displaymodule | 7:6cd8c36cbdb3 | 269 | Serial.print(calibrationMatrix.c); |
displaymodule | 7:6cd8c36cbdb3 | 270 | Serial.println(F(";")); |
displaymodule | 7:6cd8c36cbdb3 | 271 | Serial.print(F("calibrationMatrix.d = ")); |
displaymodule | 7:6cd8c36cbdb3 | 272 | Serial.print(calibrationMatrix.d); |
displaymodule | 7:6cd8c36cbdb3 | 273 | Serial.println(F(";")); |
displaymodule | 7:6cd8c36cbdb3 | 274 | Serial.print(F("calibrationMatrix.e = ")); |
displaymodule | 7:6cd8c36cbdb3 | 275 | Serial.print(calibrationMatrix.e); |
displaymodule | 7:6cd8c36cbdb3 | 276 | Serial.println(F(";")); |
displaymodule | 7:6cd8c36cbdb3 | 277 | Serial.print(F("calibrationMatrix.f = ")); |
displaymodule | 7:6cd8c36cbdb3 | 278 | Serial.print(calibrationMatrix.f); |
displaymodule | 7:6cd8c36cbdb3 | 279 | Serial.println(F(";")); |
displaymodule | 7:6cd8c36cbdb3 | 280 | Serial.println("-------------------------------"); |
displaymodule | 7:6cd8c36cbdb3 | 281 | #endif |
displaymodule | 7:6cd8c36cbdb3 | 282 | } |