Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version -> 0.1.5 #22

Merged
merged 3 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/og3/din.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace og3 {
class DIn : public Module {
public:
DIn(const char* name_, ModuleSystem* module_system_, uint8_t pin_, const char* description,
VariableGroup* vg, bool publish = true);
VariableGroup* vg, bool publish = true, bool invert = false);

// Read the dio pin and return isHigh().
bool read();
Expand All @@ -23,6 +23,7 @@ class DIn : public Module {

private:
const uint8_t m_pin;
const bool m_invert;
BinarySensorVariable m_is_high;
};

Expand Down
2 changes: 1 addition & 1 deletion include/og3/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Module {
void add_init_fn(const Thunk& thunk);
void add_start_fn(const Thunk& thunk);
void add_update_fn(const Thunk& thunk);
void add_html_button(String* body, const char* title, const char* url);
void add_html_button(String* body, const char* title, const char* url) const;
unsigned sorted_index() const { return m_sorted_idx; }

protected:
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "og3",
"version": "0.1.4",
"version": "0.1.5",
"description": "A library for esp projects",
"keywords": "esp32, esp8266, modules, tasks, mqtt",
"authors": [
Expand Down
6 changes: 4 additions & 2 deletions src/din.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
namespace og3 {

DIn::DIn(const char* name_, ModuleSystem* module_system_, uint8_t pin_, const char* description,
VariableGroup* vg, bool publish)
VariableGroup* vg, bool publish, bool invert)
: Module(name_, module_system_),
m_pin(pin_),
m_invert(invert),
m_is_high(name_, false, description, vg, publish) {
add_init_fn([this]() { pinMode(m_pin, INPUT); });
}

bool DIn::read() {
const bool is_high = (HIGH == digitalRead(m_pin));
const bool pin_is_high = (HIGH == digitalRead(m_pin));
const bool is_high = m_invert ? !pin_is_high : pin_is_high;
if (is_high != m_is_high.value()) {
log()->debugf("%s -> %s", name(), is_high ? "high" : "low");
}
Expand Down
2 changes: 1 addition & 1 deletion src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Module::add_init_fn(const Thunk& thunk) { m_module_system->add_init_fn(thun
void Module::add_start_fn(const Thunk& thunk) { m_module_system->add_start_fn(thunk, this); }
void Module::add_update_fn(const Thunk& thunk) { m_module_system->add_update_fn(thunk, this); }

void Module::add_html_button(String* body, const char* title, const char* url) {
void Module::add_html_button(String* body, const char* title, const char* url) const {
*body += F("<p><form action='");
*body += url;
*body += F("' method='get'><button>");
Expand Down
Loading