libkovan  1
The kovan standard library
button.hpp
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright 2012 KISS Institute for Practical Robotics *
3  * *
4  * This file is part of libkovan. *
5  * *
6  * libkovan is free software: you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation, either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * libkovan is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with libkovan. Check the LICENSE file in the project root. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  **************************************************************************/
20 
29 #ifndef _BUTTON_HPP_
30 #define _BUTTON_HPP_
31 
32 #include "sensor.hpp"
33 #include "button_ids.hpp"
34  #include "export.h"
35 
36 
43 class EXPORT_SYM AbstractButton : public Sensor<bool>
44 {
45 public:
46  virtual ~AbstractButton();
47  virtual void setPressed(bool pressed) = 0;
48 
54  inline bool isPressed() const { return value(); };
55 
60  inline bool isNotPressed() const { return !isPressed(); }
61 
70  inline bool isClicked() const
71  {
72  const bool ret = isPressed();
73  waitUntilReleased();
74  return ret;
75  }
76 
77 
78 
83  virtual void waitUntilReleased() const;
84 
89  virtual void waitUntilPressed() const;
90 
95  virtual void waitUntilClicked() const;
96 };
97 
105 {
106 public:
107  virtual ~AbstractTextButton();
108 
114  virtual void setText(const char *text) = 0;
115 
121  virtual const char *text() const = 0;
122 
128  virtual bool isTextDirty() const = 0;
129 
134  virtual void resetText() = 0;
135 };
136 
138 {
139 public:
140  IdButton(const Button::Type::Id& id, const char *defaultText);
141  ~IdButton();
142 
143  virtual void setText(const char *text);
144  virtual const char *text() const;
145  virtual bool isTextDirty() const;
146  virtual void setPressed(bool pressed);
147  virtual bool value() const;
148  virtual void resetText();
149 
150 private:
151  Button::Type::Id m_id;
152  char *m_defaultText;
153 };
154 
161 {
162 public:
168  static void show();
169 
175  static void hide();
176 
183  static void setShown(const bool& shown);
184 
190  static bool isShown();
191 };
192 
197 namespace Button
198 {
200  extern EXPORT_SYM IdButton A;
202  extern EXPORT_SYM IdButton B;
204  extern EXPORT_SYM IdButton C;
205 
207  extern EXPORT_SYM IdButton X;
209  extern EXPORT_SYM IdButton Y;
211  extern EXPORT_SYM IdButton Z;
212 
214  extern EXPORT_SYM IdButton Side;
215 
216  // extern AbstractButton side;
217 
219  extern EXPORT_SYM IdButton *const all[7];
220 }
221 
222 #endif
Helper methods to manipulate and access the state of the X, Y, and Z buttons.
Definition: button.hpp:160
virtual void setText(const char *text)=0
The base class for all sensors of any type.
Definition: sensor.hpp:45
EXPORT_SYM IdButton A
The A button instance.
virtual bool isTextDirty() const =0
virtual void setPressed(bool pressed)=0
Base sensor classes.
virtual T value() const =0
EXPORT_SYM IdButton X
The X button instance.
EXPORT_SYM IdButton B
The B button instance.
EXPORT_SYM IdButton *const all[7]
Pointers to all 6 system buttons.
virtual const char * text() const =0
virtual void resetText()=0
bool isPressed() const
Definition: button.hpp:54
EXPORT_SYM IdButton Z
The Z button instance.
EXPORT_SYM IdButton Y
The Y button instance.
The base class for all buttons that have text.
Definition: button.hpp:104
Definition: button.hpp:137
EXPORT_SYM IdButton C
The C button instance.
bool isNotPressed() const
Definition: button.hpp:60
#define EXPORT_SYM
Definition: export.h:7
EXPORT_SYM IdButton Side
The Side button instance.
Definition: button.hpp:197
Id
Definition: button_ids.hpp:28
The base class for all buttons.
Definition: button.hpp:43
bool isClicked() const
Definition: button.hpp:70