acquisition_thread.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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