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
JoystickAcquisitionThread::joystick_name
const char * joystick_name() const
Get joystick name.
Definition: acquisition_thread.cpp:455
JoystickAcquisitionThread::num_buttons
char num_buttons() const
Get number of buttons.
Definition: acquisition_thread.cpp:446
fawkes::Mutex
Definition: mutex.h:36
JoystickAcquisitionThread::finalize
virtual void finalize()
Finalize the thread.
Definition: acquisition_thread.cpp:252
JoystickForceFeedback
Definition: force_feedback.h:29
JoystickAcquisitionThread
Definition: acquisition_thread.h:41
JoystickAcquisitionThread::loop
virtual void loop()
Code to execute in the thread.
Definition: acquisition_thread.cpp:262
JoystickAcquisitionThread::init
virtual void init()
Initialize the thread.
Definition: acquisition_thread.cpp:90
JoystickAcquisitionThread::unlock
void unlock()
Unlock data.
Definition: acquisition_thread.cpp:427
JoystickAcquisitionThread::ff
JoystickForceFeedback * ff() const
Access force feedback of joystick.
Definition: acquisition_thread.h:67
fawkes::LoggingAspect::logger
Logger * logger
Definition: logging.h:50
fawkes::Logger
Definition: logger.h:40
JoystickAcquisitionThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: acquisition_thread.h:75
fawkes
fawkes::LoggingAspect
Definition: logging.h:36
JoystickAcquisitionThread::num_axes
char num_axes() const
Get number of axes.
Definition: acquisition_thread.cpp:437
JoystickAcquisitionThread::lock_if_new_data
bool lock_if_new_data()
Lock data if fresh.
Definition: acquisition_thread.cpp:413
JoystickAcquisitionThread::axis_values
float * axis_values()
Get values for the axes.
Definition: acquisition_thread.cpp:479
fawkes::Thread
Definition: thread.h:44
fawkes::ConfigurableAspect
Definition: configurable.h:36
JoystickAcquisitionThread::JoystickAcquisitionThread
JoystickAcquisitionThread()
Constructor.
Definition: acquisition_thread.cpp:56
JoystickAcquisitionThread::pressed_buttons
unsigned int pressed_buttons() const
Pressed buttons.
Definition: acquisition_thread.cpp:464
JoystickBlackBoardHandler
Definition: bb_handler.h:25