Leosac  0.7.0
OpenSourceAccessControl
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 };
std::chrono::system_clock::time_point next_update() const
This method shall returns the time point at which we want to be updated.
bool turn_on(zmqpp::message *msg=nullptr)
Write to PFDigital to turn the gpio on.
std::string name_
bool turn_off()
Write to PFDigital turn the gpio off.
zmqpp::socket * bus_push_
PUSH socket to write to the bus.
zmqpp::socket sock_
listen to command from other component.
void handle_message()
The PFGpioModule will register this method so its called when a message is ready on the pin socket...
This is a implementation class.
PFDigitalPin(zmqpp::context &ctx, const std::string &name, int gpio_no, Direction direction, bool value, uint8_t hardware_address)
Create a new GPIO pin.
void update()
Let the GPIO pin perform internal task.
bool want_update_
Does this object wants to be update()d ?
void send_state()
Send the current GPIO state on the socket.
uint8_t hardware_address_
bool read_value()
Ask the PiFace device for this pin&#39;s value and return it.
void publish_state()
std::chrono::system_clock::time_point next_update_time_
Time point of next wished update.
uint8_t gpio_no_
const Direction direction_
This is the direction of the GPIO pin.
bool default_value_
The default value of the pin, it is only relevant is the pin is output.
PFDigitalPin & operator=(const PFDigitalPin &)=delete