Added ota update animation

This commit is contained in:
CommanderRedYT
2021-11-18 15:15:48 +01:00
parent ce1cd04497
commit 5ea2423bd3
12 changed files with 133 additions and 4 deletions

View File

@ -155,6 +155,7 @@ set(headers
displays/starfielddisplay.h
displays/statusdisplay.h
displays/updatedisplay.h
displays/menus/ledstripselectotamode.h
icons/alert.h
icons/battery.h
icons/bluetooth.h
@ -336,6 +337,7 @@ set(sources
displays/menus/timesettingsmenu.cpp
displays/menus/wifiscanmenu.cpp
displays/menus/wifisettingsmenu.cpp
displays/menus/ledstripselectotamode.cpp
displays/metersdisplay.cpp
displays/pingpongdisplay.cpp
displays/poweroffdisplay.cpp

View File

@ -172,6 +172,7 @@ struct EnableLedstripStVOFrontlight : public RefAccessorSaveSettings<bool> { boo
struct AnimationMultiplierAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.ledstrip.animationMultiplier; } };
struct LedstripBrightnessAccessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return settings.ledstrip.brightness; } };
struct LedstripEnableBlinkAnimation : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.ledstrip.enableAnimBlink; } };
struct LedstripOtaAnimationAccessor : public RefAccessorSaveSettings<OtaAnimationModes> { OtaAnimationModes &getRef() const override { return settings.ledstrip.otaMode; } };
#endif
// Battery

View File

@ -17,6 +17,7 @@
#include "accessors/settingsaccessors.h"
#ifdef FEATURE_LEDSTRIP
#include "ledstrip.h"
#include "displays/menus/ledstripselectotamode.h"
#endif
#include "displays/ledstripcolorsdisplay.h"
#include "displays/menus/mainmenu.h"
@ -125,6 +126,7 @@ LedstripMenu::LedstripMenu()
if (!simplified) { constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_STVO_FRONTLENGTH, LedsStVOFrontLengthAccessor>, SwitchScreenAction<StVOLengthChangeScreen>>>(); }
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECTANIMATION>, SwitchScreenAction<LedstripSelectAnimationMenu>>>();
if (!simplified) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LEDSTRIP_CHANGE_OTA_ANIM>, SwitchScreenAction<ledstripOtaAnimationChangeMenu>>>(); }
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BLINKANIMATION>, SwitchScreenAction<LedstripSelectBlinkMenu>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_MULTIPLIER>, SwitchScreenAction<animationMultiplierChangeScreen>>>();
if (!simplified) { constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_LEDSCOUNT, LedsCountAccessor>, SwitchScreenAction<LedsCountChangeScreen>>>(); }

View File

@ -0,0 +1,44 @@
#pragma once
// Local includes
#include "menudisplay.h"
#include "utils.h"
#include "menuitem.h"
#include "ledstrip.h"
#include "icons/back.h"
#include "texts.h"
#include "actions/switchscreenaction.h"
#include "accessors/settingsaccessors.h"
#include "ledstripmenu.h"
#ifdef FEATURE_LEDSTRIP
using namespace espgui;
template <OtaAnimationModes mode>
class LedstripChangeOtaAnimModeAction : public virtual ActionInterface
{
public:
void triggered() override
{
settings.ledstrip.otaMode = mode;
saveSettings();
}
};
namespace {
class ledstripOtaAnimationChangeMenu :
public MenuDisplay,
public StaticText<TEXT_BLINKANIMATION>,
public BackActionInterface<SwitchScreenAction<LedstripMenu>>
{
public:
ledstripOtaAnimationChangeMenu()
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_OTAANIM_NONE>, LedstripChangeOtaAnimModeAction<OtaAnimationModes::None>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_OTAANIM_PROGRESS>, LedstripChangeOtaAnimModeAction<OtaAnimationModes::GreenProgressBar>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_OTAANIM_COLOR>, LedstripChangeOtaAnimModeAction<OtaAnimationModes::ColorChangeAll>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<LedstripMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
}
};
} // Namespace
#endif

View File

