Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 #pragma pack(push,4)
92  /** Internal data storage, do NOT modify! */
93  typedef struct {
94  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
95  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
96  uint8_t num_axes; /**<
97  The number of axes of this joystick
98  */
99  uint8_t num_buttons; /**<
100  The number of buttons of this joystick.
101  */
102  uint8_t supported_ff_effects; /**<
103  Bit field indicating available force-feedback effects.
104  */
105  uint32_t pressed_buttons; /**<
106  A bit field of enabled buttons. For each currently clicked button the
107  corresponding bit is set to 1. Use the BUTTON_* constants for bit-wise
108  comparisons.
109  */
110  float axis[8]; /**< Values of axes. */
111  uint8_t ff_effects; /**<
112  Currently running effects. Either 0 if no effect is running, or a bit-wise
113  ored field of the JFF constants.
114  */
115  } JoystickInterface_data_t;
116 #pragma pack(pop)
117 
118  JoystickInterface_data_t *data;
119 
120  public:
121  /* messages */
123  {
124  private:
125 #pragma pack(push,4)
126  /** Internal data storage, do NOT modify! */
127  typedef struct {
128  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
129  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
130  uint16_t length; /**< Effect length in ms.
131  Setting to 0 will make the effect to play continuously until stopped.
132  */
133  uint16_t delay; /**< Delay before effect starts in ms. */
134  int32_t direction; /**< Direction of effect */
135  uint16_t strong_magnitude; /**< Magnitude of heavy motor. */
136  uint16_t weak_magnitude; /**< Magnitude of light motor. */
137  } StartRumbleMessage_data_t;
138 #pragma pack(pop)
139 
140  StartRumbleMessage_data_t *data;
141 
142  public:
143  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);
146 
148  /* Methods */
149  uint16_t length() const;
150  void set_length(const uint16_t new_length);
151  size_t maxlenof_length() const;
152  uint16_t delay() const;
153  void set_delay(const uint16_t new_delay);
154  size_t maxlenof_delay() const;
155  Direction direction() const;
156  void set_direction(const Direction new_direction);
157  size_t maxlenof_direction() const;
158  uint16_t strong_magnitude() const;
159  void set_strong_magnitude(const uint16_t new_strong_magnitude);
160  size_t maxlenof_strong_magnitude() const;
161  uint16_t weak_magnitude() const;
162  void set_weak_magnitude(const uint16_t new_weak_magnitude);
163  size_t maxlenof_weak_magnitude() const;
164  virtual Message * clone() const;
165  };
166 
167  class StopRumbleMessage : public Message
168  {
169  private:
170 #pragma pack(push,4)
171  /** Internal data storage, do NOT modify! */
172  typedef struct {
173  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
174  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
175  } StopRumbleMessage_data_t;
176 #pragma pack(pop)
177 
178  StopRumbleMessage_data_t *data;
179 
180  public:
183 
185  /* Methods */
186  virtual Message * clone() const;
187  };
188 
189  class StopAllMessage : public Message
190  {
191  private:
192 #pragma pack(push,4)
193  /** Internal data storage, do NOT modify! */
194  typedef struct {
195  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
196  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
197  } StopAllMessage_data_t;
198 #pragma pack(pop)
199 
200  StopAllMessage_data_t *data;
201 
202  public:
203  StopAllMessage();
204  ~StopAllMessage();
205 
206  StopAllMessage(const StopAllMessage *m);
207  /* Methods */
208  virtual Message * clone() const;
209  };
210 
211  virtual bool message_valid(const Message *message) const;
212  private:
215 
216  public:
217  /* Methods */
218  uint8_t num_axes() const;
219  void set_num_axes(const uint8_t new_num_axes);
220  size_t maxlenof_num_axes() const;
221  uint8_t num_buttons() const;
222  void set_num_buttons(const uint8_t new_num_buttons);
223  size_t maxlenof_num_buttons() const;
224  uint8_t supported_ff_effects() const;
225  void set_supported_ff_effects(const uint8_t new_supported_ff_effects);
226  size_t maxlenof_supported_ff_effects() const;
227  uint32_t pressed_buttons() const;
228  void set_pressed_buttons(const uint32_t new_pressed_buttons);
229  size_t maxlenof_pressed_buttons() const;
230  float * axis() const;
231  float axis(unsigned int index) const;
232  void set_axis(unsigned int index, const float new_axis);
233  void set_axis(const float * new_axis);
234  size_t maxlenof_axis() const;
235  uint8_t ff_effects() const;
236  void set_ff_effects(const uint8_t new_ff_effects);
237  size_t maxlenof_ff_effects() const;
238  virtual Message * create_message(const char *type) const;
239 
240  virtual void copy_values(const Interface *other);
241  virtual const char * enum_tostring(const char *enumtype, int val) const;
242 
243 };
244 
245 } // end namespace fawkes
246 
247 #endif
void set_direction(const Direction new_direction)
Set direction value.
static const uint32_t BUTTON_14
BUTTON_14 constant.
static const uint32_t BUTTON_4
BUTTON_4 constant.
float * axis() const
Get axis value.
static const uint32_t BUTTON_15
BUTTON_15 constant.
static const uint32_t BUTTON_23
BUTTON_23 constant.
static const uint32_t BUTTON_28
BUTTON_28 constant.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:43
size_t maxlenof_supported_ff_effects() const
Get maximum length of supported_ff_effects value.
virtual void copy_values(const Interface *other)
Copy values from other interface.
static const uint32_t BUTTON_1
BUTTON_1 constant.
size_t maxlenof_num_axes() const
Get maximum length of num_axes value.
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.
size_t maxlenof_axis() const
Get maximum length of axis value.
static const uint8_t JFF_RAMP
JFF_RAMP constant.
size_t maxlenof_num_buttons() const
Get maximum length of num_buttons value.
uint32_t pressed_buttons() const
Get pressed_buttons value.
Direction
Effect direction.
uint16_t length() const
Get length value.
void set_pressed_buttons(const uint32_t new_pressed_buttons)
Set pressed_buttons value.
size_t maxlenof_delay() const
Get maximum length of delay value.
static const uint32_t BUTTON_22
BUTTON_22 constant.
uint16_t weak_magnitude() const
Get weak_magnitude value.
uint8_t ff_effects() const
Get ff_effects value.
static const uint32_t BUTTON_27
BUTTON_27 constant.
virtual Message * clone() const
Clone this message.
static const uint32_t BUTTON_8
BUTTON_8 constant.
uint16_t strong_magnitude() const
Get strong_magnitude value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
static const uint32_t BUTTON_20
BUTTON_20 constant.
uint8_t supported_ff_effects() const
Get supported_ff_effects value.
void set_weak_magnitude(const uint16_t new_weak_magnitude)
Set weak_magnitude value.
uint8_t num_axes() const
Get num_axes value.
uint8_t num_buttons() const
Get num_buttons value.
StopRumbleMessage Fawkes BlackBoard Interface Message.
void set_num_axes(const uint8_t new_num_axes)
Set num_axes 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.
void set_delay(const uint16_t new_delay)
Set delay value.
static const uint32_t BUTTON_12
BUTTON_12 constant.
static const uint32_t BUTTON_21
BUTTON_21 constant.
static const uint32_t BUTTON_19
BUTTON_19 constant.
static const uint32_t BUTTON_6
BUTTON_6 constant.
static const uint32_t BUTTON_17
BUTTON_17 constant.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
size_t maxlenof_weak_magnitude() const
Get maximum length of weak_magnitude value.
size_t maxlenof_pressed_buttons() const
Get maximum length of pressed_buttons value.
size_t maxlenof_strong_magnitude() const
Get maximum length of strong_magnitude value.
static const uint32_t BUTTON_16
BUTTON_16 constant.
uint16_t delay() const
Get delay value.
size_t maxlenof_direction() const
Get maximum length of direction value.
static const uint32_t BUTTON_24
BUTTON_24 constant.
static const uint8_t JFF_DAMPER
JFF_DAMPER constant.
size_t maxlenof_length() const
Get maximum length of length value.
static const uint32_t BUTTON_13
BUTTON_13 constant.
const char * tostring_Direction(Direction value) const
Convert Direction constant to string.
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.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
virtual Message * clone() const
Clone this message.
virtual Message * create_message(const char *type) const
Create message based on type name.
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.
static const uint8_t JFF_INERTIA
JFF_INERTIA constant.
size_t maxlenof_ff_effects() const
Get maximum length of ff_effects value.
void set_length(const uint16_t new_length)
Set length value.
void set_ff_effects(const uint8_t new_ff_effects)
Set ff_effects value.
static const uint32_t BUTTON_3
BUTTON_3 constant.
static const uint32_t BUTTON_5
BUTTON_5 constant.
void set_strong_magnitude(const uint16_t new_strong_magnitude)
Set strong_magnitude value.
Direction direction() const
Get direction value.
virtual Message * clone() const
Clone this message.
const char * type() const
Get type of interface.
Definition: interface.cpp:635
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.