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 <aspect/configurable.h>
29 #include <aspect/logging.h>
30 #include <core/threading/thread.h>
31 #include <utils/math/types.h>
32 
33 #include <string>
34 #include <vector>
35 
36 namespace fawkes {
37 class Mutex;
38 }
39 
41 
43  public fawkes::LoggingAspect,
45 {
46 public:
48  JoystickAcquisitionThread(const char * device_file,
51 
52  virtual void init();
53  virtual void finalize();
54  virtual void loop();
55 
56  bool lock_if_new_data();
57  void unlock();
58 
59  char num_axes() const;
60  char num_buttons() const;
61  const char * joystick_name() const;
62  unsigned int pressed_buttons() const;
63  float * axis_values();
64 
65  /** Access force feedback of joystick.
66  * @return instance of JoystickForceFeedback class for current joystick. */
68  ff() const
69  {
70  return ff_;
71  }
72 
73  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
74 protected:
75  virtual void
76  run()
77  {
78  Thread::run();
79  }
80 
81 private:
82  void init(const std::string &device_file, bool allow_open_fail = false);
83  void open_joystick();
84  void open_forcefeedback();
85 
86 private:
87  std::string cfg_device_file_;
88  float cfg_retry_interval_;
89  bool cfg_lazy_init_;
90  float cfg_safety_lockout_timeout_;
91  unsigned int cfg_safety_button_mask_;
92  unsigned int cfg_safety_bypass_button_mask_;
93 
94  bool safety_combo_[5];
95  bool safety_lockout_;
96 
97  int fd_;
98  bool connected_;
99  bool just_connected_;
100  unsigned int axis_array_size_;
101  char num_axes_;
102  char num_buttons_;
103  char joystick_name_[128];
104 
105  bool new_data_;
106  fawkes::Mutex *data_mutex_;
107 
108  unsigned int pressed_buttons_;
109  float * axis_values_;
110 
111  JoystickBlackBoardHandler *bbhandler_;
112  JoystickForceFeedback * ff_;
113 };
114 
115 #endif
unsigned int pressed_buttons() const
Pressed buttons.
virtual void loop()
Code to execute in the thread.
float * axis_values()
Get values for the axes.
Fawkes library namespace.
Handler class for joystick data.
Definition: bb_handler.h:26
Thread class encapsulation of pthreads.
Definition: thread.h:45
bool lock_if_new_data()
Lock data if fresh.
Joystick acqusition thread for Linux joystick API.
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
const char * joystick_name() const
Get joystick name.
JoystickForceFeedback * ff() const
Access force feedback of joystick.
Cause force feedback on a joystick.
char num_buttons() const
Get number of buttons.
virtual void finalize()
Finalize the thread.
Thread aspect to log output.
Definition: logging.h:32
Thread aspect to access configuration data.
Definition: configurable.h:32
virtual void run()
Stub to see name in backtrace for easier debugging.
Mutex mutual exclusion lock.
Definition: mutex.h:32
virtual void init()
Initialize the thread.
char num_axes() const
Get number of axes.
Interface for logging.
Definition: logger.h:41