DirectOutputR1
DirectOutput framework R1 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 
3 namespace DirectOutput.LedControl.Loader
4 {
8  public class TableConfigSetting
9  {
10 
11 
18  public OutputControlEnum OutputControl { get; set; }
19 
27  public string ColorName { get; set; }
28 
29 
30 
37  public ColorConfig ColorConfig { get; set; }
38 
45  public TableElementTypeEnum TableElementType { get; set; }
52  public int TableElementNumber { get; set; }
53 
54 
55 
63  public OutputTypeEnum OutputType
64  {
65  get
66  {
67  return (!ColorName.IsNullOrWhiteSpace() ? OutputTypeEnum.RGBOutput : OutputTypeEnum.AnalogOutput);
68  }
69  }
70 
77  public int DurationMs { get; set; }
78 
79  private int _MinDurationMs=0;
80 
87  public int MinDurationMs
88  {
89  get { return _MinDurationMs; }
90  set { _MinDurationMs = value; }
91  }
92 
93 
94 
95  private int _Intensity;
103  public int Intensity
104  {
105 
106  get { return (ColorName.IsNullOrWhiteSpace() ? _Intensity : -1); }
107  set { _Intensity = value; }
108  }
109 
110  private int _FadingDurationUpMs = 0;
111 
118  public int FadingUpDurationMs
119  {
120  get { return _FadingDurationUpMs; }
121  set { _FadingDurationUpMs = value; }
122  }
123 
124  private int _FadingDownDurationMs = 0;
125 
132  public int FadingDownDurationMs
133  {
134  get { return _FadingDownDurationMs; }
135  set { _FadingDownDurationMs = value; }
136  }
137 
144  public int Blink { get; set; }
145 
152  public int BlinkIntervalMs { get; set; }
153 
160  public int WaitDurationMs { get; set; }
161 
162 
169  public int? Layer{get;set;}
170 
180  public void ParseSettingData(string SettingData)
181  {
182 
183  string[] Parts = SettingData.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
184  if (Parts.Length == 0)
185  {
186  Log.Warning("No data to parse.");
187 
188  throw new Exception("No data to parse.");
189 
190  }
191  //Get output state and table element (if applicable)
192  bool ParseOK = true;
193  switch (Parts[0].ToUpper())
194  {
195  case "ON":
196  case "1":
197  OutputControl = OutputControlEnum.FixedOn;
198  break;
199  case "OFF":
200  case "0":
201  OutputControl = OutputControlEnum.FixedOff;
202  break;
203  case "B":
204  OutputControl = OutputControlEnum.FixedOn;
205  Blink = -1;
206  BlinkIntervalMs = 500;
207  break;
208  default:
209  if (Parts[0].Length > 1 && Parts[0].Substring(1).IsInteger())
210  {
211  OutputControl = OutputControlEnum.Controlled;
212  Char C = Parts[0].ToUpper().ToCharArray()[0];
213  if (Enum.IsDefined(typeof(TableElementTypeEnum), (int)C))
214  {
215  TableElementType = (TableElementTypeEnum)C;
216  }
217  else
218  {
219  ParseOK = false;
220  }
221 
222  TableElementNumber = Parts[0].Substring(1).ToInteger();
223  }
224  else
225  {
226  ParseOK = false;
227  }
228 
229  break;
230  }
231  if (!ParseOK)
232  {
233  Log.Warning("Cant parse the part {0} of the ledcontrol table config setting {1}.".Build(Parts[0], SettingData));
234 
235  throw new Exception("Cant parse the part {0} of the ledcontrol table config setting {1}.".Build(Parts[0], SettingData));
236 
237  }
238 
239  int IntegerCnt = 0;
240  int PartNr = 1;
241  while (Parts.Length > PartNr)
242  {
243 
244  if (Parts[PartNr].ToUpper() == "BLINK")
245  {
246  Blink = -1;
247  BlinkIntervalMs = 500;
248  }
249  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "I" && Parts[PartNr].Substring(1).IsInteger())
250  {
251  //Intensity setting
252  Intensity = Parts[PartNr].Substring(1).ToInteger().Limit(0, 48);
253  }
254  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "L" && Parts[PartNr].Substring(1).IsInteger())
255  {
256  //Layer setting
257  Layer = Parts[PartNr].Substring(1).ToInteger();
258  }
259  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "W" && Parts[PartNr].Substring(1).IsInteger())
260  {
261  //WaitDuration setting
262  WaitDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0, int.MaxValue);
263  }
264  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "M" && Parts[PartNr].Substring(1).IsInteger())
265  {
266  //MinimumDuration setting
267  MinDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0, int.MaxValue);
268  }
269  else if (Parts[PartNr].Length > 1 && Parts[PartNr].ToUpper().Substring(0, 1) == "F" && Parts[PartNr].Substring(1).IsInteger())
270  {
271 
272  //Dimming duration for up and down
273  FadingUpDurationMs = Parts[PartNr].Substring(1).ToInteger().Limit(0, int.MaxValue);
274  FadingDownDurationMs = FadingUpDurationMs;
275  }
276  else if (Parts[PartNr].Length>2 && Parts[PartNr].ToUpper().Substring(0, 2) == "FU" && Parts[PartNr].Substring(2).IsInteger())
277  {
278 
279  //Dimming up duration
280  FadingUpDurationMs = Parts[PartNr].Substring(2).ToInteger().Limit(0, int.MaxValue);
281 
282  }
283  else if (Parts[PartNr].Length > 2 && Parts[PartNr].ToUpper().Substring(0, 2) == "FD" && Parts[PartNr].Substring(2).IsInteger())
284  {
285 
286  //Dimming down duration
287  FadingDownDurationMs = Parts[PartNr].Substring(2).ToInteger().Limit(0, int.MaxValue);
288  }
289  else if (Parts[PartNr].IsInteger())
290  {
291  switch (IntegerCnt)
292  {
293  case 0:
294  if (Blink == -1)
295  {
296  //Its a blink interval
297  BlinkIntervalMs = (Parts[PartNr].ToInteger()/2).Limit(1, int.MaxValue);
298  DurationMs = 0;
299  }
300  else
301  {
302  //Its a duration
303 
304  DurationMs = Parts[PartNr].ToInteger().Limit(1, int.MaxValue);
305  }
306  break;
307  case 1:
308  if (Blink != -1)
309  {
310  Blink = Parts[PartNr].ToInteger().Limit(1, int.MaxValue);
311  if (DurationMs > 0 & Blink >= 1)
312  {
313  BlinkIntervalMs = (DurationMs / Blink / 2).Limit(1, int.MaxValue);
314  DurationMs = 0;
315 
316  }
317  }
318  break;
319  default:
320  Log.Warning("The ledcontrol table config setting {0} contains more than 2 numeric values without a type definition.".Build(SettingData));
321  throw new Exception("The ledcontrol table config setting {0} contains more than 2 numeric values without a type definition.".Build(SettingData));
322 
323  }
324  IntegerCnt++;
325  }
326  else if (PartNr == 1)
327  {
328  //This should be a color
329  ColorName = Parts[PartNr];
330  }
331  else
332  {
333  Log.Warning("Cant parse the part {0} of the ledcontrol table config setting {1}".Build(Parts[PartNr], SettingData));
334 
335  throw new Exception("Cant parse the part {0} of the ledcontrol table config setting {1}".Build(Parts[PartNr], SettingData));
336  }
337  PartNr++;
338  }
339 
340 
341 
342 
343  }
344 
345 
346 
347 
358  public TableConfigSetting(string SettingData)
359  : this()
360  {
361  ParseSettingData(SettingData);
362  }
363 
364 
365 
370  {
371  this.Intensity = 48;
372  this.Blink = 0;
373  this.DurationMs = -1;
374 
375  }
376 
377 
378 
379 
380 
381 
382 
383  }
384 }