Skip to content

Commit d577374

Browse files
committed
Add Wrap and Nearest LedCountHandling
1 parent cf5ef0e commit d577374

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Source/TTController.Common/PortConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public enum LedCountHandling
66
{
77
DoNothing,
88
Lerp,
9+
Nearest,
10+
Wrap,
911
Trim,
1012
Copy
1113
}

Source/TTController.Service/TTService.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,29 @@ void ApplyConfig(IDictionary<PortIdentifier, List<LedColor>> colorMap)
362362
colors = newColors;
363363
break;
364364
}
365+
case LedCountHandling.Nearest:
366+
{
367+
if (config.LedCount == colors.Count)
368+
break;
369+
370+
var newColors = new List<LedColor>();
371+
for (var i = 0; i < config.LedCount; i++) {
372+
var idx = (int)Math.Round((i / (config.LedCount - 1d)) * (colors.Count - 1d));
373+
newColors.Add(colors[i]);
374+
}
375+
376+
colors = newColors;
377+
break;
378+
}
379+
case LedCountHandling.Wrap:
380+
if (config.LedCount < colors.Count)
381+
break;
382+
383+
var remainder = colors.Count % config.LedCount;
384+
colors = colors.Skip(colors.Count - remainder)
385+
.Concat(colors.Take(colors.Count - remainder).Skip(colors.Count - config.LedCount))
386+
.ToList();
387+
break;
365388
case LedCountHandling.Trim:
366389
if (config.LedCount < colors.Count)
367390
colors.RemoveRange(config.LedCount, colors.Count - config.LedCount);

0 commit comments

Comments
 (0)