Skip to content

Commit

Permalink
clean and doxygen
Browse files Browse the repository at this point in the history
  • Loading branch information
InzynierDomu committed Jun 17, 2022
1 parent ef0f02c commit 208c9bf
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 53 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions src/HAL/Init.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 7 additions & 1 deletion src/HAL/Init.h
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -11,7 +18,6 @@
#include <optional>
#include <vector>


class Supervisor;

namespace HAL
Expand Down
31 changes: 22 additions & 9 deletions src/Peripherals/Analog_input.cpp
Original file line number Diff line number Diff line change
@@ -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 <PubSubClient.h>

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);
}

Expand Down
13 changes: 10 additions & 3 deletions src/Peripherals/Analog_input.h
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
30 changes: 22 additions & 8 deletions src/Peripherals/Digital_input.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
/**
* @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"

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
13 changes: 10 additions & 3 deletions src/Peripherals/Digital_input.h
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
47 changes: 35 additions & 12 deletions src/Peripherals/Digital_output.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -6,28 +13,34 @@
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];
m_topic.toCharArray(convert_buf, 30);
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)
{
Expand All @@ -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
19 changes: 13 additions & 6 deletions src/Peripherals/Digital_output.h
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/Peripherals/Peripheral_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 10 additions & 6 deletions src/Peripherals/Peripherals.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,9 +18,14 @@ namespace Peripherals

struct Peripherals
{
std::vector<Peripheral_output*> m_outputs;
std::vector<Peripheral_input*> m_inputs;
std::vector<Peripheral_output*> m_outputs; ///< outputs peripherals
std::vector<Peripheral_input*> 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())
Expand Down

0 comments on commit 208c9bf

Please sign in to comment.