This commit is contained in:
CommanderRedYT
2022-04-18 15:04:05 +02:00
parent 989da449b0
commit 5ad64d81d0
2 changed files with 35 additions and 13 deletions

View File

@@ -17,7 +17,7 @@ using namespace std::chrono_literals;
std::vector<CRGB> leds; std::vector<CRGB> leds;
uint8_t gHue = 0; uint8_t gHue = 0;
float gLedPosition = 0; int16_t gLedPosition = 0;
uint16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE; uint16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
@@ -177,7 +177,7 @@ void updateLedStrip()
} }
} }
if (have_disabled_beeper == false && (!(cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) || !configs.ledstrip.enableBeepWhenBlink.value)) if (!have_disabled_beeper && (!(cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) || !configs.ledstrip.enableBeepWhenBlink.value))
{ {
for (Controller &controller : controllers) for (Controller &controller : controllers)
controller.command.buzzer.freq = 0; controller.command.buzzer.freq = 0;
@@ -286,12 +286,15 @@ void fill_rainbow_invert_at( struct CRGB * pFirstLED, int numToFill, int invertA
hsv.hue = initialhue; hsv.hue = initialhue;
hsv.val = 255; hsv.val = 255;
hsv.sat = 240; hsv.sat = 240;
for( int i = 0; i < numToFill; i++) { for (int i = 0; i < numToFill; i++) {
hsv.hue = huecalc; hsv.hue = huecalc;
pFirstLED[i] = hsv; pFirstLED[i] = hsv;
if(i>invertAtLed){ if (i>invertAtLed)
{
huecalc -= deltahue; huecalc -= deltahue;
}else{ }
else
{
huecalc += deltahue; huecalc += deltahue;
} }
} }
@@ -330,17 +333,29 @@ void showDefaultLedstrip()
void showSnakeAnimation() void showSnakeAnimation()
{ {
float leds_per_cycle = 1. / std::max(uint8_t(1), uint8_t(configs.ledstrip.animationMultiplier.value)); const int16_t leds_per_cycle = floor<int16_t>(1. / std::max<int16_t>(1, configs.ledstrip.animationMultiplier.value)) * (avgSpeedKmh + 1);
leds_per_cycle = leds_per_cycle * (avgSpeedKmh + 1);
fadeToBlackBy(&*std::begin(leds), leds.size(), floor(20*leds_per_cycle)); fadeToBlackBy(&*std::begin(leds), leds.size(), floor(20*leds_per_cycle));
if(gLedPosition >= leds.size()){gLedPosition = 0;} if (gLedPosition >= leds.size())
if(gHue == 255){gHue = 0;} {
for(int i = floor(gLedPosition); i < floor(gLedPosition + leds_per_cycle); i++){ gLedPosition = 0;
}
if (gHue == 255) {
gHue = 0;
}
for(int16_t i = floor(gLedPosition); i < floor(gLedPosition + leds_per_cycle); i++)
{
leds[i] |= CHSV(gHue, 255, 255); leds[i] |= CHSV(gHue, 255, 255);
uint8_t snake_2_pos = floor(leds.size()/2) + i; uint8_t snake_2_pos = floor(leds.size() / 2) + i;
if(snake_2_pos > leds.size()){snake_2_pos -= leds.size();}
if (snake_2_pos > leds.size())
{
snake_2_pos -= leds.size();
}
leds[snake_2_pos] |= CHSV(gHue, 255, 255); leds[snake_2_pos] |= CHSV(gHue, 255, 255);
} }
gLedPosition += leds_per_cycle; gLedPosition += leds_per_cycle;
gHue += 5; gHue += 5;
} }
@@ -348,7 +363,13 @@ void showSnakeAnimation()
void showEfficiencyAnimation() void showEfficiencyAnimation()
{ {
uint16_t color = getEfficiencyClassColor(); uint16_t color = getEfficiencyClassColor();
std::fill(std::begin(leds), std::end(leds), CRGB(((((color >> 11) & 0x1F) * 527) + 23) >> 6, ((((color >> 5) & 0x3F) * 259) + 33) >> 6, (((color & 0x1F) * 527) + 23) >> 6)); std::fill(std::begin(leds),
std::end(leds),
CRGB(
((((color >> 11) & 0x1F) * 527) + 23) >> 6,
((((color >> 5) & 0x3F) * 259) + 33) >> 6,
(((color & 0x1F) * 527) + 23) >> 6)
);
} }
void showCustomColor() void showCustomColor()

View File

@@ -39,6 +39,7 @@ enum Bobbycar_Side
extern std::vector<CRGB> leds; extern std::vector<CRGB> leds;
extern uint8_t gHue; extern uint8_t gHue;
extern int16_t gLedPosition;
extern uint16_t blinkAnimation; extern uint16_t blinkAnimation;