-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef0f02c
commit 208c9bf
Showing
11 changed files
with
141 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters