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