diff --git a/src/floower-esp32/automaton.cpp b/src/floower-esp32/automaton.cpp index aec4f52..575aced 100644 --- a/src/floower-esp32/automaton.cpp +++ b/src/floower-esp32/automaton.cpp @@ -56,7 +56,7 @@ void Automaton::onLeafTouch(FloowerTouchEvent event) { if (disabledTouchUp) { disabledTouchUp = false; } - else if (floower->isIdle()) { + else if (!floower->arePetalsMoving() && !floower->isChangingColor()) { if (state == STATE_STANDBY) { // open + set color if (!floower->isLit()) { diff --git a/src/floower-esp32/floower-esp32.ino b/src/floower-esp32/floower-esp32.ino index 5f5f43d..d26483a 100644 --- a/src/floower-esp32/floower-esp32.ino +++ b/src/floower-esp32/floower-esp32.ino @@ -128,7 +128,7 @@ void loop() { periodicOperationsTime = now + PERIODIC_OPERATIONS_INTERVAL; periodicOperation(); } - if (initRemoteTime != 0 && initRemoteTime < now && floower.isIdle()) { + if (initRemoteTime != 0 && initRemoteTime < now && !floower.arePetalsMoving()) { initRemoteTime = 0; remote.init(); remote.startAdvertising(); @@ -141,7 +141,7 @@ void loop() { // plan to enter deep sleep in inactivity if (deepSleepEnabled && !batteryDead) { // plan to enter deep sleep to save power if floower is in open/dark position & remote is not connected - if (!batteryCharging && !floower.isLit() && floower.isIdle() && floower.getPetalsOpenLevel() == 0 && !remote.isConnected()) { + if (!batteryCharging && !floower.isLit() && !floower.arePetalsMoving() && floower.getPetalsOpenLevel() == 0 && !remote.isConnected()) { if (deepSleepTime == 0) { planDeepSleep(DEEP_SLEEP_INACTIVITY_TIMEOUT); } @@ -158,8 +158,8 @@ void loop() { } #endif - // save some power when flower is idle - if (floower.isIdle()) { + // save some power when flower is not animating + if (!floower.isAnimating()) { delay(10); } } diff --git a/src/floower-esp32/floower.cpp b/src/floower-esp32/floower.cpp index 12ce4a5..37e1efb 100644 --- a/src/floower-esp32/floower.cpp +++ b/src/floower-esp32/floower.cpp @@ -237,6 +237,7 @@ void Floower::setColor(RgbColor color, FloowerColorMode colorMode, int transitio pixelsColorMode = colorMode; pixelsTargetColor = color; + interruptiblePixelsAnimation = false; ESP_LOGI(LOG_TAG, "Color %d,%d,%d", color.R, color.G, color.B); @@ -291,6 +292,8 @@ RgbColor Floower::getCurrentColor() { } void Floower::startAnimation(FloowerColorAnimation animation) { + interruptiblePixelsAnimation = true; + if (animation == RAINBOW) { pixelsOriginColor = pixelsColor; animations.StartAnimation(1, 10000, [=](const AnimationParam& param){ pixelsRainbowAnimationUpdate(param); }); @@ -359,12 +362,16 @@ bool Floower::isLit() { return pixelsPowerOn; } +bool Floower::isAnimating() { + return !animations.IsAnimating(); +} + bool Floower::arePetalsMoving() { return animations.IsAnimationActive(0); } -bool Floower::isIdle() { - return !animations.IsAnimating(); +bool Floower::isChangingColor() { + return (!interruptiblePixelsAnimation && animations.IsAnimationActive(1)); } void Floower::acty() { diff --git a/src/floower-esp32/floower.h b/src/floower-esp32/floower.h index cd4b500..164d42c 100644 --- a/src/floower-esp32/floower.h +++ b/src/floower-esp32/floower.h @@ -56,9 +56,10 @@ class Floower { RgbColor getCurrentColor(); void startAnimation(FloowerColorAnimation animation); void stopAnimation(bool retainColor); - bool arePetalsMoving(); bool isLit(); - bool isIdle(); + bool isAnimating(); + bool arePetalsMoving(); + bool isChangingColor(); void acty(); Battery readBatteryState(); @@ -107,6 +108,11 @@ class Floower { FloowerColorMode pixelsColorMode; bool pixelsPowerOn; + // leds animations + bool interruptiblePixelsAnimation = false; + RgbColor candleOriginColors[6]; + RgbColor candleTargetColors[6]; + // touch FloowerOnLeafTouchCallback touchCallback; static unsigned long touchStartedTime; @@ -122,10 +128,6 @@ class Floower { // acty unsigned long actyOffTime; - - // animations - RgbColor candleOriginColors[6]; - RgbColor candleTargetColors[6]; }; #endif diff --git a/src/floower-esp32/remote.cpp b/src/floower-esp32/remote.cpp index 0ed0cbc..2141814 100644 --- a/src/floower-esp32/remote.cpp +++ b/src/floower-esp32/remote.cpp @@ -191,7 +191,7 @@ void Remote::onTakeOver(RemoteTakeOverCallback callback) { } void Remote::setBatteryLevel(uint8_t level, bool charging) { - if (deviceConnected && batteryService != nullptr && floower->isIdle()) { + if (deviceConnected && batteryService != nullptr && !floower->arePetalsMoving()) { ESP_LOGD(LOG_TAG, "level: %d, charging: %d", level, charging); BLECharacteristic* characteristic = batteryService->getCharacteristic(BATTERY_LEVEL_UUID);