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 uint32_t JoystickInterface::BUTTON_1 = 1u;
00046
00047 const uint32_t JoystickInterface::BUTTON_2 = 2u;
00048
00049 const uint32_t JoystickInterface::BUTTON_3 = 4u;
00050
00051 const uint32_t JoystickInterface::BUTTON_4 = 8u;
00052
00053 const uint32_t JoystickInterface::BUTTON_5 = 16u;
00054
00055 const uint32_t JoystickInterface::BUTTON_6 = 32u;
00056
00057 const uint32_t JoystickInterface::BUTTON_7 = 64u;
00058
00059 const uint32_t JoystickInterface::BUTTON_8 = 128u;
00060
00061 const uint32_t JoystickInterface::BUTTON_9 = 256u;
00062
00063 const uint32_t JoystickInterface::BUTTON_10 = 512u;
00064
00065 const uint32_t JoystickInterface::BUTTON_11 = 1024u;
00066
00067 const uint32_t JoystickInterface::BUTTON_12 = 2048u;
00068
00069 const uint32_t JoystickInterface::BUTTON_13 = 4096u;
00070
00071 const uint32_t JoystickInterface::BUTTON_14 = 8192u;
00072
00073 const uint32_t JoystickInterface::BUTTON_15 = 16384u;
00074
00075 const uint32_t JoystickInterface::BUTTON_16 = 32768u;
00076
00077 const uint32_t JoystickInterface::BUTTON_17 = 65536u;
00078
00079 const uint32_t JoystickInterface::BUTTON_18 = 131072u;
00080
00081 const uint32_t JoystickInterface::BUTTON_19 = 262144u;
00082
00083 const uint32_t JoystickInterface::BUTTON_20 = 524288u;
00084
00085 const uint32_t JoystickInterface::BUTTON_21 = 1048576u;
00086
00087 const uint32_t JoystickInterface::BUTTON_22 = 2097152u;
00088
00089 const uint32_t JoystickInterface::BUTTON_23 = 4194304u;
00090
00091 const uint32_t JoystickInterface::BUTTON_24 = 8388608u;
00092
00093 const uint32_t JoystickInterface::BUTTON_25 = 16777216u;
00094
00095 const uint32_t JoystickInterface::BUTTON_26 = 33554432u;
00096
00097 const uint32_t JoystickInterface::BUTTON_27 = 67108864u;
00098
00099 const uint32_t JoystickInterface::BUTTON_28 = 134217728u;
00100
00101 const uint32_t JoystickInterface::BUTTON_29 = 268435456u;
00102
00103 const uint32_t JoystickInterface::BUTTON_30 = 536870912u;
00104
00105 const uint32_t JoystickInterface::BUTTON_31 = 1073741824u;
00106
00107 const uint32_t 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 data_ts = (interface_data_ts_t *)data_ptr;
00116 memset(data_ptr, 0, data_size);
00117 add_fieldinfo(IFT_BYTE, "num_axes", 1, &data->num_axes);
00118 add_fieldinfo(IFT_BYTE, "num_buttons", 1, &data->num_buttons);
00119 add_fieldinfo(IFT_UINT32, "pressed_buttons", 1, &data->pressed_buttons);
00120 add_fieldinfo(IFT_FLOAT, "axis_x", 4, &data->axis_x);
00121 add_fieldinfo(IFT_FLOAT, "axis_y", 4, &data->axis_y);
00122 unsigned char tmp_hash[] = {0x20, 0xe5, 0x9c, 0x19, 0x6e, 0xd2, 0xcf, 0xcc, 0xf2, 0x5d, 0x70, 0x88, 0x52, 0x66, 0x7a, 0x1e};
00123 set_hash(tmp_hash);
00124 }
00125
00126
00127 JoystickInterface::~JoystickInterface()
00128 {
00129 free(data_ptr);
00130 }
00131
00132
00133
00134
00135
00136
00137
00138 uint8_t
00139 JoystickInterface::num_axes() const
00140 {
00141 return data->num_axes;
00142 }
00143
00144
00145
00146
00147
00148 size_t
00149 JoystickInterface::maxlenof_num_axes() const
00150 {
00151 return 1;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160 void
00161 JoystickInterface::set_num_axes(const uint8_t new_num_axes)
00162 {
00163 data->num_axes = new_num_axes;
00164 data_changed = true;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173 uint8_t
00174 JoystickInterface::num_buttons() const
00175 {
00176 return data->num_buttons;
00177 }
00178
00179
00180
00181
00182
00183 size_t
00184 JoystickInterface::maxlenof_num_buttons() const
00185 {
00186 return 1;
00187 }
00188
00189
00190
00191
00192
00193
00194
00195 void
00196 JoystickInterface::set_num_buttons(const uint8_t new_num_buttons)
00197 {
00198 data->num_buttons = new_num_buttons;
00199 data_changed = true;
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 uint32_t
00211 JoystickInterface::pressed_buttons() const
00212 {
00213 return data->pressed_buttons;
00214 }
00215
00216
00217
00218
00219
00220 size_t
00221 JoystickInterface::maxlenof_pressed_buttons() const
00222 {
00223 return 1;
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 void
00235 JoystickInterface::set_pressed_buttons(const uint32_t new_pressed_buttons)
00236 {
00237 data->pressed_buttons = new_pressed_buttons;
00238 data_changed = true;
00239 }
00240
00241
00242
00243
00244
00245 float *
00246 JoystickInterface::axis_x() const
00247 {
00248 return data->axis_x;
00249 }
00250
00251
00252
00253
00254
00255
00256
00257 float
00258 JoystickInterface::axis_x(unsigned int index) const
00259 {
00260 if (index > 4) {
00261 throw Exception("Index value %u out of bounds (0..4)", index);
00262 }
00263 return data->axis_x[index];
00264 }
00265
00266
00267
00268
00269
00270 size_t
00271 JoystickInterface::maxlenof_axis_x() const
00272 {
00273 return 4;
00274 }
00275
00276
00277
00278
00279
00280 void
00281 JoystickInterface::set_axis_x(const float * new_axis_x)
00282 {
00283 memcpy(data->axis_x, new_axis_x, sizeof(float) * 4);
00284 data_changed = true;
00285 }
00286
00287
00288
00289
00290
00291
00292 void
00293 JoystickInterface::set_axis_x(unsigned int index, const float new_axis_x)
00294 {
00295 if (index > 4) {
00296 throw Exception("Index value %u out of bounds (0..4)", index);
00297 }
00298 data->axis_x[index] = new_axis_x;
00299 }
00300
00301
00302
00303
00304 float *
00305 JoystickInterface::axis_y() const
00306 {
00307 return data->axis_y;
00308 }
00309
00310
00311
00312
00313
00314
00315
00316 float
00317 JoystickInterface::axis_y(unsigned int index) const
00318 {
00319 if (index > 4) {
00320 throw Exception("Index value %u out of bounds (0..4)", index);
00321 }
00322 return data->axis_y[index];
00323 }
00324
00325
00326
00327
00328
00329 size_t
00330 JoystickInterface::maxlenof_axis_y() const
00331 {
00332 return 4;
00333 }
00334
00335
00336
00337
00338
00339 void
00340 JoystickInterface::set_axis_y(const float * new_axis_y)
00341 {
00342 memcpy(data->axis_y, new_axis_y, sizeof(float) * 4);
00343 data_changed = true;
00344 }
00345
00346
00347
00348
00349
00350
00351 void
00352 JoystickInterface::set_axis_y(unsigned int index, const float new_axis_y)
00353 {
00354 if (index > 4) {
00355 throw Exception("Index value %u out of bounds (0..4)", index);
00356 }
00357 data->axis_y[index] = new_axis_y;
00358 }
00359
00360 Message *
00361 JoystickInterface::create_message(const char *type) const
00362 {
00363 throw UnknownTypeException("The given type '%s' does not match any known "
00364 "message type for this interface type.", type);
00365 }
00366
00367
00368
00369
00370
00371 void
00372 JoystickInterface::copy_values(const Interface *other)
00373 {
00374 const JoystickInterface *oi = dynamic_cast<const JoystickInterface *>(other);
00375 if (oi == NULL) {
00376 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00377 type(), other->type());
00378 }
00379 memcpy(data, oi->data, sizeof(JoystickInterface_data_t));
00380 }
00381
00382 const char *
00383 JoystickInterface::enum_tostring(const char *enumtype, int val) const
00384 {
00385 throw UnknownTypeException("Unknown enum type %s", enumtype);
00386 }
00387
00388
00389
00390
00391
00392
00393 bool
00394 JoystickInterface::message_valid(const Message *message) const
00395 {
00396 return false;
00397 }
00398
00399
00400 EXPORT_INTERFACE(JoystickInterface)
00401
00402
00403
00404 }