From 028f79103add487281eadeb85680b390d9c3de9a Mon Sep 17 00:00:00 2001 From: Emma Baird Date: Mon, 3 Jun 2024 17:57:31 +0100 Subject: [PATCH] Updates to High Power Relay code --- lib/sensors/high_power_relay.cpp | 29 ++++++++++++++++++++++++++++- lib/sensors/high_power_relay.hpp | 13 +++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/sensors/high_power_relay.cpp b/lib/sensors/high_power_relay.cpp index fabe2105..c18fe767 100644 --- a/lib/sensors/high_power_relay.cpp +++ b/lib/sensors/high_power_relay.cpp @@ -1 +1,28 @@ -#include "high_power_relay.hpp" \ No newline at end of file +#include "high_power_relay.hpp" + +namespace hyped::sensors { + +std::optional HpRelay::create(core::ILogger &logger, + std::shared_ptr gpio, + const std::uint8_t new_pin) +{ + const auto reader = gpio->getReader(new_pin, io::Edge::kNone); + if (!reader) { + logger.log(core::LogLevel::kFatal, "Failed to create HpRelay instance"); + return std::nullopt; + } + logger.log(core::LogLevel::kDebug, "Successfully created HpRelay instance"); + return Keyence(logger, *reader); +} + +HpRelay::HpRelay(core::ILogger &logger, std::shared_ptr gpio_reader) + : gpio_reader_(gpio_reader), + logger_(logger) +{ +} + +HpRelay::~HpRelay() +{ +} + +} // namespace hyped::sensors \ No newline at end of file diff --git a/lib/sensors/high_power_relay.hpp b/lib/sensors/high_power_relay.hpp index 57a7ced7..80714843 100644 --- a/lib/sensors/high_power_relay.hpp +++ b/lib/sensors/high_power_relay.hpp @@ -9,11 +9,12 @@ namespace hyped::sensors { class HpRelay { - public: + public: static std::optional create(core::ILogger &logger, - std::shared_ptr gpio, - const std::uint8_t new_pin); - - + std::shared_ptr gpio, + const std::uint8_t new_pin); + + ~HpRelay(); }; -} // namespace::sensors \ No newline at end of file + +} // namespace hyped::sensors \ No newline at end of file