Fawkes API Fawkes Development Version
|
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 #pragma pack(push,4) 00043 /** Internal data storage, do NOT modify! */ 00044 typedef struct { 00045 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00046 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00047 bool enabled; /**< 00048 True if the switch is currently enabled. 00049 */ 00050 float value; /**< 00051 If switches support multiple states these can be indicated with 00052 this value. For example for a switch that notes the intensity it 00053 could be a value in the valid range. 00054 */ 00055 float history; /**< 00056 This value records the number of seconds a switch has been 00057 enabled continuously -- or not. The time is recorded in 00058 seconds. A positive value indicates time the switch was turned 00059 on, a negative value indicates the time (when converted to the 00060 absolute value) the button has not been pressed. Zero means 00061 "just initialized". 00062 */ 00063 uint32_t short_activations; /**< 00064 Number of consecutive short clicks (turned on). Can be used to recognize 00065 patterns of clicks. This is an optional field. 00066 */ 00067 uint32_t long_activations; /**< 00068 Number of consecutive short clicks (turned on). Can be used to recognize 00069 patterns of clicks. This is an optional field. 00070 */ 00071 uint32_t activation_count; /**< 00072 Number that is to be incremented whenever a short or long activation 00073 happened. Can be used to decide if a change in status happened. 00074 */ 00075 } SwitchInterface_data_t; 00076 #pragma pack(pop) 00077 00078 SwitchInterface_data_t *data; 00079 00080 public: 00081 /* messages */ 00082 class SetMessage : public Message 00083 { 00084 private: 00085 #pragma pack(push,4) 00086 /** Internal data storage, do NOT modify! */ 00087 typedef struct { 00088 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00089 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00090 bool enabled; /**< 00091 True if the switch is currently enabled. 00092 */ 00093 float value; /**< 00094 If switches support multiple states these can be indicated with 00095 this value. For example for a switch that notes the intensity it 00096 could be a value in the valid range. 00097 */ 00098 } SetMessage_data_t; 00099 #pragma pack(pop) 00100 00101 SetMessage_data_t *data; 00102 00103 public: 00104 SetMessage(const bool ini_enabled, const float ini_value); 00105 SetMessage(); 00106 ~SetMessage(); 00107 00108 SetMessage(const SetMessage *m); 00109 /* Methods */ 00110 bool is_enabled() const; 00111 void set_enabled(const bool new_enabled); 00112 size_t maxlenof_enabled() const; 00113 float value() const; 00114 void set_value(const float new_value); 00115 size_t maxlenof_value() const; 00116 virtual Message * clone() const; 00117 }; 00118 00119 class EnableSwitchMessage : public Message 00120 { 00121 private: 00122 #pragma pack(push,4) 00123 /** Internal data storage, do NOT modify! */ 00124 typedef struct { 00125 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00126 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00127 } EnableSwitchMessage_data_t; 00128 #pragma pack(pop) 00129 00130 EnableSwitchMessage_data_t *data; 00131 00132 public: 00133 EnableSwitchMessage(); 00134 ~EnableSwitchMessage(); 00135 00136 EnableSwitchMessage(const EnableSwitchMessage *m); 00137 /* Methods */ 00138 virtual Message * clone() const; 00139 }; 00140 00141 class DisableSwitchMessage : public Message 00142 { 00143 private: 00144 #pragma pack(push,4) 00145 /** Internal data storage, do NOT modify! */ 00146 typedef struct { 00147 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00148 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00149 } DisableSwitchMessage_data_t; 00150 #pragma pack(pop) 00151 00152 DisableSwitchMessage_data_t *data; 00153 00154 public: 00155 DisableSwitchMessage(); 00156 ~DisableSwitchMessage(); 00157 00158 DisableSwitchMessage(const DisableSwitchMessage *m); 00159 /* Methods */ 00160 virtual Message * clone() const; 00161 }; 00162 00163 class EnableDurationMessage : public Message 00164 { 00165 private: 00166 #pragma pack(push,4) 00167 /** Internal data storage, do NOT modify! */ 00168 typedef struct { 00169 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00170 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00171 float duration; /**< Duration in seconds for which 00172 the switch should be enabled. */ 00173 float value; /**< 00174 If switches support multiple states these can be indicated with 00175 this value. For example for a switch that notes the intensity it 00176 could be a value in the valid range. 00177 */ 00178 } EnableDurationMessage_data_t; 00179 #pragma pack(pop) 00180 00181 EnableDurationMessage_data_t *data; 00182 00183 public: 00184 EnableDurationMessage(const float ini_duration, const float ini_value); 00185 EnableDurationMessage(); 00186 ~EnableDurationMessage(); 00187 00188 EnableDurationMessage(const EnableDurationMessage *m); 00189 /* Methods */ 00190 float duration() const; 00191 void set_duration(const float new_duration); 00192 size_t maxlenof_duration() const; 00193 float value() const; 00194 void set_value(const float new_value); 00195 size_t maxlenof_value() const; 00196 virtual Message * clone() const; 00197 }; 00198 00199 virtual bool message_valid(const Message *message) const; 00200 private: 00201 SwitchInterface(); 00202 ~SwitchInterface(); 00203 00204 public: 00205 /* Methods */ 00206 bool is_enabled() const; 00207 void set_enabled(const bool new_enabled); 00208 size_t maxlenof_enabled() const; 00209 float value() const; 00210 void set_value(const float new_value); 00211 size_t maxlenof_value() const; 00212 float history() const; 00213 void set_history(const float new_history); 00214 size_t maxlenof_history() const; 00215 uint32_t short_activations() const; 00216 void set_short_activations(const uint32_t new_short_activations); 00217 size_t maxlenof_short_activations() const; 00218 uint32_t long_activations() const; 00219 void set_long_activations(const uint32_t new_long_activations); 00220 size_t maxlenof_long_activations() const; 00221 uint32_t activation_count() const; 00222 void set_activation_count(const uint32_t new_activation_count); 00223 size_t maxlenof_activation_count() const; 00224 virtual Message * create_message(const char *type) const; 00225 00226 virtual void copy_values(const Interface *other); 00227 virtual const char * enum_tostring(const char *enumtype, int val) const; 00228 00229 }; 00230 00231 } // end namespace fawkes 00232 00233 #endif