SwitchInterface.h

00001
00002 /***************************************************************************
00003  *  SwitchInterface.h - Fawkes BlackBoard Interface - SwitchInterface
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_SWITCHINTERFACE_H_
00025 #define __INTERFACES_SWITCHINTERFACE_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 SwitchInterface : public Interface
00034 {
00035  /// @cond INTERNALS
00036  INTERFACE_MGMT_FRIENDS(SwitchInterface)
00037  /// @endcond
00038  public:
00039   /* constants */
00040
00041  private:
00042   /** Internal data storage, do NOT modify! */
00043   typedef struct {
00044     unsigned int short_activations; /**< 
00045       Number of consecutive short clicks (turned on). Can be used to recognize
00046       patterns of clicks. This is an optional field.
00047      */
00048     unsigned int long_activations; /**< 
00049       Number of consecutive short clicks (turned on). Can be used to recognize
00050       patterns of clicks. This is an optional field.
00051      */
00052     unsigned int activation_count; /**< 
00053       Number that is to be incremented whenever a short or long activation
00054       happened. Can be used to decide if a change in status happened.
00055      */
00056     float value; /**< 
00057       If switches support multiple states these can be indicated with
00058       this value. For example for a switch that notes the intensity it
00059       could be a value in the valid range.
00060      */
00061     float history; /**< 
00062       This value records the number of seconds a switch has been
00063       enabled continuously -- or not. The time is recorded in
00064       seconds. A positive value indicates time the switch was turned
00065       on, a negative value indicates the time (when converted to the
00066       absolute value) the button has not been pressed. Zero means
00067       "just initialized".
00068      */
00069     bool enabled; /**< 
00070       True if the switch is currently enabled.
00071      */
00072   } SwitchInterface_data_t;
00073
00074   SwitchInterface_data_t *data;
00075
00076  public:
00077   /* messages */
00078   class SetMessage : public Message
00079   {
00080    private:
00081     /** Internal data storage, do NOT modify! */
00082     typedef struct {
00083       float value; /**< 
00084       If switches support multiple states these can be indicated with
00085       this value. For example for a switch that notes the intensity it
00086       could be a value in the valid range.
00087      */
00088       bool enabled; /**< 
00089       True if the switch is currently enabled.
00090      */
00091     } SetMessage_data_t;
00092
00093     SetMessage_data_t *data;
00094
00095    public:
00096     SetMessage(const bool ini_enabled, const float ini_value);
00097     SetMessage();
00098     ~SetMessage();
00099
00100     SetMessage(const SetMessage *m);
00101     /* Methods */
00102     bool is_enabled() const;
00103     void set_enabled(const bool new_enabled);
00104     size_t maxlenof_enabled() const;
00105     float value() const;
00106     void set_value(const float new_value);
00107     size_t maxlenof_value() const;
00108     virtual Message * clone() const;
00109   };
00110
00111   class EnableSwitchMessage : public Message
00112   {
00113    public:
00114     EnableSwitchMessage();
00115     ~EnableSwitchMessage();
00116
00117     EnableSwitchMessage(const EnableSwitchMessage *m);
00118     /* Methods */
00119     virtual Message * clone() const;
00120   };
00121
00122   class DisableSwitchMessage : public Message
00123   {
00124    public:
00125     DisableSwitchMessage();
00126     ~DisableSwitchMessage();
00127
00128     DisableSwitchMessage(const DisableSwitchMessage *m);
00129     /* Methods */
00130     virtual Message * clone() const;
00131   };
00132
00133   virtual bool message_valid(const Message *message) const;
00134  private:
00135   SwitchInterface();
00136   ~SwitchInterface();
00137
00138  public:
00139   /* Methods */
00140   bool is_enabled() const;
00141   void set_enabled(const bool new_enabled);
00142   size_t maxlenof_enabled() const;
00143   float value() const;
00144   void set_value(const float new_value);
00145   size_t maxlenof_value() const;
00146   float history() const;
00147   void set_history(const float new_history);
00148   size_t maxlenof_history() const;
00149   unsigned int short_activations() const;
00150   void set_short_activations(const unsigned int new_short_activations);
00151   size_t maxlenof_short_activations() const;
00152   unsigned int long_activations() const;
00153   void set_long_activations(const unsigned int new_long_activations);
00154   size_t maxlenof_long_activations() const;
00155   unsigned int activation_count() const;
00156   void set_activation_count(const unsigned int new_activation_count);
00157   size_t maxlenof_activation_count() const;
00158   virtual Message * create_message(const char *type) const;
00159
00160   virtual void copy_values(const Interface *other);
00161
00162 };
00163
00164 } // end namespace fawkes
00165
00166 #endif