This commit is contained in:
greyhash
2022-04-22 22:54:29 +02:00
parent 48f9e32cd4
commit d5e863eb6b
2 changed files with 36 additions and 37 deletions

View File

@ -228,7 +228,7 @@ void showAnimation()
case LedstripAnimation::SpeedSync: showSpeedSyncAnimation(); break;
case LedstripAnimation::CustomColor: showCustomColor(); break;
case LedstripAnimation::SnakeAnimation: showSnakeAnimation(); break;
case LedstripAnimation::SpeedOMeter: showEfficiencyAnimation(); break;
case LedstripAnimation::GasOMeter: showGasOMeterAnimation(); break;
default: showDefaultLedstrip();
}
}
@ -360,44 +360,43 @@ void showSnakeAnimation()
gHue += 5;
}
void showEfficiencyAnimation()
void showGasOMeterAnimation()
{
//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))
{
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);
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(SpeedOMeter)
x(GasOMeter)
DECLARE_BOBBYTYPESAFE_ENUM(LedstripAnimation, : uint8_t, LedstripAnimationValues)
enum Bobbycar_Side
@ -49,7 +49,7 @@ void showBetterRainbow();
void showSpeedSyncAnimation();
void showCustomColor();
void showSnakeAnimation();
void showEfficiencyAnimation();
void showGasOMeterAnimation();
void showOtaAnimation();
void initLedStrip();