Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * acquisition_thread.h - Thread that retrieves the joystick data 00004 * 00005 * Created: Sat Nov 22 18:10:35 2008 00006 * Copyright 2006-2008 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #ifndef __PLUGINS_JOYSTICK_ACQUISITION_THREAD_H_ 00024 #define __PLUGINS_JOYSTICK_ACQUISITION_THREAD_H_ 00025 00026 #include "bb_handler.h" 00027 00028 #include <core/threading/thread.h> 00029 #include <aspect/logging.h> 00030 #include <aspect/configurable.h> 00031 00032 #include <utils/math/types.h> 00033 00034 #include <string> 00035 #include <vector> 00036 00037 namespace fawkes { 00038 class Mutex; 00039 } 00040 00041 class JoystickForceFeedback; 00042 00043 class JoystickAcquisitionThread 00044 : public fawkes::Thread, 00045 public fawkes::LoggingAspect, 00046 public fawkes::ConfigurableAspect 00047 { 00048 public: 00049 JoystickAcquisitionThread(); 00050 JoystickAcquisitionThread(const char *device_file, 00051 JoystickBlackBoardHandler *handler, 00052 fawkes::Logger *logger); 00053 00054 virtual void init(); 00055 virtual void finalize(); 00056 virtual void loop(); 00057 00058 bool lock_if_new_data(); 00059 void unlock(); 00060 00061 char num_axes() const; 00062 char num_buttons() const; 00063 const char * joystick_name() const; 00064 unsigned int pressed_buttons() const; 00065 float * axis_values(); 00066 00067 /** Access force feedback of joystick. 00068 * @return instance of JoystickForceFeedback class for current joystick. */ 00069 JoystickForceFeedback * ff() const { return __ff; } 00070 00071 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */ 00072 protected: virtual void run() { Thread::run(); } 00073 00074 private: 00075 void init(std::string device_file); 00076 void open_joystick(); 00077 void open_forcefeedback(); 00078 00079 private: 00080 std::string __cfg_device_file; 00081 00082 int __fd; 00083 bool __connected; 00084 unsigned int __axis_array_size; 00085 char __num_axes; 00086 char __num_buttons; 00087 char __joystick_name[128]; 00088 00089 bool __new_data; 00090 fawkes::Mutex *__data_mutex; 00091 00092 unsigned int __pressed_buttons; 00093 float *__axis_values; 00094 00095 JoystickBlackBoardHandler *__bbhandler; 00096 JoystickForceFeedback *__ff; 00097 }; 00098 00099 00100 #endif