14
14
limitations under the License.
15
15
*/
16
16
#include " FastLEDControllerUtils.h"
17
+ #include < math.h>
17
18
18
19
void CLP::transformLLFanToStrip (FastLEDController* controller, uint8_t channelIndex)
19
20
{
@@ -33,9 +34,9 @@ void CLP::transformLLFanToStrip(FastLEDController* controller, uint8_t channelIn
33
34
void CLP::scale (FastLEDController* controller, uint8_t channelIndex, int scaleToSize)
34
35
{
35
36
auto leds = controller->getLEDs (channelIndex);
36
- float scaleFactor = (float )controller->getLEDCount (channelIndex) / scaleToSize;
37
+ const float scaleFactor = (float )controller->getLEDCount (channelIndex) / scaleToSize;
37
38
for (int ledIndex = scaleToSize - 1 ; ledIndex >= 0 ; ledIndex--) {
38
- leds[ledIndex] = leds[( int ) (ledIndex * scaleFactor)];
39
+ leds[ledIndex] = leds[round (ledIndex * scaleFactor)];
39
40
}
40
41
}
41
42
@@ -48,3 +49,34 @@ void CLP::repeat(FastLEDController* controller, uint8_t channelIndex, uint8_t ti
48
49
memcpy (leds + (count * i), leds, sizeof (CRGB) * count);
49
50
}
50
51
}
52
+
53
+ void CLP::scaleSegments (FastLEDController* controller, uint8_t channelIndex, const SegmentScaling* const segments, int segmentsCount)
54
+ {
55
+ auto leds = controller->getLEDs (channelIndex);
56
+ int ledStripIndexAfterScaling = 0 ;
57
+ int ledStripIndexBeforeScaling = 0 ;
58
+ for (int i = 0 ; i < segmentsCount; i++) {
59
+ ledStripIndexAfterScaling += segments[i].scaleToSize ;
60
+ ledStripIndexBeforeScaling += segments[i].segmentLength ;
61
+ }
62
+
63
+ for (int i = segmentsCount - 1 ; i >= 0 ; i--) {
64
+ const float scaleFactor = (float )segments[i].segmentLength / segments[i].scaleToSize ;
65
+ ledStripIndexAfterScaling -= segments[i].scaleToSize ;
66
+ ledStripIndexBeforeScaling -= segments[i].segmentLength ;
67
+ for (int ledIndex = segments[i].scaleToSize - 1 ; ledIndex >= 0 ; ledIndex--) {
68
+ leds[ledStripIndexAfterScaling + ledIndex] = leds[ledStripIndexBeforeScaling + round (ledIndex * scaleFactor)];
69
+ }
70
+ }
71
+ }
72
+
73
+ void CLP::reverse (FastLEDController* controller, uint8_t channelIndex)
74
+ {
75
+ auto leds = controller->getLEDs (channelIndex);
76
+ auto maxIndex = controller->getLEDCount (channelIndex) - 1 ;
77
+ for (int ledIndex = 0 ; ledIndex < maxIndex - ledIndex; ledIndex++) {
78
+ CRGB temp = leds[ledIndex];
79
+ leds[ledIndex] = leds[maxIndex - ledIndex];
80
+ leds[maxIndex - ledIndex] = temp;
81
+ }
82
+ }
0 commit comments