Leosac  0.8.0
Open Source Access Control
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 }
Leosac::Module::SysFsGpio::SysFsGpioPin::update
void update()
Update the PIN.
Definition: SysFSGPIOPin.cpp:200
Leosac::Module::SysFsGpio::SysFsGpioPin::next_update
std::chrono::system_clock::time_point next_update() const
This method shall returns the time point at which we want to be updated.
Definition: SysFSGPIOPin.cpp:195
Leosac::Module::SysFsGpio::SysFsGpioPin::SysFsGpioPin
SysFsGpioPin(zmqpp::context &ctx, const std::string &name, int gpio_no, Direction direction, InterruptMode interrupt_mode, bool initial_value, SysFsGpioModule &module)
Definition: SysFSGPIOPin.cpp:29
Leosac::Module::SysFsGpio::SysFsGpioPin::handle_interrupt
void handle_interrupt()
Interrupt happened for this GPIO ping.
Definition: SysFSGPIOPin.cpp:172
Leosac::Module::SysFsGpio::SysFsGpioPin::operator=
SysFsGpioPin & operator=(const SysFsGpioPin &)=delete
Leosac::Module::SysFsGpio::SysFsGpioPin::set_direction
void set_direction(Direction dir)
Write direction to the direction file.
Definition: SysFSGPIOPin.cpp:90
Leosac::Module::SysFsGpio::SysFsGpioPin::initial_value_
const bool initial_value_
Initial value of the PIN.
Definition: SysFSGPIOPin.hpp:155
Leosac::Module::SysFsGpio::SysFsGpioPin::read_value
bool read_value()
Read value from filesystem.
Definition: SysFSGPIOPin.cpp:167
Leosac::Module::SysFsGpio::SysFsGpioPin::InterruptMode::Both
@ Both
Leosac::Module::SysFsGpio::SysFsGpioPin::toggle
bool toggle()
Read to sysfs and then write the opposite value.
Definition: SysFSGPIOPin.cpp:160
Leosac::Module::SysFsGpio::SysFsGpioPin::InterruptMode::Rising
@ Rising
Leosac::Module::SysFsGpio::SysFsGpioConfig
Internal configuration helper for sysfsgpio module.
Definition: SysFsGpioConfig.hpp:40
Leosac::Module::SysFsGpio::SysFsGpioPin::InterruptMode::None
@ None
Leosac::Module::SysFsGpio::SysFsGpioPin::name_
std::string name_
Definition: SysFSGPIOPin.hpp:145
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::SysFsGpio::SysFsGpioPin::sock_
zmqpp::socket sock_
listen to command from other component.
Definition: SysFSGPIOPin.hpp:143
Leosac::Module::SysFsGpio::SysFsGpioPin::handle_message
void handle_message()
The SysFsGpioModule will register this method so its called when a message is ready on the pin socket...
Definition: SysFSGPIOPin.cpp:112
Leosac::Hardware::GPIO::Direction
Direction
Definition: GPIO.hpp:44
Leosac::Module::SysFsGpio::SysFsGpioPin::set_interrupt
void set_interrupt(InterruptMode mode)
Write interrupt mode to the edge file.
Definition: SysFSGPIOPin.cpp:96
Leosac::Module::SysFsGpio::SysFsGpioPin::next_update_time_
std::chrono::system_clock::time_point next_update_time_
Time point of next wished update.
Definition: SysFSGPIOPin.hpp:167
Leosac::Module::SysFsGpio::SysFsGpioPin::InterruptMode
InterruptMode
Definition: SysFSGPIOPin.hpp:46
GPIO.hpp
Leosac::Module::SysFsGpio::SysFsGpioPin::turn_on
bool turn_on(zmqpp::message *msg=nullptr)
Write to sysfs to turn the gpio on.
Definition: SysFSGPIOPin.cpp:133
SysFsGpioModule.hpp
Leosac::Module::SysFsGpio::SysFsGpioPin::InterruptMode::Falling
@ Falling
Leosac::Module::SysFsGpio::SysFsGpioPin::gpio_no_
int gpio_no_
Number of the GPIO.
Definition: SysFSGPIOPin.hpp:138
Leosac::Module::SysFsGpio::SysFsGpioPin::~SysFsGpioPin
~SysFsGpioPin()
Definition: SysFSGPIOPin.cpp:59
Leosac::Module::SysFsGpio::SysFsGpioPin::turn_off
bool turn_off()
Write to sysfs to turn the gpio on.
Definition: SysFSGPIOPin.cpp:154
Leosac::Module::SysFsGpio::SysFsGpioModule
Handle GPIO management over sysfs.
Definition: SysFsGpioModule.hpp:49
Leosac::Module::SysFsGpio::SysFsGpioPin::register_sockets
void register_sockets(zmqpp::reactor *reactor)
Register own socket to the module's reactor.
Definition: SysFSGPIOPin.cpp:187
Leosac::Module::SysFsGpio::SysFsGpioPin::Direction
Hardware::GPIO::Direction Direction
Definition: SysFSGPIOPin.hpp:44
Leosac::Module::SysFsGpio::SysFsGpioPin::file_fd_
int file_fd_
File descriptor of the GPIO in sysfs.
Definition: SysFSGPIOPin.hpp:133
Leosac::Module::SysFsGpio::SysFsGpioPin
This is a implementation class.
Definition: SysFSGPIOPin.hpp:41
Leosac::Module::SysFsGpio::SysFsGpioPin::path_cfg_
const SysFsGpioConfig & path_cfg_
Definition: SysFSGPIOPin.hpp:162
Leosac::Module::SysFsGpio::SysFsGpioPin::module_
SysFsGpioModule & module_
Reference to the module.
Definition: SysFSGPIOPin.hpp:160
Leosac::Module::SysFsGpio::SysFsGpioPin::direction_
const Direction direction_
Direction of the PIN.
Definition: SysFSGPIOPin.hpp:150