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