2 using System.Collections.Generic;
6 using System.Xml.Serialization;
20 #region Config properties
21 private int _Width = 1;
31 get {
return _Width; }
32 set { _Width = value.Limit(0,
int.MaxValue); }
35 private int _Height = 1;
45 get {
return _Height; }
46 set { _Height = value.Limit(0,
int.MaxValue); }
56 public int NumberOfLeds
58 get {
return Width * Height; }
68 public int NumberOfOutputs
70 get {
return NumberOfLeds * 3; }
87 get {
return _LedStripAranggement; }
88 set { _LedStripAranggement = value; }
104 get {
return _ColorOrder; }
105 set { _ColorOrder = value; }
109 private int _FirstLedNumber = 1;
116 public int FirstLedNumber
118 get {
return _FirstLedNumber; }
119 set { _FirstLedNumber = value.Limit(1,
int.MaxValue); }
122 private string _FadingCurveName =
"Linear";
123 private Curve FadingCurve = null;
132 public string FadingCurveName
134 get {
return _FadingCurveName; }
135 set { _FadingCurveName = value; }
142 FadingCurve = Cabinet.
Curves[FadingCurveName];
144 else if (!FadingCurveName.IsNullOrWhiteSpace())
149 Enum.TryParse(FadingCurveName, out T);
150 FadingCurve =
new Curve(T);
155 Cabinet.
Curves.Add(FadingCurveName);
172 public string OutputControllerName {
get; set; }
196 public override void Init(Cabinet Cabinet)
198 this.Cabinet = Cabinet;
205 BuildMappingTables();
206 OutputData =
new byte[NumberOfOutputs];
207 InitFadingCurve(Cabinet);
219 if (OutputController != null && NumberOfLeds > 0)
221 OutputController.
SetValues((FirstLedNumber - 1) * 3,
new byte[NumberOfLeds]);
230 if (OutputController != null && Layers.Count > 0)
233 OutputController.
SetValues((FirstLedNumber-1)*3, OutputData);
252 return Layers[LayerNr];
259 private int[,] OutputMappingTable =
new int[0, 0];
261 private void BuildMappingTables()
264 OutputMappingTable =
new int[Width, Height];
265 bool FirstException =
true;
268 for (
int Y = 0; Y < Height; Y++)
270 for (
int X = 0; X < Width; X++)
273 switch (LedStripArrangement)
276 LedNr = (Y * Width) + X;
279 LedNr = ((Height - 1 - Y) * Width) + X;
282 LedNr = (Y * Width) + (Width - 1 - X);
285 LedNr = ((Height - 1 - Y) * Width) + (Width - 1 - X);
288 LedNr = X * Height + Y;
291 LedNr = ((Width - 1 - X) * Height) + Y;
294 LedNr = (X * Height) + (Height - 1 - Y);
297 LedNr = ((Width - 1 - X) * Height) + (Height - 1 - Y);
300 LedNr = (Width * Y) + ((Y & 1) == 0 ? X : (Width - 1 - X));
303 LedNr = (Width * (Height - 1 - Y)) + (((Height - 1 - Y) & 1) == 0 ? X : (Width - 1 - X));
306 LedNr = (Width * Y) + ((Y & 1) == 1 ? X : (Width - 1 - X));
309 LedNr = (Width * (Height - 1 - Y)) + (((Height - 1 - Y) & 1) == 1 ? X : (Width - 1 - X));
312 LedNr = (Height * X) + ((X & 1) == 0 ? Y : (Height - 1 - Y));
315 LedNr = (Height * (Width - 1 - X)) + ((X & 1) == 1 ? Y : (Height - 1 - Y));
318 LedNr = (Height * X) + ((X & 1) == 1 ? Y : (Height - 1 - Y));
321 LedNr = (Height * (Width - 1 - X)) + ((X & 1) == 0 ? Y : (Height - 1 - Y));
326 Log.
Exception(
"Unknow LedStripArrangement value ({0}) found. Will use LeftRightTopDown mapping as fallback.".Build(LedStripArrangement.ToString()));
327 FirstException =
false;
329 LedNr = (Y * Width) + X;
333 OutputMappingTable[X, Y] = LedNr * 3;
340 byte[] OutputData =
new byte[0];
346 private void SetOutputData()
348 if (Layers.Count > 0)
351 float[, ,] Value =
new float[Width, Height, 3];
353 foreach (KeyValuePair<
int,
RGBAColor[,]> KV
in Layers)
358 for (
int y = 0; y < Height; y++)
360 for (
int x = 0; x < Width; x++)
362 int Alpha = D[x, y].
Alpha.Limit(0, 255);
365 Value[x, y, 0] = AlphaMappingTable.AlphaMapping[255 - Alpha, (int)Value[x, y, 0]] + AlphaMappingTable.AlphaMapping[Alpha, D[x, y].
Red.Limit(0, 255)];
366 Value[x, y, 1] = AlphaMappingTable.AlphaMapping[255 - Alpha, (int)Value[x, y, 1]] + AlphaMappingTable.AlphaMapping[Alpha, D[x, y].
Green.Limit(0, 255)];
367 Value[x, y, 2] = AlphaMappingTable.AlphaMapping[255 - Alpha, (int)Value[x, y, 2]] + AlphaMappingTable.AlphaMapping[Alpha, D[x, y].
Blue.Limit(0, 255)];
381 byte[] FadingTable = FadingCurve.
Data;
385 for (
int y = 0; y < Height; y++)
387 for (
int x = 0; x < Width; x++)
389 int OutputNumber = OutputMappingTable[x, y];
390 OutputData[OutputNumber] = FadingTable[(int)Value[x, y, 0]];
391 OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 1]];
392 OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 2]];
397 for (
int y = 0; y < Height; y++)
399 for (
int x = 0; x < Width; x++)
401 int OutputNumber = OutputMappingTable[x, y];
402 OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 0]];
403 OutputData[OutputNumber] = FadingTable[(int)Value[x, y, 1]];
404 OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 2]];
411 for (
int y = 0; y < Height; y++)
413 for (
int x = 0; x < Width; x++)
415 int OutputNumber = OutputMappingTable[x, y];
416 OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 0]];
417 OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 1]];
418 OutputData[OutputNumber] = FadingTable[(int)Value[x, y, 2]];
423 for (
int y = 0; y < Height; y++)
425 for (
int x = 0; x < Width; x++)
427 int OutputNumber = OutputMappingTable[x, y];
428 OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 0]];
429 OutputData[OutputNumber] = FadingTable[(int)Value[x, y, 1]];
430 OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 2]];
435 for (
int y = 0; y < Height; y++)
437 for (
int x = 0; x < Width; x++)
439 int OutputNumber = OutputMappingTable[x, y];
440 OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 0]];
441 OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 1]];
442 OutputData[OutputNumber] = FadingTable[(int)Value[x, y, 2]];
448 for (
int y = 0; y < Height; y++)
450 for (
int x = 0; x < Width; x++)
452 int OutputNumber = OutputMappingTable[x, y];
453 OutputData[OutputNumber] = FadingTable[(int)Value[x, y, 0]];
454 OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 1]];
455 OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 2]];
Sorted dictionary of layers for the matrix toys.
The Cabinet object describes the parts of a pinball cabinet (toys, outputcontrollers, outputs and more).
CurveList Curves
List of named curve objects used to set Curves for toys.
This class stores information on colors used for toys and effects (e.g. RGBLed).
The namespace DirectOutput.Cab.Toys contains all toy related classes.
Interface for toys having a matrix of elements (e.g. ledstrips)
void SetValues(int FirstOutput, byte[] Values)
Sets the values for one or several outputs of the controller.
bool Contains(string Name)
Checks if a INamedItem object with the specified name exists in the list.
override void Init(Cabinet Cabinet)
Initializes the toy.
A simple logger used to record important events and exceptions.
RGBOrderEnum
Enum used to define the order of the colors of a multicolor element (e.g. RGB led). Depending on the connection of the multi color element, the order of the colors does maybe not match the default Red - Green - Blue order (e.g. addressable WS2812 led chips are using Green - Red - Blue).
Out.OutputControllerList OutputControllers
List of IOutputController objects representing the output controllers in the cabinet.
int Red
Brightness for Red.
Common interface for all toy implementations. The abstract class ToyBase implements this interface...
override void UpdateOutputs()
Updates the data of the assigned output controller
int Green
Brightness for Green.
The namespace DirectOutput.Cab contains all cabinet related classes like the Cabinet class itself...
LedStripArrangementEnum
Enum used to specify the arrangement of the ledstripe(s).
DirectOutput.Cab.Out is the namespace for all output controller related classes like different output...
int Blue
Brightness for Blue.
int Alpha
Alpha value for the color.
override void Reset()
Resets the toy. Turns all outputs off.
Represents a adressable led strip.
This interface defines additional methods for output controllers which allow for direct modification ...
Namespace for objects dealing with layers
Base class for toys which need update calls to update the state of their assigned outputs...
byte[] Data
Gets or sets the curve data array. The curve array must have 256 elements.
CurveTypeEnum
Enumeration of predefined curves.
Represents a curve which can be used to map values (e.g. adjust a brighnetss value of a led to the br...
The namespace DirectOutput.General contains classes for general use.
RGBAColor[,] GetLayer(int LayerNr)
Gets the 2 dimensional RGBAColor array for the specified layer.
static void Exception(string Message, Exception E=null)
Writes a exception message to the log.