Fawkes API  Fawkes Development Version
acquisition_thread.h
1 
2 /***************************************************************************
3  * acquisition_thread.h - Thread that retrieves the joystick data
4  *
5  * Created: Sat Nov 22 18:10:35 2008
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __PLUGINS_JOYSTICK_ACQUISITION_THREAD_H_
24 #define __PLUGINS_JOYSTICK_ACQUISITION_THREAD_H_
25 
26 #include "bb_handler.h"
27 
28 #include <core/threading/thread.h>
29 #include <aspect/logging.h>
30 #include <aspect/configurable.h>
31 
32 #include <utils/math/types.h>
33 
34 #include <string>
35 #include <vector>
36 
37 namespace fawkes {
38  class Mutex;
39 }
40 
42 
44 : public fawkes::Thread,
45  public fawkes::LoggingAspect,
47 {
48  public:
50  JoystickAcquisitionThread(const char *device_file,
52  fawkes::Logger *logger);
53 
54  virtual void init();
55  virtual void finalize();
56  virtual void loop();
57 
58  bool lock_if_new_data();
59  void unlock();
60 
61  char num_axes() const;
62  char num_buttons() const;
63  const char * joystick_name() const;
64  unsigned int pressed_buttons() const;
65  float * axis_values();
66 
67  /** Access force feedback of joystick.
68  * @return instance of JoystickForceFeedback class for current joystick. */
69  JoystickForceFeedback * ff() const { return ff_; }
70 
71  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
72  protected: virtual void run() { Thread::run(); }
73 
74  private:
75  void init(std::string device_file);
76  void open_joystick();
77  void open_forcefeedback();
78 
79  private:
80  std::string cfg_device_file_;
81  float cfg_safety_lockout_timeout_;
82  unsigned int cfg_safety_button_mask_;
83  unsigned int cfg_safety_bypass_button_mask_;
84 
85  bool safety_combo_[5];
86  bool safety_lockout_;
87 
88  int fd_;
89  bool connected_;
90  bool just_connected_;
91  unsigned int axis_array_size_;
92  char num_axes_;
93  char num_buttons_;
94  char joystick_name_[128];
95 
96  bool new_data_;
97  fawkes::Mutex *data_mutex_;
98 
99  unsigned int pressed_buttons_;
100  float *axis_values_;
101 
102  JoystickBlackBoardHandler *bbhandler_;
104 };
105 
106 
107 #endif
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
Handler class for joystick data.
Definition: bb_handler.h:26
Thread class encapsulation of pthreads.
Definition: thread.h:42
Joystick acqusition thread for Linux joystick API.
JoystickForceFeedback * ff() const
Access force feedback of joystick.
Cause force feedback on a joystick.
Thread aspect to log output.
Definition: logging.h:35
Thread aspect to access configuration data.
Definition: configurable.h:35
virtual void run()
Stub to see name in backtrace for easier debugging.
Mutex mutual exclusion lock.
Definition: mutex.h:32
Interface for logging.
Definition: logger.h:34