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 <core/threading/thread.h> 00027 #include <aspect/logging.h> 00028 #include <aspect/configurable.h> 00029 00030 #include <utils/math/types.h> 00031 00032 #include <string> 00033 #include <vector> 00034 00035 namespace fawkes { 00036 class Mutex; 00037 } 00038 00039 class JoystickBlackBoardHandler 00040 { 00041 public: 00042 virtual ~JoystickBlackBoardHandler(); 00043 virtual void joystick_changed(unsigned int pressed_buttons, 00044 float *axis_x_values, float *axis_y_values) = 0; 00045 virtual void joystick_plugged(char num_axes, char num_buttons) = 0; 00046 virtual void joystick_unplugged() = 0; 00047 }; 00048 00049 class JoystickAcquisitionThread 00050 : public fawkes::Thread, 00051 public fawkes::LoggingAspect, 00052 public fawkes::ConfigurableAspect 00053 { 00054 public: 00055 JoystickAcquisitionThread(); 00056 JoystickAcquisitionThread(const char *device_file, 00057 JoystickBlackBoardHandler *handler, 00058 fawkes::Logger *logger); 00059 00060 virtual void init(); 00061 virtual void finalize(); 00062 virtual void loop(); 00063 00064 bool lock_if_new_data(); 00065 void unlock(); 00066 00067 char num_axes() const; 00068 char num_buttons() const; 00069 const char * joystick_name() const; 00070 unsigned int pressed_buttons() const; 00071 float * axis_x_values(); 00072 float * axis_y_values(); 00073 00074 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */ 00075 protected: virtual void run() { Thread::run(); } 00076 00077 private: 00078 void init(std::string device_file); 00079 void open_joystick(); 00080 00081 private: 00082 std::string __cfg_device_file; 00083 00084 int __fd; 00085 bool __connected; 00086 unsigned int __axis_array_size; 00087 char __num_axes; 00088 char __num_buttons; 00089 char __joystick_name[128]; 00090 00091 bool __new_data; 00092 fawkes::Mutex *__data_mutex; 00093 00094 unsigned int __pressed_buttons; 00095 float *__axis_x_values; 00096 float *__axis_y_values; 00097 00098 JoystickBlackBoardHandler *__bbhandler; 00099 }; 00100 00101 00102 #endif