DirectOuput Framework R2
DirectOutput framework R2 for virtual pinball cabinets
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
TableConfigSetting.cs
Go to the documentation of this file.
1 using System;
2 using DirectOutput.FX.MatrixFX;
3 
4 namespace DirectOutput.LedControl.Loader
5 {
9  public class TableConfigSetting
10  {
11 
12 
19  public OutputControlEnum OutputControl { get; set; }
20 
28  public string ColorName { get; set; }
29 
30 
31 
38  public ColorConfig ColorConfig { get; set; }
39 
40 
44  public string TableElement = null;
45 
46 
50  public string Condition = null;
51 
52 
60  public OutputTypeEnum OutputType
61  {
62  get
63  {
64  return (!ColorName.IsNullOrWhiteSpace() ? OutputTypeEnum.RGBOutput : OutputTypeEnum.AnalogOutput);
65  }
66  }
67 
74  public int DurationMs { get; set; }
75 
76  private int _MinDurationMs = 0;
77 
84  public int MinDurationMs
85  {
86  get { return _MinDurationMs; }
87  set { _MinDurationMs = value; }
88  }
89 
90 
97  public int MaxDurationMs { get; set; }
98 
105  public int ExtDurationMs { get; set; }
106 
107  private int _Intensity;
115  public int Intensity
116  {
117 
118  get { return (ColorName.IsNullOrWhiteSpace() ? _Intensity : -1); }
119  set { _Intensity = value; }
120  }
121 
122  private int _FadingDurationUpMs = 0;
123 
130  public int FadingUpDurationMs
131  {
132  get { return _FadingDurationUpMs; }
133  set { _FadingDurationUpMs = value; }
134  }
135 
136  private int _FadingDownDurationMs = 0;
137 
144  public int FadingDownDurationMs
145  {
146  get { return _FadingDownDurationMs; }
147  set { _FadingDownDurationMs = value; }
148  }
149 
156  public int Blink { get; set; }
157 
164  public int BlinkIntervalMs { get; set; }
165 
166 
173  public int BlinkIntervalMsNested { get; set; }
174 
175  private int _BlinkPulseWidthNested = 50;
176 
184  public int BlinkPulseWidthNested
185  {
186  get { return _BlinkPulseWidthNested; }
187  set { _BlinkPulseWidthNested = value.Limit(1, 99); }
188  }
189 
190  private int _BlinkPulseWidth = 50;
191 
199  public int BlinkPulseWidth
200  {
201  get { return _BlinkPulseWidth; }
202  set { _BlinkPulseWidth = value.Limit(1, 99); }
203  }
204 
205 
206  public int BlinkLow;
207 
214  public bool Invert { get; set; }
215 
222  public bool NoBool { get; set; }
223 
224 
231  public int WaitDurationMs { get; set; }
232 
233 
240  public int? Layer { get; set; }
241 
242 
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;
252  public MatrixShiftDirectionEnum? AreaDirection = null;
253  public bool IsArea = false;
254 
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;
261 
262  public int AreaBitmapAnimationStepSize = 1;
263  public int AreaBitmapAnimationStepCount = 0;
264  public int AreaBitmapAnimationFrameDuration = 30;
265  public MatrixAnimationStepDirectionEnum AreaBitmapAnimationDirection = MatrixAnimationStepDirectionEnum.Frame;
266  public AnimationBehaviourEnum AreaBitmapAnimationBehaviour = AnimationBehaviourEnum.Loop;
267 
277  public void ParseSettingData(string SettingData)
278  {
279  string S = SettingData.Trim();
280 
281  if (S.StartsWith("("))
282  {
283  //It is a condition
284 
285  int BracketCnt = 1;
286  int ClosingBracketPos = -1;
287  for (int i = 1; i < S.Length; i++)
288  {
289  if (S[i] == '(') { BracketCnt++; }
290  else if (S[i] == ')') { BracketCnt--; }
291 
292  if (BracketCnt == 0)
293  {
294  ClosingBracketPos = i;
295  break;
296  }
297  }
298 
299 
300  if (ClosingBracketPos > 0)
301  {
302  Condition = S.Substring(0, ClosingBracketPos + 1);
303  OutputControl = OutputControlEnum.Condition;
304  S = S.Substring(Condition.Length).Trim();
305  //TODO: Maybe add a check for the condition validity
306 
307  }
308  else
309  {
310  Log.Warning("No closing bracket found for condition in setting {0}.".Build(S));
311 
312  throw new Exception("No closing bracket found for condition in setting {0}.".Build(S));
313  }
314 
315 
316 
317 
318  }
319  else
320  {
321  //not a condition
322 
323  string[] P = SettingData.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
324  if (P.Length == 0)
325  {
326  Log.Warning("No data to parse.");
327 
328  throw new Exception("No data to parse.");
329  }
330 
331  //Get output state and table element (if applicable)
332  bool ParseOK = true;
333  switch (P[0].ToUpper())
334  {
335  case "ON":
336  case "1":
337  OutputControl = OutputControlEnum.FixedOn;
338  break;
339  case "OFF":
340  case "0":
341  OutputControl = OutputControlEnum.FixedOff;
342  break;
343  case "B":
344  case "BLINK":
345  OutputControl = OutputControlEnum.FixedOn;
346  Blink = -1;
347  BlinkIntervalMs = 1000;
348  break;
349  default:
350  if (Enum.IsDefined(typeof(TableElementTypeEnum), (int)P[0][0]))
351  {
352  //This seems to be a variable
353 
354  string[] ATE = P[0].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
355  foreach (string E in ATE)
356  {
357  if (E.Length < 2 || !Enum.IsDefined(typeof(TableElementTypeEnum), (int)E[0]) || !E.Substring(1).IsInteger())
358  {
359  ParseOK = false;
360  break;
361  }
362  }
363 
364  if (ParseOK)
365  {
366  TableElement = P[0];
367 
368  OutputControl = OutputControlEnum.Controlled;
369  }
370  }
371  else
372  {
373  ParseOK = false;
374  }
375 
376 
377 
378  break;
379  }
380  if (!ParseOK)
381  {
382  Log.Warning("Cant parse the part {0} of the ledcontrol table config setting {1}.".Build(P[0], SettingData));
383 
384  throw new Exception("Cant parse the part {0} of the ledcontrol table config setting {1}.".Build(P[0], SettingData));
385  }
386 
387  //Remove first part
388  S = S.Substring(S.IndexOf(P[0]) + P[0].Length).Trim();
389 
390  }
391 
392 
393  string[] Parts = S.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
394 
395 
396  int IntegerCnt = 0;
397  int PartNr = 0;
398 
399  while (Parts.Length > PartNr)
400  {
401 
402  if (Parts[PartNr].ToUpper() == "BLINK")
403  {
404  Blink = -1;
405  BlinkIntervalMs = 1000;
406  }
407  else if (Parts[PartNr].ToUpper() == "INVERT")
408  {
409  Invert = true;
410  }
411  else if (Parts[PartNr].ToUpper() == "NOBOOL")
412  {
413  NoBool = true;
414  }
415 
416  else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() == "ABT" && Parts[PartNr].Substring(3).IsInteger())
417  {
418  AreaBitmapTop = Parts[PartNr].Substring(3).ToInteger();
419  IsArea = true;
420  IsBitmap = true;
421  }
422  else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() == "ABL" && Parts[PartNr].Substring(3).IsInteger())
423  {
424  AreaBitmapLeft = Parts[PartNr].Substring(3).ToInteger();
425  IsArea = true;
426  IsBitmap = true;
427  }
428  else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() == "ABW" && Parts[PartNr].Substring(3).IsInteger())
429  {
430  AreaBitmapWidth = Parts[PartNr].Substring(3).ToInteger();
431  IsArea = true;
432  IsBitmap = true;
433  }
434  else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() == "ABH" && Parts[PartNr].Substring(3).IsInteger())
435  {
436  AreaBitmapHeight = Parts[PartNr].Substring(3).ToInteger();
437  IsArea = true;
438  IsBitmap = true;
439  }
440  else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() == "ABF" && Parts[PartNr].Substring(3).IsInteger())
441  {
442  AreaBitmapFrame = Parts[PartNr].Substring(3).ToInteger();
443  IsArea = true;
444  IsBitmap = true;
445  }
446  else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() == "AAS" && Parts[PartNr].Substring(3).IsInteger())
447  {
448  AreaBitmapAnimationStepSize = Parts[PartNr].Substring(3).ToInteger();
449  IsArea = true;
450  IsBitmap = true;
451  }
452  else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() == "AAC" && Parts[PartNr].Substring(3).IsInteger())
453  {
454  AreaBitmapAnimationStepCount = Parts[PartNr].Substring(3).ToInteger();
455  IsArea = true;
456  IsBitmap = true;
457  }
458  else if (Parts[PartNr].Length > 3 && Parts[PartNr].Substring(0, 3).ToUpper() == "AAF" && Parts[PartNr].Substring(3).IsInteger())
459  {
460  AreaBitmapAnimationFrameDuration = 1000/Parts[PartNr].Substring(3).ToInteger().Limit(10,int.MaxValue);
461  IsArea = true;
462  IsBitmap = true;
463  }
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]))
465  {
466 
467  AreaBitmapAnimationDirection = (MatrixAnimationStepDirectionEnum)Parts[PartNr].Substring(3, 1).ToUpper()[0];
468  IsArea = true;
469  IsBitmap = true;
470  }
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]))
472  {
473 
474  AreaBitmapAnimationBehaviour = (AnimationBehaviourEnum)Parts[PartNr].Substring(3, 1).ToUpper()[0];
475  IsArea = true;
476  IsBitmap = true;
477  }
478 
479  else if (Parts[PartNr].Length > 5 && Parts[PartNr].Substring(0, 5).ToUpper() == "AFDEN" && Parts[PartNr].Substring(5).IsInteger())
480  {
481  AreaFlickerDensity = Parts[PartNr].Substring(5).ToInteger();
482  IsArea = true;
483  }
484  else if (Parts[PartNr].Length > 5 && Parts[PartNr].Substring(0, 5).ToUpper() == "AFMIN" && Parts[PartNr].Substring(5).IsInteger())
485  {
486  AreaFlickerMinDurationMs = Parts[PartNr].Substring(5).ToInteger();
487  IsArea = true;
488  }
489  else if (Parts[PartNr].Length > 5 && Parts[PartNr].Substring(0, 5).ToUpper() == "AFMAX" && Parts[PartNr].Substring(5).IsInteger())
490  {
491  AreaFlickerMaxDurationMs = Parts[PartNr].Substring(5).ToInteger();
492  IsArea = true;
493  }
494  else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() == "AA" && Parts[PartNr].Substring(2).IsInteger())
495  {
496  AreaAcceleration = Parts[PartNr].Substring(2).ToInteger();
497  IsArea = true;
498  }
499 
500  else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() == "AT" && Parts[PartNr].Substring(2).IsInteger())
501  {
502  AreaTop = Parts[PartNr].Substring(2).ToInteger().Limit(0, 100);
503  IsArea = true;
504  }
505  else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() == "AL" && Parts[PartNr].Substring(2).IsInteger())
506  {
507  AreaLeft = Parts[PartNr].Substring(2).ToInteger().Limit(0, 100);
508  IsArea = true;
509  }
510  else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() == "AW" && Parts[PartNr].Substring(2).IsInteger())
511  {
512  AreaWidth = Parts[PartNr].Substring(2).ToInteger().Limit(0, 100);
513  IsArea = true;
514  }
515  else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() == "AH" && Parts[PartNr].Substring(2).IsInteger())
516  {
517  AreaHeight = Parts[PartNr].Substring(2).ToInteger().Limit(0, 100);
518  IsArea = true;
519  }
520  else if (Parts[PartNr].Length > 2 && Parts[PartNr].Substring(0, 2).ToUpper() == "AS" && Parts[PartNr].Substring(2).IsInteger())
521  {
522  AreaSpeed = Parts[PartNr].Substring(2).ToInteger().Limit(1, 10000);
523  IsArea = true;
524  }
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]))
526  {
527 
528  AreaDirection = (MatrixShiftDirectionEnum)Parts[PartNr].Substring(2, 1).ToUpper()[0];
529  IsArea = true;
530  }
531  else if (Parts[PartNr].Length > 3 && Parts[PartNr].ToUpper().Substring(0, 3) == "MAX" && Parts[PartNr].Substring(3).IsInteger())
532  {
533  MaxDurationMs = Parts[PartNr].Substring(3).ToInteger().Limit(0, int.MaxValue);
534  }
535  else if (Parts[PartNr].Length > 3 && Parts[PartNr].ToUpper().Substring(0, 3) == "BNP" && Parts[PartNr].Substring(3).IsInteger())
536  {
537  BlinkIntervalMsNested = Parts[PartNr].Substring(3).ToInteger().Limit(0, int.MaxValue);
538  }
539  else if (Parts[PartNr].Length > 4 && Parts[PartNr].ToUpper().Substring(0, 4) == "BNPW" && Parts[PartNr].Substring(4).IsInteger())
540  {
541  BlinkPulseWidthNested = Parts[PartNr].Substring(4).ToInteger().Limit(1, 99);
542  }
543 
544  else if (Parts[PartNr].Length > 3 && Parts[PartNr].ToUpper().Substring(0, 3) == "BPW" && Parts[PartNr].Substring(3).IsInteger())
545  {
546  BlinkPulseWidth = Parts[PartNr].Substring(3).ToInteger().Limit(1, 99);
547  }
548  else if (Parts[PartNr].Length > 3 && Parts[PartNr].ToUpper().Substring(0, 3) == "BL#" && Parts[PartNr].Substring(3).IsHexString())
549  {
550 
551  BlinkLow = Parts[PartNr].Substring(3).HexToInt().Limit(0, 255);
552  }
553  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "BL" && Parts[PartNr].Substring(1).IsInteger())
554  {
555 
556  BlinkLow = (int)(((double)Parts[PartNr].Substring(2).ToInteger().Limit(0, 48)) * 5.3125);
557  }
558  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "E" && Parts[PartNr].Substring(1).IsInteger())
559  {
560 
561  ExtDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0, int.MaxValue);
562  }
563  else if (Parts[PartNr].Length > 2 && Parts[PartNr].ToUpper().Substring(0, 2) == "I#" && Parts[PartNr].Substring(2).IsHexString())
564  {
565  //Intensity setting
566  Intensity = Parts[PartNr].Substring(2).HexToInt().Limit(0, 255);
567  }
568  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "I" && Parts[PartNr].Substring(1).IsInteger())
569  {
570  //Intensity setting
571  Intensity = (int)(((double)Parts[PartNr].Substring(1).ToInteger().Limit(0, 48)) * 5.3125);
572  }
573  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "L" && Parts[PartNr].Substring(1).IsInteger())
574  {
575  //Layer setting
576  Layer = Parts[PartNr].Substring(1).ToInteger();
577  }
578  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "W" && Parts[PartNr].Substring(1).IsInteger())
579  {
580  //WaitDuration setting
581  WaitDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0, int.MaxValue);
582  }
583  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "M" && Parts[PartNr].Substring(1).IsInteger())
584  {
585  //MinimumDuration setting
586  MinDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0, int.MaxValue);
587  }
588  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "F" && Parts[PartNr].Substring(1).IsInteger())
589  {
590 
591  //Dimming duration for up and down
592  FadingUpDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0, int.MaxValue);
593  FadingDownDurationMs = FadingUpDurationMs;
594  }
595  else if (Parts[PartNr].Length > 2 && Parts[PartNr].ToUpper().Substring(0, 2) == "FU" && Parts[PartNr].Substring(2).IsInteger())
596  {
597 
598  //Dimming up duration
599  FadingUpDurationMs = Parts[PartNr].Substring(2).ToInteger().Limit(0, int.MaxValue);
600 
601  }
602  else if (Parts[PartNr].Length > 2 && Parts[PartNr].ToUpper().Substring(0, 2) == "FD" && Parts[PartNr].Substring(2).IsInteger())
603  {
604 
605  //Dimming down duration
606  FadingDownDurationMs = Parts[PartNr].Substring(2).ToInteger().Limit(0, int.MaxValue);
607  }
608  else if (Parts[PartNr].IsInteger())
609  {
610  switch (IntegerCnt)
611  {
612  case 0:
613  if (Blink == -1)
614  {
615  //Its a blink interval
616  BlinkIntervalMs = (Parts[PartNr].ToInteger()).Limit(1, int.MaxValue);
617  DurationMs = 0;
618  }
619  else
620  {
621  //Its a duration
622 
623  DurationMs = Parts[PartNr].ToInteger().Limit(1, int.MaxValue);
624  }
625  break;
626  case 1:
627  if (Blink != -1)
628  {
629  Blink = Parts[PartNr].ToInteger().Limit(1, int.MaxValue);
630  if (DurationMs > 0 & Blink >= 1)
631  {
632  BlinkIntervalMs = (DurationMs / Blink).Limit(1, int.MaxValue);
633  DurationMs = 0;
634 
635  }
636  }
637  break;
638  default:
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));
641 
642  }
643  IntegerCnt++;
644  }
645  else if (PartNr == 0)
646  {
647  //This should be a color
648  ColorName = Parts[PartNr];
649  }
650  else
651  {
652  Log.Warning("Cant parse the part {0} of the ledcontrol table config setting {1}".Build(Parts[PartNr], SettingData));
653 
654  throw new Exception("Cant parse the part {0} of the ledcontrol table config setting {1}".Build(Parts[PartNr], SettingData));
655  }
656  PartNr++;
657  }
658 
659 
660 
661 
662  }
663 
664 
665 
666 
677  public TableConfigSetting(string SettingData)
678  : this()
679  {
680  ParseSettingData(SettingData);
681  }
682 
683 
684 
689  {
690  this.Intensity = 255;
691  this.Blink = 0;
692  this.DurationMs = -1;
693 
694  }
695 
696 
697 
698 
699 
700 
701 
702  }
703 }