summaryrefslogtreecommitdiff
path: root/NxWidgets/nxwm
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-10-14 14:52:17 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-10-14 14:52:17 -0600
commit360abde7b0f21861292648de869ab0d1ba655444 (patch)
tree0a6742d3c1fcabf62c07992fa8e9dff53cad3583 /NxWidgets/nxwm
parentb33449923aee0b4320bed6b3f4880fcc75da32ab (diff)
downloadnuttx-360abde7b0f21861292648de869ab0d1ba655444.tar.gz
nuttx-360abde7b0f21861292648de869ab0d1ba655444.tar.bz2
nuttx-360abde7b0f21861292648de869ab0d1ba655444.zip
NxWM::CCalibration: Add an option to provide some instructions in the center of the calibration screen
Diffstat (limited to 'NxWidgets/nxwm')
-rw-r--r--NxWidgets/nxwm/include/ccalibration.hxx8
-rw-r--r--NxWidgets/nxwm/include/nxwmconfig.hxx25
-rw-r--r--NxWidgets/nxwm/src/ccalibration.cxx184
3 files changed, 191 insertions, 26 deletions
diff --git a/NxWidgets/nxwm/include/ccalibration.hxx b/NxWidgets/nxwm/include/ccalibration.hxx
index f114a19a2..376462ca8 100644
--- a/NxWidgets/nxwm/include/ccalibration.hxx
+++ b/NxWidgets/nxwm/include/ccalibration.hxx
@@ -32,7 +32,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
-
+
#ifndef __INCLUDE_CCALIBRATION_HXX
#define __INCLUDE_CCALIBRATION_HXX
@@ -48,6 +48,8 @@
#include "cnxstring.hxx"
#include "cwidgeteventhandler.hxx"
#include "cwidgetcontrol.hxx"
+#include "clabel.hxx"
+#include "cnxfont.hxx"
#include "ctaskbar.hxx"
#include "iapplication.hxx"
@@ -146,6 +148,10 @@ namespace NxWM
CTaskbar *m_taskbar; /**< The taskbar (used to terminate calibration) */
CFullScreenWindow *m_window; /**< The window for the calibration display */
CTouchscreen *m_touchscreen; /**< The touchscreen device */
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ NXWidgets::CLabel *m_text; /**< Calibration message */
+ NXWidgets::CNxFont *m_font; /**< The font used in the message */
+#endif
pthread_t m_thread; /**< The calibration thread ID */
struct SCalibScreenInfo m_screenInfo; /**< Describes the current calibration display */
struct nxgl_point_s m_touchPos; /**< This is the last touch position */
diff --git a/NxWidgets/nxwm/include/nxwmconfig.hxx b/NxWidgets/nxwm/include/nxwmconfig.hxx
index ad8e0e97d..65384341b 100644
--- a/NxWidgets/nxwm/include/nxwmconfig.hxx
+++ b/NxWidgets/nxwm/include/nxwmconfig.hxx
@@ -39,7 +39,7 @@
/****************************************************************************
* Included Files
****************************************************************************/
-
+
#include <nuttx/config.h>
#include <nuttx/input/touchscreen.h>
@@ -116,7 +116,7 @@
*
* CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR - Normal background color. Default:
* MKRGB(148,189,215)
- * CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR - Select background color.
+ * CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR - Select background color.
* Default: MKRGB(206,227,241)
* CONFIG_NXWM_DEFAULT_SHINEEDGECOLOR - Color of the bright edge of a border.
* Default: MKRGB(255,255,255)
@@ -265,7 +265,7 @@
* CONFIG_NXWM_STARTWINDOW_HSPACING - Horizontal spacing. Default: 4 rows
* CONFIG_NXWM_STARTWINDOW_ICON - The glyph to use as the start window icon
* CONFIG_NXWM_STARTWINDOW_MQNAME - The well known name of the message queue
- * Used to communicated from CWindowMessenger to the start window thread.
+ * Used to communicated from CWindowMessenger to the start window thread.
* Default: "/dev/nxwm"
* CONFIG_NXWM_STARTWINDOW_MXMSGS - The maximum number of messages to queue
* before blocking. Defualt 32
@@ -465,8 +465,10 @@
* CONFIG_NXWM_CALIBRATION_CIRCLECOLOR - The color of the circle in the
* touchscreen calibration display. Default: MKRGB(255, 255, 255) (white)
* CONFIG_NXWM_CALIBRATION_TOUCHEDCOLOR - The color of the circle in the
- * touchscreen calibration display after the touch is recorder. Default:
+ * touchscreen calibration display after the touch is recorder. Default:
* MKRGB(255, 255, 96) (very light yellow)
+ * CONFIG_NXWM_CALIBRATION_FONTID - Use this default NxWidgets font ID
+ * instead of the system font ID (NXFONT_DEFAULT).
* CONFIG_NXWM_CALIBRATION_ICON - The ICON to use for the touchscreen
* calibration application. Default: NxWM::g_calibrationBitmap
* CONFIG_NXWM_CALIBRATION_SIGNO - The realtime signal used to wake up the
@@ -475,6 +477,13 @@
* thread. Default: SCHED_PRIORITY_DEFAULT
* CONFIG_NXWM_CALIBRATION_LISTENERSTACK - Calibration listener thread stack
* size. Default 2048
+ * CONFIG_NXWM_CALIBRATION_MARGIN
+ * The Calbration display consists of a target press offset from the edges
+ * of the display by this number of pixels (in the horizontal direction)
+ * or rows (in the vertical). The closer that you can comfortabley
+ * position the press positions to the edge, the more accurate will be the
+ * linear interpolation (provide that the hardware provides equally good
+ * measurements near the edges).
*/
#ifndef CONFIG_NXWM_CALIBRATION_BACKGROUNDCOLOR
@@ -493,6 +502,10 @@
# define CONFIG_NXWM_CALIBRATION_TOUCHEDCOLOR MKRGB(255, 255, 96)
#endif
+#ifndef CONFIG_NXWM_CALIBRATION_FONTID
+# define CONFIG_NXWM_CALIBRATION_FONTID NXFONT_DEFAULT
+#endif
+
#ifndef CONFIG_NXWM_CALIBRATION_ICON
# define CONFIG_NXWM_CALIBRATION_ICON NxWM::g_calibrationBitmap
#endif
@@ -509,6 +522,10 @@
# define CONFIG_NXWM_CALIBRATION_LISTENERSTACK 2048
#endif
+#ifndef CONFIG_NXWM_CALIBRATION_MARGIN
+# define CONFIG_NXWM_CALIBRATION_MARGIN 40
+#endif
+
/* Hexcalculator applications ***********************************************/
/**
* Calibration display settings:
diff --git a/NxWidgets/nxwm/src/ccalibration.cxx b/NxWidgets/nxwm/src/ccalibration.cxx
index 04233d5ef..d30ab690e 100644
--- a/NxWidgets/nxwm/src/ccalibration.cxx
+++ b/NxWidgets/nxwm/src/ccalibration.cxx
@@ -64,20 +64,30 @@
* Positional/size data for the calibration lines and circles
*/
-#define CALIBRATION_LEFTX 40
-#define CALIBRATION_RIGHTX (windowSize.w - 41)
-#define CALIBRATION_TOPY 40
-#define CALIBRATION_BOTTOMY (windowSize.h - 41)
+#define CALIBRATION_LEFTX CONFIG_NXWM_CALIBRATION_MARGIN
+#define CALIBRATION_RIGHTX (windowSize.w - CONFIG_NXWM_CALIBRATION_MARGIN + 1)
+#define CALIBRATION_TOPY CONFIG_NXWM_CALIBRATION_MARGIN
+#define CALIBRATION_BOTTOMY (windowSize.h - CONFIG_NXWM_CALIBRATION_MARGIN + 1)
#define CALIBRATION_CIRCLE_RADIUS 16
#define CALIBRATION_LINE_THICKNESS 2
/****************************************************************************
- * CCalibration Implementation Classes
+ * Private Data
****************************************************************************/
using namespace NxWM;
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+static const char g_touchmsg[] = "Touch";
+static const char g_againmsg[] = "Again";
+static const char g_okmsg[] = "OK";
+#endif
+
+/****************************************************************************
+ * CCalibration Implementation Classes
+ ****************************************************************************/
+
/**
* CCalibration Constructor
*
@@ -99,6 +109,14 @@ CCalibration::CCalibration(CTaskbar *taskbar, CFullScreenWindow *window,
m_calthread = CALTHREAD_NOTRUNNING;
m_calphase = CALPHASE_NOT_STARTED;
m_touched = false;
+
+ // Nullify widgets that will be instantiated when the calibration thread
+ // is started
+
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ m_text = (NXWidgets::CLabel *)0;
+ m_font = (NXWidgets::CNxFont *)0;
+#endif
}
/**
@@ -180,7 +198,7 @@ void CCalibration::stop(void)
if (m_thread != 0)
{
- // Is the calibration thread running?
+ // Is the calibration thread running?
if (isRunning())
{
@@ -191,10 +209,15 @@ void CCalibration::stop(void)
m_calthread = CALTHREAD_STOPREQUESTED;
// Try to wake up the calibration thread so that it will see our
- // terminatin request
+ // termination request
- gvdbg("Stopping calibration: m_calthread=%d\n", (int)m_calthread);
+ gvdbg("Stopping calibration: m_calthread=%d\n", (int)m_calthread);
(void)pthread_kill(m_thread, CONFIG_NXWM_CALIBRATION_SIGNO);
+
+ // Wait for the calibration thread to exit
+
+ FAR pthread_addr_t value;
+ (void)pthread_join(m_thread, &value);
}
}
}
@@ -328,6 +351,9 @@ void CCalibration::touchscreenInput(struct touch_sample_s &sample)
if (!m_touched)
{
m_screenInfo.circleFillColor = CONFIG_NXWM_CALIBRATION_TOUCHEDCOLOR;
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ m_text->setText(g_okmsg);
+#endif
showCalibration();
m_touched = true;
}
@@ -361,8 +387,11 @@ void CCalibration::touchscreenInput(struct touch_sample_s &sample)
else
{
// No... restore the un-highlighted circle
-
+
m_screenInfo.circleFillColor = CONFIG_NXWM_CALIBRATION_CIRCLECOLOR;
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ m_text->setText("");
+#endif
showCalibration();
}
}
@@ -415,10 +444,6 @@ bool CCalibration::startCalibration(enum ECalThreadState initialState)
return false;
}
- // Detach from the pthread so that we do not have any memory leaks
-
- (void)pthread_detach(m_thread);
-
gvdbg("Calibration thread m_calthread=%d\n", (int)m_calthread);
return true;
}
@@ -436,12 +461,87 @@ FAR void *CCalibration::calibration(FAR void *arg)
CCalibration *This = (CCalibration *)arg;
bool stalled = true;
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ // Create widgets that will be used in the calibration display
+ // Select a font for the calculator
+
+ This->m_font = new NXWidgets::
+ CNxFont((nx_fontid_e)CONFIG_NXWM_CALIBRATION_FONTID,
+ CONFIG_NXWM_DEFAULT_FONTCOLOR, CONFIG_NXWM_TRANSPARENT_COLOR);
+ if (!This->m_font)
+ {
+ gdbg("ERROR failed to create font\n");
+ return false;
+ }
+
+ // Recover the window instance contained in the application window
+
+ NXWidgets::INxWindow *window = This->m_window->getWindow();
+
+ // Get the size of the window
+
+ struct nxgl_size_s windowSize;
+ if (!window->getSize(&windowSize))
+ {
+ gdbg("ERROR: Failed to get window size\n");
+ delete This->m_font;
+ This->m_font = (NXWidgets::CNxFont *)0;
+ return false;
+ }
+
+ // How big can the label be?
+
+ struct nxgl_size_s labelSize;
+ labelSize.w = (windowSize.w - 2*CONFIG_NXWM_CALIBRATION_MARGIN - 20);
+ labelSize.h = This->m_font->getHeight() + 2*4;
+
+ // Where should the label be?
+
+ struct nxgl_point_s labelPos;
+ labelPos.x = ((windowSize.w - labelSize.w) / 2);
+ labelPos.y = ((windowSize.h - labelSize.h) / 2);
+
+ // Get the widget control associated with the application window
+
+ NXWidgets::CWidgetControl *control = This->m_window->getWidgetControl();
+
+ // Create a label to show the calibration message.
+
+ This->m_text = new NXWidgets::
+ CLabel(control, labelPos.x, labelPos.y, labelSize.w, labelSize.h, "");
+
+ if (!This->m_text)
+ {
+ gdbg("ERROR: Failed to create CLabel\n");
+ delete This->m_font;
+ This->m_font = (NXWidgets::CNxFont *)0;
+ return false;
+ }
+
+ // No border
+
+ This->m_text->setBorderless(true);
+
+ // Center text
+
+ This->m_text->setTextAlignmentHoriz(NXWidgets::CLabel::TEXT_ALIGNMENT_HORIZ_CENTER);
+
+ // Disable drawing and events until we are asked to redraw the window
+
+ This->m_text->disableDrawing();
+ This->m_text->setRaisesEvents(false);
+
+ // Select the font
+
+ This->m_text->setFont(This->m_font);
+#endif
+
// The calibration thread is now running
This->m_calthread = CALTHREAD_RUNNING;
This->m_calphase = CALPHASE_NOT_STARTED;
gvdbg("Started: m_calthread=%d\n", (int)This->m_calthread);
-
+
// Loop until calibration completes or we have been requested to terminate
while (This->m_calthread != CALTHREAD_STOPREQUESTED &&
@@ -468,7 +568,7 @@ FAR void *CCalibration::calibration(FAR void *arg)
}
// The calibration thread will stall if has been asked to hide the
- // display. While stalled, we will just sleep for a bit abd test
+ // display. While stalled, we will just sleep for a bit and test
// the state again. If we are re-awakened by a redraw(), then we
// will be given a signal which will wake us up immediately.
//
@@ -494,14 +594,33 @@ FAR void *CCalibration::calibration(FAR void *arg)
if (This->m_calthread == CALTHREAD_RUNNING)
{
This->touchscreenInput(sample);
- }
+ }
}
}
+ // Hide the message
+
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ This->m_text->setText("");
+ This->m_text->enableDrawing();
+ This->m_text->redraw();
+ This->m_text->disableDrawing();
+#endif
+
// Perform the final steps of calibration
This->finishCalibration();
+ // Destroy widgets
+
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ delete This->m_text;
+ This->m_text = (NXWidgets::CLabel *)0;
+
+ delete This->m_font;
+ This->m_font = (NXWidgets::CNxFont *)0;
+#endif
+
gvdbg("Terminated: m_calthread=%d\n", (int)This->m_calthread);
return (FAR void *)0;
}
@@ -552,6 +671,9 @@ void CCalibration::stateMachine(void)
m_screenInfo.pos.y = CALIBRATION_TOPY;
m_screenInfo.lineColor = CONFIG_NXWM_CALIBRATION_LINECOLOR;
m_screenInfo.circleFillColor = CONFIG_NXWM_CALIBRATION_CIRCLECOLOR;
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ m_text->setText(g_touchmsg);
+#endif
showCalibration();
// Then set up the current state
@@ -568,7 +690,7 @@ void CCalibration::stateMachine(void)
m_calibData[CALIB_UPPER_LEFT_INDEX].x = m_touchPos.x;
m_calibData[CALIB_UPPER_LEFT_INDEX].y = m_touchPos.y;
- // Clear the previous screen by re-drawing it using the backgro9und
+ // Clear the previous screen by re-drawing it using the background
// color. That is much faster than clearing the whole display
m_screenInfo.lineColor = CONFIG_NXWM_CALIBRATION_BACKGROUNDCOLOR;
@@ -581,6 +703,9 @@ void CCalibration::stateMachine(void)
m_screenInfo.pos.y = CALIBRATION_TOPY;
m_screenInfo.lineColor = CONFIG_NXWM_CALIBRATION_LINECOLOR;
m_screenInfo.circleFillColor = CONFIG_NXWM_CALIBRATION_CIRCLECOLOR;
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ m_text->setText(g_touchmsg);
+#endif
showCalibration();
// Then set up the current state
@@ -610,6 +735,9 @@ void CCalibration::stateMachine(void)
m_screenInfo.pos.y = CALIBRATION_BOTTOMY;
m_screenInfo.lineColor = CONFIG_NXWM_CALIBRATION_LINECOLOR;
m_screenInfo.circleFillColor = CONFIG_NXWM_CALIBRATION_CIRCLECOLOR;
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ m_text->setText(g_touchmsg);
+#endif
showCalibration();
// Then set up the current state
@@ -639,6 +767,9 @@ void CCalibration::stateMachine(void)
m_screenInfo.pos.y = CALIBRATION_BOTTOMY;
m_screenInfo.lineColor = CONFIG_NXWM_CALIBRATION_LINECOLOR;
m_screenInfo.circleFillColor = CONFIG_NXWM_CALIBRATION_CIRCLECOLOR;
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ m_text->setText(g_touchmsg);
+#endif
showCalibration();
// Then set up the current state
@@ -660,6 +791,9 @@ void CCalibration::stateMachine(void)
m_screenInfo.lineColor = CONFIG_NXWM_CALIBRATION_BACKGROUNDCOLOR;
m_screenInfo.circleFillColor = CONFIG_NXWM_CALIBRATION_BACKGROUNDCOLOR;
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ m_text->setText(g_touchmsg);
+#endif
showCalibration();
// Inform any waiter that calibration is complete
@@ -711,14 +845,22 @@ void CCalibration::showCalibration(void)
m_screenInfo.circleFillColor);
/* Draw horizontal line */
-
+
port->drawFilledRect(0, m_screenInfo.pos.y, windowSize.w, CALIBRATION_LINE_THICKNESS,
m_screenInfo.lineColor);
/* Draw vertical line */
-
+
port->drawFilledRect(m_screenInfo.pos.x, 0, CALIBRATION_LINE_THICKNESS, windowSize.h,
m_screenInfo.lineColor);
+
+ /* Show the touchscreen message */
+
+#ifdef CONFIG_NXWM_CALIBRATION_MESSAGES
+ m_text->enableDrawing();
+ m_text->redraw();
+ m_text->disableDrawing();
+#endif
}
/**
@@ -733,7 +875,7 @@ void CCalibration::finishCalibration(void)
if (m_calphase == CALPHASE_COMPLETE)
{
// Yes... Get the final Calibration data
-
+
struct SCalibrationData caldata;
if (createCalibrationData(caldata))
{
@@ -773,7 +915,7 @@ bool CCalibration::createCalibrationData(struct SCalibrationData &data)
struct nxgl_size_s windowSize;
if (!window->getSize(&windowSize))
{
- gdbg("NXWidgets::INxWindow::getSize failed\n");
+ gdbg("NXWidgets::INxWindow::getSize failed\n");
return false;
}