2 using DirectOutput.FX.MatrixFX;
4 namespace DirectOutput.LedControl.Loader
28 public string ColorName {
get;
set; }
44 public string TableElement = null;
74 public int DurationMs {
get;
set; }
76 private int _MinDurationMs = 0;
84 public int MinDurationMs
86 get {
return _MinDurationMs; }
87 set { _MinDurationMs = value; }
97 public int MaxDurationMs {
get;
set; }
105 public int ExtDurationMs {
get;
set; }
107 private int _Intensity;
118 get {
return (ColorName.IsNullOrWhiteSpace() ? _Intensity : -1); }
119 set { _Intensity = value; }
122 private int _FadingDurationUpMs = 0;
130 public int FadingUpDurationMs
132 get {
return _FadingDurationUpMs; }
133 set { _FadingDurationUpMs = value; }
136 private int _FadingDownDurationMs = 0;
144 public int FadingDownDurationMs
146 get {
return _FadingDownDurationMs; }
147 set { _FadingDownDurationMs = value; }
156 public int Blink {
get;
set; }
164 public int BlinkIntervalMs {
get;
set; }
173 public int BlinkIntervalMsNested {
get;
set; }
175 private int _BlinkPulseWidthNested = 50;
184 public int BlinkPulseWidthNested
186 get {
return _BlinkPulseWidthNested; }
187 set { _BlinkPulseWidthNested = value.Limit(1, 99); }
190 private int _BlinkPulseWidth = 50;
199 public int BlinkPulseWidth
201 get {
return _BlinkPulseWidth; }
202 set { _BlinkPulseWidth = value.Limit(1, 99); }
214 public bool Invert {
get;
set; }
222 public bool NoBool {
get;
set; }
231 public int WaitDurationMs {
get;
set; }
240 public int? Layer {
get;
set; }
243 public int AreaLeft = 0;
244 public int AreaTop = 0;
245 public int AreaWidth = 100;
246 public int AreaHeight = 100;
247 public int AreaSpeed = 100;
248 public int AreaAcceleration = 0;
249 public int AreaFlickerDensity = 0;
250 public int AreaFlickerMinDurationMs = 0;
251 public int AreaFlickerMaxDurationMs = 0;
253 public bool IsArea =
false;
255 public bool IsBitmap =
false;
256 public int AreaBitmapTop = 0;
257 public int AreaBitmapLeft = 0;
258 public int AreaBitmapWidth = -1;
259 public int AreaBitmapHeight = -1;
260 public int AreaBitmapFrame=0;
262 public int AreaBitmapAnimationStepSize = 1;
263 public int AreaBitmapAnimationStepCount = 0;
264 public int AreaBitmapAnimationFrameDuration = 30;
277 public void ParseSettingData(
string SettingData)
279 string S = SettingData.Trim();
281 if (S.StartsWith(
"("))
286 int ClosingBracketPos = -1;
287 for (
int i = 1; i < S.Length; i++)
289 if (S[i] ==
'(') { BracketCnt++; }
290 else if (S[i] ==
')') { BracketCnt--; }
294 ClosingBracketPos = i;
300 if (ClosingBracketPos > 0)
302 Condition = S.Substring(0, ClosingBracketPos + 1);
304 S = S.Substring(
Condition.Length).Trim();
310 Log.
Warning(
"No closing bracket found for condition in setting {0}.".Build(S));
312 throw new Exception(
"No closing bracket found for condition in setting {0}.".Build(S));
323 string[] P = SettingData.Split(
new char[] {
' ' }, StringSplitOptions.RemoveEmptyEntries);
328 throw new Exception(
"No data to parse.");
333 switch (P[0].ToUpper())
347 BlinkIntervalMs = 1000;
354 string[] ATE = P[0].Split(
new char[] {
'|' }, StringSplitOptions.RemoveEmptyEntries );
355 foreach (
string E
in ATE)
357 if (E.Length < 2 || !Enum.IsDefined(typeof(
TableElementTypeEnum), (
int)E[0]) || !E.Substring(1).IsInteger())
382 Log.
Warning(
"Cant parse the part {0} of the ledcontrol table config setting {1}.".Build(P[0], SettingData));
384 throw new Exception(
"Cant parse the part {0} of the ledcontrol table config setting {1}.".Build(P[0], SettingData));
388 S = S.Substring(S.IndexOf(P[0]) + P[0].Length).Trim();
393 string[] Parts = S.Split(
new char[] {
' ' }, StringSplitOptions.RemoveEmptyEntries);
399 while (Parts.Length > PartNr)
402 if (Parts[PartNr].ToUpper() ==
"BLINK")
405 BlinkIntervalMs = 1000;
407 else if (Parts[PartNr].ToUpper() ==
"INVERT")
411 else if (Parts[PartNr].ToUpper() ==
"NOBOOL")
416 else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() ==
"ABT" && Parts[PartNr].Substring(3).IsInteger())
418 AreaBitmapTop = Parts[PartNr].Substring(3).ToInteger();
422 else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() ==
"ABL" && Parts[PartNr].Substring(3).IsInteger())
424 AreaBitmapLeft = Parts[PartNr].Substring(3).ToInteger();
428 else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() ==
"ABW" && Parts[PartNr].Substring(3).IsInteger())
430 AreaBitmapWidth = Parts[PartNr].Substring(3).ToInteger();
434 else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() ==
"ABH" && Parts[PartNr].Substring(3).IsInteger())
436 AreaBitmapHeight = Parts[PartNr].Substring(3).ToInteger();
440 else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() ==
"ABF" && Parts[PartNr].Substring(3).IsInteger())
442 AreaBitmapFrame = Parts[PartNr].Substring(3).ToInteger();
446 else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() ==
"AAS" && Parts[PartNr].Substring(3).IsInteger())
448 AreaBitmapAnimationStepSize = Parts[PartNr].Substring(3).ToInteger();
452 else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() ==
"AAC" && Parts[PartNr].Substring(3).IsInteger())
454 AreaBitmapAnimationStepCount = Parts[PartNr].Substring(3).ToInteger();
458 else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() ==
"AAF" && Parts[PartNr].Substring(3).IsInteger())
460 AreaBitmapAnimationFrameDuration = 1000/Parts[PartNr].Substring(3).ToInteger().Limit(10,
int.MaxValue);
464 else if (Parts[PartNr].Length == 4 && Parts[PartNr].Substring(0, 3).ToUpper() ==
"AAD" && Enum.IsDefined(typeof(
MatrixAnimationStepDirectionEnum), (
int)Parts[PartNr].Substring(3, 1).ToUpper()[0]))
471 else if (Parts[PartNr].Length == 4 && Parts[PartNr].Substring(0, 3).ToUpper() ==
"AAB" && Enum.IsDefined(typeof(
AnimationBehaviourEnum), (
int)Parts[PartNr].Substring(3, 1).ToUpper()[0]))
479 else if (Parts[PartNr].Length > 5 && Parts[PartNr].Substring(0, 5).ToUpper() ==
"AFDEN" && Parts[PartNr].Substring(5).IsInteger())
481 AreaFlickerDensity = Parts[PartNr].Substring(5).ToInteger();
484 else if (Parts[PartNr].Length > 5 && Parts[PartNr].Substring(0, 5).ToUpper() ==
"AFMIN" && Parts[PartNr].Substring(5).IsInteger())
486 AreaFlickerMinDurationMs = Parts[PartNr].Substring(5).ToInteger();
489 else if (Parts[PartNr].Length > 5 && Parts[PartNr].Substring(0, 5).ToUpper() ==
"AFMAX" && Parts[PartNr].Substring(5).IsInteger())
491 AreaFlickerMaxDurationMs = Parts[PartNr].Substring(5).ToInteger();
494 else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() ==
"AA" && Parts[PartNr].Substring(2).IsInteger())
496 AreaAcceleration = Parts[PartNr].Substring(2).ToInteger();
500 else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() ==
"AT" && Parts[PartNr].Substring(2).IsInteger())
502 AreaTop = Parts[PartNr].Substring(2).ToInteger().Limit(0, 100);
505 else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() ==
"AL" && Parts[PartNr].Substring(2).IsInteger())
507 AreaLeft = Parts[PartNr].Substring(2).ToInteger().Limit(0, 100);
510 else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() ==
"AW" && Parts[PartNr].Substring(2).IsInteger())
512 AreaWidth = Parts[PartNr].Substring(2).ToInteger().Limit(0, 100);
515 else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() ==
"AH" && Parts[PartNr].Substring(2).IsInteger())
517 AreaHeight = Parts[PartNr].Substring(2).ToInteger().Limit(0, 100);
520 else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() ==
"AS" && Parts[PartNr].Substring(2).IsInteger())
522 AreaSpeed = Parts[PartNr].Substring(2).ToInteger().Limit(1, 10000);
525 else if (Parts[PartNr].Length == 3 && Parts[PartNr].Substring(0, 2).ToUpper() ==
"AD" && Enum.IsDefined(typeof(
MatrixShiftDirectionEnum), (
int)Parts[PartNr].Substring(2, 1).ToUpper()[0]))
531 else if (Parts[PartNr].Length > 3 && Parts[PartNr].ToUpper().Substring(0, 3) ==
"MAX" && Parts[PartNr].Substring(3).IsInteger())
533 MaxDurationMs = Parts[PartNr].Substring(3).ToInteger().Limit(0,
int.MaxValue);
535 else if (Parts[PartNr].Length > 3 && Parts[PartNr].ToUpper().Substring(0, 3) ==
"BNP" && Parts[PartNr].Substring(3).IsInteger())
537 BlinkIntervalMsNested = Parts[PartNr].Substring(3).ToInteger().Limit(0,
int.MaxValue);
539 else if (Parts[PartNr].Length > 4 && Parts[PartNr].ToUpper().Substring(0, 4) ==
"BNPW" && Parts[PartNr].Substring(4).IsInteger())
541 BlinkPulseWidthNested = Parts[PartNr].Substring(4).ToInteger().Limit(1, 99);
544 else if (Parts[PartNr].Length > 3 && Parts[PartNr].ToUpper().Substring(0, 3) ==
"BPW" && Parts[PartNr].Substring(3).IsInteger())
546 BlinkPulseWidth = Parts[PartNr].Substring(3).ToInteger().Limit(1, 99);
548 else if (Parts[PartNr].Length > 3 && Parts[PartNr].ToUpper().Substring(0, 3) ==
"BL#" && Parts[PartNr].Substring(3).IsHexString())
551 BlinkLow = Parts[PartNr].Substring(3).HexToInt().Limit(0, 255);
553 else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) ==
"BL" && Parts[PartNr].Substring(1).IsInteger())
556 BlinkLow = (int)(((
double)Parts[PartNr].Substring(2).ToInteger().Limit(0, 48)) * 5.3125);
558 else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) ==
"E" && Parts[PartNr].Substring(1).IsInteger())
561 ExtDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0,
int.MaxValue);
563 else if (Parts[PartNr].Length > 2 && Parts[PartNr].ToUpper().Substring(0, 2) ==
"I#" && Parts[PartNr].Substring(2).IsHexString())
566 Intensity = Parts[PartNr].Substring(2).HexToInt().Limit(0, 255);
568 else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) ==
"I" && Parts[PartNr].Substring(1).IsInteger())
571 Intensity = (int)(((
double)Parts[PartNr].Substring(1).ToInteger().Limit(0, 48)) * 5.3125);
573 else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) ==
"L" && Parts[PartNr].Substring(1).IsInteger())
576 Layer = Parts[PartNr].Substring(1).ToInteger();
578 else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) ==
"W" && Parts[PartNr].Substring(1).IsInteger())
581 WaitDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0,
int.MaxValue);
583 else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) ==
"M" && Parts[PartNr].Substring(1).IsInteger())
586 MinDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0,
int.MaxValue);
588 else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) ==
"F" && Parts[PartNr].Substring(1).IsInteger())
592 FadingUpDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0,
int.MaxValue);
593 FadingDownDurationMs = FadingUpDurationMs;
595 else if (Parts[PartNr].Length > 2 && Parts[PartNr].ToUpper().Substring(0, 2) ==
"FU" && Parts[PartNr].Substring(2).IsInteger())
599 FadingUpDurationMs = Parts[PartNr].Substring(2).ToInteger().Limit(0,
int.MaxValue);
602 else if (Parts[PartNr].Length > 2 && Parts[PartNr].ToUpper().Substring(0, 2) ==
"FD" && Parts[PartNr].Substring(2).IsInteger())
606 FadingDownDurationMs = Parts[PartNr].Substring(2).ToInteger().Limit(0,
int.MaxValue);
608 else if (Parts[PartNr].IsInteger())
616 BlinkIntervalMs = (Parts[PartNr].ToInteger()).Limit(1,
int.MaxValue);
623 DurationMs = Parts[PartNr].ToInteger().Limit(1,
int.MaxValue);
629 Blink = Parts[PartNr].ToInteger().Limit(1,
int.MaxValue);
630 if (DurationMs > 0 & Blink >= 1)
632 BlinkIntervalMs = (DurationMs / Blink).Limit(1,
int.MaxValue);
639 Log.
Warning(
"The ledcontrol table config setting {0} contains more than 2 numeric values without a type definition.".Build(SettingData));
640 throw new Exception(
"The ledcontrol table config setting {0} contains more than 2 numeric values without a type definition.".Build(SettingData));
645 else if (PartNr == 0)
648 ColorName = Parts[PartNr];
652 Log.
Warning(
"Cant parse the part {0} of the ledcontrol table config setting {1}".Build(Parts[PartNr], SettingData));
654 throw new Exception(
"Cant parse the part {0} of the ledcontrol table config setting {1}".Build(Parts[PartNr], SettingData));
680 ParseSettingData(SettingData);
690 this.Intensity = 255;
692 this.DurationMs = -1;