Skip to content

Commit 52c7722

Browse files
author
Bjarne Loft
committed
Add support for calling setValue for a sketch
1 parent 26d33b3 commit 52c7722

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/Entry.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ void Entry::update() {
9595
lastUpdate = time;
9696
String value = inFunction();
9797
if (value != "") {
98-
if (value != getValue() || force > getForce()) {
99-
setValue(value.c_str());
100-
force = 0;
101-
}
98+
if(setValue(value.c_str(), force > getForce())) {
99+
force = 0;
100+
}
102101
}
103102
}
104103
}
@@ -166,14 +165,18 @@ char *Entry::getValue() {
166165
return lastValue;
167166
}
168167

169-
void Entry::setValue(const char *value) {
170-
lastUpdate = millis();
171-
if(lastValue) {
172-
free(lastValue);
168+
bool Entry::setValue(const char *value, bool force) {
169+
if(force || strcmp(value, lastValue) != 0) {
170+
lastUpdate = millis();
171+
if(lastValue) {
172+
free(lastValue);
173+
}
174+
lastValue = (char*)malloc(strlen(value)+1);
175+
strcpy(lastValue, value);
176+
publish(value);
177+
return true;
173178
}
174-
lastValue = (char*)malloc(strlen(value)+1);
175-
strcpy(lastValue, value);
176-
publish(value);
179+
return false;
177180
}
178181

179182
long Entry::getLastUpdate() {

src/Entry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Entry {
6363
* Get last value
6464
*/
6565
char *getValue();
66-
void setValue(const char *value);
66+
bool setValue(const char *value, bool force = false);
6767

6868
/**
6969
*

0 commit comments

Comments
 (0)