Leosac  0.8.0
Open Source Access Control
FGPIO.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 
45 class FGPIO
46 {
47  public:
48  FGPIO(zmqpp::context &ctx, const std::string &gpio_name);
49 
54  FGPIO(const FGPIO &) = delete;
55 
59  ~FGPIO() = default;
60 
64  bool turnOn(std::chrono::milliseconds duration);
65 
69  bool turnOn();
70 
74  bool turnOff();
75 
79  bool toggle();
80 
85  bool isOn();
86 
90  bool isOff();
91 
95  const std::string &name() const;
96 
97  private:
98  std::string gpio_name_;
99 
103  zmqpp::socket backend_;
104 
108  zmqpp::poller poller_;
109 };
110 }
111 }
Leosac::Hardware::FGPIO::gpio_name_
std::string gpio_name_
Definition: FGPIO.hpp:98
Leosac::Hardware::FGPIO::toggle
bool toggle()
Toggle the GPIO value by sending a message to the backend GPIO impl.
Definition: FGPIO.cpp:79
Leosac::Hardware::FGPIO::poller_
zmqpp::poller poller_
A poller to not wait for infinity in case something went wrong.
Definition: FGPIO.hpp:108
Leosac::Hardware::FGPIO
A Facade to a GPIO object.
Definition: FGPIO.hpp:45
Leosac::Hardware::FGPIO::name
const std::string & name() const
Name of the GPIO pin as defined in the configuration file.
Definition: FGPIO.cpp:113
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Hardware::FGPIO::~FGPIO
~FGPIO()=default
Default destructor, RAII does the job.
Leosac::Hardware::FGPIO::isOn
bool isOn()
Query the value of the GPIO and returns true if the LED is ON.
Definition: FGPIO.cpp:93
Leosac::Hardware::FGPIO::isOff
bool isOff()
Similar to isOn().
Definition: FGPIO.cpp:108
Leosac::Hardware::FGPIO::FGPIO
FGPIO(zmqpp::context &ctx, const std::string &gpio_name)
Definition: FGPIO.cpp:26
Leosac::Hardware::FGPIO::turnOff
bool turnOff()
Turn the GPIO OFF by sending a message to the backend GPIO impl.
Definition: FGPIO.cpp:65
Leosac::Hardware::FGPIO::backend_
zmqpp::socket backend_
A socket to talk to the backend GPIO.
Definition: FGPIO.hpp:103
Leosac::Hardware::FGPIO::turnOn
bool turnOn()
Turn the GPIO ON by sending a message to the backend GPIO impl.
Definition: FGPIO.cpp:51