diff --git a/README.md b/README.md index 1d96504..c6e736c 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,12 @@ Part list: - U2 DHT22 humidity and temperature sensor - U3 EEPROM 24C16 - U4 ESP8266 NodeMCU -- U5 RTC DS1207 +- U5 RTC DS1307 - Y1 Oscillator 32,788 KHz Parts optional (on I2C) -- MCP23017 (max 8) -- PCF8591 (max 8) +- MCP23017 (max 8 pcs) +- PCF8591 (max 8 pcs) ## IDE diff --git a/src/HAL/Init.cpp b/src/HAL/Init.cpp index 9fc814c..15b3019 100644 --- a/src/HAL/Init.cpp +++ b/src/HAL/Init.cpp @@ -1,3 +1,10 @@ +/** + * @file Init.cpp + * @author by Szymon Markiewicz (https://github.com/InzynierDomu/) + * @brief Main HAL run + * @date 2022-06 + */ + #include "Init.h" #include "Analog_controller.h" diff --git a/src/HAL/Init.h b/src/HAL/Init.h index 7832690..11df715 100644 --- a/src/HAL/Init.h +++ b/src/HAL/Init.h @@ -1,3 +1,10 @@ +/** + * @file Init.h + * @author by Szymon Markiewicz (https://github.com/InzynierDomu/) + * @brief Main HAL run + * @date 2022-06 + */ + #pragma once #include "../Keyboard_buttons.h" @@ -11,7 +18,6 @@ #include #include - class Supervisor; namespace HAL diff --git a/src/Peripherals/Analog_input.cpp b/src/Peripherals/Analog_input.cpp index cd09bf5..cadb59d 100644 --- a/src/Peripherals/Analog_input.cpp +++ b/src/Peripherals/Analog_input.cpp @@ -1,28 +1,41 @@ +/** + * @file Analog_input.cpp + * @author by Szymon Markiewicz (https://github.com/InzynierDomu/) + * @brief Analog input handling + * @date 2022-06 + */ + #include "Analog_input.h" #include "HAL/Real_clock.h" #include "Logger.h" -#include - namespace Peripherals { -Analog_input::Analog_input(HAL::Analog_controller* controller, const int pin, const String topic) +/** + * @brief Construct a new Analog_input::Analog_input object + * @param controller: analog expander + * @param pin: pin number + * @param topic: mqtt topic to publish + */ +Analog_input::Analog_input(HAL::Analog_controller* controller, const uint8_t pin, const String& topic) : m_controller(controller) , m_logger(Logger("Analog input (topic:" + topic + " pin:" + String(pin) + ")", HAL::Real_clock::get_instance()->get_time_callback())) -{ - m_pin = pin; - m_topic = topic; -} +, m_topic(topic) +, m_pin(pin) +{} +/** + * @brief publish actual analog measurment value on pin + * @param client: mqtt client + */ void Analog_input::publish(PubSubClient& client) { char buf[4]; - // String topic = m_topic; int value = m_controller->get_value(m_pin); sprintf(buf, "%d", value); - m_logger.log(String(value), Log_type::debug); + m_logger.log(String(value)); client.publish(m_topic.c_str(), buf); } diff --git a/src/Peripherals/Analog_input.h b/src/Peripherals/Analog_input.h index 914de99..ca4b157 100644 --- a/src/Peripherals/Analog_input.h +++ b/src/Peripherals/Analog_input.h @@ -1,3 +1,10 @@ +/** + * @file Analog_input.h + * @author by Szymon Markiewicz (https://github.com/InzynierDomu/) + * @brief Analog input handling + * @date 2022-06 + */ + #pragma once #include "HAL/Analog_controller.h" @@ -11,15 +18,15 @@ namespace Peripherals class Analog_input : public Peripheral_input { public: - Analog_input(HAL::Analog_controller* controller, const int pin, const String topic); + Analog_input(HAL::Analog_controller* controller, const uint8_t pin, const String& topic); void publish(PubSubClient& client) override; private: HAL::Analog_controller* m_controller; Logger m_logger; - String m_topic; - uint8_t m_pin; + const String& m_topic; ///< mqtt topic to publishing + const uint8_t m_pin; ///< pin number on expander }; } // namespace Peripherals \ No newline at end of file diff --git a/src/Peripherals/Digital_input.cpp b/src/Peripherals/Digital_input.cpp index f7a07e0..3396d73 100644 --- a/src/Peripherals/Digital_input.cpp +++ b/src/Peripherals/Digital_input.cpp @@ -1,3 +1,10 @@ +/** + * @file Digital_input.cpp + * @author by Szymon Markiewicz (https://github.com/InzynierDomu/) + * @brief Digital input handling + * @date 2022-06 + */ + #include "Digital_input.h" #include "HAL/Real_clock.h" @@ -5,21 +12,28 @@ namespace Peripherals { -Digital_input::Digital_input(HAL::GPIO_controller* controller, int pin, String topic) +/** + * @brief Construct a new Digital_input::Digital_input object + * @param controller: GPIO expander + * @param pin: pin number + * @param topic: mqtt topic to publish + */ +Digital_input::Digital_input(HAL::GPIO_controller* controller, const uint8_t pin, const String& topic) : m_controller(controller) , m_logger(Logger("Digital input (topic:" + topic + " pin:" + String(pin) + ")", HAL::Real_clock::get_instance()->get_time_callback())) -{ - m_pin = pin; - m_topic = topic; -} +, m_topic(topic) +, m_pin(pin) +{} +/** + * @brief publish actual pin state + * @param client: mqtt client + */ void Digital_input::publish(PubSubClient& client) { - char topic[30]; - m_topic.toCharArray(topic, 30); uint8_t state = m_controller->get_state(m_pin); m_logger.log(String(state)); - client.publish(topic, &state, 1); + client.publish(m_topic.c_str(), &state, 1); } } // namespace Peripherals diff --git a/src/Peripherals/Digital_input.h b/src/Peripherals/Digital_input.h index 43b8d5b..a43c280 100644 --- a/src/Peripherals/Digital_input.h +++ b/src/Peripherals/Digital_input.h @@ -1,3 +1,10 @@ +/** + * @file Digital_input.h + * @author by Szymon Markiewicz (https://github.com/InzynierDomu/) + * @brief Digital input handling + * @date 2022-06 + */ + #pragma once #include "HAL/GPIO_controller.h" @@ -12,15 +19,15 @@ namespace Peripherals class Digital_input : public Peripheral_input { public: - Digital_input(HAL::GPIO_controller* controller, int pin, String topic); + Digital_input(HAL::GPIO_controller* controller, const uint8_t pin, const String& topic); void publish(PubSubClient& client) override; private: HAL::GPIO_controller* m_controller; Logger m_logger; - String m_topic; - uint8_t m_pin; + const String& m_topic; ///< mqtt topic to publishing + const uint8_t m_pin; ///< pin number on expander }; } // namespace Peripherals \ No newline at end of file diff --git a/src/Peripherals/Digital_output.cpp b/src/Peripherals/Digital_output.cpp index 6cb2112..0484f43 100644 --- a/src/Peripherals/Digital_output.cpp +++ b/src/Peripherals/Digital_output.cpp @@ -1,3 +1,10 @@ +/** + * @file Digital_output.cpp + * @author by Szymon Markiewicz (https://github.com/InzynierDomu/) + * @brief Digital output handling + * @date 2022-06 + */ + #include "Digital_output.h" #include "HAL/Real_clock.h" @@ -6,14 +13,22 @@ namespace Peripherals { -Digital_output::Digital_output(HAL::GPIO_controller* controller, PubSubClient& client, int pin, String topic, Scheduler& scheduler) +/** + * @brief Construct a new Digital_output::Digital_output object + * @param controller: GPIO expander + * @param client: MQTT client + * @param pin: pin number + * @param topic: mqtt topic to subscribe + * @param scheduler: event scheduler + */ +Digital_output::Digital_output(HAL::GPIO_controller* controller, PubSubClient& client, const uint8_t pin, const String& topic, + Scheduler& scheduler) : m_controller(controller) , m_logger(new Logger("Digital output (topic:" + topic + " pin:" + String(pin) + ")", HAL::Real_clock::get_instance()->get_time_callback())) , m_scheduler(scheduler) +, m_topic(topic) +, m_pin(pin) { - m_pin = pin; - m_topic = topic; - m_controller->set_in_out(OUTPUT, m_pin); char convert_buf[30]; @@ -21,13 +36,11 @@ Digital_output::Digital_output(HAL::GPIO_controller* controller, PubSubClient& c client.subscribe(convert_buf); } -void Digital_output::turn_off() -{ - m_controller->turn_off_pin(m_pin); - m_logger->log("turn off"); -} - -void Digital_output::set_value(uint8_t value) +/** + * @brief set value on output pin + * @param value: turn on, of or turn on for some time + */ +void Digital_output::set_value(const uint8_t value) { if (value < 2) { @@ -50,9 +63,19 @@ void Digital_output::set_value(uint8_t value) } } -String Digital_output::get_topic() +/** + * @brief get output topic + * @return String topic + */ +String Digital_output::get_topic() const { return m_topic; } +void Digital_output::turn_off() +{ + m_controller->turn_off_pin(m_pin); + m_logger->log("turn off"); +} + } // namespace Peripherals diff --git a/src/Peripherals/Digital_output.h b/src/Peripherals/Digital_output.h index 82f7eea..795ab56 100644 --- a/src/Peripherals/Digital_output.h +++ b/src/Peripherals/Digital_output.h @@ -1,3 +1,10 @@ +/** + * @file Digital_output.h + * @author by Szymon Markiewicz (https://github.com/InzynierDomu/) + * @brief Digital output handling + * @date 2022-06 + */ + #pragma once #include "HAL/GPIO_controller.h" @@ -15,19 +22,19 @@ namespace Peripherals class Digital_output : public Peripheral_output { public: - Digital_output(HAL::GPIO_controller* controller, PubSubClient& client, int pin, String topic, Scheduler& scheduler); - void set_value(uint8_t value) override; - String get_topic(); + Digital_output(HAL::GPIO_controller* controller, PubSubClient& client, const uint8_t pin, const String& topic, Scheduler& scheduler); + void set_value(const uint8_t value) override; + String get_topic() const override; private: void turn_off(); HAL::GPIO_controller* m_controller; Logger* m_logger; - Scheduler& m_scheduler; + Scheduler& m_scheduler; - String m_topic; - uint8_t m_pin; + const String& m_topic; ///< mqtt topic to subscribe + const uint8_t m_pin; ///< pin number on expander }; } // namespace Peripherals \ No newline at end of file diff --git a/src/Peripherals/Peripheral_output.h b/src/Peripherals/Peripheral_output.h index 84b6b21..f550fd4 100644 --- a/src/Peripherals/Peripheral_output.h +++ b/src/Peripherals/Peripheral_output.h @@ -7,8 +7,8 @@ class Peripheral_output { public: virtual ~Peripheral_output() {} - virtual void set_value(uint8_t value) = 0; - virtual String get_topic() = 0; + virtual void set_value(const uint8_t value) = 0; + virtual String get_topic() const = 0; }; } // namespace Peripherals \ No newline at end of file diff --git a/src/Peripherals/Peripherals.h b/src/Peripherals/Peripherals.h index 8a8db5d..3c3ed73 100644 --- a/src/Peripherals/Peripherals.h +++ b/src/Peripherals/Peripherals.h @@ -1,9 +1,8 @@ /** * @file Peripherals.h - * @brief GreenHouse 2.0 - Peripherals container structure - * @author Szymon Markiewicz - * @details http://www.inzynierdomu.pl/ - * @date 06-2022 + * @brief Peripherals container structure + * @author by Szymon Markiewicz (https://github.com/InzynierDomu/) + * @date 2022-06 */ #pragma once @@ -19,9 +18,14 @@ namespace Peripherals struct Peripherals { - std::vector m_outputs; - std::vector m_inputs; + std::vector m_outputs; ///< outputs peripherals + std::vector m_inputs; ///< inputs peripherals + /** + * @brief Get the output object + * @param topic: with what topic want to find output + * @return Peripheral_output* output + */ Peripheral_output* get_output(String topic) { if (!m_outputs.empty())