Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * JoystickInterface.h - Fawkes BlackBoard Interface - JoystickInterface 00004 * 00005 * Templated created: Thu Oct 12 10:49:19 2006 00006 * Copyright 2008 Tim Niemueller 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #ifndef __INTERFACES_JOYSTICKINTERFACE_H_ 00025 #define __INTERFACES_JOYSTICKINTERFACE_H_ 00026 00027 #include <interface/interface.h> 00028 #include <interface/message.h> 00029 #include <interface/field_iterator.h> 00030 00031 namespace fawkes { 00032 00033 class JoystickInterface : public Interface 00034 { 00035 /// @cond INTERNALS 00036 INTERFACE_MGMT_FRIENDS(JoystickInterface) 00037 /// @endcond 00038 public: 00039 /* constants */ 00040 static const uint32_t BUTTON_1; 00041 static const uint32_t BUTTON_2; 00042 static const uint32_t BUTTON_3; 00043 static const uint32_t BUTTON_4; 00044 static const uint32_t BUTTON_5; 00045 static const uint32_t BUTTON_6; 00046 static const uint32_t BUTTON_7; 00047 static const uint32_t BUTTON_8; 00048 static const uint32_t BUTTON_9; 00049 static const uint32_t BUTTON_10; 00050 static const uint32_t BUTTON_11; 00051 static const uint32_t BUTTON_12; 00052 static const uint32_t BUTTON_13; 00053 static const uint32_t BUTTON_14; 00054 static const uint32_t BUTTON_15; 00055 static const uint32_t BUTTON_16; 00056 static const uint32_t BUTTON_17; 00057 static const uint32_t BUTTON_18; 00058 static const uint32_t BUTTON_19; 00059 static const uint32_t BUTTON_20; 00060 static const uint32_t BUTTON_21; 00061 static const uint32_t BUTTON_22; 00062 static const uint32_t BUTTON_23; 00063 static const uint32_t BUTTON_24; 00064 static const uint32_t BUTTON_25; 00065 static const uint32_t BUTTON_26; 00066 static const uint32_t BUTTON_27; 00067 static const uint32_t BUTTON_28; 00068 static const uint32_t BUTTON_29; 00069 static const uint32_t BUTTON_30; 00070 static const uint32_t BUTTON_31; 00071 static const uint32_t BUTTON_32; 00072 static const uint8_t JFF_RUMBLE; 00073 static const uint8_t JFF_PERIODIC; 00074 static const uint8_t JFF_RAMP; 00075 static const uint8_t JFF_SPRING; 00076 static const uint8_t JFF_FRICTION; 00077 static const uint8_t JFF_DAMPER; 00078 static const uint8_t JFF_INERTIA; 00079 static const uint8_t JFF_CONSTANT; 00080 00081 /** Effect direction. */ 00082 typedef enum { 00083 DIRECTION_DOWN = 0 /**< Down. */, 00084 DIRECTION_LEFT = 16384 /**< Left. */, 00085 DIRECTION_UP = 32768 /**< Up. */, 00086 DIRECTION_RIGHT = 49152 /**< Right. */ 00087 } Direction; 00088 const char * tostring_Direction(Direction value) const; 00089 00090 private: 00091 #pragma pack(push,4) 00092 /** Internal data storage, do NOT modify! */ 00093 typedef struct { 00094 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00095 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00096 uint8_t num_axes; /**< 00097 The number of axes of this joystick 00098 */ 00099 uint8_t num_buttons; /**< 00100 The number of buttons of this joystick. 00101 */ 00102 uint8_t supported_ff_effects; /**< 00103 Bit field indicating available force-feedback effects. 00104 */ 00105 uint32_t pressed_buttons; /**< 00106 A bit field of enabled buttons. For each currently clicked button the 00107 corresponding bit is set to 1. Use the BUTTON_* constants for bit-wise 00108 comparisons. 00109 */ 00110 float axis[8]; /**< Values of axes. */ 00111 uint8_t ff_effects; /**< 00112 Currently running effects. Either 0 if no effect is running, or a bit-wise 00113 ored field of the JFF constants. 00114 */ 00115 } JoystickInterface_data_t; 00116 #pragma pack(pop) 00117 00118 JoystickInterface_data_t *data; 00119 00120 public: 00121 /* messages */ 00122 class StartRumbleMessage : public Message 00123 { 00124 private: 00125 #pragma pack(push,4) 00126 /** Internal data storage, do NOT modify! */ 00127 typedef struct { 00128 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00129 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00130 uint16_t length; /**< Effect length in ms. 00131 Setting to 0 will make the effect to play continuously until stopped. 00132 */ 00133 uint16_t delay; /**< Delay before effect starts in ms. */ 00134 int32_t direction; /**< Direction of effect */ 00135 uint16_t strong_magnitude; /**< Magnitude of heavy motor. */ 00136 uint16_t weak_magnitude; /**< Magnitude of light motor. */ 00137 } StartRumbleMessage_data_t; 00138 #pragma pack(pop) 00139 00140 StartRumbleMessage_data_t *data; 00141 00142 public: 00143 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); 00144 StartRumbleMessage(); 00145 ~StartRumbleMessage(); 00146 00147 StartRumbleMessage(const StartRumbleMessage *m); 00148 /* Methods */ 00149 uint16_t length() const; 00150 void set_length(const uint16_t new_length); 00151 size_t maxlenof_length() const; 00152 uint16_t delay() const; 00153 void set_delay(const uint16_t new_delay); 00154 size_t maxlenof_delay() const; 00155 Direction direction() const; 00156 void set_direction(const Direction new_direction); 00157 size_t maxlenof_direction() const; 00158 uint16_t strong_magnitude() const; 00159 void set_strong_magnitude(const uint16_t new_strong_magnitude); 00160 size_t maxlenof_strong_magnitude() const; 00161 uint16_t weak_magnitude() const; 00162 void set_weak_magnitude(const uint16_t new_weak_magnitude); 00163 size_t maxlenof_weak_magnitude() const; 00164 virtual Message * clone() const; 00165 }; 00166 00167 class StopRumbleMessage : public Message 00168 { 00169 private: 00170 #pragma pack(push,4) 00171 /** Internal data storage, do NOT modify! */ 00172 typedef struct { 00173 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00174 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00175 } StopRumbleMessage_data_t; 00176 #pragma pack(pop) 00177 00178 StopRumbleMessage_data_t *data; 00179 00180 public: 00181 StopRumbleMessage(); 00182 ~StopRumbleMessage(); 00183 00184 StopRumbleMessage(const StopRumbleMessage *m); 00185 /* Methods */ 00186 virtual Message * clone() const; 00187 }; 00188 00189 class StopAllMessage : public Message 00190 { 00191 private: 00192 #pragma pack(push,4) 00193 /** Internal data storage, do NOT modify! */ 00194 typedef struct { 00195 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00196 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00197 } StopAllMessage_data_t; 00198 #pragma pack(pop) 00199 00200 StopAllMessage_data_t *data; 00201 00202 public: 00203 StopAllMessage(); 00204 ~StopAllMessage(); 00205 00206 StopAllMessage(const StopAllMessage *m); 00207 /* Methods */ 00208 virtual Message * clone() const; 00209 }; 00210 00211 virtual bool message_valid(const Message *message) const; 00212 private: 00213 JoystickInterface(); 00214 ~JoystickInterface(); 00215 00216 public: 00217 /* Methods */ 00218 uint8_t num_axes() const; 00219 void set_num_axes(const uint8_t new_num_axes); 00220 size_t maxlenof_num_axes() const; 00221 uint8_t num_buttons() const; 00222 void set_num_buttons(const uint8_t new_num_buttons); 00223 size_t maxlenof_num_buttons() const; 00224 uint8_t supported_ff_effects() const; 00225 void set_supported_ff_effects(const uint8_t new_supported_ff_effects); 00226 size_t maxlenof_supported_ff_effects() const; 00227 uint32_t pressed_buttons() const; 00228 void set_pressed_buttons(const uint32_t new_pressed_buttons); 00229 size_t maxlenof_pressed_buttons() const; 00230 float * axis() const; 00231 float axis(unsigned int index) const; 00232 void set_axis(unsigned int index, const float new_axis); 00233 void set_axis(const float * new_axis); 00234 size_t maxlenof_axis() const; 00235 uint8_t ff_effects() const; 00236 void set_ff_effects(const uint8_t new_ff_effects); 00237 size_t maxlenof_ff_effects() const; 00238 virtual Message * create_message(const char *type) const; 00239 00240 virtual void copy_values(const Interface *other); 00241 virtual const char * enum_tostring(const char *enumtype, int val) const; 00242 00243 }; 00244 00245 } // end namespace fawkes 00246 00247 #endif