Leosac  0.7.0
OpenSourceAccessControl
SysFSGPIOPin.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 "SysFsGpioModule.hpp"
23 #include "hardware/GPIO.hpp"
24 #include <zmqpp/zmqpp.hpp>
25 
26 namespace Leosac
27 {
28 namespace Module
29 {
30 namespace SysFsGpio
31 {
32 class SysFsGpioModule;
33 class SysFsGpioConfig;
34 
42 {
43  public:
45 
46  enum class InterruptMode
47  {
48  None,
49  Rising,
50  Falling,
51  Both,
52  };
53 
54  SysFsGpioPin(zmqpp::context &ctx, const std::string &name, int gpio_no,
55  Direction direction, InterruptMode interrupt_mode,
56  bool initial_value, SysFsGpioModule &module);
57 
58  ~SysFsGpioPin();
59 
60  SysFsGpioPin(const SysFsGpioPin &) = delete;
61 
62  SysFsGpioPin &operator=(const SysFsGpioPin &) = delete;
63 
64  SysFsGpioPin &operator=(SysFsGpioPin &&) = delete;
65 
66  SysFsGpioPin(SysFsGpioPin &&o) = delete;
67 
72  void register_sockets(zmqpp::reactor *reactor);
73 
77  std::chrono::system_clock::time_point next_update() const;
78 
86  void update();
87 
88  private:
92  void handle_interrupt();
93 
97  bool read_value();
98 
102  bool turn_on(zmqpp::message *msg = nullptr);
103 
107  bool turn_off();
108 
112  bool toggle();
113 
118  void handle_message();
119 
123  void set_direction(Direction dir);
124 
128  void set_interrupt(InterruptMode mode);
129 
133  int file_fd_;
134 
138  int gpio_no_;
139 
143  zmqpp::socket sock_;
144 
145  std::string name_;
146 
151 
155  const bool initial_value_;
156 
161 
163 
167  std::chrono::system_clock::time_point next_update_time_;
168 };
169 }
170 }
171 }
void handle_interrupt()
Interrupt happened for this GPIO ping.
zmqpp::socket sock_
listen to command from other component.
This is the header file for a generated source file, GitSHA1.cpp.
void register_sockets(zmqpp::reactor *reactor)
Register own socket to the module&#39;s reactor.
SysFsGpioPin(zmqpp::context &ctx, const std::string &name, int gpio_no, Direction direction, InterruptMode interrupt_mode, bool initial_value, SysFsGpioModule &module)
void set_direction(Direction dir)
Write direction to the direction file.
void set_interrupt(InterruptMode mode)
Write interrupt mode to the edge file.
bool read_value()
Read value from filesystem.
void handle_message()
The SysFsGpioModule will register this method so its called when a message is ready on the pin socket...
bool toggle()
Read to sysfs and then write the opposite value.
Handle GPIO management over sysfs.
const Direction direction_
Direction of the PIN.
std::chrono::system_clock::time_point next_update_time_
Time point of next wished update.
bool turn_off()
Write to sysfs to turn the gpio on.
Internal configuration helper for sysfsgpio module.
This is a implementation class.
SysFsGpioPin & operator=(const SysFsGpioPin &)=delete
std::chrono::system_clock::time_point next_update() const
This method shall returns the time point at which we want to be updated.
int file_fd_
File descriptor of the GPIO in sysfs.
SysFsGpioModule & module_
Reference to the module.
bool turn_on(zmqpp::message *msg=nullptr)
Write to sysfs to turn the gpio on.
const bool initial_value_
Initial value of the PIN.