Leosac  0.7.0
OpenSourceAccessControl
FLED.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac 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 Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <chrono>
23 #include <string>
24 #include <zmqpp/poller.hpp>
25 #include <zmqpp/socket.hpp>
26 
27 namespace Leosac
28 {
29 namespace Hardware
30 {
31 
44 class FLED
45 {
46  public:
47  struct State
48  {
50  : st(UNKNOWN)
51  , duration(0)
52  , speed(0)
53  , value(false)
54  {
55  }
56 
60  enum
61  {
62  ON,
63  OFF,
66  } st;
67 
72  int64_t duration;
73 
77  int64_t speed;
78 
83  bool value;
84  };
85 
86  FLED(zmqpp::context &ctx, const std::string &led_name);
87 
92  FLED(const FLED &) = delete;
93 
97  ~FLED() = default;
98 
102  bool turnOn(int duration);
103 
107  bool turnOn(std::chrono::milliseconds duration);
108 
112  bool turnOn();
113 
117  bool turnOff();
118 
122  bool toggle();
123 
128  bool blink();
129 
133  bool blink(std::chrono::milliseconds duration, std::chrono::milliseconds speed);
134 
135  bool blink(int duration, int speed);
136 
143  bool isOn();
144 
150  bool isOff();
151 
155  bool isBlinking();
156 
161  State state();
162 
168  zmqpp::socket &backend();
169 
170  private:
174  zmqpp::socket backend_;
175 
179  zmqpp::poller poller_;
180 };
181 }
182 }
int64_t duration
Set only if st is BLINKING, it represents the total duration of blinking.
Definition: FLED.hpp:72
bool blink()
Make the LED blink.
Definition: FLED.cpp:93
This is the header file for a generated source file, GitSHA1.cpp.
enum Leosac::Hardware::FLED::State::@0 st
Internal state of the LED.
bool value
Set only if st is BLINKING : value of the LED (true if ON, false otherwise).
Definition: FLED.hpp:83
FLED(zmqpp::context &ctx, const std::string &led_name)
Definition: FLED.cpp:26
zmqpp::socket backend_
A socket to talk to the backend LED.
Definition: FLED.hpp:174
bool turnOff()
Turn the LED OFF by sending a message to the backend LED impl.
Definition: FLED.cpp:67
bool isOn()
Query the value of the GPIO and returns true if the LED is ON.
Definition: FLED.cpp:128
zmqpp::poller poller_
A poller to not wait for infinity in case something went wrong.
Definition: FLED.hpp:179
State state()
Return the state of the device.
Definition: FLED.cpp:152
bool toggle()
Toggle the LED value by sending a message to the backend LED impl.
Definition: FLED.cpp:80
bool isBlinking()
Returns true is the LED is currently blinking.
Definition: FLED.cpp:147
~FLED()=default
Default destructor.
int64_t speed
Set only if st is BLINKING, it represents the speed of blinking.
Definition: FLED.hpp:77
A Facade to a LED object.
Definition: FLED.hpp:44
zmqpp::socket & backend()
Access the backend socket (which is connect to the LED device) to send command directly.
Definition: FLED.cpp:192
bool turnOn()
Turn the LED ON by sending a message to the backend LED impl.
Definition: FLED.cpp:54
bool isOff()
Similar to isOn().
Definition: FLED.cpp:142