Skip to content

Commit

Permalink
1.38
Browse files Browse the repository at this point in the history
  • Loading branch information
klausahrenberg committed Oct 15, 2023
1 parent d5d42b4 commit de0f498
Show file tree
Hide file tree
Showing 17 changed files with 1,050 additions and 788 deletions.
50 changes: 50 additions & 0 deletions src/WAnalog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef W_ANALOG_INPUT_H
#define W_ANALOG_INPUT_H

#include "WInput.h"

class WAnalog : public WInput {
public:
WAnalog(int analogPin, int minimum = 0, int maximum = 100) : WInput(analogPin, INPUT) {
_minimum = minimum;
_maximum = maximum;
_analogMinimum = 0;
#ifdef ESP8266
_analogMaximum = 1023;
#elif ESP32
_analogMaximum = 4095;
#endif
}

void loop(unsigned long now) {
if ((this->isInitialized()) && (hasProperty())) {
int ain = analogRead(pin());
ain = constrain(ain, _analogMinimum, _analogMaximum);
ain = map(ain, _minimum, _maximum, _analogMinimum, _analogMaximum);

switch (property()->type()) {
INTEGER: {
property()->asInt(ain);
break;
}
BYTE: {
property()->asByte(ain);
break;
}
DOUBLE: {
property()->asDouble(ain);
break;
}
}
}
}

private:
int _analogMinimum;
int _analogMaximum;
int _minimum;
int _maximum;

};

#endif
10 changes: 6 additions & 4 deletions src/WDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WDevice {
const char* type() { return _type; }

void addProperty(WProperty* property) {
property->setDeviceNotification(std::bind(&WDevice::onPropertyChange, this));
property->deviceNotification(std::bind(&WDevice::onPropertyChange, this));
_properties->add(property);
}

Expand Down Expand Up @@ -80,7 +80,7 @@ class WDevice {
if (property->isVisible(visibility)) {
property->toJsonValue(json, false);
}
property->setUnChanged();
property->changed(false);
});
}

Expand Down Expand Up @@ -136,7 +136,7 @@ class WDevice {
virtual bool off() { return false; }

virtual bool areAllPropertiesRequested() {
return (_properties->getIf([this](WProperty* p){return (!p->isRequested());}) == nullptr);
return (_properties->getIf([this](WProperty* p){return (!p->requested());}) == nullptr);
}

WPropertyVisibility visibility() { return _visibility; }
Expand Down Expand Up @@ -167,9 +167,11 @@ class WDevice {

unsigned long lastStateNotify() { return _lastStateNotify; }

void setLastStateNotify(unsigned long lastStateNotify) { _lastStateNotify = lastStateNotify; }
void lastStateNotify(unsigned long lastStateNotify) { _lastStateNotify = lastStateNotify; }

unsigned long stateNotifyInterval() { return _stateNotifyInterval; }

void stateNotifyInterval(unsigned long stateNotifyInterval) { _stateNotifyInterval = stateNotifyInterval; }

bool needsWebThings() {
bool result = false;
Expand Down
Loading

0 comments on commit de0f498

Please sign in to comment.