diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-05-11 00:05:25 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-05-11 00:05:25 +0000 |
commit | a280d993608d0c40ad0b4efc8adcbf72f67d53a4 (patch) | |
tree | 0c718467856492451acfb8af51db3d59abad08fb /NxWidgets/nxwm/include | |
parent | 68f3044b5099572850a9e81a1c63161c20809547 (diff) | |
download | nuttx-a280d993608d0c40ad0b4efc8adcbf72f67d53a4.tar.gz nuttx-a280d993608d0c40ad0b4efc8adcbf72f67d53a4.tar.bz2 nuttx-a280d993608d0c40ad0b4efc8adcbf72f67d53a4.zip |
NxWM: Finishes touchscreen implementation; NuttX: Standardize touchscreen initialization interfaces for all boards
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4721 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'NxWidgets/nxwm/include')
-rw-r--r-- | NxWidgets/nxwm/include/ccalibration.hxx | 7 | ||||
-rw-r--r-- | NxWidgets/nxwm/include/ctaskbar.hxx | 12 | ||||
-rw-r--r-- | NxWidgets/nxwm/include/ctouchscreen.hxx | 119 | ||||
-rw-r--r-- | NxWidgets/nxwm/include/nxwmconfig.hxx | 34 |
4 files changed, 162 insertions, 10 deletions
diff --git a/NxWidgets/nxwm/include/ccalibration.hxx b/NxWidgets/nxwm/include/ccalibration.hxx index 0adcd894f..42eb56ad2 100644 --- a/NxWidgets/nxwm/include/ccalibration.hxx +++ b/NxWidgets/nxwm/include/ccalibration.hxx @@ -50,7 +50,6 @@ #include "iapplication.hxx" #include "cfullscreenwindow.hxx" -#include "ctouchscreen.hxx" /**************************************************************************** * Pre-processor Definitions @@ -73,6 +72,12 @@ namespace NxWM { /** + * Forward references + */ + + struct CTouchscreen; + + /** * Touchscreen calibration data */ diff --git a/NxWidgets/nxwm/include/ctaskbar.hxx b/NxWidgets/nxwm/include/ctaskbar.hxx index 69595163c..398087f84 100644 --- a/NxWidgets/nxwm/include/ctaskbar.hxx +++ b/NxWidgets/nxwm/include/ctaskbar.hxx @@ -386,6 +386,18 @@ namespace NxWM bool stopApplication(IApplication *app); /** + * Get the size of the physical display device as it is known to the task + * bar. + * + * @return The size of the display + */ + + inline bool getWindowSize(FAR struct nxgl_size_s *size) + { + return m_taskbar->getSize(size); + } + + /** * Simulate a mouse click on the icon at index. This inline method is only * used during automated testing of NxWM. */ diff --git a/NxWidgets/nxwm/include/ctouchscreen.hxx b/NxWidgets/nxwm/include/ctouchscreen.hxx index f8eaeaee8..c3aa198cb 100644 --- a/NxWidgets/nxwm/include/ctouchscreen.hxx +++ b/NxWidgets/nxwm/include/ctouchscreen.hxx @@ -43,8 +43,13 @@ #include <nuttx/nx/nxglib.h> #include <semaphore.h> +#include <pthread.h> + #include <nuttx/input/touchscreen.h> +#include "cnxserver.hxx" +#include "ccalibration.hxx" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -63,16 +68,68 @@ namespace NxWM class CTouchscreen { private: - int m_touchFd; /**< File descriptor of the opened touchscreen device */ - sem_t m_waitSem; /**< Semaphore the supports waits for touchscreen data */ + /** + * The state of the listener thread. + */ + + enum EListenerState + { + LISTENER_NOTRUNNING = 0, /**< The listener thread has not yet been started */ + LISTENER_STARTED, /**< The listener thread has been started, but is not yet running */ + LISTENER_RUNNING, /**< The listener thread is running normally */ + LISTENER_STOPREQUESTED, /**< The listener thread has been requested to stop */ + LISTENER_TERMINATED, /**< The listener thread terminated normally */ + LISTENER_FAILED /**< The listener thread terminated abnormally */ + }; + + /** + * CTouchscreen state data + */ + + NXWidgets::CNxServer *m_server; /**< The current NX server */ + int m_touchFd; /**< File descriptor of the opened touchscreen device */ + sem_t m_waitSem; /**< Semaphore the supports waits for touchscreen data */ + pthread_t m_thread; /**< The listener thread ID */ + volatile enum EListenerState m_state; /**< The state of the listener thread */ + volatile bool m_enabled; /**< True: Normal touchscreen processing */ + volatile bool m_capture; /**< True: There is a thread waiting for raw touch data */ + volatile bool m_calibrated; /**< True: If have calibration data */ + struct nxgl_size_s m_windowSize; /**< The size of the physical display */ + struct SCalibrationData m_calibData; /**< Calibration data */ + struct touch_sample_s m_sample; /**< In normal mode, touch data is collected here */ + struct touch_sample_s *m_touch; /**< Points to the current touch data buffer */ + + /** + * The touchscreen listener thread. This is the entry point of a thread that + * listeners for and dispatches touchscreens events to the NX server. + * + * @param arg. The CTouchscreen 'this' pointer cast to a void*. + * @return This function normally does not return but may return NULL on + * error conditions. + */ + + static FAR void *listener(FAR void *arg); + + /** + * Inject touchscreen data into NX as mouse intput + * + * @param sample. The buffer where data was collected. + */ + + void handleMouseInput(struct touch_sample_s *sample); public: /** * CTouchscreen Constructor + * + * @param server. An instance of the NX server. This will be needed for + * injecting mouse data. + * @param windowSize. The size of the physical window in pixels. This + * is needed for touchscreen scaling. */ - CTouchscreen(void); + CTouchscreen(NXWidgets::CNxServer *server, struct nxgl_size_s *windowSize); /** * CTouchscreen Destructor @@ -81,22 +138,66 @@ namespace NxWM ~CTouchscreen(void); /** - * Initialize the touchscreen device. Initialization is separate from - * object instantiation so that failures can be reported. + * Start the touchscreen listener thread. * - * @return True if the touchscreen device was correctly initialized + * @return True if the touchscreen listener thread was correctly started. */ - bool open(void); + bool start(void); + + /** + * Enable/disable touchscreen data processing. When enabled, touchscreen events + * are calibrated and forwarded to the NX layer which dispatches the touchscreen + * events in window-relative positions to the correct NX window. + * + * When disabled, touchscreen data is not forwarded to NX, but is instead captured + * and made available for touchscreen calibration. The touchscreen driver is + * initially disabled and must be specifically enabled be begin normal processing. + * Normal processing also requires calibration data (see method setCalibrationData) + * + * @param capture. True enables capture mode; false disables. + */ + + inline void setEnabled(bool enable) + { + // Set the capture flag. m_calibrated must also be set to get to normal + // mode where touchscreen data is forwarded to NX. + + m_enabled = enable; + } + + /** + * Provide touchscreen calibration data. If calibration data is received (and + * the touchscreen is enabled), then received touchscreen data will be scaled + * using the calibration data and forward to the NX layer which dispatches the + * touchscreen events in window-relative positions to the correct NX window. + * + * @param data. A reference to the touchscreen data. + */ + + inline void setCalibrationData(struct SCalibrationData &caldata) + { + // Save a copy of the calibration data + + m_calibData = caldata; + + // Note that we have calibration data. Data will now be scaled and forwarded + // to NX (unless we are still in cpature mode) + + m_calibrated = true; + } /** - * Capture raw driver data. + * Capture raw driver data. This method will capture mode one raw touchscreen + * input. The normal use of this method is for touchscreen calibration. * + * This function is not re-entrant: There may be only one thread waiting for + * raw touchscreen data. * * @return True if the raw touchscreen data was sucessfully obtained */ - bool waitRawTouchData(struct touch_sample_s &touch); + bool waitRawTouchData(struct touch_sample_s *touch); }; } diff --git a/NxWidgets/nxwm/include/nxwmconfig.hxx b/NxWidgets/nxwm/include/nxwmconfig.hxx index 4e08b0481..4e51cea1d 100644 --- a/NxWidgets/nxwm/include/nxwmconfig.hxx +++ b/NxWidgets/nxwm/include/nxwmconfig.hxx @@ -42,6 +42,8 @@ #include <nuttx/config.h> +#include <nuttx/input/touchscreen.h> + #include "nxconfig.hxx" #include "crlepalettebitmap.hxx" @@ -322,12 +324,43 @@ #endif /* Touchscreen device *******************************************************/ +/** + * Touchscreen device settings + * + * CONFIG_NXWM_TOUCHSCREEN_DEVNO - Touchscreen device minor number, i.e., the + * N in /dev/inputN. Default: 0 + * CONFIG_NXWM_TOUCHSCREEN_DEVNO - The full path to the touchscreen device. + * Default: "/dev/input0" + * CONFIG_NXWM_TOUCHSCREEN_SIGNO - The realtime signal used to wake up the + * touchscreen listener thread. Default: 5 + */ + +#ifndef CONFIG_NXWM_TOUCHSCREEN_DEVNO +# define CONFIG_NXWM_TOUCHSCREEN_DEVNO 0 +#endif #ifndef CONFIG_NXWM_TOUCHSCREEN_DEVPATH # define CONFIG_NXWM_TOUCHSCREEN_DEVPATH "/dev/input0" #endif +#ifndef CONFIG_NXWM_TOUCHSCREEN_SIGNO +# define CONFIG_NXWM_TOUCHSCREEN_SIGNO 5 +#endif + /* Calibration display ******************************************************/ +/** + * Calibration display settings: + * + * CONFIG_NXWM_CALIBRATION_BACKGROUNDCOLOR - The background color of the + * touchscreen calibration display. Default: Same as + * CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR + * CONFIG_NXWM_CALIBRATION_LINECOLOR - The color of the lines used in the + * touchscreen calibration display. Default: MKRGB(0, 0, 128) (dark blue) + * CONFIG_NXWM_CALIBRATION_BACKGROUNDCOLOR - The background color of the + * touchscreen calibration display. Default: MKRGB(255, 255, 255) (white) + * CONFIG_NXWM_CALIBRATION_ICON - The ICON to use for the touchscreen + * calibration application. Default: NxWM::g_calibrationBitmap + */ #ifndef CONFIG_NXWM_CALIBRATION_BACKGROUNDCOLOR # define CONFIG_NXWM_CALIBRATION_BACKGROUNDCOLOR CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR @@ -344,6 +377,7 @@ #ifndef CONFIG_NXWM_CALIBRATION_ICON # define CONFIG_NXWM_CALIBRATION_ICON NxWM::g_calibrationBitmap #endif + /**************************************************************************** * Global Function Prototypes ****************************************************************************/ |