@ -8,6 +8,7 @@
#include "espchrono.h"
#include "ledstripdefines.h"
#include "utils.h"
#include "ota.h"
using namespace std::chrono_literals;
@ -31,11 +32,11 @@ void updateLedStrip()
{
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
static bool have_disabled_beeper = false;
const bool enAnim = settings.ledstrip.enableAnimBlink;
if (cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH))
{
std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0});
const bool enAnim = settings.ledstrip.enableAnimBlink;
if (espchrono::millis_clock::now().time_since_epoch() % 750ms < 375ms || enAnim)
{
const auto anim_to_fill = time_to_percent(750ms, 500ms, 100ms, settings.ledstrip.enableFullBlink ? (leds.size() / 2) : settings.ledstrip.bigOffset - settings.ledstrip.smallOffset, settings.ledstrip.enableFullBlink);
@ -212,7 +213,7 @@ void updateLedStrip()
void showAnimation()
{
if (settings.ledstrip.enableLedAnimation && !simplified)
if (settings.ledstrip.enableLedAnimation && !simplified && (!asyncOtaTaskStarted || settings.ledstrip.otaMode != OtaAnimationModes::None))
{
if (animation_type == LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW) showDefaultLedstrip();
else if (animation_type == LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW) showBetterRainbow();
@ -220,12 +221,47 @@ void showAnimation()
else if (animation_type == LEDSTRIP_ANIMATION_TYPE_CUSTOMCOLOR) showCustomColor();
else showDefaultLedstrip();
}
else if (asyncOtaTaskStarted && settings.ledstrip.otaMode != OtaAnimationModes::None)
{
// show ota animation
showOtaAnimation();
}
else
{
std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0});
}
}
void showOtaAnimation()
{
std::fill(std::begin(leds), std::end(leds), CRGB{0,0,0});
const auto leds_count = leds.size();
const int one_percent = leds_count / 100;
float percentage = 0;
const auto progress = asyncOta->progress();
if (const auto totalSize = asyncOta->totalSize(); totalSize && *totalSize > 0)
{
percentage = (float(progress) / *totalSize * 100);
if (settings.ledstrip.otaMode == OtaAnimationModes::GreenProgressBar)
{
int numLeds = one_percent * percentage;
if (numLeds >= leds_count)
{
numLeds = leds_count - 1;
}
std::fill(std::begin(leds), std::begin(leds) + numLeds, CRGB{0,255,0});
}
else if (settings.ledstrip.otaMode == OtaAnimationModes::ColorChangeAll)
{
const uint8_t redChannel = 255 - (2.55 * percentage);
const uint8_t greenChannel = 2.55 * percentage;
std::fill(std::begin(leds), std::end(leds), CRGB{redChannel, greenChannel, 0});
}
}
}
void showBetterRainbow()
{
fill_rainbow(&*std::begin(leds), leds.size(), gHue);

View File

@ -20,6 +20,13 @@ enum Bobbycar_Side
FRONT
};
enum OtaAnimationModes
{
None,
GreenProgressBar,
ColorChangeAll
};
extern std::vector<CRGB> leds;
extern uint8_t gHue;
@ -31,6 +38,7 @@ void showAnimation();
void showBetterRainbow();
void showSpeedSyncAnimation();
void showCustomColor();
void showOtaAnimation();
void initLedStrip();
void updateLedStrip();

View File

@ -13,6 +13,7 @@
#include "settings.h"
#include "stringsettings.h"
#include "ledstripdefines.h"
#include "ledstrip.h"
using namespace std::chrono_literals;
@ -246,7 +247,8 @@ constexpr Settings::Ledstrip defaultLedstrip {
.stvoFrontEnable = false,
.animationMultiplier = 10,
.brightness = 255,
.enableAnimBlink = false
.enableAnimBlink = false,
.otaMode = OtaAnimationModes::GreenProgressBar
};
#endif

View File

