00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <interfaces/JoystickInterface.h>
00025
00026 #include <core/exceptions/software.h>
00027
00028 #include <cstring>
00029 #include <cstdlib>
00030
00031 namespace fawkes {
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 const unsigned int JoystickInterface::BUTTON_1 = 1;
00046
00047 const unsigned int JoystickInterface::BUTTON_2 = 2;
00048
00049 const unsigned int JoystickInterface::BUTTON_3 = 4;
00050
00051 const unsigned int JoystickInterface::BUTTON_4 = 8;
00052
00053 const unsigned int JoystickInterface::BUTTON_5 = 16;
00054
00055 const unsigned int JoystickInterface::BUTTON_6 = 32;
00056
00057 const unsigned int JoystickInterface::BUTTON_7 = 64;
00058
00059 const unsigned int JoystickInterface::BUTTON_8 = 128;
00060
00061 const unsigned int JoystickInterface::BUTTON_9 = 256;
00062
00063 const unsigned int JoystickInterface::BUTTON_10 = 512;
00064
00065 const unsigned int JoystickInterface::BUTTON_11 = 1024;
00066
00067 const unsigned int JoystickInterface::BUTTON_12 = 2048;
00068
00069 const unsigned int JoystickInterface::BUTTON_13 = 4096;
00070
00071 const unsigned int JoystickInterface::BUTTON_14 = 8192;
00072
00073 const unsigned int JoystickInterface::BUTTON_15 = 16384;
00074
00075 const unsigned int JoystickInterface::BUTTON_16 = 32768;
00076
00077 const unsigned int JoystickInterface::BUTTON_17 = 65536;
00078
00079 const unsigned int JoystickInterface::BUTTON_18 = 131072;
00080
00081 const unsigned int JoystickInterface::BUTTON_19 = 262144;
00082
00083 const unsigned int JoystickInterface::BUTTON_20 = 524288;
00084
00085 const unsigned int JoystickInterface::BUTTON_21 = 1048576;
00086
00087 const unsigned int JoystickInterface::BUTTON_22 = 2097152;
00088
00089 const unsigned int JoystickInterface::BUTTON_23 = 4194304;
00090
00091 const unsigned int JoystickInterface::BUTTON_24 = 8388608;
00092
00093 const unsigned int JoystickInterface::BUTTON_25 = 16777216;
00094
00095 const unsigned int JoystickInterface::BUTTON_26 = 33554432;
00096
00097 const unsigned int JoystickInterface::BUTTON_27 = 67108864;
00098
00099 const unsigned int JoystickInterface::BUTTON_28 = 134217728;
00100
00101 const unsigned int JoystickInterface::BUTTON_29 = 268435456;
00102
00103 const unsigned int JoystickInterface::BUTTON_30 = 536870912;
00104
00105 const unsigned int JoystickInterface::BUTTON_31 = 1073741824;
00106
00107 const unsigned int JoystickInterface::BUTTON_32 = 2147483648U;
00108
00109
00110 JoystickInterface::JoystickInterface() : Interface()
00111 {
00112 data_size = sizeof(JoystickInterface_data_t);
00113 data_ptr = malloc(data_size);
00114 data = (JoystickInterface_data_t *)data_ptr;
00115 memset(data_ptr, 0, data_size);
00116 add_fieldinfo(IFT_BYTE, "num_axes", 1, &data->num_axes);
00117 add_fieldinfo(IFT_BYTE, "num_buttons", 1, &data->num_buttons);
00118 add_fieldinfo(IFT_UINT, "pressed_buttons", 1, &data->pressed_buttons);
00119 add_fieldinfo(IFT_FLOAT, "axis_x", 4, &data->axis_x);
00120 add_fieldinfo(IFT_FLOAT, "axis_y", 4, &data->axis_y);
00121 unsigned char tmp_hash[] = {0xc1, 0x79, 0x75, 0x4e, 0x3e, 0xfa, 0x1, 0x53, 0x18, 0xb0, 0x9d, 0x9b, 0x43, 0x41, 0xa, 0x86};
00122 set_hash(tmp_hash);
00123 }
00124
00125
00126 JoystickInterface::~JoystickInterface()
00127 {
00128 free(data_ptr);
00129 }
00130
00131
00132
00133
00134
00135
00136
00137 unsigned char
00138 JoystickInterface::num_axes() const
00139 {
00140 return data->num_axes;
00141 }
00142
00143
00144
00145
00146
00147 size_t
00148 JoystickInterface::maxlenof_num_axes() const
00149 {
00150 return 1;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159 void
00160 JoystickInterface::set_num_axes(const unsigned char new_num_axes)
00161 {
00162 data->num_axes = new_num_axes;
00163 }
00164
00165
00166
00167
00168
00169
00170
00171 unsigned char
00172 JoystickInterface::num_buttons() const
00173 {
00174 return data->num_buttons;
00175 }
00176
00177
00178
00179
00180
00181 size_t
00182 JoystickInterface::maxlenof_num_buttons() const
00183 {
00184 return 1;
00185 }
00186
00187
00188
00189
00190
00191
00192
00193 void
00194 JoystickInterface::set_num_buttons(const unsigned char new_num_buttons)
00195 {
00196 data->num_buttons = new_num_buttons;
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 unsigned int
00208 JoystickInterface::pressed_buttons() const
00209 {
00210 return data->pressed_buttons;
00211 }
00212
00213
00214
00215
00216
00217 size_t
00218 JoystickInterface::maxlenof_pressed_buttons() const
00219 {
00220 return 1;
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 void
00232 JoystickInterface::set_pressed_buttons(const unsigned int new_pressed_buttons)
00233 {
00234 data->pressed_buttons = new_pressed_buttons;
00235 }
00236
00237
00238
00239
00240
00241 float *
00242 JoystickInterface::axis_x() const
00243 {
00244 return data->axis_x;
00245 }
00246
00247
00248
00249
00250
00251
00252
00253 float
00254 JoystickInterface::axis_x(unsigned int index) const
00255 {
00256 if (index > 4) {
00257 throw Exception("Index value %u out of bounds (0..4)", index);
00258 }
00259 return data->axis_x[index];
00260 }
00261
00262
00263
00264
00265
00266 size_t
00267 JoystickInterface::maxlenof_axis_x() const
00268 {
00269 return 4;
00270 }
00271
00272
00273
00274
00275
00276 void
00277 JoystickInterface::set_axis_x(const float * new_axis_x)
00278 {
00279 memcpy(data->axis_x, new_axis_x, sizeof(float) * 4);
00280 }
00281
00282
00283
00284
00285
00286
00287 void
00288 JoystickInterface::set_axis_x(unsigned int index, const float new_axis_x)
00289 {
00290 if (index > 4) {
00291 throw Exception("Index value %u out of bounds (0..4)", index);
00292 }
00293 data->axis_x[index] = new_axis_x;
00294 }
00295
00296
00297
00298
00299 float *
00300 JoystickInterface::axis_y() const
00301 {
00302 return data->axis_y;
00303 }
00304
00305
00306
00307
00308
00309
00310
00311 float
00312 JoystickInterface::axis_y(unsigned int index) const
00313 {
00314 if (index > 4) {
00315 throw Exception("Index value %u out of bounds (0..4)", index);
00316 }
00317 return data->axis_y[index];
00318 }
00319
00320
00321
00322
00323
00324 size_t
00325 JoystickInterface::maxlenof_axis_y() const
00326 {
00327 return 4;
00328 }
00329
00330
00331
00332
00333
00334 void
00335 JoystickInterface::set_axis_y(const float * new_axis_y)
00336 {
00337 memcpy(data->axis_y, new_axis_y, sizeof(float) * 4);
00338 }
00339
00340
00341
00342
00343
00344
00345 void
00346 JoystickInterface::set_axis_y(unsigned int index, const float new_axis_y)
00347 {
00348 if (index > 4) {
00349 throw Exception("Index value %u out of bounds (0..4)", index);
00350 }
00351 data->axis_y[index] = new_axis_y;
00352 }
00353
00354 Message *
00355 JoystickInterface::create_message(const char *type) const
00356 {
00357 throw UnknownTypeException("The given type '%s' does not match any known "
00358 "message type for this interface type.", type);
00359 }
00360
00361
00362
00363
00364
00365 void
00366 JoystickInterface::copy_values(const Interface *other)
00367 {
00368 const JoystickInterface *oi = dynamic_cast<const JoystickInterface *>(other);
00369 if (oi == NULL) {
00370 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00371 type(), other->type());
00372 }
00373 memcpy(data, oi->data, sizeof(JoystickInterface_data_t));
00374 }
00375
00376
00377
00378
00379
00380 bool
00381 JoystickInterface::message_valid(const Message *message) const
00382 {
00383 return false;
00384 }
00385
00386
00387 EXPORT_INTERFACE(JoystickInterface)
00388
00389
00390
00391 }