Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * JoystickInterface.cpp - 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 #include <interfaces/JoystickInterface.h> 00025 00026 #include <core/exceptions/software.h> 00027 00028 #include <cstring> 00029 #include <cstdlib> 00030 00031 namespace fawkes { 00032 00033 /** @class JoystickInterface <interfaces/JoystickInterface.h> 00034 * JoystickInterface Fawkes BlackBoard Interface. 00035 * 00036 This interface provides access to a joystick. It provides up to 00037 five axes, where each has a X and a Y value between -1.0 and 1.0. 00038 Up to 32 buttons are support via an uint32 bit field. 00039 00040 * @ingroup FawkesInterfaces 00041 */ 00042 00043 00044 /** BUTTON_1 constant */ 00045 const uint32_t JoystickInterface::BUTTON_1 = 1u; 00046 /** BUTTON_2 constant */ 00047 const uint32_t JoystickInterface::BUTTON_2 = 2u; 00048 /** BUTTON_3 constant */ 00049 const uint32_t JoystickInterface::BUTTON_3 = 4u; 00050 /** BUTTON_4 constant */ 00051 const uint32_t JoystickInterface::BUTTON_4 = 8u; 00052 /** BUTTON_5 constant */ 00053 const uint32_t JoystickInterface::BUTTON_5 = 16u; 00054 /** BUTTON_6 constant */ 00055 const uint32_t JoystickInterface::BUTTON_6 = 32u; 00056 /** BUTTON_7 constant */ 00057 const uint32_t JoystickInterface::BUTTON_7 = 64u; 00058 /** BUTTON_8 constant */ 00059 const uint32_t JoystickInterface::BUTTON_8 = 128u; 00060 /** BUTTON_9 constant */ 00061 const uint32_t JoystickInterface::BUTTON_9 = 256u; 00062 /** BUTTON_10 constant */ 00063 const uint32_t JoystickInterface::BUTTON_10 = 512u; 00064 /** BUTTON_11 constant */ 00065 const uint32_t JoystickInterface::BUTTON_11 = 1024u; 00066 /** BUTTON_12 constant */ 00067 const uint32_t JoystickInterface::BUTTON_12 = 2048u; 00068 /** BUTTON_13 constant */ 00069 const uint32_t JoystickInterface::BUTTON_13 = 4096u; 00070 /** BUTTON_14 constant */ 00071 const uint32_t JoystickInterface::BUTTON_14 = 8192u; 00072 /** BUTTON_15 constant */ 00073 const uint32_t JoystickInterface::BUTTON_15 = 16384u; 00074 /** BUTTON_16 constant */ 00075 const uint32_t JoystickInterface::BUTTON_16 = 32768u; 00076 /** BUTTON_17 constant */ 00077 const uint32_t JoystickInterface::BUTTON_17 = 65536u; 00078 /** BUTTON_18 constant */ 00079 const uint32_t JoystickInterface::BUTTON_18 = 131072u; 00080 /** BUTTON_19 constant */ 00081 const uint32_t JoystickInterface::BUTTON_19 = 262144u; 00082 /** BUTTON_20 constant */ 00083 const uint32_t JoystickInterface::BUTTON_20 = 524288u; 00084 /** BUTTON_21 constant */ 00085 const uint32_t JoystickInterface::BUTTON_21 = 1048576u; 00086 /** BUTTON_22 constant */ 00087 const uint32_t JoystickInterface::BUTTON_22 = 2097152u; 00088 /** BUTTON_23 constant */ 00089 const uint32_t JoystickInterface::BUTTON_23 = 4194304u; 00090 /** BUTTON_24 constant */ 00091 const uint32_t JoystickInterface::BUTTON_24 = 8388608u; 00092 /** BUTTON_25 constant */ 00093 const uint32_t JoystickInterface::BUTTON_25 = 16777216u; 00094 /** BUTTON_26 constant */ 00095 const uint32_t JoystickInterface::BUTTON_26 = 33554432u; 00096 /** BUTTON_27 constant */ 00097 const uint32_t JoystickInterface::BUTTON_27 = 67108864u; 00098 /** BUTTON_28 constant */ 00099 const uint32_t JoystickInterface::BUTTON_28 = 134217728u; 00100 /** BUTTON_29 constant */ 00101 const uint32_t JoystickInterface::BUTTON_29 = 268435456u; 00102 /** BUTTON_30 constant */ 00103 const uint32_t JoystickInterface::BUTTON_30 = 536870912u; 00104 /** BUTTON_31 constant */ 00105 const uint32_t JoystickInterface::BUTTON_31 = 1073741824u; 00106 /** BUTTON_32 constant */ 00107 const uint32_t JoystickInterface::BUTTON_32 = 2147483648u; 00108 /** JFF_RUMBLE constant */ 00109 const uint8_t JoystickInterface::JFF_RUMBLE = 1; 00110 /** JFF_PERIODIC constant */ 00111 const uint8_t JoystickInterface::JFF_PERIODIC = 2; 00112 /** JFF_RAMP constant */ 00113 const uint8_t JoystickInterface::JFF_RAMP = 4; 00114 /** JFF_SPRING constant */ 00115 const uint8_t JoystickInterface::JFF_SPRING = 8; 00116 /** JFF_FRICTION constant */ 00117 const uint8_t JoystickInterface::JFF_FRICTION = 16; 00118 /** JFF_DAMPER constant */ 00119 const uint8_t JoystickInterface::JFF_DAMPER = 32; 00120 /** JFF_INERTIA constant */ 00121 const uint8_t JoystickInterface::JFF_INERTIA = 64; 00122 /** JFF_CONSTANT constant */ 00123 const uint8_t JoystickInterface::JFF_CONSTANT = 128; 00124 00125 /** Constructor */ 00126 JoystickInterface::JoystickInterface() : Interface() 00127 { 00128 data_size = sizeof(JoystickInterface_data_t); 00129 data_ptr = malloc(data_size); 00130 data = (JoystickInterface_data_t *)data_ptr; 00131 data_ts = (interface_data_ts_t *)data_ptr; 00132 memset(data_ptr, 0, data_size); 00133 add_fieldinfo(IFT_BYTE, "num_axes", 1, &data->num_axes); 00134 add_fieldinfo(IFT_BYTE, "num_buttons", 1, &data->num_buttons); 00135 add_fieldinfo(IFT_BYTE, "supported_ff_effects", 1, &data->supported_ff_effects); 00136 add_fieldinfo(IFT_UINT32, "pressed_buttons", 1, &data->pressed_buttons); 00137 add_fieldinfo(IFT_FLOAT, "axis", 8, &data->axis); 00138 add_fieldinfo(IFT_UINT8, "ff_effects", 1, &data->ff_effects); 00139 add_messageinfo("StartRumbleMessage"); 00140 add_messageinfo("StopRumbleMessage"); 00141 add_messageinfo("StopAllMessage"); 00142 unsigned char tmp_hash[] = {0xeb, 0x7c, 0xd1, 0x1c, 0xae, 0xa, 0x37, 0x45, 0x5c, 0xa, 0x5e, 0xda, 0x5e, 0x17, 0xdd, 0x42}; 00143 set_hash(tmp_hash); 00144 } 00145 00146 /** Destructor */ 00147 JoystickInterface::~JoystickInterface() 00148 { 00149 free(data_ptr); 00150 } 00151 /** Convert Direction constant to string. 00152 * @param value value to convert to string 00153 * @return constant value as string. 00154 */ 00155 const char * 00156 JoystickInterface::tostring_Direction(Direction value) const 00157 { 00158 switch (value) { 00159 case DIRECTION_DOWN: return "DIRECTION_DOWN"; 00160 case DIRECTION_LEFT: return "DIRECTION_LEFT"; 00161 case DIRECTION_UP: return "DIRECTION_UP"; 00162 case DIRECTION_RIGHT: return "DIRECTION_RIGHT"; 00163 default: return "UNKNOWN"; 00164 } 00165 } 00166 /* Methods */ 00167 /** Get num_axes value. 00168 * 00169 The number of axes of this joystick 00170 00171 * @return num_axes value 00172 */ 00173 uint8_t 00174 JoystickInterface::num_axes() const 00175 { 00176 return data->num_axes; 00177 } 00178 00179 /** Get maximum length of num_axes value. 00180 * @return length of num_axes value, can be length of the array or number of 00181 * maximum number of characters for a string 00182 */ 00183 size_t 00184 JoystickInterface::maxlenof_num_axes() const 00185 { 00186 return 1; 00187 } 00188 00189 /** Set num_axes value. 00190 * 00191 The number of axes of this joystick 00192 00193 * @param new_num_axes new num_axes value 00194 */ 00195 void 00196 JoystickInterface::set_num_axes(const uint8_t new_num_axes) 00197 { 00198 data->num_axes = new_num_axes; 00199 data_changed = true; 00200 } 00201 00202 /** Get num_buttons value. 00203 * 00204 The number of buttons of this joystick. 00205 00206 * @return num_buttons value 00207 */ 00208 uint8_t 00209 JoystickInterface::num_buttons() const 00210 { 00211 return data->num_buttons; 00212 } 00213 00214 /** Get maximum length of num_buttons value. 00215 * @return length of num_buttons value, can be length of the array or number of 00216 * maximum number of characters for a string 00217 */ 00218 size_t 00219 JoystickInterface::maxlenof_num_buttons() const 00220 { 00221 return 1; 00222 } 00223 00224 /** Set num_buttons value. 00225 * 00226 The number of buttons of this joystick. 00227 00228 * @param new_num_buttons new num_buttons value 00229 */ 00230 void 00231 JoystickInterface::set_num_buttons(const uint8_t new_num_buttons) 00232 { 00233 data->num_buttons = new_num_buttons; 00234 data_changed = true; 00235 } 00236 00237 /** Get supported_ff_effects value. 00238 * 00239 Bit field indicating available force-feedback effects. 00240 00241 * @return supported_ff_effects value 00242 */ 00243 uint8_t 00244 JoystickInterface::supported_ff_effects() const 00245 { 00246 return data->supported_ff_effects; 00247 } 00248 00249 /** Get maximum length of supported_ff_effects value. 00250 * @return length of supported_ff_effects value, can be length of the array or number of 00251 * maximum number of characters for a string 00252 */ 00253 size_t 00254 JoystickInterface::maxlenof_supported_ff_effects() const 00255 { 00256 return 1; 00257 } 00258 00259 /** Set supported_ff_effects value. 00260 * 00261 Bit field indicating available force-feedback effects. 00262 00263 * @param new_supported_ff_effects new supported_ff_effects value 00264 */ 00265 void 00266 JoystickInterface::set_supported_ff_effects(const uint8_t new_supported_ff_effects) 00267 { 00268 data->supported_ff_effects = new_supported_ff_effects; 00269 data_changed = true; 00270 } 00271 00272 /** Get pressed_buttons value. 00273 * 00274 A bit field of enabled buttons. For each currently clicked button the 00275 corresponding bit is set to 1. Use the BUTTON_* constants for bit-wise 00276 comparisons. 00277 00278 * @return pressed_buttons value 00279 */ 00280 uint32_t 00281 JoystickInterface::pressed_buttons() const 00282 { 00283 return data->pressed_buttons; 00284 } 00285 00286 /** Get maximum length of pressed_buttons value. 00287 * @return length of pressed_buttons value, can be length of the array or number of 00288 * maximum number of characters for a string 00289 */ 00290 size_t 00291 JoystickInterface::maxlenof_pressed_buttons() const 00292 { 00293 return 1; 00294 } 00295 00296 /** Set pressed_buttons value. 00297 * 00298 A bit field of enabled buttons. For each currently clicked button the 00299 corresponding bit is set to 1. Use the BUTTON_* constants for bit-wise 00300 comparisons. 00301 00302 * @param new_pressed_buttons new pressed_buttons value 00303 */ 00304 void 00305 JoystickInterface::set_pressed_buttons(const uint32_t new_pressed_buttons) 00306 { 00307 data->pressed_buttons = new_pressed_buttons; 00308 data_changed = true; 00309 } 00310 00311 /** Get axis value. 00312 * Values of axes. 00313 * @return axis value 00314 */ 00315 float * 00316 JoystickInterface::axis() const 00317 { 00318 return data->axis; 00319 } 00320 00321 /** Get axis value at given index. 00322 * Values of axes. 00323 * @param index index of value 00324 * @return axis value 00325 * @exception Exception thrown if index is out of bounds 00326 */ 00327 float 00328 JoystickInterface::axis(unsigned int index) const 00329 { 00330 if (index > 8) { 00331 throw Exception("Index value %u out of bounds (0..8)", index); 00332 } 00333 return data->axis[index]; 00334 } 00335 00336 /** Get maximum length of axis value. 00337 * @return length of axis value, can be length of the array or number of 00338 * maximum number of characters for a string 00339 */ 00340 size_t 00341 JoystickInterface::maxlenof_axis() const 00342 { 00343 return 8; 00344 } 00345 00346 /** Set axis value. 00347 * Values of axes. 00348 * @param new_axis new axis value 00349 */ 00350 void 00351 JoystickInterface::set_axis(const float * new_axis) 00352 { 00353 memcpy(data->axis, new_axis, sizeof(float) * 8); 00354 data_changed = true; 00355 } 00356 00357 /** Set axis value at given index. 00358 * Values of axes. 00359 * @param new_axis new axis value 00360 * @param index index for of the value 00361 */ 00362 void 00363 JoystickInterface::set_axis(unsigned int index, const float new_axis) 00364 { 00365 if (index > 8) { 00366 throw Exception("Index value %u out of bounds (0..8)", index); 00367 } 00368 data->axis[index] = new_axis; 00369 data_changed = true; 00370 } 00371 /** Get ff_effects value. 00372 * 00373 Currently running effects. Either 0 if no effect is running, or a bit-wise 00374 ored field of the JFF constants. 00375 00376 * @return ff_effects value 00377 */ 00378 uint8_t 00379 JoystickInterface::ff_effects() const 00380 { 00381 return data->ff_effects; 00382 } 00383 00384 /** Get maximum length of ff_effects value. 00385 * @return length of ff_effects value, can be length of the array or number of 00386 * maximum number of characters for a string 00387 */ 00388 size_t 00389 JoystickInterface::maxlenof_ff_effects() const 00390 { 00391 return 1; 00392 } 00393 00394 /** Set ff_effects value. 00395 * 00396 Currently running effects. Either 0 if no effect is running, or a bit-wise 00397 ored field of the JFF constants. 00398 00399 * @param new_ff_effects new ff_effects value 00400 */ 00401 void 00402 JoystickInterface::set_ff_effects(const uint8_t new_ff_effects) 00403 { 00404 data->ff_effects = new_ff_effects; 00405 data_changed = true; 00406 } 00407 00408 /* =========== message create =========== */ 00409 Message * 00410 JoystickInterface::create_message(const char *type) const 00411 { 00412 if ( strncmp("StartRumbleMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) { 00413 return new StartRumbleMessage(); 00414 } else if ( strncmp("StopRumbleMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) { 00415 return new StopRumbleMessage(); 00416 } else if ( strncmp("StopAllMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) { 00417 return new StopAllMessage(); 00418 } else { 00419 throw UnknownTypeException("The given type '%s' does not match any known " 00420 "message type for this interface type.", type); 00421 } 00422 } 00423 00424 00425 /** Copy values from other interface. 00426 * @param other other interface to copy values from 00427 */ 00428 void 00429 JoystickInterface::copy_values(const Interface *other) 00430 { 00431 const JoystickInterface *oi = dynamic_cast<const JoystickInterface *>(other); 00432 if (oi == NULL) { 00433 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)", 00434 type(), other->type()); 00435 } 00436 memcpy(data, oi->data, sizeof(JoystickInterface_data_t)); 00437 } 00438 00439 const char * 00440 JoystickInterface::enum_tostring(const char *enumtype, int val) const 00441 { 00442 if (strcmp(enumtype, "Direction") == 0) { 00443 return tostring_Direction((Direction)val); 00444 } 00445 throw UnknownTypeException("Unknown enum type %s", enumtype); 00446 } 00447 00448 /* =========== messages =========== */ 00449 /** @class JoystickInterface::StartRumbleMessage <interfaces/JoystickInterface.h> 00450 * StartRumbleMessage Fawkes BlackBoard Interface Message. 00451 * 00452 00453 */ 00454 00455 00456 /** Constructor with initial values. 00457 * @param ini_length initial value for length 00458 * @param ini_delay initial value for delay 00459 * @param ini_direction initial value for direction 00460 * @param ini_strong_magnitude initial value for strong_magnitude 00461 * @param ini_weak_magnitude initial value for weak_magnitude 00462 */ 00463 JoystickInterface::StartRumbleMessage::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) : Message("StartRumbleMessage") 00464 { 00465 data_size = sizeof(StartRumbleMessage_data_t); 00466 data_ptr = malloc(data_size); 00467 memset(data_ptr, 0, data_size); 00468 data = (StartRumbleMessage_data_t *)data_ptr; 00469 data_ts = (message_data_ts_t *)data_ptr; 00470 data->length = ini_length; 00471 data->delay = ini_delay; 00472 data->direction = ini_direction; 00473 data->strong_magnitude = ini_strong_magnitude; 00474 data->weak_magnitude = ini_weak_magnitude; 00475 add_fieldinfo(IFT_UINT16, "length", 1, &data->length); 00476 add_fieldinfo(IFT_UINT16, "delay", 1, &data->delay); 00477 add_fieldinfo(IFT_ENUM, "direction", 1, &data->direction, "Direction"); 00478 add_fieldinfo(IFT_UINT16, "strong_magnitude", 1, &data->strong_magnitude); 00479 add_fieldinfo(IFT_UINT16, "weak_magnitude", 1, &data->weak_magnitude); 00480 } 00481 /** Constructor */ 00482 JoystickInterface::StartRumbleMessage::StartRumbleMessage() : Message("StartRumbleMessage") 00483 { 00484 data_size = sizeof(StartRumbleMessage_data_t); 00485 data_ptr = malloc(data_size); 00486 memset(data_ptr, 0, data_size); 00487 data = (StartRumbleMessage_data_t *)data_ptr; 00488 data_ts = (message_data_ts_t *)data_ptr; 00489 add_fieldinfo(IFT_UINT16, "length", 1, &data->length); 00490 add_fieldinfo(IFT_UINT16, "delay", 1, &data->delay); 00491 add_fieldinfo(IFT_ENUM, "direction", 1, &data->direction, "Direction"); 00492 add_fieldinfo(IFT_UINT16, "strong_magnitude", 1, &data->strong_magnitude); 00493 add_fieldinfo(IFT_UINT16, "weak_magnitude", 1, &data->weak_magnitude); 00494 } 00495 00496 /** Destructor */ 00497 JoystickInterface::StartRumbleMessage::~StartRumbleMessage() 00498 { 00499 free(data_ptr); 00500 } 00501 00502 /** Copy constructor. 00503 * @param m message to copy from 00504 */ 00505 JoystickInterface::StartRumbleMessage::StartRumbleMessage(const StartRumbleMessage *m) : Message("StartRumbleMessage") 00506 { 00507 data_size = m->data_size; 00508 data_ptr = malloc(data_size); 00509 memcpy(data_ptr, m->data_ptr, data_size); 00510 data = (StartRumbleMessage_data_t *)data_ptr; 00511 data_ts = (message_data_ts_t *)data_ptr; 00512 } 00513 00514 /* Methods */ 00515 /** Get length value. 00516 * Effect length in ms. 00517 Setting to 0 will make the effect to play continuously until stopped. 00518 00519 * @return length value 00520 */ 00521 uint16_t 00522 JoystickInterface::StartRumbleMessage::length() const 00523 { 00524 return data->length; 00525 } 00526 00527 /** Get maximum length of length value. 00528 * @return length of length value, can be length of the array or number of 00529 * maximum number of characters for a string 00530 */ 00531 size_t 00532 JoystickInterface::StartRumbleMessage::maxlenof_length() const 00533 { 00534 return 1; 00535 } 00536 00537 /** Set length value. 00538 * Effect length in ms. 00539 Setting to 0 will make the effect to play continuously until stopped. 00540 00541 * @param new_length new length value 00542 */ 00543 void 00544 JoystickInterface::StartRumbleMessage::set_length(const uint16_t new_length) 00545 { 00546 data->length = new_length; 00547 } 00548 00549 /** Get delay value. 00550 * Delay before effect starts in ms. 00551 * @return delay value 00552 */ 00553 uint16_t 00554 JoystickInterface::StartRumbleMessage::delay() const 00555 { 00556 return data->delay; 00557 } 00558 00559 /** Get maximum length of delay value. 00560 * @return length of delay value, can be length of the array or number of 00561 * maximum number of characters for a string 00562 */ 00563 size_t 00564 JoystickInterface::StartRumbleMessage::maxlenof_delay() const 00565 { 00566 return 1; 00567 } 00568 00569 /** Set delay value. 00570 * Delay before effect starts in ms. 00571 * @param new_delay new delay value 00572 */ 00573 void 00574 JoystickInterface::StartRumbleMessage::set_delay(const uint16_t new_delay) 00575 { 00576 data->delay = new_delay; 00577 } 00578 00579 /** Get direction value. 00580 * Direction of effect 00581 * @return direction value 00582 */ 00583 JoystickInterface::Direction 00584 JoystickInterface::StartRumbleMessage::direction() const 00585 { 00586 return (JoystickInterface::Direction)data->direction; 00587 } 00588 00589 /** Get maximum length of direction value. 00590 * @return length of direction value, can be length of the array or number of 00591 * maximum number of characters for a string 00592 */ 00593 size_t 00594 JoystickInterface::StartRumbleMessage::maxlenof_direction() const 00595 { 00596 return 1; 00597 } 00598 00599 /** Set direction value. 00600 * Direction of effect 00601 * @param new_direction new direction value 00602 */ 00603 void 00604 JoystickInterface::StartRumbleMessage::set_direction(const Direction new_direction) 00605 { 00606 data->direction = new_direction; 00607 } 00608 00609 /** Get strong_magnitude value. 00610 * Magnitude of heavy motor. 00611 * @return strong_magnitude value 00612 */ 00613 uint16_t 00614 JoystickInterface::StartRumbleMessage::strong_magnitude() const 00615 { 00616 return data->strong_magnitude; 00617 } 00618 00619 /** Get maximum length of strong_magnitude value. 00620 * @return length of strong_magnitude value, can be length of the array or number of 00621 * maximum number of characters for a string 00622 */ 00623 size_t 00624 JoystickInterface::StartRumbleMessage::maxlenof_strong_magnitude() const 00625 { 00626 return 1; 00627 } 00628 00629 /** Set strong_magnitude value. 00630 * Magnitude of heavy motor. 00631 * @param new_strong_magnitude new strong_magnitude value 00632 */ 00633 void 00634 JoystickInterface::StartRumbleMessage::set_strong_magnitude(const uint16_t new_strong_magnitude) 00635 { 00636 data->strong_magnitude = new_strong_magnitude; 00637 } 00638 00639 /** Get weak_magnitude value. 00640 * Magnitude of light motor. 00641 * @return weak_magnitude value 00642 */ 00643 uint16_t 00644 JoystickInterface::StartRumbleMessage::weak_magnitude() const 00645 { 00646 return data->weak_magnitude; 00647 } 00648 00649 /** Get maximum length of weak_magnitude value. 00650 * @return length of weak_magnitude value, can be length of the array or number of 00651 * maximum number of characters for a string 00652 */ 00653 size_t 00654 JoystickInterface::StartRumbleMessage::maxlenof_weak_magnitude() const 00655 { 00656 return 1; 00657 } 00658 00659 /** Set weak_magnitude value. 00660 * Magnitude of light motor. 00661 * @param new_weak_magnitude new weak_magnitude value 00662 */ 00663 void 00664 JoystickInterface::StartRumbleMessage::set_weak_magnitude(const uint16_t new_weak_magnitude) 00665 { 00666 data->weak_magnitude = new_weak_magnitude; 00667 } 00668 00669 /** Clone this message. 00670 * Produces a message of the same type as this message and copies the 00671 * data to the new message. 00672 * @return clone of this message 00673 */ 00674 Message * 00675 JoystickInterface::StartRumbleMessage::clone() const 00676 { 00677 return new JoystickInterface::StartRumbleMessage(this); 00678 } 00679 /** @class JoystickInterface::StopRumbleMessage <interfaces/JoystickInterface.h> 00680 * StopRumbleMessage Fawkes BlackBoard Interface Message. 00681 * 00682 00683 */ 00684 00685 00686 /** Constructor */ 00687 JoystickInterface::StopRumbleMessage::StopRumbleMessage() : Message("StopRumbleMessage") 00688 { 00689 data_size = sizeof(StopRumbleMessage_data_t); 00690 data_ptr = malloc(data_size); 00691 memset(data_ptr, 0, data_size); 00692 data = (StopRumbleMessage_data_t *)data_ptr; 00693 data_ts = (message_data_ts_t *)data_ptr; 00694 } 00695 00696 /** Destructor */ 00697 JoystickInterface::StopRumbleMessage::~StopRumbleMessage() 00698 { 00699 free(data_ptr); 00700 } 00701 00702 /** Copy constructor. 00703 * @param m message to copy from 00704 */ 00705 JoystickInterface::StopRumbleMessage::StopRumbleMessage(const StopRumbleMessage *m) : Message("StopRumbleMessage") 00706 { 00707 data_size = m->data_size; 00708 data_ptr = malloc(data_size); 00709 memcpy(data_ptr, m->data_ptr, data_size); 00710 data = (StopRumbleMessage_data_t *)data_ptr; 00711 data_ts = (message_data_ts_t *)data_ptr; 00712 } 00713 00714 /* Methods */ 00715 /** Clone this message. 00716 * Produces a message of the same type as this message and copies the 00717 * data to the new message. 00718 * @return clone of this message 00719 */ 00720 Message * 00721 JoystickInterface::StopRumbleMessage::clone() const 00722 { 00723 return new JoystickInterface::StopRumbleMessage(this); 00724 } 00725 /** @class JoystickInterface::StopAllMessage <interfaces/JoystickInterface.h> 00726 * StopAllMessage Fawkes BlackBoard Interface Message. 00727 * 00728 00729 */ 00730 00731 00732 /** Constructor */ 00733 JoystickInterface::StopAllMessage::StopAllMessage() : Message("StopAllMessage") 00734 { 00735 data_size = sizeof(StopAllMessage_data_t); 00736 data_ptr = malloc(data_size); 00737 memset(data_ptr, 0, data_size); 00738 data = (StopAllMessage_data_t *)data_ptr; 00739 data_ts = (message_data_ts_t *)data_ptr; 00740 } 00741 00742 /** Destructor */ 00743 JoystickInterface::StopAllMessage::~StopAllMessage() 00744 { 00745 free(data_ptr); 00746 } 00747 00748 /** Copy constructor. 00749 * @param m message to copy from 00750 */ 00751 JoystickInterface::StopAllMessage::StopAllMessage(const StopAllMessage *m) : Message("StopAllMessage") 00752 { 00753 data_size = m->data_size; 00754 data_ptr = malloc(data_size); 00755 memcpy(data_ptr, m->data_ptr, data_size); 00756 data = (StopAllMessage_data_t *)data_ptr; 00757 data_ts = (message_data_ts_t *)data_ptr; 00758 } 00759 00760 /* Methods */ 00761 /** Clone this message. 00762 * Produces a message of the same type as this message and copies the 00763 * data to the new message. 00764 * @return clone of this message 00765 */ 00766 Message * 00767 JoystickInterface::StopAllMessage::clone() const 00768 { 00769 return new JoystickInterface::StopAllMessage(this); 00770 } 00771 /** Check if message is valid and can be enqueued. 00772 * @param message Message to check 00773 * @return true if the message is valid, false otherwise. 00774 */ 00775 bool 00776 JoystickInterface::message_valid(const Message *message) const 00777 { 00778 const StartRumbleMessage *m0 = dynamic_cast<const StartRumbleMessage *>(message); 00779 if ( m0 != NULL ) { 00780 return true; 00781 } 00782 const StopRumbleMessage *m1 = dynamic_cast<const StopRumbleMessage *>(message); 00783 if ( m1 != NULL ) { 00784 return true; 00785 } 00786 const StopAllMessage *m2 = dynamic_cast<const StopAllMessage *>(message); 00787 if ( m2 != NULL ) { 00788 return true; 00789 } 00790 return false; 00791 } 00792 00793 /// @cond INTERNALS 00794 EXPORT_INTERFACE(JoystickInterface) 00795 /// @endcond 00796 00797 00798 } // end namespace fawkes