Fawkes API  Fawkes Development Version
SwitchInterface.h
1 
2 /***************************************************************************
3  * SwitchInterface.h - Fawkes BlackBoard Interface - SwitchInterface
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 #ifndef _INTERFACES_SWITCHINTERFACE_H_
25 #define _INTERFACES_SWITCHINTERFACE_H_
26 
27 #include <interface/interface.h>
28 #include <interface/message.h>
29 #include <interface/field_iterator.h>
30 
31 namespace fawkes {
32 
33 class SwitchInterface : public Interface
34 {
35  /// @cond INTERNALS
36  INTERFACE_MGMT_FRIENDS(SwitchInterface)
37  /// @endcond
38  public:
39  /* constants */
40 
41  private:
42  /** Internal data storage, do NOT modify! */
43  typedef struct {
44  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
45  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
46  bool enabled; /**<
47  True if the switch is currently enabled.
48  */
49  float value; /**<
50  If switches support multiple states these can be indicated with
51  this value. For example for a switch that notes the intensity it
52  could be a value in the valid range.
53  */
54  float history; /**<
55  This value records the number of seconds a switch has been
56  enabled continuously -- or not. The time is recorded in
57  seconds. A positive value indicates time the switch was turned
58  on, a negative value indicates the time (when converted to the
59  absolute value) the button has not been pressed. Zero means
60  "just initialized".
61  */
62  uint32_t short_activations; /**<
63  Number of consecutive short clicks (turned on). Can be used to recognize
64  patterns of clicks. This is an optional field.
65  */
66  uint32_t long_activations; /**<
67  Number of consecutive short clicks (turned on). Can be used to recognize
68  patterns of clicks. This is an optional field.
69  */
70  uint32_t activation_count; /**<
71  Number that is to be incremented whenever a short or long activation
72  happened. Can be used to decide if a change in status happened.
73  */
74  } SwitchInterface_data_t;
75 
76  SwitchInterface_data_t *data;
77 
78  public:
79  /* messages */
80  class SetMessage : public Message
81  {
82  private:
83  /** Internal data storage, do NOT modify! */
84  typedef struct {
85  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
86  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
87  bool enabled; /**<
88  True if the switch is currently enabled.
89  */
90  float value; /**<
91  If switches support multiple states these can be indicated with
92  this value. For example for a switch that notes the intensity it
93  could be a value in the valid range.
94  */
95  } SetMessage_data_t;
96 
97  SetMessage_data_t *data;
98 
99  public:
100  SetMessage(const bool ini_enabled, const float ini_value);
101  SetMessage();
102  ~SetMessage();
103 
104  explicit SetMessage(const SetMessage *m);
105  /* Methods */
106  bool is_enabled() const;
107  void set_enabled(const bool new_enabled);
108  size_t maxlenof_enabled() const;
109  float value() const;
110  void set_value(const float new_value);
111  size_t maxlenof_value() const;
112  virtual Message * clone() const;
113  };
114 
115  class EnableSwitchMessage : public Message
116  {
117  private:
118  /** Internal data storage, do NOT modify! */
119  typedef struct {
120  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
121  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
122  } EnableSwitchMessage_data_t;
123 
124  EnableSwitchMessage_data_t *data;
125 
126  public:
129 
130  explicit EnableSwitchMessage(const EnableSwitchMessage *m);
131  /* Methods */
132  virtual Message * clone() const;
133  };
134 
135  class DisableSwitchMessage : public Message
136  {
137  private:
138  /** Internal data storage, do NOT modify! */
139  typedef struct {
140  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
141  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
142  } DisableSwitchMessage_data_t;
143 
144  DisableSwitchMessage_data_t *data;
145 
146  public:
149 
150  explicit DisableSwitchMessage(const DisableSwitchMessage *m);
151  /* Methods */
152  virtual Message * clone() const;
153  };
154 
155  class EnableDurationMessage : public Message
156  {
157  private:
158  /** Internal data storage, do NOT modify! */
159  typedef struct {
160  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
161  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
162  float duration; /**< Duration in seconds for which
163  the switch should be enabled. */
164  float value; /**<
165  If switches support multiple states these can be indicated with
166  this value. For example for a switch that notes the intensity it
167  could be a value in the valid range.
168  */
169  } EnableDurationMessage_data_t;
170 
171  EnableDurationMessage_data_t *data;
172 
173  public:
174  EnableDurationMessage(const float ini_duration, const float ini_value);
177 
178  explicit EnableDurationMessage(const EnableDurationMessage *m);
179  /* Methods */
180  float duration() const;
181  void set_duration(const float new_duration);
182  size_t maxlenof_duration() const;
183  float value() const;
184  void set_value(const float new_value);
185  size_t maxlenof_value() const;
186  virtual Message * clone() const;
187  };
188 
189  virtual bool message_valid(const Message *message) const;
190  private:
191  SwitchInterface();
192  ~SwitchInterface();
193 
194  public:
195  /* Methods */
196  bool is_enabled() const;
197  void set_enabled(const bool new_enabled);
198  size_t maxlenof_enabled() const;
199  float value() const;
200  void set_value(const float new_value);
201  size_t maxlenof_value() const;
202  float history() const;
203  void set_history(const float new_history);
204  size_t maxlenof_history() const;
205  uint32_t short_activations() const;
206  void set_short_activations(const uint32_t new_short_activations);
207  size_t maxlenof_short_activations() const;
208  uint32_t long_activations() const;
209  void set_long_activations(const uint32_t new_long_activations);
210  size_t maxlenof_long_activations() const;
211  uint32_t activation_count() const;
212  void set_activation_count(const uint32_t new_activation_count);
213  size_t maxlenof_activation_count() const;
214  virtual Message * create_message(const char *type) const;
215 
216  virtual void copy_values(const Interface *other);
217  virtual const char * enum_tostring(const char *enumtype, int val) const;
218 
219 };
220 
221 } // end namespace fawkes
222 
223 #endif
fawkes::SwitchInterface::set_short_activations
void set_short_activations(const uint32_t new_short_activations)
Set short_activations value.
Definition: SwitchInterface.cpp:230
fawkes::SwitchInterface::enum_tostring
virtual const char * enum_tostring(const char *enumtype, int val) const
Definition: SwitchInterface.cpp:344
fawkes::SwitchInterface::maxlenof_value
size_t maxlenof_value() const
Get maximum length of value value.
Definition: SwitchInterface.cpp:134
fawkes::SwitchInterface::SetMessage::maxlenof_value
size_t maxlenof_value() const
Get maximum length of value value.
Definition: SwitchInterface.cpp:457
fawkes::SwitchInterface::long_activations
uint32_t long_activations() const
Get long_activations value.
Definition: SwitchInterface.cpp:244
fawkes::SwitchInterface::create_message
virtual Message * create_message(const char *type) const
Definition: SwitchInterface.cpp:312
fawkes::SwitchInterface::SetMessage
Definition: SwitchInterface.h:89
fawkes::SwitchInterface::maxlenof_long_activations
size_t maxlenof_long_activations() const
Get maximum length of long_activations value.
Definition: SwitchInterface.cpp:254
fawkes::SwitchInterface::EnableDurationMessage::maxlenof_duration
size_t maxlenof_duration() const
Get maximum length of duration value.
Definition: SwitchInterface.cpp:648
fawkes::SwitchInterface::EnableDurationMessage::value
float value() const
Get value value.
Definition: SwitchInterface.cpp:673
fawkes::SwitchInterface
Definition: SwitchInterface.h:37
fawkes::SwitchInterface::set_value
void set_value(const float new_value)
Set value value.
Definition: SwitchInterface.cpp:148
fawkes::Message
Definition: message.h:40
fawkes::SwitchInterface::EnableDurationMessage
Definition: SwitchInterface.h:164
fawkes::SwitchInterface::maxlenof_history
size_t maxlenof_history() const
Get maximum length of history value.
Definition: SwitchInterface.cpp:176
fawkes::SwitchInterface::SetMessage::set_enabled
void set_enabled(const bool new_enabled)
Set enabled value.
Definition: SwitchInterface.cpp:433
fawkes::SwitchInterface::message_valid
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Definition: SwitchInterface.cpp:717
fawkes::Interface::type
const char * type() const
Get type of interface.
Definition: interface.cpp:643
fawkes::SwitchInterface::set_activation_count
void set_activation_count(const uint32_t new_activation_count)
Set activation_count value.
Definition: SwitchInterface.cpp:304
fawkes::SwitchInterface::DisableSwitchMessage
Definition: SwitchInterface.h:144
fawkes::SwitchInterface::copy_values
virtual void copy_values(const Interface *other)
Copy values from other interface.
Definition: SwitchInterface.cpp:333
fawkes::SwitchInterface::history
float history() const
Get history value.
Definition: SwitchInterface.cpp:166
fawkes::SwitchInterface::SetMessage::is_enabled
bool is_enabled() const
Get enabled value.
Definition: SwitchInterface.cpp:411
fawkes::SwitchInterface::EnableDurationMessage::clone
virtual Message * clone() const
Clone this message.
Definition: SwitchInterface.cpp:708
fawkes::SwitchInterface::EnableSwitchMessage
Definition: SwitchInterface.h:124
fawkes::SwitchInterface::EnableSwitchMessage::EnableSwitchMessage
EnableSwitchMessage()
Constructor.
Definition: SwitchInterface.cpp:494
fawkes::SwitchInterface::EnableSwitchMessage::clone
virtual Message * clone() const
Clone this message.
Definition: SwitchInterface.cpp:528
fawkes::SwitchInterface::maxlenof_enabled
size_t maxlenof_enabled() const
Get maximum length of enabled value.
Definition: SwitchInterface.cpp:97
fawkes::SwitchInterface::set_history
void set_history(const float new_history)
Set history value.
Definition: SwitchInterface.cpp:193
fawkes::SwitchInterface::activation_count
uint32_t activation_count() const
Get activation_count value.
Definition: SwitchInterface.cpp:281
fawkes::SwitchInterface::set_enabled
void set_enabled(const bool new_enabled)
Set enabled value.
Definition: SwitchInterface.cpp:109
fawkes::SwitchInterface::EnableDurationMessage::~EnableDurationMessage
~EnableDurationMessage()
Destructor.
Definition: SwitchInterface.cpp:614
fawkes::SwitchInterface::DisableSwitchMessage::clone
virtual Message * clone() const
Clone this message.
Definition: SwitchInterface.cpp:574
fawkes
fawkes::SwitchInterface::EnableDurationMessage::maxlenof_value
size_t maxlenof_value() const
Get maximum length of value value.
Definition: SwitchInterface.cpp:683
fawkes::SwitchInterface::SetMessage::value
float value() const
Get value value.
Definition: SwitchInterface.cpp:447
fawkes::SwitchInterface::SetMessage::maxlenof_enabled
size_t maxlenof_enabled() const
Get maximum length of enabled value.
Definition: SwitchInterface.cpp:421
fawkes::SwitchInterface::value
float value() const
Get value value.
Definition: SwitchInterface.cpp:124
fawkes::Interface
Definition: interface.h:77
fawkes::SwitchInterface::SetMessage::set_value
void set_value(const float new_value)
Set value value.
Definition: SwitchInterface.cpp:471
fawkes::SwitchInterface::DisableSwitchMessage::DisableSwitchMessage
DisableSwitchMessage()
Constructor.
Definition: SwitchInterface.cpp:540
fawkes::SwitchInterface::SetMessage::SetMessage
SetMessage()
Constructor.
Definition: SwitchInterface.cpp:374
fawkes::SwitchInterface::EnableSwitchMessage::~EnableSwitchMessage
~EnableSwitchMessage()
Destructor.
Definition: SwitchInterface.cpp:504
fawkes::SwitchInterface::EnableDurationMessage::duration
float duration() const
Get duration value.
Definition: SwitchInterface.cpp:638
fawkes::SwitchInterface::set_long_activations
void set_long_activations(const uint32_t new_long_activations)
Set long_activations value.
Definition: SwitchInterface.cpp:267
fawkes::SwitchInterface::SetMessage::~SetMessage
~SetMessage()
Destructor.
Definition: SwitchInterface.cpp:386
fawkes::SwitchInterface::is_enabled
bool is_enabled() const
Get enabled value.
Definition: SwitchInterface.cpp:87
fawkes::SwitchInterface::maxlenof_activation_count
size_t maxlenof_activation_count() const
Get maximum length of activation_count value.
Definition: SwitchInterface.cpp:291
fawkes::SwitchInterface::EnableDurationMessage::set_value
void set_value(const float new_value)
Set value value.
Definition: SwitchInterface.cpp:697
fawkes::SwitchInterface::maxlenof_short_activations
size_t maxlenof_short_activations() const
Get maximum length of short_activations value.
Definition: SwitchInterface.cpp:217
fawkes::SwitchInterface::DisableSwitchMessage::~DisableSwitchMessage
~DisableSwitchMessage()
Destructor.
Definition: SwitchInterface.cpp:550
fawkes::SwitchInterface::SetMessage::clone
virtual Message * clone() const
Clone this message.
Definition: SwitchInterface.cpp:482
fawkes::SwitchInterface::EnableDurationMessage::set_duration
void set_duration(const float new_duration)
Set duration value.
Definition: SwitchInterface.cpp:659
fawkes::SwitchInterface::short_activations
uint32_t short_activations() const
Get short_activations value.
Definition: SwitchInterface.cpp:207
fawkes::SwitchInterface::EnableDurationMessage::EnableDurationMessage
EnableDurationMessage()
Constructor.
Definition: SwitchInterface.cpp:602