@ -21,6 +21,7 @@
#include "bluetoothmode.h"
#endif
#include "unifiedmodelmode.h"
#include "ledstrip.h"
enum class LarsmModeMode : uint8_t { Mode1, Mode2, Mode3, Mode4 };
@ -171,6 +172,7 @@ struct Settings
int16_t animationMultiplier;
uint8_t brightness;
bool enableAnimBlink;
OtaAnimationModes otaMode;
} ledstrip;
#endif
@ -304,6 +306,7 @@ void Settings::executeForEveryCommonSetting(T &&callable)
callable("ledAnimMul", ledstrip.animationMultiplier);
callable("ledbrightness", ledstrip.brightness);
callable("enAnimBlink", ledstrip.enableAnimBlink);
callable("ledOtaAnim", ledstrip.otaMode);
#endif
callable("batteryCS", battery.cellsSeries);

View File

@ -189,6 +189,16 @@ template<> struct nvsGetterHelper<UnifiedModelMode> { static esp_err_t nvs_get(n
*out_value = UnifiedModelMode(tempValue);
return err;
}};
#if defined(FEATURE_LEDSTRIP) && defined(FEATURE_OTA)
template<> struct nvsGetterHelper<OtaAnimationModes> { static esp_err_t nvs_get(nvs_handle handle, const char* key, OtaAnimationModes* out_value)
{
uint8_t tempValue;
esp_err_t err = nvs_get_u8(handle, key, &tempValue);
if (err == ESP_OK)
*out_value = OtaAnimationModes(tempValue);
return err;
}};
#endif
template<> struct nvsGetterHelper<wifi_mode_t> { static esp_err_t nvs_get(nvs_handle handle, const char* key, wifi_mode_t* out_value)
{
uint8_t tempValue;
@ -345,6 +355,12 @@ template<> struct nvsSetterHelper<UnifiedModelMode> { static esp_err_t nvs_set(n
{
return nvs_set_u8(handle, key, uint8_t(value));
}};
#if defined(FEATURE_LEDSTRIP) && defined(FEATURE_OTA)
template<> struct nvsSetterHelper<OtaAnimationModes> { static esp_err_t nvs_set(nvs_handle handle, const char* key, OtaAnimationModes value)
{
return nvs_set_u8(handle, key, uint8_t(value));
}};
#endif
template<> struct nvsSetterHelper<wifi_mode_t> { static esp_err_t nvs_set(nvs_handle handle, const char* key, wifi_mode_t value)
{
return nvs_set_u8(handle, key, uint8_t(value));

View File

@ -294,6 +294,11 @@ constexpr char TEXT_ANIMATION_MULTIPLIER[] = "Animation Multiplier";
constexpr char TEXT_LEDSTRIP_BRIGHTNESS[] = "Ledstrip Brightness";
constexpr char TEXT_LEDSTRIP_ALLCUSTOMOFF[] = "All custom off";
constexpr char TEXT_LEDSTRIP_EN_BLINK_ANIM[] = "Animated Blink";
constexpr char TEXT_LEDSTRIP_CHANGE_OTA_ANIM[] = "Change Ota animation";
constexpr char TEXT_OTAANIM_NONE[] = "None";
constexpr char TEXT_OTAANIM_PROGRESS[] = "Progress Bar";
constexpr char TEXT_OTAANIM_COLOR[] = "Color change";
//constexpr char TEXT_BACK[] = "Back";
//LedstripSelectAnimationMenu

View File

@ -39,7 +39,8 @@ typename std::enable_if<
!std::is_same<T, std::string>::value &&
!std::is_same<T, espchrono::minutes32>::value &&
!std::is_same<T, espchrono::DayLightSavingMode>::value &&
!std::is_same<T, UnifiedModelMode>::value
!std::is_same<T, UnifiedModelMode>::value &&
!std::is_same<T, OtaAnimationModes>::value
, bool>::type
showInputForSetting(std::string_view key, T value, JsonObject &body)
{
@ -119,6 +120,15 @@ showInputForSetting(std::string_view key, T value, JsonObject &body)
return true;
}
template<typename T>
typename std::enable_if<
std::is_same<T, OtaAnimationModes>::value
, bool>::type
showInputForSetting(std::string_view key, T value, JsonObject &body)
{
body[key] = int(value);
return true;
}
esp_err_t webserver_dump_nvs_handler(httpd_req_t *req)
{