JoystickInterface.h

00001 
00002 /***************************************************************************
00003  *  JoystickInterface.h - 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 #ifndef __INTERFACES_JOYSTICKINTERFACE_H_
00025 #define __INTERFACES_JOYSTICKINTERFACE_H_
00026 
00027 #include <interface/interface.h>
00028 #include <interface/message.h>
00029 #include <interface/field_iterator.h>
00030 
00031 namespace fawkes {
00032 
00033 class JoystickInterface : public Interface
00034 {
00035  /// @cond INTERNALS
00036  INTERFACE_MGMT_FRIENDS(JoystickInterface)
00037  /// @endcond
00038  public:
00039   /* constants */
00040   static const uint32_t BUTTON_1;
00041   static const uint32_t BUTTON_2;
00042   static const uint32_t BUTTON_3;
00043   static const uint32_t BUTTON_4;
00044   static const uint32_t BUTTON_5;
00045   static const uint32_t BUTTON_6;
00046   static const uint32_t BUTTON_7;
00047   static const uint32_t BUTTON_8;
00048   static const uint32_t BUTTON_9;
00049   static const uint32_t BUTTON_10;
00050   static const uint32_t BUTTON_11;
00051   static const uint32_t BUTTON_12;
00052   static const uint32_t BUTTON_13;
00053   static const uint32_t BUTTON_14;
00054   static const uint32_t BUTTON_15;
00055   static const uint32_t BUTTON_16;
00056   static const uint32_t BUTTON_17;
00057   static const uint32_t BUTTON_18;
00058   static const uint32_t BUTTON_19;
00059   static const uint32_t BUTTON_20;
00060   static const uint32_t BUTTON_21;
00061   static const uint32_t BUTTON_22;
00062   static const uint32_t BUTTON_23;
00063   static const uint32_t BUTTON_24;
00064   static const uint32_t BUTTON_25;
00065   static const uint32_t BUTTON_26;
00066   static const uint32_t BUTTON_27;
00067   static const uint32_t BUTTON_28;
00068   static const uint32_t BUTTON_29;
00069   static const uint32_t BUTTON_30;
00070   static const uint32_t BUTTON_31;
00071   static const uint32_t BUTTON_32;
00072 
00073  private:
00074 #pragma pack(push,4)
00075   /** Internal data storage, do NOT modify! */
00076   typedef struct {
00077     int64_t timestamp_sec;  /**< Interface Unix timestamp, seconds */
00078     int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
00079     uint8_t num_axes; /**< 
00080       The number of axes of this joystick
00081      */
00082     uint8_t num_buttons; /**< 
00083       The number of buttons of this joystick.
00084      */
00085     uint32_t pressed_buttons; /**< 
00086       A bit field of enabled buttons. For each currently clicked button the
00087       corresponding bit is set to 1. Use the BUTTON_* constants for bit-wise
00088       comparisons.
00089      */
00090     float axis_x[4]; /**< X values of axes */
00091     float axis_y[4]; /**< Y values of axes */
00092   } JoystickInterface_data_t;
00093 #pragma pack(pop)
00094 
00095   JoystickInterface_data_t *data;
00096 
00097  public:
00098   /* messages */
00099   virtual bool message_valid(const Message *message) const;
00100  private:
00101   JoystickInterface();
00102   ~JoystickInterface();
00103 
00104  public:
00105   /* Methods */
00106   uint8_t num_axes() const;
00107   void set_num_axes(const uint8_t new_num_axes);
00108   size_t maxlenof_num_axes() const;
00109   uint8_t num_buttons() const;
00110   void set_num_buttons(const uint8_t new_num_buttons);
00111   size_t maxlenof_num_buttons() const;
00112   uint32_t pressed_buttons() const;
00113   void set_pressed_buttons(const uint32_t new_pressed_buttons);
00114   size_t maxlenof_pressed_buttons() const;
00115   float * axis_x() const;
00116   float axis_x(unsigned int index) const;
00117   void set_axis_x(unsigned int index, const float new_axis_x);
00118   void set_axis_x(const float * new_axis_x);
00119   size_t maxlenof_axis_x() const;
00120   float * axis_y() const;
00121   float axis_y(unsigned int index) const;
00122   void set_axis_y(unsigned int index, const float new_axis_y);
00123   void set_axis_y(const float * new_axis_y);
00124   size_t maxlenof_axis_y() const;
00125   virtual Message * create_message(const char *type) const;
00126 
00127   virtual void copy_values(const Interface *other);
00128   virtual const char * enum_tostring(const char *enumtype, int val) const;
00129 
00130 };
00131 
00132 } // end namespace fawkes
00133 
00134 #endif