Leosac  0.8.0
Open Source Access Control
PFDigitalPin.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 "hardware/GPIO.hpp"
23 #include <chrono>
24 #include <string>
25 #include <zmqpp/zmqpp.hpp>
26 
34 {
36 
47  PFDigitalPin(zmqpp::context &ctx, const std::string &name, int gpio_no,
48  Direction direction, bool value, uint8_t hardware_address);
49 
50  ~PFDigitalPin();
51 
52  PFDigitalPin(const PFDigitalPin &) = delete;
53  PFDigitalPin &operator=(const PFDigitalPin &) = delete;
54 
56  PFDigitalPin &operator=(PFDigitalPin &&) = delete;
57 
58  void publish_state();
59 
69  void update();
70 
76  std::chrono::system_clock::time_point next_update() const;
77 
83  bool turn_on(zmqpp::message *msg = nullptr);
84 
88  bool turn_off();
89 
90  bool toggle();
91 
96  void handle_message();
97 
101  void send_state();
102 
103  uint8_t gpio_no_;
104 
108  zmqpp::socket sock_;
109 
113  zmqpp::socket *bus_push_;
114 
115  std::string name_;
116 
120  bool read_value();
121 
127 
133 
137  std::chrono::system_clock::time_point next_update_time_;
138 
140 
145 };
PFDigitalPin::PFDigitalPin
PFDigitalPin(zmqpp::context &ctx, const std::string &name, int gpio_no, Direction direction, bool value, uint8_t hardware_address)
Create a new GPIO pin.
Definition: PFDigitalPin.cpp:24
PFDigitalPin::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: PFDigitalPin.cpp:146
PFDigitalPin::operator=
PFDigitalPin & operator=(const PFDigitalPin &)=delete
PFDigitalPin
This is a implementation class.
Definition: PFDigitalPin.hpp:33
PFDigitalPin::direction_
const Direction direction_
This is the direction of the GPIO pin.
Definition: PFDigitalPin.hpp:126
PFDigitalPin::~PFDigitalPin
~PFDigitalPin()
Definition: PFDigitalPin.cpp:43
PFDigitalPin::update
void update()
Let the GPIO pin perform internal task.
Definition: PFDigitalPin.cpp:139
PFDigitalPin::publish_state
void publish_state()
Definition: PFDigitalPin.cpp:153
PFDigitalPin::name_
std::string name_
Definition: PFDigitalPin.hpp:115
PFDigitalPin::hardware_address_
uint8_t hardware_address_
Definition: PFDigitalPin.hpp:139
PFDigitalPin::turn_on
bool turn_on(zmqpp::message *msg=nullptr)
Write to PFDigital to turn the gpio on.
Definition: PFDigitalPin.cpp:86
PFDigitalPin::toggle
bool toggle()
Definition: PFDigitalPin.cpp:116
PFDigitalPin::handle_message
void handle_message()
The PFGpioModule will register this method so its called when a message is ready on the pin socket.
Definition: PFDigitalPin.cpp:64
PFDigitalPin::gpio_no_
uint8_t gpio_no_
Definition: PFDigitalPin.hpp:103
PFDigitalPin::bus_push_
zmqpp::socket * bus_push_
PUSH socket to write to the bus.
Definition: PFDigitalPin.hpp:113
PFDigitalPin::send_state
void send_state()
Send the current GPIO state on the socket.
Definition: PFDigitalPin.cpp:160
PFDigitalPin::read_value
bool read_value()
Ask the PiFace device for this pin's value and return it.
Definition: PFDigitalPin.cpp:132
Leosac::Hardware::GPIO::Direction
Direction
Definition: GPIO.hpp:44
PFDigitalPin::want_update_
bool want_update_
Does this object wants to be update()d ?
Definition: PFDigitalPin.hpp:144
GPIO.hpp
PFDigitalPin::turn_off
bool turn_off()
Write to PFDigital turn the gpio off.
Definition: PFDigitalPin.cpp:106
PFDigitalPin::default_value_
bool default_value_
The default value of the pin, it is only relevant is the pin is output.
Definition: PFDigitalPin.hpp:132
PFDigitalPin::next_update_time_
std::chrono::system_clock::time_point next_update_time_
Time point of next wished update.
Definition: PFDigitalPin.hpp:137
PFDigitalPin::sock_
zmqpp::socket sock_
listen to command from other component.
Definition: PFDigitalPin.hpp:108