New fancy SpeedOMeter

This commit is contained in:
greyhash
2022-04-19 09:12:40 +02:00
parent eb3e1862b2
commit 48f9e32cd4
2 changed files with 39 additions and 11 deletions

View File

@ -3,6 +3,7 @@
// 3rdparty lib includes
#include <cpputils.h>
#include <espchrono.h>
#include <math.h>
// local includes
#include "globals.h"
@ -11,7 +12,6 @@
#include "ota.h"
#include "time_bobbycar.h"
#include "utils.h"
#include "drivingstatistics.h"
using namespace std::chrono_literals;
@ -228,7 +228,7 @@ void showAnimation()
case LedstripAnimation::SpeedSync: showSpeedSyncAnimation(); break;
case LedstripAnimation::CustomColor: showCustomColor(); break;
case LedstripAnimation::SnakeAnimation: showSnakeAnimation(); break;
case LedstripAnimation::EfficiencyAnimation: showEfficiencyAnimation(); break;
case LedstripAnimation::SpeedOMeter: showEfficiencyAnimation(); break;
default: showDefaultLedstrip();
}
}
@ -362,14 +362,42 @@ void showSnakeAnimation()
void showEfficiencyAnimation()
{
uint16_t color = getEfficiencyClassColor();
std::fill(std::begin(leds),
std::end(leds),
CRGB(
((((color >> 11) & 0x1F) * 527u) + 23u) >> 6,
((((color >> 5) & 0x3F) * 259u) + 33u) >> 6,
(((color & 0x1F) * 527u) + 23u) >> 6)
);
//uint16_t color = getEfficiencyClassColor();
//std::fill(std::begin(leds),
// std::end(leds),
// CRGB(
// ((((color >> 11) & 0x1F) * 527u) + 23u) >> 6,
// ((((color >> 5) & 0x3F) * 259u) + 33u) >> 6,
// (((color & 0x1F) * 527u) + 23u) >> 6)
// );
if (const auto avgVoltage = controllers.getAvgVoltage(); avgVoltage)
{
auto watt = sumCurrent * *avgVoltage;
auto w_per_kmh = watt / std::abs(avgSpeedKmh);
CRGB color = 0;
if(isinf(w_per_kmh) || isnan(w_per_kmh)){
color = 0;
}
else if(w_per_kmh <= -40){
color = CRGB(255, 0, 255);
}
else if(w_per_kmh < -20){
color = CRGB(255, 0, cpputils::mapValueClamped<float>(w_per_kmh, -40, -20, 255., 0.));
}
else if(w_per_kmh < 0){
color = CRGB(255, cpputils::mapValueClamped<float>(w_per_kmh, -20, 0, 0., 255.), 0);
}
else if(w_per_kmh < 20){
color = CRGB(cpputils::mapValueClamped<float>(w_per_kmh, 0, 20, 255., 0.), 255, 0);
}
else if(w_per_kmh < 40){
color = CRGB(0, cpputils::mapValueClamped<float>(w_per_kmh, 20, 40, 255., 0.), cpputils::mapValueClamped<float>(w_per_kmh, 20, 40, 0., 255.));
}
else{
color = CRGB(0, 0, 255);
}
std::fill(std::begin(leds), std::end(leds), color);
}
}
void showCustomColor()

View File

@ -22,7 +22,7 @@ DECLARE_BOBBYTYPESAFE_ENUM(OtaAnimationModes, : uint8_t, OtaAnimationModesValues
x(SpeedSync) \
x(CustomColor) \
x(SnakeAnimation) \
x(EfficiencyAnimation)
x(SpeedOMeter)
DECLARE_BOBBYTYPESAFE_ENUM(LedstripAnimation, : uint8_t, LedstripAnimationValues)
enum Bobbycar_Side