Skip to content

Commit 5b34bc5

Browse files
authored
Merge pull request #138 from Legion2/improve-visor
improve visor hardware lighting effect
2 parents b5b75e9 + 0e11f5e commit 5b34bc5

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/FastLEDController.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,13 @@ bool FastLEDController::renderTemperature(ChannelData& channelData, LEDGroup& gr
232232
}
233233

234234
bool FastLEDController::renderVisor(ChannelData& channelData, LEDGroup& group, int groupLedCount) {
235-
int duration = applySpeed(150 * groupLedCount, group.speed);
236-
int steps = groupLedCount * 2;
235+
int duration = applySpeed(120 * groupLedCount, group.speed);
236+
const int resolution = 64;
237+
int steps = groupLedCount * 2 * resolution;
237238
int count = animation_step_count(duration, steps);
238239
if (count > 0) {
239240
int step = animation_step(duration, steps);
240-
if (step >= groupLedCount ? count > step - groupLedCount : count > step) {
241+
if (step >= steps / 2 ? count > step - steps / 2 : count > step) {
241242
if (group.extra == GroupExtra::Random) {
242243
group.color1 = randomColor();
243244
group.color2 = randomColor();
@@ -247,13 +248,25 @@ bool FastLEDController::renderVisor(ChannelData& channelData, LEDGroup& group, i
247248
group.color2 = temp;
248249
}
249250
}
250-
fill_solid(&channelData.leds[group.ledIndex], groupLedCount, CRGB::Black);
251-
int gradientLength = 4;
252-
int gradientMiddlePosition = (step >= groupLedCount) ? steps - step - 1 : step;
253-
int gradientStartPosition = gradientMiddlePosition - ((gradientLength - 1) / 2);
254-
fill_gradient_RGB(&channelData.leds[group.ledIndex], constrain(gradientStartPosition, 0, groupLedCount - 1),
255-
group.color1, constrain(gradientStartPosition + (gradientLength - 1), 0, groupLedCount - 1),
256-
group.color2);
251+
const float gradientLength = 3.0f;
252+
float pos = step / (float)resolution;
253+
float gradientMiddlePosition = (pos >= groupLedCount) ? (groupLedCount * 2) - pos : pos;
254+
gradientMiddlePosition -= 0.5f;
255+
const float gradientStartPosition = gradientMiddlePosition - (gradientLength / 2);
256+
const float gradientEndPosition = gradientMiddlePosition + (gradientLength / 2);
257+
for (int i = 0; i < groupLedCount; i++) {
258+
CRGB color = CRGB::Black;
259+
if (i >= gradientStartPosition - 1 && i < gradientStartPosition) {
260+
color = group.color1;
261+
color.nscale8((i - (gradientStartPosition - 1)) * 256.0);
262+
} else if (i >= gradientStartPosition && i < gradientEndPosition) {
263+
color = blend(group.color1, group.color2, ((i - gradientStartPosition) / gradientLength) * 256);
264+
} else if (i >= gradientEndPosition && i < gradientEndPosition + 1) {
265+
color = group.color2;
266+
color.nscale8((1 - (i - gradientEndPosition)) * 256.0);
267+
}
268+
channelData.leds[group.ledIndex + i] = color;
269+
}
257270
return true;
258271
}
259272
return false;

0 commit comments

Comments
 (0)