48 #ifdef CONFIG_NXWM_TOUCHSCREEN_CONFIGDATA 49 # include "platform/configdata.h" 65 # error "NX is not enabled (CONFIG_NX)" 72 #define CALIBRATION_LEFTX CONFIG_NXWM_CALIBRATION_MARGIN 73 #define CALIBRATION_RIGHTX (windowSize.w - CONFIG_NXWM_CALIBRATION_MARGIN + 1) 74 #define CALIBRATION_TOPY CONFIG_NXWM_CALIBRATION_MARGIN 75 #define CALIBRATION_BOTTOMY (windowSize.h - CONFIG_NXWM_CALIBRATION_MARGIN + 1) 77 #define CALIBRATION_CIRCLE_RADIUS 16 78 #define CALIBRATION_LINE_THICKNESS 2 84 #ifndef CONFIG_DEBUG_INPUT 97 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 132 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 200 ginfo(
"Starting calibration: m_calthread=%d\n", (
int)
m_calthread);
211 ginfo(
"Stopping calibration: m_calthread=%d\n", (
int)
m_calthread);
230 ginfo(
"Stopping calibration: m_calthread=%d\n", (
int)m_calthread);
231 (void)pthread_kill(
m_thread, CONFIG_NXWM_CALIBRATION_SIGNO);
235 FAR pthread_addr_t value;
236 (void)pthread_join(
m_thread, &value);
277 (void)pthread_kill(
m_thread, CONFIG_NXWM_CALIBRATION_SIGNO);
289 uint8_t waitcount = 0;
299 ginfo(
"Starting calibration: m_calthread=%d\n", (
int)
m_calthread);
305 while (!
isRunning() && (++waitcount < 10))
319 (void)pthread_kill(
m_thread, CONFIG_NXWM_CALIBRATION_SIGNO);
346 if ((sample.point[0].flags & (TOUCH_DOWN|TOUCH_MOVE)) != 0)
351 if ((sample.point[0].flags & TOUCH_DOWN) != 0 ||
359 iinfo(
"Touch id: %d flags: %02x x: %d y: %d h: %d w: %d pressure: %d\n",
360 sample.point[0].id, sample.point[0].flags, sample.point[0].x,
361 sample.point[0].y, sample.point[0].h, sample.point[0].w,
362 sample.point[0].pressure);
370 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 385 else if ((sample.point[0].flags & TOUCH_UP) != 0)
397 iinfo(
"State: %d Screen x: %d y: %d Touch x: %d y: %d\n",
408 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 421 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 433 CNxFont((nx_fontid_e)CONFIG_NXWM_CALIBRATION_FONTID,
434 CONFIG_NXWM_DEFAULT_FONTCOLOR, CONFIG_NXWM_TRANSPARENT_COLOR);
437 gerr(
"ERROR failed to create font\n");
447 struct nxgl_size_s windowSize;
448 if (!window->
getSize(&windowSize))
450 gerr(
"ERROR: Failed to get window size\n");
461 if (altStringWidth > maxStringWidth)
463 maxStringWidth = altStringWidth;
468 struct nxgl_size_s labelSize;
469 labelSize.w = maxStringWidth + 2*4;
474 struct nxgl_point_s labelPos;
475 labelPos.x = ((windowSize.w - labelSize.w) / 2);
476 labelPos.y = ((windowSize.h - labelSize.h) / 2);
485 CLabel(control, labelPos.x, labelPos.y, labelSize.w, labelSize.h,
"");
489 gerr(
"ERROR: Failed to create CLabel\n");
542 gwarn(
"WARNING: The calibration thread is already running\n");
549 (void)pthread_attr_init(&attr);
551 struct sched_param param;
552 param.sched_priority = CONFIG_NXWM_CALIBRATION_LISTENERPRIO;
553 (void)pthread_attr_setschedparam(&attr, ¶m);
555 (void)pthread_attr_setstacksize(&attr, CONFIG_NXWM_CALIBRATION_LISTENERSTACK);
566 gerr(
"ERROR: pthread_create failed: %d\n", ret);
570 ginfo(
"Calibration thread m_calthread=%d\n", (
int)
m_calthread);
587 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 592 gerr(
"ERROR: failed to create widgets\n");
605 ginfo(
"Started: m_calthread=%d\n", (
int)This->
m_calthread);
644 std::usleep(500*1000);
650 struct touch_sample_s sample;
665 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 676 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 682 ginfo(
"Terminated: m_calthread=%d\n", (
int)This->
m_calthread);
683 return (FAR
void *)0;
693 #ifdef CONFIG_NXWM_CALIBRATION_AVERAGE 708 if (
m_nsamples < CONFIG_NXWM_CALIBRATION_NSAMPLES)
716 #ifdef CONFIG_NXWM_CALIBRATION_NSAMPLES 719 int xValue = INT_MAX;
722 int yValue = INT_MAX;
725 for (
int i = 0; i < CONFIG_NXWM_CALIBRATION_NSAMPLES; i++)
751 for (
int i = 0; i < CONFIG_NXWM_CALIBRATION_NSAMPLES-1; i++)
770 #if NXWM_CALIBRATION_NAVERAGE > 1 776 for (
int i = 0; i < NXWM_CALIBRATION_NAVERAGE; i++)
782 average.x = xaccum / NXWM_CALIBRATION_NAVERAGE;
783 average.y = yaccum / NXWM_CALIBRATION_NAVERAGE;
789 iinfo(
"Average: Touch x: %d y: %d\n", average.x, average.y);
804 #ifdef CONFIG_NXWM_CALIBRATION_AVERAGE 807 struct nxgl_point_s average;
847 struct nxgl_size_s windowSize;
848 if (!window->
getSize(&windowSize))
870 CONFIG_NXWM_CALIBRATION_BACKGROUNDCOLOR);
878 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 894 #ifdef CONFIG_NXWM_CALIBRATION_AVERAGE 915 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 931 #ifdef CONFIG_NXWM_CALIBRATION_AVERAGE 932 m_calibData[CALIB_UPPER_RIGHT_INDEX].x = average.x;
933 m_calibData[CALIB_UPPER_RIGHT_INDEX].y = average.y;
952 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 968 #ifdef CONFIG_NXWM_CALIBRATION_AVERAGE 969 m_calibData[CALIB_LOWER_RIGHT_INDEX].x = average.x;
970 m_calibData[CALIB_LOWER_RIGHT_INDEX].y = average.y;
989 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 1005 #ifdef CONFIG_NXWM_CALIBRATION_AVERAGE 1006 m_calibData[CALIB_LOWER_LEFT_INDEX].x = average.x;
1007 m_calibData[CALIB_LOWER_LEFT_INDEX].y = average.y;
1018 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 1034 iinfo(
"New m_calphase=%d Screen x: %d y: %d\n",
1060 struct nxgl_size_s windowSize;
1061 if (!window->
getSize(&windowSize))
1083 #ifdef CONFIG_NXWM_CALIBRATION_MESSAGES 1106 #ifdef CONFIG_NXWM_TOUCHSCREEN_CONFIGDATA 1110 int ret = platform_setconfig(CONFIGDATA_TSCALIBRATION, 0,
1111 (FAR
const uint8_t *)&caldata,
1115 gerr(
"ERROR: Failed to save calibration data\n");
1152 struct nxgl_size_s windowSize;
1153 if (!window->
getSize(&windowSize))
1155 gerr(
"ERROR: NXWidgets::INxWindow::getSize failed\n");
1159 #ifdef CONFIG_NXWM_CALIBRATION_ANISOTROPIC 1167 float topX = (float)
m_calibData[CALIB_UPPER_LEFT_INDEX].x;
1168 float bottomX = (float)
m_calibData[CALIB_LOWER_LEFT_INDEX].x;
1170 float topY = (float)
m_calibData[CALIB_UPPER_LEFT_INDEX].y;
1171 float bottomY = (float)
m_calibData[CALIB_LOWER_LEFT_INDEX].y;
1173 data.
left.
slope = (bottomX - topX) / (bottomY - topY);
1178 topX = (float)
m_calibData[CALIB_UPPER_RIGHT_INDEX].x;
1179 bottomX = (float)
m_calibData[CALIB_LOWER_RIGHT_INDEX].x;
1181 topY = (float)
m_calibData[CALIB_UPPER_RIGHT_INDEX].y;
1182 bottomY = (float)
m_calibData[CALIB_LOWER_RIGHT_INDEX].y;
1184 data.
right.
slope = (bottomX - topX) / (bottomY - topY);
1196 float leftX = (float)
m_calibData[CALIB_UPPER_LEFT_INDEX].x;
1197 float rightX = (float)
m_calibData[CALIB_UPPER_RIGHT_INDEX].x;
1199 float leftY = (float)
m_calibData[CALIB_UPPER_LEFT_INDEX].y;
1200 float rightY = (float)
m_calibData[CALIB_UPPER_RIGHT_INDEX].y;
1202 data.
top.
slope = (rightY - leftY) / (rightX - leftX);
1207 leftX = (float)
m_calibData[CALIB_LOWER_LEFT_INDEX].x;
1208 rightX = (float)
m_calibData[CALIB_LOWER_RIGHT_INDEX].x;
1210 leftY = (float)
m_calibData[CALIB_LOWER_LEFT_INDEX].y;
1211 rightY = (float)
m_calibData[CALIB_LOWER_RIGHT_INDEX].y;
1213 data.
bottom.
slope = (rightY - leftY) / (rightX - leftX);
1220 data.
leftX = CALIBRATION_LEFTX;
1221 data.
rightX = CALIBRATION_RIGHTX;
1222 data.
topY = CALIBRATION_TOPY;
1223 data.
bottomY = CALIBRATION_BOTTOMY;
1236 b16_t leftX = (
m_calibData[CALIB_UPPER_LEFT_INDEX].x +
1238 b16_t rightX = (
m_calibData[CALIB_UPPER_RIGHT_INDEX].x +
1241 data.
xSlope = b16divb16(itob16(CALIBRATION_RIGHTX - CALIBRATION_LEFTX), (rightX - leftX));
1242 data.
xOffset = itob16(CALIBRATION_LEFTX) - b16mulb16(leftX, data.
xSlope);
1244 iinfo(
"New xSlope: %08x xOffset: %08x\n", data.
xSlope, data.
xOffset);
1257 b16_t topY = (
m_calibData[CALIB_UPPER_LEFT_INDEX].y +
1259 b16_t bottomY = (
m_calibData[CALIB_LOWER_LEFT_INDEX].y +
1262 data.
ySlope = b16divb16(itob16(CALIBRATION_BOTTOMY - CALIBRATION_TOPY), (bottomY - topY));
1263 data.
yOffset = itob16(CALIBRATION_TOPY) - b16mulb16(topY, data.
ySlope);
1265 iinfo(
"New ySlope: %08x yOffset: %08x\n", data.
ySlope, data.
yOffset);
1297 gerr(
"ERROR: Failed to create CFullScreenWindow\n");
1303 if (!window->
open())
1305 gerr(
"ERROR: Failed to open CFullScreenWindow \n");
1316 gerr(
"ERROR: Failed to instantiate CCalibration\n");
struct SCalibrationLine left
bool isFullScreen(void) const
CGraphicsPort * getGraphicsPort(void)
void destroyWidgets(void)
struct SCalibrationLine right
bool isFullScreen(void) const
IApplicationWindow * getWindow(void) const
void disableDrawing(void)
void setRaisesEvents(bool raises)
CTouchscreen * m_touchscreen
bool stopApplication(IApplication *app)
CCalibrationFactory(CTaskbar *taskbar, CTouchscreen *touchscreen)
void block(IApplication *app)
NXWidgets::CWidgetControl * getWidgetControl(void) const
struct SCalibScreenInfo m_screenInfo
nxgl_coord_t getStringWidth(const CNxString &text) const
void drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, nxgl_mxpixel_t color)
bool isRunning(void) const
virtual void setTextAlignmentHoriz(TextAlignmentHoriz alignment)
NXWidgets::IBitmap * getIcon(void)
virtual bool getSize(FAR struct nxgl_size_s *pSize)=0
bool waitRawTouchData(struct touch_sample_s *touch)
void setEnabled(bool enable)
NXWidgets::INxWindow * getWindow(void) const
struct nxgl_point_s m_calibData[CALIB_DATA_POINTS]
CFullScreenWindow * openFullScreenWindow(void)
CFullScreenWindow * m_window
struct nxgl_point_s m_touchPos
void touchscreenInput(struct touch_sample_s &sample)
NXWidgets::CLabel * m_text
void drawFilledRect(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, nxgl_mxpixel_t color)
bool createCalibrationData(struct SCalibrationData &data)
bool averageSamples(struct nxgl_point_s &average)
struct SCalibrationLine top
bool startCalibration(enum ECalThreadState initialState)
const uint8_t getHeight(void) const
static const char g_againMsg[]
NXWidgets::IBitmap * getIcon(void)
struct SCalibrationLine bottom
IApplication * create(void)
nxgl_mxpixel_t circleFillColor
virtual CWidgetControl * getWidgetControl(void) const =0
void setCalibrationData(const struct SCalibrationData &caldata)
static const NXWidgets::SRlePaletteBitmapEntry bitmap[]
static const char g_okMsg[]
static FAR void * calibration(FAR void *arg)
bool isStarted(void) const
static const char g_touchMsg[]
NXWidgets::CNxFont * m_font
void showCalibration(void)
virtual void setFont(CNxFont *font)
void finishCalibration(void)
virtual void setText(const CNxString &text)
void setBorderless(bool isBorderless)
CCalibration(CTaskbar *taskbar, CFullScreenWindow *window, CTouchscreen *touchscreen)
NXWidgets::CNxString getName(void)
volatile uint8_t m_calthread
struct nxgl_point_s m_sampleData[CONFIG_NXWM_CALIBRATION_NSAMPLES]