Fawkes API  Fawkes Development Version
force_feedback.h
1 
2 /***************************************************************************
3  * force_feedback.h - Force feedback for joysticks using Linux input API
4  *
5  * Created: Sun Feb 06 23:50:57 2011 (Super Bowl XLV)
6  * Copyright 2006-2011 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_FORCE_FEEDBACK_H_
24 #define _PLUGINS_JOYSTICK_FORCE_FEEDBACK_H_
25 
26 #include <linux/input.h>
27 
28 #include <stdint.h>
29 
31 {
32 public:
33  /** Direction of the effect. */
34  typedef enum {
35  DIRECTION_DOWN = 0x0000, /**< Downward effect direction. */
36  DIRECTION_LEFT = 0x4000, /**< Left effect direction. */
37  DIRECTION_UP = 0x8000, /**< Upward effect direction. */
38  DIRECTION_RIGHT = 0xC000 /**< Right effect direction. */
40 
41  JoystickForceFeedback(const char *device_name);
43 
44  void rumble(uint16_t strong_magnitude,
45  uint16_t weak_magnitude,
46  Direction direction = DIRECTION_DOWN,
47  uint16_t length = 0,
48  uint16_t delay = 0);
49 
50  void stop_all();
51  void stop_rumble();
52 
53  bool
55  {
56  return (rumble_.id != -1);
57  }
58  bool
60  {
61  return can_rumble_;
62  }
63  bool
65  {
66  return can_periodic_;
67  }
68  bool
70  {
71  return can_constant_;
72  }
73  bool
75  {
76  return can_spring_;
77  }
78  bool
80  {
81  return can_friction_;
82  }
83  bool
85  {
86  return can_damper_;
87  }
88  bool
90  {
91  return can_inertia_;
92  }
93  bool
95  {
96  return can_ramp_;
97  }
98  bool
100  {
101  return can_square_;
102  }
103  bool
105  {
106  return can_triangle_;
107  }
108  bool
110  {
111  return can_sine_;
112  }
113  bool
115  {
116  return can_saw_up_;
117  }
118  bool
120  {
121  return can_saw_down_;
122  }
123  bool
125  {
126  return can_custom_;
127  }
128 
129 private:
130  int fd_;
131  struct ff_effect rumble_;
132 
133  int num_effects_;
134 
135  bool can_rumble_;
136  bool can_periodic_;
137  bool can_constant_;
138  bool can_spring_;
139  bool can_friction_;
140  bool can_damper_;
141  bool can_inertia_;
142  bool can_ramp_;
143  bool can_square_;
144  bool can_triangle_;
145  bool can_sine_;
146  bool can_saw_up_;
147  bool can_saw_down_;
148  bool can_custom_;
149 };
150 
151 #endif
JoystickForceFeedback::can_spring
bool can_spring()
Check if spring effect is supported.
Definition: force_feedback.h:74
JoystickForceFeedback::stop_all
void stop_all()
Stop all current effects.
Definition: force_feedback.cpp:291
JoystickForceFeedback::can_ramp
bool can_ramp()
Check if ramp effect is supported.
Definition: force_feedback.h:94
JoystickForceFeedback::can_damper
bool can_damper()
Check if damper effect is supported.
Definition: force_feedback.h:84
JoystickForceFeedback::can_saw_down
bool can_saw_down()
Check if downward saw effect is supported.
Definition: force_feedback.h:119
JoystickForceFeedback::can_triangle
bool can_triangle()
Check if triangle effect is supported.
Definition: force_feedback.h:104
JoystickForceFeedback::can_rumble
bool can_rumble()
Check if rumbling effect is supported.
Definition: force_feedback.h:59
JoystickForceFeedback::~JoystickForceFeedback
~JoystickForceFeedback()
Destructor.
Definition: force_feedback.cpp:227
JoystickForceFeedback::DIRECTION_DOWN
@ DIRECTION_DOWN
Downward effect direction.
Definition: force_feedback.h:35
JoystickForceFeedback
Cause force feedback on a joystick.
Definition: force_feedback.h:31
JoystickForceFeedback::can_periodic
bool can_periodic()
Check if periodic effect is supported.
Definition: force_feedback.h:64
JoystickForceFeedback::DIRECTION_LEFT
@ DIRECTION_LEFT
Left effect direction.
Definition: force_feedback.h:36
JoystickForceFeedback::can_friction
bool can_friction()
Check if friction effect is supported.
Definition: force_feedback.h:79
JoystickForceFeedback::DIRECTION_UP
@ DIRECTION_UP
Upward effect direction.
Definition: force_feedback.h:37
JoystickForceFeedback::can_saw_up
bool can_saw_up()
Check if upward saw effect is supported.
Definition: force_feedback.h:114
JoystickForceFeedback::can_sine
bool can_sine()
Check if sine effect is supported.
Definition: force_feedback.h:109
JoystickForceFeedback::rumble
void rumble(uint16_t strong_magnitude, uint16_t weak_magnitude, Direction direction=DIRECTION_DOWN, uint16_t length=0, uint16_t delay=0)
Rumble the joystick.
Definition: force_feedback.cpp:246
JoystickForceFeedback::stop_rumble
void stop_rumble()
Stop rumbling.
Definition: force_feedback.cpp:279
JoystickForceFeedback::Direction
Direction
Direction of the effect.
Definition: force_feedback.h:34
JoystickForceFeedback::can_square
bool can_square()
Check if square effect is supported.
Definition: force_feedback.h:99
JoystickForceFeedback::JoystickForceFeedback
JoystickForceFeedback(const char *device_name)
Constructor.
Definition: force_feedback.cpp:123
JoystickForceFeedback::can_constant
bool can_constant()
Check if constant effect is supported.
Definition: force_feedback.h:69
JoystickForceFeedback::can_custom
bool can_custom()
Check if custom effect is supported.
Definition: force_feedback.h:124
JoystickForceFeedback::can_inertia
bool can_inertia()
Check if inertia effect is supported.
Definition: force_feedback.h:89
JoystickForceFeedback::is_rumbling
bool is_rumbling()
Check if rumbling effect is active.
Definition: force_feedback.h:54
JoystickForceFeedback::DIRECTION_RIGHT
@ DIRECTION_RIGHT
Right effect direction.
Definition: force_feedback.h:38