Choreonoid  1.8
Joystick.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_UTIL_JOYSTICK_H
7 #define CNOID_UTIL_JOYSTICK_H
8 
9 #include "JoystickInterface.h"
10 #include "Signal.h"
11 #include <string>
12 #include "exportdecl.h"
13 
14 namespace cnoid {
15 
16 class JoystickImpl;
17 
18 class CNOID_EXPORT Joystick : public JoystickInterface
19 {
20 public:
21  Joystick();
22  Joystick(const char* device);
23  virtual ~Joystick();
24 
25  std::string device() const;
26  int fileDescriptor() const;
27 
28  bool makeReady();
29  bool isReady() const;
30  const char* errorMessage() const;
31 
32  enum AxisID {
41  NUM_STD_AXES
42  };
43 
44  enum ButtonID {
45  A_BUTTON, // Cross
46  B_BUTTON, // Circle
47  X_BUTTON, // Square
48  Y_BUTTON, // Triangle
56  NUM_STD_BUTTONS
57  };
58 
59  virtual int numAxes() const override;
60  virtual int numButtons() const override;
61  virtual bool readCurrentState() override;
62  virtual double getPosition(int axis) const override;
63  virtual bool getButtonState(int button) const override;
64 
65  void setAxisEnabled(int axis, bool on);
66 
68  //double getDefaultPosition(int axis) const;
69 
70 #ifdef __linux__
71  bool getButtonDown(int button) const;
72  bool getButtonUp(int button) const;
73  bool getButtonHold(int button, int duration/*(msec)*/) const;
74  bool getButtonHoldOn(int button, int duration/*(msec)*/) const;
75 #endif
76 
77  bool isActive() const;
78  SignalProxy<void(int id, bool isPressed)> sigButton();
79  SignalProxy<void(int id, double position)> sigAxis();
80 
81 private:
82  JoystickImpl* impl;
83  friend class JoystickImpl;
84 };
85 
86 }
87 
88 #endif
cnoid::Joystick::LOGO_BUTTON
@ LOGO_BUTTON
Definition: Joystick.h:55
cnoid::Joystick::A_BUTTON
@ A_BUTTON
Definition: Joystick.h:45
cnoid::Joystick::Y_BUTTON
@ Y_BUTTON
Definition: Joystick.h:48
cnoid::Joystick::B_BUTTON
@ B_BUTTON
Definition: Joystick.h:46
cnoid::Joystick
Definition: Joystick.h:18
cnoid::Joystick::R_STICK_H_AXIS
@ R_STICK_H_AXIS
Definition: Joystick.h:35
cnoid::Joystick::R_TRIGGER_AXIS
@ R_TRIGGER_AXIS
Definition: Joystick.h:40
cnoid::Joystick::DIRECTIONAL_PAD_V_AXIS
@ DIRECTIONAL_PAD_V_AXIS
Definition: Joystick.h:38
cnoid::JoystickInterface
Definition: JoystickInterface.h:13
cnoid::Joystick::R_BUTTON
@ R_BUTTON
Definition: Joystick.h:50
cnoid::Joystick::AxisID
AxisID
Definition: Joystick.h:32
cnoid::Joystick::START_BUTTON
@ START_BUTTON
Definition: Joystick.h:52
cnoid::Joystick::L_STICK_BUTTON
@ L_STICK_BUTTON
Definition: Joystick.h:53
cnoid::Joystick::L_BUTTON
@ L_BUTTON
Definition: Joystick.h:49
cnoid::Joystick::DIRECTIONAL_PAD_H_AXIS
@ DIRECTIONAL_PAD_H_AXIS
Definition: Joystick.h:37
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::Joystick::ButtonID
ButtonID
Definition: Joystick.h:44
cnoid::Joystick::SELECT_BUTTON
@ SELECT_BUTTON
Definition: Joystick.h:51
Signal.h
cnoid::Joystick::L_STICK_V_AXIS
@ L_STICK_V_AXIS
Definition: Joystick.h:34
cnoid::Joystick::R_STICK_BUTTON
@ R_STICK_BUTTON
Definition: Joystick.h:54
cnoid::Joystick::X_BUTTON
@ X_BUTTON
Definition: Joystick.h:47
cnoid::Joystick::L_STICK_H_AXIS
@ L_STICK_H_AXIS
Definition: Joystick.h:33
JoystickInterface.h
cnoid::Joystick::R_STICK_V_AXIS
@ R_STICK_V_AXIS
Definition: Joystick.h:36
cnoid::SignalProxy
Definition: Signal.h:470
cnoid::Joystick::L_TRIGGER_AXIS
@ L_TRIGGER_AXIS
Definition: Joystick.h:39