Fawkes API  Fawkes Development Version
JoystickInterface.h
1 
2 /***************************************************************************
3  * JoystickInterface.h - Fawkes BlackBoard Interface - JoystickInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2008 Tim Niemueller
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. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __INTERFACES_JOYSTICKINTERFACE_H_
25 #define __INTERFACES_JOYSTICKINTERFACE_H_
26 
27 #include <interface/interface.h>
28 #include <interface/message.h>
29 #include <interface/field_iterator.h>
30 
31 namespace fawkes {
32 
34 {
35  /// @cond INTERNALS
36  INTERFACE_MGMT_FRIENDS(JoystickInterface)
37  /// @endcond
38  public:
39  /* constants */
40  static const uint32_t BUTTON_1;
41  static const uint32_t BUTTON_2;
42  static const uint32_t BUTTON_3;
43  static const uint32_t BUTTON_4;
44  static const uint32_t BUTTON_5;
45  static const uint32_t BUTTON_6;
46  static const uint32_t BUTTON_7;
47  static const uint32_t BUTTON_8;
48  static const uint32_t BUTTON_9;
49  static const uint32_t BUTTON_10;
50  static const uint32_t BUTTON_11;
51  static const uint32_t BUTTON_12;
52  static const uint32_t BUTTON_13;
53  static const uint32_t BUTTON_14;
54  static const uint32_t BUTTON_15;
55  static const uint32_t BUTTON_16;
56  static const uint32_t BUTTON_17;
57  static const uint32_t BUTTON_18;
58  static const uint32_t BUTTON_19;
59  static const uint32_t BUTTON_20;
60  static const uint32_t BUTTON_21;
61  static const uint32_t BUTTON_22;
62  static const uint32_t BUTTON_23;
63  static const uint32_t BUTTON_24;
64  static const uint32_t BUTTON_25;
65  static const uint32_t BUTTON_26;
66  static const uint32_t BUTTON_27;
67  static const uint32_t BUTTON_28;
68  static const uint32_t BUTTON_29;
69  static const uint32_t BUTTON_30;
70  static const uint32_t BUTTON_31;
71  static const uint32_t BUTTON_32;
72  static const uint8_t JFF_RUMBLE;
73  static const uint8_t JFF_PERIODIC;
74  static const uint8_t JFF_RAMP;
75  static const uint8_t JFF_SPRING;
76  static const uint8_t JFF_FRICTION;
77  static const uint8_t JFF_DAMPER;
78  static const uint8_t JFF_INERTIA;
79  static const uint8_t JFF_CONSTANT;
80 
81  /** Effect direction. */
82  typedef enum {
83  DIRECTION_DOWN = 0 /**< Down. */,
84  DIRECTION_LEFT = 16384 /**< Left. */,
85  DIRECTION_UP = 32768 /**< Up. */,
86  DIRECTION_RIGHT = 49152 /**< Right. */
87  } Direction;
88  const char * tostring_Direction(Direction value) const;
89 
90  private:
91  /** Internal data storage, do NOT modify! */
92  typedef struct __attribute__((packed)) {
93  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
94  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
95  uint8_t num_axes; /**<
96  The number of axes of this joystick
97  */
98  uint8_t num_buttons; /**<
99  The number of buttons of this joystick.
100  */
101  uint8_t supported_ff_effects; /**<
102  Bit field indicating available force-feedback effects.
103  */
104  uint32_t pressed_buttons; /**<
105  A bit field of enabled buttons. For each currently clicked button the
106  corresponding bit is set to 1. Use the BUTTON_* constants for bit-wise
107  comparisons.
108  */
109  float axis[8]; /**< Values of axes. */
110  uint8_t ff_effects; /**<
111  Currently running effects. Either 0 if no effect is running, or a bit-wise
112  ored field of the JFF constants.
113  */
114  } JoystickInterface_data_t;
115 
116  JoystickInterface_data_t *data;
117 
118  interface_enum_map_t enum_map_Direction;
119  public:
120  /* messages */
122  {
123  private:
124  /** Internal data storage, do NOT modify! */
125  typedef struct __attribute__((packed)) {
126  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
127  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
128  uint16_t length; /**< Effect length in ms.
129  Setting to 0 will make the effect to play continuously until stopped.
130  */
131  uint16_t delay; /**< Delay before effect starts in ms. */
132  int32_t direction; /**< Direction of effect */
133  uint16_t strong_magnitude; /**< Magnitude of heavy motor. */
134  uint16_t weak_magnitude; /**< Magnitude of light motor. */
135  } StartRumbleMessage_data_t;
136 
137  StartRumbleMessage_data_t *data;
138 
139  interface_enum_map_t enum_map_Direction;
140  public:
141  StartRumbleMessage(const uint16_t ini_length, const uint16_t ini_delay, const Direction ini_direction, const uint16_t ini_strong_magnitude, const uint16_t ini_weak_magnitude);
144 
146  /* Methods */
147  uint16_t length() const;
148  void set_length(const uint16_t new_length);
149  size_t maxlenof_length() const;
150  uint16_t delay() const;
151  void set_delay(const uint16_t new_delay);
152  size_t maxlenof_delay() const;
153  Direction direction() const;
154  void set_direction(const Direction new_direction);
155  size_t maxlenof_direction() const;
156  uint16_t strong_magnitude() const;
157  void set_strong_magnitude(const uint16_t new_strong_magnitude);
158  size_t maxlenof_strong_magnitude() const;
159  uint16_t weak_magnitude() const;
160  void set_weak_magnitude(const uint16_t new_weak_magnitude);
161  size_t maxlenof_weak_magnitude() const;
162  virtual Message * clone() const;
163  };
164 
165  class StopRumbleMessage : public Message
166  {
167  private:
168  /** Internal data storage, do NOT modify! */
169  typedef struct __attribute__((packed)) {
170  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
171  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
172  } StopRumbleMessage_data_t;
173 
174  StopRumbleMessage_data_t *data;
175 
176  interface_enum_map_t enum_map_Direction;
177  public:
180 
182  /* Methods */
183  virtual Message * clone() const;
184  };
185 
186  class StopAllMessage : public Message
187  {
188  private:
189  /** Internal data storage, do NOT modify! */
190  typedef struct __attribute__((packed)) {
191  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
192  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
193  } StopAllMessage_data_t;
194 
195  StopAllMessage_data_t *data;
196 
197  interface_enum_map_t enum_map_Direction;
198  public:
199  StopAllMessage();
200  ~StopAllMessage();
201 
202  StopAllMessage(const StopAllMessage *m);
203  /* Methods */
204  virtual Message * clone() const;
205  };
206 
207  virtual bool message_valid(const Message *message) const;
208  private:
211 
212  public:
213  /* Methods */
214  uint8_t num_axes() const;
215  void set_num_axes(const uint8_t new_num_axes);
216  size_t maxlenof_num_axes() const;
217  uint8_t num_buttons() const;
218  void set_num_buttons(const uint8_t new_num_buttons);
219  size_t maxlenof_num_buttons() const;
220  uint8_t supported_ff_effects() const;
221  void set_supported_ff_effects(const uint8_t new_supported_ff_effects);
222  size_t maxlenof_supported_ff_effects() const;
223  uint32_t pressed_buttons() const;
224  void set_pressed_buttons(const uint32_t new_pressed_buttons);
225  size_t maxlenof_pressed_buttons() const;
226  float * axis() const;
227  float axis(unsigned int index) const;
228  void set_axis(unsigned int index, const float new_axis);
229  void set_axis(const float * new_axis);
230  size_t maxlenof_axis() const;
231  uint8_t ff_effects() const;
232  void set_ff_effects(const uint8_t new_ff_effects);
233  size_t maxlenof_ff_effects() const;
234  virtual Message * create_message(const char *type) const;
235 
236  virtual void copy_values(const Interface *other);
237  virtual const char * enum_tostring(const char *enumtype, int val) const;
238 
239 };
240 
241 } // end namespace fawkes
242 
243 #endif
static const uint32_t BUTTON_14
BUTTON_14 constant.
static const uint32_t BUTTON_4
BUTTON_4 constant.
static const uint32_t BUTTON_15
BUTTON_15 constant.
static const uint32_t BUTTON_23
BUTTON_23 constant.
size_t maxlenof_ff_effects() const
Get maximum length of ff_effects value.
static const uint32_t BUTTON_28
BUTTON_28 constant.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
virtual void copy_values(const Interface *other)
Copy values from other interface.
static const uint32_t BUTTON_1
BUTTON_1 constant.
StopAllMessage Fawkes BlackBoard Interface Message.
JoystickInterface Fawkes BlackBoard Interface.
static const uint8_t JFF_SPRING
JFF_SPRING constant.
static const uint32_t BUTTON_7
BUTTON_7 constant.
static const uint32_t BUTTON_32
BUTTON_32 constant.
static const uint8_t JFF_RAMP
JFF_RAMP constant.
Fawkes library namespace.
Direction
Effect direction.
void set_pressed_buttons(const uint32_t new_pressed_buttons)
Set pressed_buttons value.
static const uint32_t BUTTON_22
BUTTON_22 constant.
static const uint32_t BUTTON_27
BUTTON_27 constant.
static const uint32_t BUTTON_8
BUTTON_8 constant.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
static const uint32_t BUTTON_20
BUTTON_20 constant.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
float * axis() const
Get axis value.
StopRumbleMessage Fawkes BlackBoard Interface Message.
void set_num_axes(const uint8_t new_num_axes)
Set num_axes value.
size_t maxlenof_num_buttons() const
Get maximum length of num_buttons value.
static const uint32_t BUTTON_11
BUTTON_11 constant.
static const uint8_t JFF_FRICTION
JFF_FRICTION constant.
static const uint8_t JFF_PERIODIC
JFF_PERIODIC constant.
static const uint32_t BUTTON_18
BUTTON_18 constant.
static const uint32_t BUTTON_12
BUTTON_12 constant.
const char * type() const
Get type of interface.
Definition: interface.cpp:651
static const uint32_t BUTTON_21
BUTTON_21 constant.
static const uint32_t BUTTON_19
BUTTON_19 constant.
uint8_t supported_ff_effects() const
Get supported_ff_effects value.
uint32_t pressed_buttons() const
Get pressed_buttons value.
static const uint32_t BUTTON_6
BUTTON_6 constant.
static const uint32_t BUTTON_17
BUTTON_17 constant.
static const uint32_t BUTTON_16
BUTTON_16 constant.
static const uint32_t BUTTON_24
BUTTON_24 constant.
static const uint8_t JFF_DAMPER
JFF_DAMPER constant.
static const uint32_t BUTTON_13
BUTTON_13 constant.
uint8_t ff_effects() const
Get ff_effects value.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
StartRumbleMessage Fawkes BlackBoard Interface Message.
static const uint8_t JFF_RUMBLE
JFF_RUMBLE constant.
static const uint32_t BUTTON_10
BUTTON_10 constant.
void set_supported_ff_effects(const uint8_t new_supported_ff_effects)
Set supported_ff_effects value.
static const uint32_t BUTTON_30
BUTTON_30 constant.
void set_axis(unsigned int index, const float new_axis)
Set axis value at given index.
static const uint32_t BUTTON_2
BUTTON_2 constant.
static const uint32_t BUTTON_29
BUTTON_29 constant.
static const uint32_t BUTTON_9
BUTTON_9 constant.
uint8_t num_axes() const
Get num_axes value.
static const uint8_t JFF_INERTIA
JFF_INERTIA constant.
size_t maxlenof_pressed_buttons() const
Get maximum length of pressed_buttons value.
const char * tostring_Direction(Direction value) const
Convert Direction constant to string.
void set_ff_effects(const uint8_t new_ff_effects)
Set ff_effects value.
static const uint32_t BUTTON_3
BUTTON_3 constant.
uint8_t num_buttons() const
Get num_buttons value.
static const uint32_t BUTTON_5
BUTTON_5 constant.
size_t maxlenof_axis() const
Get maximum length of axis value.
size_t maxlenof_num_axes() const
Get maximum length of num_axes value.
virtual Message * create_message(const char *type) const
Create message based on type name.
std::map< int, std::string > interface_enum_map_t
Map of enum integer to string values.
Definition: types.h:53
static const uint8_t JFF_CONSTANT
JFF_CONSTANT constant.
void set_num_buttons(const uint8_t new_num_buttons)
Set num_buttons value.
static const uint32_t BUTTON_26
BUTTON_26 constant.
static const uint32_t BUTTON_31
BUTTON_31 constant.
static const uint32_t BUTTON_25
BUTTON_25 constant.
size_t maxlenof_supported_ff_effects() const
Get maximum length of supported_ff_effects value.