Fawkes API Fawkes Development Version
JoystickInterface.cpp
1
2/***************************************************************************
3 * JoystickInterface.cpp - 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#include <interfaces/JoystickInterface.h>
25
26#include <core/exceptions/software.h>
27
28#include <map>
29#include <string>
30#include <cstring>
31#include <cstdlib>
32
33namespace fawkes {
34
35/** @class JoystickInterface <interfaces/JoystickInterface.h>
36 * JoystickInterface Fawkes BlackBoard Interface.
37 *
38 This interface provides access to a joystick. It provides up to
39 five axes, where each has a X and a Y value between -1.0 and 1.0.
40 Up to 32 buttons are support via an uint32 bit field.
41
42 * @ingroup FawkesInterfaces
43 */
44
45
46/** BUTTON_1 constant */
47const uint32_t JoystickInterface::BUTTON_1 = 1u;
48/** BUTTON_2 constant */
49const uint32_t JoystickInterface::BUTTON_2 = 2u;
50/** BUTTON_3 constant */
51const uint32_t JoystickInterface::BUTTON_3 = 4u;
52/** BUTTON_4 constant */
53const uint32_t JoystickInterface::BUTTON_4 = 8u;
54/** BUTTON_5 constant */
55const uint32_t JoystickInterface::BUTTON_5 = 16u;
56/** BUTTON_6 constant */
57const uint32_t JoystickInterface::BUTTON_6 = 32u;
58/** BUTTON_7 constant */
59const uint32_t JoystickInterface::BUTTON_7 = 64u;
60/** BUTTON_8 constant */
61const uint32_t JoystickInterface::BUTTON_8 = 128u;
62/** BUTTON_9 constant */
63const uint32_t JoystickInterface::BUTTON_9 = 256u;
64/** BUTTON_10 constant */
65const uint32_t JoystickInterface::BUTTON_10 = 512u;
66/** BUTTON_11 constant */
67const uint32_t JoystickInterface::BUTTON_11 = 1024u;
68/** BUTTON_12 constant */
69const uint32_t JoystickInterface::BUTTON_12 = 2048u;
70/** BUTTON_13 constant */
71const uint32_t JoystickInterface::BUTTON_13 = 4096u;
72/** BUTTON_14 constant */
73const uint32_t JoystickInterface::BUTTON_14 = 8192u;
74/** BUTTON_15 constant */
75const uint32_t JoystickInterface::BUTTON_15 = 16384u;
76/** BUTTON_16 constant */
77const uint32_t JoystickInterface::BUTTON_16 = 32768u;
78/** BUTTON_17 constant */
79const uint32_t JoystickInterface::BUTTON_17 = 65536u;
80/** BUTTON_18 constant */
81const uint32_t JoystickInterface::BUTTON_18 = 131072u;
82/** BUTTON_19 constant */
83const uint32_t JoystickInterface::BUTTON_19 = 262144u;
84/** BUTTON_20 constant */
85const uint32_t JoystickInterface::BUTTON_20 = 524288u;
86/** BUTTON_21 constant */
87const uint32_t JoystickInterface::BUTTON_21 = 1048576u;
88/** BUTTON_22 constant */
89const uint32_t JoystickInterface::BUTTON_22 = 2097152u;
90/** BUTTON_23 constant */
91const uint32_t JoystickInterface::BUTTON_23 = 4194304u;
92/** BUTTON_24 constant */
93const uint32_t JoystickInterface::BUTTON_24 = 8388608u;
94/** BUTTON_25 constant */
95const uint32_t JoystickInterface::BUTTON_25 = 16777216u;
96/** BUTTON_26 constant */
97const uint32_t JoystickInterface::BUTTON_26 = 33554432u;
98/** BUTTON_27 constant */
99const uint32_t JoystickInterface::BUTTON_27 = 67108864u;
100/** BUTTON_28 constant */
101const uint32_t JoystickInterface::BUTTON_28 = 134217728u;
102/** BUTTON_29 constant */
103const uint32_t JoystickInterface::BUTTON_29 = 268435456u;
104/** BUTTON_30 constant */
105const uint32_t JoystickInterface::BUTTON_30 = 536870912u;
106/** BUTTON_31 constant */
107const uint32_t JoystickInterface::BUTTON_31 = 1073741824u;
108/** BUTTON_32 constant */
109const uint32_t JoystickInterface::BUTTON_32 = 2147483648u;
110/** JFF_RUMBLE constant */
111const uint8_t JoystickInterface::JFF_RUMBLE = 1;
112/** JFF_PERIODIC constant */
113const uint8_t JoystickInterface::JFF_PERIODIC = 2;
114/** JFF_RAMP constant */
115const uint8_t JoystickInterface::JFF_RAMP = 4;
116/** JFF_SPRING constant */
117const uint8_t JoystickInterface::JFF_SPRING = 8;
118/** JFF_FRICTION constant */
119const uint8_t JoystickInterface::JFF_FRICTION = 16;
120/** JFF_DAMPER constant */
121const uint8_t JoystickInterface::JFF_DAMPER = 32;
122/** JFF_INERTIA constant */
123const uint8_t JoystickInterface::JFF_INERTIA = 64;
124/** JFF_CONSTANT constant */
125const uint8_t JoystickInterface::JFF_CONSTANT = 128;
126
127/** Constructor */
128JoystickInterface::JoystickInterface() : Interface()
129{
130 data_size = sizeof(JoystickInterface_data_t);
131 data_ptr = malloc(data_size);
132 data = (JoystickInterface_data_t *)data_ptr;
133 data_ts = (interface_data_ts_t *)data_ptr;
134 memset(data_ptr, 0, data_size);
135 enum_map_Direction[(int)DIRECTION_DOWN] = "DIRECTION_DOWN";
136 enum_map_Direction[(int)DIRECTION_LEFT] = "DIRECTION_LEFT";
137 enum_map_Direction[(int)DIRECTION_UP] = "DIRECTION_UP";
138 enum_map_Direction[(int)DIRECTION_RIGHT] = "DIRECTION_RIGHT";
139 add_fieldinfo(IFT_BYTE, "num_axes", 1, &data->num_axes);
140 add_fieldinfo(IFT_BYTE, "num_buttons", 1, &data->num_buttons);
141 add_fieldinfo(IFT_BYTE, "supported_ff_effects", 1, &data->supported_ff_effects);
142 add_fieldinfo(IFT_UINT32, "pressed_buttons", 1, &data->pressed_buttons);
143 add_fieldinfo(IFT_FLOAT, "axis", 8, &data->axis);
144 add_fieldinfo(IFT_UINT8, "ff_effects", 1, &data->ff_effects);
145 add_messageinfo("StartRumbleMessage");
146 add_messageinfo("StopRumbleMessage");
147 add_messageinfo("StopAllMessage");
148 unsigned char tmp_hash[] = {0xeb, 0x7c, 0xd1, 0x1c, 0xae, 0xa, 0x37, 0x45, 0x5c, 0xa, 0x5e, 0xda, 0x5e, 0x17, 0xdd, 0x42};
149 set_hash(tmp_hash);
150}
151
152/** Destructor */
153JoystickInterface::~JoystickInterface()
154{
155 free(data_ptr);
156}
157/** Convert Direction constant to string.
158 * @param value value to convert to string
159 * @return constant value as string.
160 */
161const char *
162JoystickInterface::tostring_Direction(Direction value) const
163{
164 switch (value) {
165 case DIRECTION_DOWN: return "DIRECTION_DOWN";
166 case DIRECTION_LEFT: return "DIRECTION_LEFT";
167 case DIRECTION_UP: return "DIRECTION_UP";
168 case DIRECTION_RIGHT: return "DIRECTION_RIGHT";
169 default: return "UNKNOWN";
170 }
171}
172/* Methods */
173/** Get num_axes value.
174 *
175 The number of axes of this joystick
176
177 * @return num_axes value
178 */
179uint8_t
180JoystickInterface::num_axes() const
181{
182 return data->num_axes;
183}
184
185/** Get maximum length of num_axes value.
186 * @return length of num_axes value, can be length of the array or number of
187 * maximum number of characters for a string
188 */
189size_t
190JoystickInterface::maxlenof_num_axes() const
191{
192 return 1;
193}
194
195/** Set num_axes value.
196 *
197 The number of axes of this joystick
198
199 * @param new_num_axes new num_axes value
200 */
201void
202JoystickInterface::set_num_axes(const uint8_t new_num_axes)
203{
204 set_field(data->num_axes, new_num_axes);
205}
206
207/** Get num_buttons value.
208 *
209 The number of buttons of this joystick.
210
211 * @return num_buttons value
212 */
213uint8_t
214JoystickInterface::num_buttons() const
215{
216 return data->num_buttons;
217}
218
219/** Get maximum length of num_buttons value.
220 * @return length of num_buttons value, can be length of the array or number of
221 * maximum number of characters for a string
222 */
223size_t
224JoystickInterface::maxlenof_num_buttons() const
225{
226 return 1;
227}
228
229/** Set num_buttons value.
230 *
231 The number of buttons of this joystick.
232
233 * @param new_num_buttons new num_buttons value
234 */
235void
236JoystickInterface::set_num_buttons(const uint8_t new_num_buttons)
237{
238 set_field(data->num_buttons, new_num_buttons);
239}
240
241/** Get supported_ff_effects value.
242 *
243 Bit field indicating available force-feedback effects.
244
245 * @return supported_ff_effects value
246 */
247uint8_t
248JoystickInterface::supported_ff_effects() const
249{
250 return data->supported_ff_effects;
251}
252
253/** Get maximum length of supported_ff_effects value.
254 * @return length of supported_ff_effects value, can be length of the array or number of
255 * maximum number of characters for a string
256 */
257size_t
258JoystickInterface::maxlenof_supported_ff_effects() const
259{
260 return 1;
261}
262
263/** Set supported_ff_effects value.
264 *
265 Bit field indicating available force-feedback effects.
266
267 * @param new_supported_ff_effects new supported_ff_effects value
268 */
269void
270JoystickInterface::set_supported_ff_effects(const uint8_t new_supported_ff_effects)
271{
272 set_field(data->supported_ff_effects, new_supported_ff_effects);
273}
274
275/** Get pressed_buttons value.
276 *
277 A bit field of enabled buttons. For each currently clicked button the
278 corresponding bit is set to 1. Use the BUTTON_* constants for bit-wise
279 comparisons.
280
281 * @return pressed_buttons value
282 */
283uint32_t
284JoystickInterface::pressed_buttons() const
285{
286 return data->pressed_buttons;
287}
288
289/** Get maximum length of pressed_buttons value.
290 * @return length of pressed_buttons value, can be length of the array or number of
291 * maximum number of characters for a string
292 */
293size_t
294JoystickInterface::maxlenof_pressed_buttons() const
295{
296 return 1;
297}
298
299/** Set pressed_buttons value.
300 *
301 A bit field of enabled buttons. For each currently clicked button the
302 corresponding bit is set to 1. Use the BUTTON_* constants for bit-wise
303 comparisons.
304
305 * @param new_pressed_buttons new pressed_buttons value
306 */
307void
308JoystickInterface::set_pressed_buttons(const uint32_t new_pressed_buttons)
309{
310 set_field(data->pressed_buttons, new_pressed_buttons);
311}
312
313/** Get axis value.
314 * Values of axes.
315 * @return axis value
316 */
317float *
318JoystickInterface::axis() const
319{
320 return data->axis;
321}
322
323/** Get axis value at given index.
324 * Values of axes.
325 * @param index index of value
326 * @return axis value
327 * @exception Exception thrown if index is out of bounds
328 */
329float
330JoystickInterface::axis(unsigned int index) const
331{
332 if (index > 7) {
333 throw Exception("Index value %u out of bounds (0..7)", index);
334 }
335 return data->axis[index];
336}
337
338/** Get maximum length of axis value.
339 * @return length of axis value, can be length of the array or number of
340 * maximum number of characters for a string
341 */
342size_t
343JoystickInterface::maxlenof_axis() const
344{
345 return 8;
346}
347
348/** Set axis value.
349 * Values of axes.
350 * @param new_axis new axis value
351 */
352void
353JoystickInterface::set_axis(const float * new_axis)
354{
355 set_field(data->axis, new_axis);
356}
357
358/** Set axis value at given index.
359 * Values of axes.
360 * @param new_axis new axis value
361 * @param index index for of the value
362 */
363void
364JoystickInterface::set_axis(unsigned int index, const float new_axis)
365{
366 set_field(data->axis, index, new_axis);
367}
368/** Get ff_effects value.
369 *
370 Currently running effects. Either 0 if no effect is running, or a bit-wise
371 ored field of the JFF constants.
372
373 * @return ff_effects value
374 */
375uint8_t
376JoystickInterface::ff_effects() const
377{
378 return data->ff_effects;
379}
380
381/** Get maximum length of ff_effects value.
382 * @return length of ff_effects value, can be length of the array or number of
383 * maximum number of characters for a string
384 */
385size_t
386JoystickInterface::maxlenof_ff_effects() const
387{
388 return 1;
389}
390
391/** Set ff_effects value.
392 *
393 Currently running effects. Either 0 if no effect is running, or a bit-wise
394 ored field of the JFF constants.
395
396 * @param new_ff_effects new ff_effects value
397 */
398void
399JoystickInterface::set_ff_effects(const uint8_t new_ff_effects)
400{
401 set_field(data->ff_effects, new_ff_effects);
402}
403
404/* =========== message create =========== */
405Message *
406JoystickInterface::create_message(const char *type) const
407{
408 if ( strncmp("StartRumbleMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
409 return new StartRumbleMessage();
410 } else if ( strncmp("StopRumbleMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
411 return new StopRumbleMessage();
412 } else if ( strncmp("StopAllMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
413 return new StopAllMessage();
414 } else {
415 throw UnknownTypeException("The given type '%s' does not match any known "
416 "message type for this interface type.", type);
417 }
418}
419
420
421/** Copy values from other interface.
422 * @param other other interface to copy values from
423 */
424void
425JoystickInterface::copy_values(const Interface *other)
426{
427 const JoystickInterface *oi = dynamic_cast<const JoystickInterface *>(other);
428 if (oi == NULL) {
429 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
430 type(), other->type());
431 }
432 memcpy(data, oi->data, sizeof(JoystickInterface_data_t));
433}
434
435const char *
436JoystickInterface::enum_tostring(const char *enumtype, int val) const
437{
438 if (strcmp(enumtype, "Direction") == 0) {
439 return tostring_Direction((Direction)val);
440 }
441 throw UnknownTypeException("Unknown enum type %s", enumtype);
442}
443
444/* =========== messages =========== */
445/** @class JoystickInterface::StartRumbleMessage <interfaces/JoystickInterface.h>
446 * StartRumbleMessage Fawkes BlackBoard Interface Message.
447 *
448
449 */
450
451
452/** Constructor with initial values.
453 * @param ini_length initial value for length
454 * @param ini_delay initial value for delay
455 * @param ini_direction initial value for direction
456 * @param ini_strong_magnitude initial value for strong_magnitude
457 * @param ini_weak_magnitude initial value for weak_magnitude
458 */
459JoystickInterface::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")
460{
461 data_size = sizeof(StartRumbleMessage_data_t);
462 data_ptr = malloc(data_size);
463 memset(data_ptr, 0, data_size);
464 data = (StartRumbleMessage_data_t *)data_ptr;
466 data->length = ini_length;
467 data->delay = ini_delay;
468 data->direction = ini_direction;
469 data->strong_magnitude = ini_strong_magnitude;
470 data->weak_magnitude = ini_weak_magnitude;
471 enum_map_Direction[(int)DIRECTION_DOWN] = "DIRECTION_DOWN";
472 enum_map_Direction[(int)DIRECTION_LEFT] = "DIRECTION_LEFT";
473 enum_map_Direction[(int)DIRECTION_UP] = "DIRECTION_UP";
474 enum_map_Direction[(int)DIRECTION_RIGHT] = "DIRECTION_RIGHT";
475 add_fieldinfo(IFT_UINT16, "length", 1, &data->length);
476 add_fieldinfo(IFT_UINT16, "delay", 1, &data->delay);
477 add_fieldinfo(IFT_ENUM, "direction", 1, &data->direction, "Direction", &enum_map_Direction);
478 add_fieldinfo(IFT_UINT16, "strong_magnitude", 1, &data->strong_magnitude);
479 add_fieldinfo(IFT_UINT16, "weak_magnitude", 1, &data->weak_magnitude);
480}
481/** Constructor */
483{
484 data_size = sizeof(StartRumbleMessage_data_t);
485 data_ptr = malloc(data_size);
486 memset(data_ptr, 0, data_size);
487 data = (StartRumbleMessage_data_t *)data_ptr;
489 enum_map_Direction[(int)DIRECTION_DOWN] = "DIRECTION_DOWN";
490 enum_map_Direction[(int)DIRECTION_LEFT] = "DIRECTION_LEFT";
491 enum_map_Direction[(int)DIRECTION_UP] = "DIRECTION_UP";
492 enum_map_Direction[(int)DIRECTION_RIGHT] = "DIRECTION_RIGHT";
493 add_fieldinfo(IFT_UINT16, "length", 1, &data->length);
494 add_fieldinfo(IFT_UINT16, "delay", 1, &data->delay);
495 add_fieldinfo(IFT_ENUM, "direction", 1, &data->direction, "Direction", &enum_map_Direction);
496 add_fieldinfo(IFT_UINT16, "strong_magnitude", 1, &data->strong_magnitude);
497 add_fieldinfo(IFT_UINT16, "weak_magnitude", 1, &data->weak_magnitude);
498}
499
500/** Destructor */
502{
503 free(data_ptr);
504}
505
506/** Copy constructor.
507 * @param m message to copy from
508 */
510{
511 data_size = m->data_size;
512 data_ptr = malloc(data_size);
513 memcpy(data_ptr, m->data_ptr, data_size);
514 data = (StartRumbleMessage_data_t *)data_ptr;
516}
517
518/* Methods */
519/** Get length value.
520 * Effect length in ms.
521 Setting to 0 will make the effect to play continuously until stopped.
522
523 * @return length value
524 */
525uint16_t
527{
528 return data->length;
529}
530
531/** Get maximum length of length value.
532 * @return length of length value, can be length of the array or number of
533 * maximum number of characters for a string
534 */
535size_t
537{
538 return 1;
539}
540
541/** Set length value.
542 * Effect length in ms.
543 Setting to 0 will make the effect to play continuously until stopped.
544
545 * @param new_length new length value
546 */
547void
549{
550 set_field(data->length, new_length);
551}
552
553/** Get delay value.
554 * Delay before effect starts in ms.
555 * @return delay value
556 */
557uint16_t
559{
560 return data->delay;
561}
562
563/** Get maximum length of delay value.
564 * @return length of delay value, can be length of the array or number of
565 * maximum number of characters for a string
566 */
567size_t
569{
570 return 1;
571}
572
573/** Set delay value.
574 * Delay before effect starts in ms.
575 * @param new_delay new delay value
576 */
577void
579{
580 set_field(data->delay, new_delay);
581}
582
583/** Get direction value.
584 * Direction of effect
585 * @return direction value
586 */
589{
590 return (JoystickInterface::Direction)data->direction;
591}
592
593/** Get maximum length of direction value.
594 * @return length of direction value, can be length of the array or number of
595 * maximum number of characters for a string
596 */
597size_t
599{
600 return 1;
601}
602
603/** Set direction value.
604 * Direction of effect
605 * @param new_direction new direction value
606 */
607void
609{
610 set_field(data->direction, new_direction);
611}
612
613/** Get strong_magnitude value.
614 * Magnitude of heavy motor.
615 * @return strong_magnitude value
616 */
617uint16_t
619{
620 return data->strong_magnitude;
621}
622
623/** Get maximum length of strong_magnitude value.
624 * @return length of strong_magnitude value, can be length of the array or number of
625 * maximum number of characters for a string
626 */
627size_t
629{
630 return 1;
631}
632
633/** Set strong_magnitude value.
634 * Magnitude of heavy motor.
635 * @param new_strong_magnitude new strong_magnitude value
636 */
637void
639{
640 set_field(data->strong_magnitude, new_strong_magnitude);
641}
642
643/** Get weak_magnitude value.
644 * Magnitude of light motor.
645 * @return weak_magnitude value
646 */
647uint16_t
649{
650 return data->weak_magnitude;
651}
652
653/** Get maximum length of weak_magnitude value.
654 * @return length of weak_magnitude value, can be length of the array or number of
655 * maximum number of characters for a string
656 */
657size_t
659{
660 return 1;
661}
662
663/** Set weak_magnitude value.
664 * Magnitude of light motor.
665 * @param new_weak_magnitude new weak_magnitude value
666 */
667void
669{
670 set_field(data->weak_magnitude, new_weak_magnitude);
671}
672
673/** Clone this message.
674 * Produces a message of the same type as this message and copies the
675 * data to the new message.
676 * @return clone of this message
677 */
678Message *
680{
682}
683/** @class JoystickInterface::StopRumbleMessage <interfaces/JoystickInterface.h>
684 * StopRumbleMessage Fawkes BlackBoard Interface Message.
685 *
686
687 */
688
689
690/** Constructor */
692{
693 data_size = sizeof(StopRumbleMessage_data_t);
694 data_ptr = malloc(data_size);
695 memset(data_ptr, 0, data_size);
696 data = (StopRumbleMessage_data_t *)data_ptr;
698 enum_map_Direction[(int)DIRECTION_DOWN] = "DIRECTION_DOWN";
699 enum_map_Direction[(int)DIRECTION_LEFT] = "DIRECTION_LEFT";
700 enum_map_Direction[(int)DIRECTION_UP] = "DIRECTION_UP";
701 enum_map_Direction[(int)DIRECTION_RIGHT] = "DIRECTION_RIGHT";
702}
703
704/** Destructor */
706{
707 free(data_ptr);
708}
709
710/** Copy constructor.
711 * @param m message to copy from
712 */
714{
715 data_size = m->data_size;
716 data_ptr = malloc(data_size);
717 memcpy(data_ptr, m->data_ptr, data_size);
718 data = (StopRumbleMessage_data_t *)data_ptr;
720}
721
722/* Methods */
723/** Clone this message.
724 * Produces a message of the same type as this message and copies the
725 * data to the new message.
726 * @return clone of this message
727 */
728Message *
730{
732}
733/** @class JoystickInterface::StopAllMessage <interfaces/JoystickInterface.h>
734 * StopAllMessage Fawkes BlackBoard Interface Message.
735 *
736
737 */
738
739
740/** Constructor */
742{
743 data_size = sizeof(StopAllMessage_data_t);
744 data_ptr = malloc(data_size);
745 memset(data_ptr, 0, data_size);
746 data = (StopAllMessage_data_t *)data_ptr;
748 enum_map_Direction[(int)DIRECTION_DOWN] = "DIRECTION_DOWN";
749 enum_map_Direction[(int)DIRECTION_LEFT] = "DIRECTION_LEFT";
750 enum_map_Direction[(int)DIRECTION_UP] = "DIRECTION_UP";
751 enum_map_Direction[(int)DIRECTION_RIGHT] = "DIRECTION_RIGHT";
752}
753
754/** Destructor */
756{
757 free(data_ptr);
758}
759
760/** Copy constructor.
761 * @param m message to copy from
762 */
764{
765 data_size = m->data_size;
766 data_ptr = malloc(data_size);
767 memcpy(data_ptr, m->data_ptr, data_size);
768 data = (StopAllMessage_data_t *)data_ptr;
770}
771
772/* Methods */
773/** Clone this message.
774 * Produces a message of the same type as this message and copies the
775 * data to the new message.
776 * @return clone of this message
777 */
778Message *
780{
781 return new JoystickInterface::StopAllMessage(this);
782}
783/** Check if message is valid and can be enqueued.
784 * @param message Message to check
785 * @return true if the message is valid, false otherwise.
786 */
787bool
789{
790 const StartRumbleMessage *m0 = dynamic_cast<const StartRumbleMessage *>(message);
791 if ( m0 != NULL ) {
792 return true;
793 }
794 const StopRumbleMessage *m1 = dynamic_cast<const StopRumbleMessage *>(message);
795 if ( m1 != NULL ) {
796 return true;
797 }
798 const StopAllMessage *m2 = dynamic_cast<const StopAllMessage *>(message);
799 if ( m2 != NULL ) {
800 return true;
801 }
802 return false;
803}
804
805/// @cond INTERNALS
806EXPORT_INTERFACE(JoystickInterface)
807/// @endcond
808
809
810} // end namespace fawkes
Base class for exceptions in Fawkes.
Definition: exception.h:36
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
const char * type() const
Get type of interface.
Definition: interface.cpp:652
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:244
void set_field(FieldT &field, DataT &data)
Set a field, set data_changed to true and update data_changed accordingly.
Definition: interface.h:304
StartRumbleMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_length() const
Get maximum length of length value.
uint16_t length() const
Get length value.
size_t maxlenof_weak_magnitude() const
Get maximum length of weak_magnitude value.
uint16_t strong_magnitude() const
Get strong_magnitude value.
void set_delay(const uint16_t new_delay)
Set delay value.
uint16_t weak_magnitude() const
Get weak_magnitude value.
void set_direction(const Direction new_direction)
Set direction value.
void set_strong_magnitude(const uint16_t new_strong_magnitude)
Set strong_magnitude value.
void set_length(const uint16_t new_length)
Set length value.
size_t maxlenof_direction() const
Get maximum length of direction value.
size_t maxlenof_strong_magnitude() const
Get maximum length of strong_magnitude value.
virtual Message * clone() const
Clone this message.
Direction direction() const
Get direction value.
size_t maxlenof_delay() const
Get maximum length of delay value.
void set_weak_magnitude(const uint16_t new_weak_magnitude)
Set weak_magnitude value.
StopAllMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
StopRumbleMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
JoystickInterface Fawkes BlackBoard Interface.
static const uint8_t JFF_SPRING
JFF_SPRING constant.
static const uint32_t BUTTON_15
BUTTON_15 constant.
static const uint8_t JFF_RUMBLE
JFF_RUMBLE constant.
static const uint32_t BUTTON_10
BUTTON_10 constant.
static const uint8_t JFF_INERTIA
JFF_INERTIA constant.
static const uint32_t BUTTON_12
BUTTON_12 constant.
static const uint32_t BUTTON_5
BUTTON_5 constant.
static const uint32_t BUTTON_27
BUTTON_27 constant.
static const uint32_t BUTTON_11
BUTTON_11 constant.
static const uint32_t BUTTON_22
BUTTON_22 constant.
static const uint32_t BUTTON_2
BUTTON_2 constant.
static const uint32_t BUTTON_7
BUTTON_7 constant.
static const uint32_t BUTTON_16
BUTTON_16 constant.
static const uint32_t BUTTON_6
BUTTON_6 constant.
static const uint8_t JFF_FRICTION
JFF_FRICTION constant.
static const uint32_t BUTTON_28
BUTTON_28 constant.
static const uint32_t BUTTON_8
BUTTON_8 constant.
static const uint32_t BUTTON_3
BUTTON_3 constant.
static const uint32_t BUTTON_24
BUTTON_24 constant.
static const uint32_t BUTTON_13
BUTTON_13 constant.
static const uint8_t JFF_DAMPER
JFF_DAMPER constant.
static const uint8_t JFF_RAMP
JFF_RAMP constant.
static const uint32_t BUTTON_20
BUTTON_20 constant.
static const uint32_t BUTTON_18
BUTTON_18 constant.
static const uint32_t BUTTON_26
BUTTON_26 constant.
static const uint32_t BUTTON_4
BUTTON_4 constant.
static const uint32_t BUTTON_30
BUTTON_30 constant.
static const uint32_t BUTTON_19
BUTTON_19 constant.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
static const uint32_t BUTTON_1
BUTTON_1 constant.
static const uint32_t BUTTON_25
BUTTON_25 constant.
static const uint32_t BUTTON_29
BUTTON_29 constant.
static const uint32_t BUTTON_31
BUTTON_31 constant.
static const uint32_t BUTTON_32
BUTTON_32 constant.
static const uint32_t BUTTON_14
BUTTON_14 constant.
static const uint32_t BUTTON_9
BUTTON_9 constant.
static const uint32_t BUTTON_23
BUTTON_23 constant.
static const uint32_t BUTTON_21
BUTTON_21 constant.
static const uint32_t BUTTON_17
BUTTON_17 constant.
static const uint8_t JFF_CONSTANT
JFF_CONSTANT constant.
static const uint8_t JFF_PERIODIC
JFF_PERIODIC constant.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
Definition: message.cpp:435
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:146
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:156
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:147
Fawkes library namespace.
@ IFT_UINT16
16 bit unsigned integer field
Definition: types.h:41
@ IFT_ENUM
field with interface specific enum type
Definition: types.h:50
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:152