Use timer to fetch position periodically after setting position
This commit is contained in:
22
src/main.cpp
22
src/main.cpp
@@ -36,7 +36,7 @@ bool sendSetPosition(uint16_t destination, float percentage);
|
|||||||
bool sendFetchPosition(uint16_t destination);
|
bool sendFetchPosition(uint16_t destination);
|
||||||
bool sendPacket(Packet *packet);
|
bool sendPacket(Packet *packet);
|
||||||
|
|
||||||
unsigned long lastCommandMillis = 0;
|
bool updatePosition(uint16_t shadeID);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(SER_BAUDRATE);
|
Serial.begin(SER_BAUDRATE);
|
||||||
@@ -54,18 +54,13 @@ void setup() {
|
|||||||
client.enableDebuggingMessages();
|
client.enableDebuggingMessages();
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
lastCommandMillis = millis();
|
|
||||||
Serial.println("Ready");
|
Serial.println("Ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
powerView.loop();
|
powerView.loop();
|
||||||
client.loop();
|
client.loop();
|
||||||
|
timer.tick();
|
||||||
if ((millis() - lastCommandMillis) > 10000) {
|
|
||||||
lastCommandMillis = millis();
|
|
||||||
sendFetchPosition(0x4EF1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void processPacket(const Packet *packet) {
|
void processPacket(const Packet *packet) {
|
||||||
@@ -111,6 +106,13 @@ void onConnectionEstablished() {
|
|||||||
float percentage = payload.toInt() / 100.0f;
|
float percentage = payload.toInt() / 100.0f;
|
||||||
sendSetPosition(shadeID, percentage);
|
sendSetPosition(shadeID, percentage);
|
||||||
// TODO: Schedule fetching position of blind
|
// TODO: Schedule fetching position of blind
|
||||||
|
timer.in(1000, updatePosition, 0x4EF1);
|
||||||
|
timer.in(3000, updatePosition, 0x4EF1);
|
||||||
|
timer.in(5000, updatePosition, 0x4EF1);
|
||||||
|
timer.in(7000, updatePosition, 0x4EF1);
|
||||||
|
timer.in(9000, updatePosition, 0x4EF1);
|
||||||
|
timer.in(15000, updatePosition, 0x4EF1);
|
||||||
|
timer.in(30000, updatePosition, 0x4EF1);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.publish("hotdog/availability", "online", true);
|
client.publish("hotdog/availability", "online", true);
|
||||||
@@ -192,3 +194,9 @@ bool sendPacket(Packet *packet) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool updatePosition(uint16_t shadeID) {
|
||||||
|
Serial.println("Triggering position update");
|
||||||
|
sendFetchPosition(shadeID);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user