Use timer to fetch position periodically after setting position

This commit is contained in:
2024-01-03 10:19:28 +11:00
parent a1cd3656d4
commit 62474c3911

View File

@@ -36,7 +36,7 @@ bool sendSetPosition(uint16_t destination, float percentage);
bool sendFetchPosition(uint16_t destination);
bool sendPacket(Packet *packet);
unsigned long lastCommandMillis = 0;
bool updatePosition(uint16_t shadeID);
void setup() {
Serial.begin(SER_BAUDRATE);
@@ -54,18 +54,13 @@ void setup() {
client.enableDebuggingMessages();
delay(100);
lastCommandMillis = millis();
Serial.println("Ready");
}
void loop() {
powerView.loop();
client.loop();
if ((millis() - lastCommandMillis) > 10000) {
lastCommandMillis = millis();
sendFetchPosition(0x4EF1);
}
timer.tick();
}
void processPacket(const Packet *packet) {
@@ -111,6 +106,13 @@ void onConnectionEstablished() {
float percentage = payload.toInt() / 100.0f;
sendSetPosition(shadeID, percentage);
// 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);
@@ -191,4 +193,10 @@ bool sendPacket(Packet *packet) {
lastRollingCode2++;
return true;
}
}
bool updatePosition(uint16_t shadeID) {
Serial.println("Triggering position update");
sendFetchPosition(shadeID);
return false;
}