2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
11 * @brief Gets the value of the joystick operation
19 #include <linux/joystick.h>
29 #include "ico-util/ico_log.h"
31 #define D_DEV_DIR_PATH "/dev/input/"
32 #define D_DEV_NAME_PARTS_JS "js"
33 #define D_DEV_NAME_G25 "Driving Force GT"
34 #define D_DEV_NAME_G27 "G27 Racing Wheel"
43 pthread_mutex_init(&mutex, NULL);
44 pthread_cond_init(&cond, NULL);
46 mutex = PTHREAD_MUTEX_INITIALIZER;
47 cond = PTHREAD_COND_INITIALIZER;
52 if (pthread_mutex_destroy(&mutex) != 0) {
53 ICO_ERR("pthread_mutex_destroy error[errno=%d]", errno);
55 if (pthread_cond_destroy(&cond) != 0) {
56 ICO_ERR("pthread_cond_destroy error[errno=%d]", errno);
62 if (pthread_mutex_lock(&mutex) != 0) {
63 ICO_ERR("pthread_mutex_lock error[errno=%d]", errno);
65 int ret = mQueue.size();
66 if (pthread_mutex_unlock(&mutex) != 0) {
67 ICO_ERR("pthread_mutex_unlock error[errno=%d]", errno);
75 struct timespec timeout;
78 if (pthread_mutex_lock(&mutex) != 0) {
79 ICO_ERR("pthread_mutex_lock error[errno=%d]", errno);
83 gettimeofday(&now, NULL);
84 nsec = now.tv_usec * 1000 + 50*1000000;
85 timeout.tv_nsec = nsec % 1000000000;
86 if (nsec < 1000000000) {
87 timeout.tv_sec = now.tv_sec;
89 timeout.tv_sec = now.tv_sec + 1;
91 if (pthread_cond_timedwait(&cond, &mutex, &timeout) != 0){
92 if (pthread_mutex_unlock(&mutex) != 0) {
93 ICO_ERR("pthread_mutex_unlock error[errno=%d]", errno);
99 item = mQueue.front();
102 if (pthread_mutex_unlock(&mutex) != 0) {
103 ICO_ERR("pthread_mutex_unlock error[errno=%d]", errno);
111 if (pthread_mutex_lock(&mutex) != 0) {
112 ICO_ERR("pthread_mutex_lock error[errno=%d]", errno);
116 pthread_cond_signal(&cond);
118 if (pthread_mutex_unlock(&mutex) != 0) {
119 ICO_ERR("pthread_mutex_unlock error[errno=%d]", errno);
124 pthread_mutex_t mutex;
126 std::queue<T> mQueue;
133 virtual ~CJoyStick();
137 virtual int Read(int *number, int *value);
138 virtual int ReadData();
140 int GetAxisCount() const;
141 int GetButtonsCount() const;
148 int deviceOpen(const std::string& dirNM, const std::string& fileParts,
149 const std::string& deviceNM, std::string& getDevice);
150 void getDevices(const std::string& dir,
151 const std::vector<std::string>& matching,
152 std::vector<std::string>& filesList) const;
153 virtual bool getDeviceName(int fd, char* devNM, size_t sz);
155 static void *loop(void *arg);
158 char m_strJoyStick[64];
161 unsigned char m_ucAxes;
162 unsigned char m_ucButtons;
163 char m_strDevName[80];
167 CJoyStickQueue<struct js_event > queue;
169 pthread_t m_threadid;
172 #endif /* CJOYSTICK_H_ */
174 * End of File.(CJoyStick.h)