26 #include <boost/iterator/transform_iterator.hpp> 27 #include <boost/property_tree/ptree.hpp> 29 #include <zmqpp/context.hpp> 30 #include <zmqpp/message.hpp> 38 zmqpp::socket *module_manager_pipe,
39 const boost::property_tree::ptree &config,
41 :
BaseModule(ctx, module_manager_pipe, config, utils)
42 , bus_push_(ctx_,
zmqpp::socket_type::push)
43 , general_cfg_(nullptr)
45 bus_push_.connect(
"inproc://zmq-bus-pull");
58 else if (str ==
"both")
60 else if (str ==
"falling")
62 else if (str ==
"rising")
70 boost::property_tree::ptree module_config = cfg.get_child(
"module_config");
74 for (
auto &node : module_config.get_child(
"gpios"))
76 boost::property_tree::ptree gpio_cfg = node.second;
79 std::string gpio_name;
80 std::string gpio_direction;
81 std::string gpio_interrupt;
83 bool gpio_initial_value;
85 gpio_name = gpio_cfg.get_child(
"name").data();
86 gpio_no = std::stoi(gpio_cfg.get_child(
"no").data());
87 gpio_direction = gpio_cfg.get_child(
"direction").data();
88 gpio_interrupt = gpio_cfg.get<std::string>(
"interrupt_mode",
"none");
89 gpio_initial_value = gpio_cfg.get<
bool>(
"value",
false);
91 using namespace Colorize;
97 interrupt_mode = gpio_interrupt_from_string(gpio_interrupt);
102 interrupt_mode, gpio_initial_value,
105 utils_->config_checker().register_object(gpio_name,
143 [](
const SysFsGpioPin *p) -> std::chrono::system_clock::time_point {
144 return p->next_update();
148 boost::make_transform_iterator(
gpios_.begin(), itr_transform),
149 boost::make_transform_iterator(
gpios_.end(), itr_transform));
151 for (
auto &gpio_pin :
gpios_)
153 if (gpio_pin->next_update() < std::chrono::system_clock::now())
void process_config(const boost::property_tree::ptree &cfg)
Process the configuration, preparing configured GPIO pin.
zmqpp::socket bus_push_
Socket to write the bus.
CoreUtilsPtr utils_
Pointer to the core utils, which gives access to scheduler and others.
SysFsGpioConfig * general_cfg_
General configuration for module.
std::string underline(const T &in)
SysFsGpioModule(zmqpp::context &ctx, zmqpp::socket *module_manager_pipe, const boost::property_tree::ptree &config, CoreUtilsPtr utils)
bool is_running_
Boolean indicating whether the main loop should run or not.
void publish_on_bus(zmqpp::message &msg)
Write the message eon the bus.
std::string green(const T &in)
unix filesystem helper functions
Base class for module implementation.
zmqpp::context & ctx_
A reference to the ZeroMQ context in case you need it to create additional socket.
const std::string & export_path() const
Returns the absolute path to the "export" sysfs file.
Internal configuration helper for sysfsgpio module.
zmqpp::reactor reactor_
The reactor object we poll() on in the main loop.
This is a implementation class.
Namespace for the module that implements GPIO support using the Linux Kernel sysfs interface...
std::vector< SysFsGpioPin * > gpios_
Vector of underlying pin object.
std::shared_ptr< CoreUtils > CoreUtilsPtr
const SysFsGpioConfig & general_config() const
Retrieve a reference to the config object.
boost::property_tree::ptree config_
The configuration tree passed to the start_module function.
void export_gpio(int gpio_no)
Write to "gpio_export_path" so the kernel export the socket to sysfs.
virtual void run() override
This is the main loop of the module.
void process_general_config()
General configuration (file paths, etc).