Leosac  0.8.0
Open Source Access Control
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 }
Leosac::Hardware::FLED::State::speed
int64_t speed
Set only if st is BLINKING, it represents the speed of blinking.
Definition: FLED.hpp:77
Leosac::Hardware::FLED::State::UNKNOWN
@ UNKNOWN
Definition: FLED.hpp:65
Leosac::Hardware::FLED::State::ON
@ ON
Definition: FLED.hpp:62
Leosac::Hardware::FLED::State::st
enum Leosac::Hardware::FLED::State::@0 st
Internal state of the LED.
Leosac::Hardware::FLED::turnOff
bool turnOff()
Turn the LED OFF by sending a message to the backend LED impl.
Definition: FLED.cpp:67
Leosac::Hardware::FLED::FLED
FLED(zmqpp::context &ctx, const std::string &led_name)
Definition: FLED.cpp:26
Leosac::Hardware::FLED::State::BLINKING
@ BLINKING
Definition: FLED.hpp:64
Leosac::Hardware::FLED::isOff
bool isOff()
Similar to isOn().
Definition: FLED.cpp:142
Leosac::Hardware::FLED
A Facade to a LED object.
Definition: FLED.hpp:44
Leosac::Hardware::FLED::State
Definition: FLED.hpp:47
Leosac::Hardware::FLED::State::State
State()
Definition: FLED.hpp:49
Leosac::Hardware::FLED::isOn
bool isOn()
Query the value of the GPIO and returns true if the LED is ON.
Definition: FLED.cpp:128
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Hardware::FLED::poller_
zmqpp::poller poller_
A poller to not wait for infinity in case something went wrong.
Definition: FLED.hpp:179
Leosac::Hardware::FLED::backend_
zmqpp::socket backend_
A socket to talk to the backend LED.
Definition: FLED.hpp:174
Leosac::Hardware::FLED::State::value
bool value
Set only if st is BLINKING : value of the LED (true if ON, false otherwise).
Definition: FLED.hpp:83
Leosac::Hardware::FLED::state
State state()
Return the state of the device.
Definition: FLED.cpp:152
Leosac::Hardware::FLED::toggle
bool toggle()
Toggle the LED value by sending a message to the backend LED impl.
Definition: FLED.cpp:80
Leosac::Hardware::FLED::State::OFF
@ OFF
Definition: FLED.hpp:63
Leosac::Hardware::FLED::~FLED
~FLED()=default
Default destructor.
Leosac::Hardware::FLED::isBlinking
bool isBlinking()
Returns true is the LED is currently blinking.
Definition: FLED.cpp:147
Leosac::Hardware::FLED::backend
zmqpp::socket & backend()
Access the backend socket (which is connect to the LED device) to send command directly.
Definition: FLED.cpp:192
Leosac::Hardware::FLED::State::duration
int64_t duration
Set only if st is BLINKING, it represents the total duration of blinking.
Definition: FLED.hpp:72
Leosac::Hardware::FLED::turnOn
bool turnOn()
Turn the LED ON by sending a message to the backend LED impl.
Definition: FLED.cpp:54
Leosac::Hardware::FLED::blink
bool blink()
Make the LED blink.
Definition: FLED.cpp:93