-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New InputPinArrayNode for simple IO + doc improvements
+ InputPinArrayNode can be used to define a vector of GPIOs that are configured as INPUT_PULLUP and announced as array of Contacts. + created doxyfile for doc generation with doxygen + added some doxygen-style doc-strings + small refactoring of RelaisNode
- Loading branch information
Showing
7 changed files
with
2,638 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
/.project | ||
/.settings | ||
src/main.cpp | ||
/html/ | ||
/latex/ |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* InputPinArrayNode.cpp | ||
* | ||
* Created on: 09.04.2018 | ||
* Author: ian | ||
*/ | ||
|
||
#include <InputPinArrayNode.h> | ||
|
||
InputPinArrayNode::InputPinArrayNode(std::vector<uint8_t> pins, InputPinChangeEventHandler& cb): | ||
HomieNode("Input", "Contact"), | ||
inputPins(pins), | ||
storedPins(pins.size()), | ||
callback(cb) { | ||
advertiseRange("pin", 0, inputPins.size()-1); | ||
} | ||
|
||
void InputPinArrayNode::setup() { | ||
for (uint8_t pin : inputPins) { | ||
pinMode(pin, INPUT_PULLUP); | ||
} | ||
} | ||
|
||
void InputPinArrayNode::loop() { | ||
uint8_t idx = 0; | ||
for (uint8_t pin : inputPins) { | ||
bool curState = digitalRead(pin); | ||
bool oldState = storedPins[idx]; | ||
if (curState != oldState) { | ||
setProperty("pin").setRange(idx).setRetained(true).send(curState ? "OPEN":"CLOSED"); | ||
storedPins[idx] = curState; | ||
callback(idx, curState); | ||
} | ||
++idx; | ||
} | ||
} | ||
|
||
void InputPinArrayNode::onReadyToOperate() { | ||
uint8_t idx = 0; | ||
for (uint8_t pin : inputPins) { | ||
bool curState = digitalRead(pin); | ||
storedPins[idx] = curState; | ||
setProperty("pin").setRange(idx).setRetained(true).send(curState ? "OPEN":"CLOSED"); | ||
idx++; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* InputPinArrayNode.h | ||
* | ||
* Created on: 09.04.2018 | ||
* Author: ian | ||
*/ | ||
|
||
#ifndef SRC_INPUTPINARRAYNODE_H_ | ||
#define SRC_INPUTPINARRAYNODE_H_ | ||
|
||
#include <HomieNode.hpp> | ||
|
||
|
||
|
||
class InputPinArrayNode: public HomieNode { | ||
|
||
|
||
public: | ||
typedef std::function<bool(uint8_t idx, bool state)> InputPinChangeEventHandler; | ||
InputPinArrayNode(std::vector<uint8_t> pins, InputPinChangeEventHandler& cb); | ||
|
||
protected: | ||
virtual void setup() override; | ||
virtual void loop() override; | ||
virtual void onReadyToOperate() override; | ||
|
||
private: | ||
std::vector<uint8_t> inputPins; | ||
std::vector<bool> storedPins; | ||
InputPinChangeEventHandler & callback; | ||
}; | ||
|
||
#endif /* SRC_INPUTPINARRAYNODE_H_ */ |
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