Skip to content

Commit

Permalink
version -> 0.1.5 (#22)
Browse files Browse the repository at this point in the history
* DIn: allow input sense to be inverted
* Module::add_html_button() make const
* version -> 0.1.5
  • Loading branch information
chl33 authored Aug 3, 2024
1 parent b8a38db commit eb0768f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
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

0 comments on commit eb0768f

Please sign in to comment.