22 #include "hardware/Buzzer_odb.h"
24 #include "hardware/LED_odb.h"
27 #include "ws/WSHelperThread.hpp"
28 #include <boost/iterator/transform_iterator.hpp>
38 boost::property_tree::ptree
const &cfg,
56 if (
config_.get_child(
"module_config").get<
bool>(
"use_database",
false))
63 auto itr_transform = [](
const std::shared_ptr<LedBuzzerImpl> &lb) {
64 return lb->next_update();
71 if (led->next_update() <= std::chrono::system_clock::now())
82 boost::property_tree::ptree module_config =
config_.get_child(
"module_config");
84 if (module_config.get<
bool>(
"use_database",
false))
96 boost::property_tree::ptree module_config =
config_.get_child(
"module_config");
98 if (
const auto &leds_node = module_config.get_child_optional(
"leds"))
100 for (
auto &node : *leds_node)
102 boost::property_tree::ptree led_cfg = node.second;
104 std::string led_name = led_cfg.get<std::string>(
"name");
105 std::string gpio_name = led_cfg.get<std::string>(
"gpio");
106 int default_blink_duration =
107 led_cfg.get<
int>(
"default_blink_duration", 1000);
108 int default_blink_speed = led_cfg.get<
int>(
"default_blink_speed", 200);
110 INFO(
"Creating LED " << led_name <<
", linked to GPIO " << gpio_name);
114 ctx_, led_name, gpio_name, default_blink_duration,
115 default_blink_speed));
116 utils_->config_checker().register_object(led_name,
121 if (
const auto &buzzers_node = module_config.get_child_optional(
"buzzers"))
123 for (
auto &node : *buzzers_node)
125 boost::property_tree::ptree buzzer_cfg = node.second;
127 std::string buzzer_name = buzzer_cfg.get<std::string>(
"name");
128 std::string gpio_name = buzzer_cfg.get<std::string>(
"gpio");
129 int default_blink_duration =
130 buzzer_cfg.get<
int>(
"default_blink_duration", 1000);
131 int default_blink_speed =
132 buzzer_cfg.get<
int>(
"default_blink_speed", 200);
134 INFO(
"Creating Buzzer " << buzzer_name <<
", linked to GPIO "
140 ctx_, buzzer_name, gpio_name, default_blink_duration,
141 default_blink_speed));
142 utils_->config_checker().register_object(
151 using namespace odb::core;
152 auto db =
utils_->database();
156 odb::transaction t(
utils_->database()->begin());
157 odb::result<Hardware::LED> result(
159 for (
const auto &led : result)
165 WARN(
"No GPIO associated with device " << led.name()
170 ctx_, led.name(), led.gpio()->name(), led.default_blink_duration(),
171 led.default_blink_speed()));
172 utils_->config_checker().register_object(led.name(),
180 odb::transaction t(
utils_->database()->begin());
181 odb::result<Hardware::Buzzer> result(
183 for (
const auto &buzzer : result)
185 if (!buzzer.enabled())
189 WARN(
"No GPIO associated with device " << buzzer.name()
194 ctx_, buzzer.name(), buzzer.gpio()->name(),
195 buzzer.default_blink_duration(), buzzer.default_blink_speed()));
196 utils_->config_checker().register_object(
202 INFO(
"LEDBuzzer module using SQL database for configuration.");