Added blink animation (Resolves #106)

This commit is contained in:
CommanderRedYT
2021-11-15 20:38:54 +01:00
parent be41e8018e
commit be05e42303
10 changed files with 126 additions and 21 deletions

View File

@ -339,7 +339,8 @@ void secondsToHMS( const float seconds, uint16_t &h, uint16_t &m, uint16_t &s )
h = t;
}
std::string get_current_driving_time_string() {
std::string get_current_driving_time_string()
{
uint16_t hour{};
uint16_t minute{};
uint16_t second{};
@ -347,3 +348,27 @@ std::string get_current_driving_time_string() {
std::string out = fmt::format("Drive: {:02d}:{:02d}:{:02d}", hour, minute, second);
return out;
}
uint8_t time_to_percent(std::chrono::duration<long, std::ratio<1,1000>> repeat, std::chrono::duration<long, std::ratio<1,1000>> riseTime, std::chrono::duration<long, std::ratio<1,1000>> fullTime, size_t numLeds, bool invert)
{
const auto now = espchrono::millis_clock::now().time_since_epoch() % repeat;
int activated = invert ? numLeds : 0;
if (now <= riseTime)
{
if (invert)
{
activated = numLeds - ((now*numLeds) / riseTime);
}
else
{
activated = (now*numLeds) / riseTime;
}
}
else if (now < riseTime + fullTime)
{
activated = invert ? 0 : numLeds;
}
else
activated = invert ? numLeds : 0;
return activated;
}