public Effect(ref LightControl MainLights) { Lights = MainLights; }
public static void Main(string[] args) { bool buttonHandled = false; //Locate and load the configuation file. //Default is Config.xml but also supports custom config XML file with command line parameter string file = "Config.xml"; foreach (string arg in args) { if (arg.ToLower().EndsWith(".xml")) { file = arg; } } //Attempt to load the config file Config.Load(file); if (!Config.ConfigLoaded) { Console.WriteLine("Can't start without Config file. Press enter to exit..."); Console.ReadLine(); return; } Buttons = new ButtonControl(); Lights = new LightControl(); Effects = new Effect(ref Lights); Buttons.Initialize(); Lights.Initialize(); while (!Console.KeyAvailable || OptionOrExit()) { if (Buttons.MainButtons.Count > 0) { if (Buttons.MainButtons[0].isOn && !buttonHandled) { buttonHandled = true; switch (Lights.LightState) { case LightStates.Off: Lights.WhiteOn(); break; case LightStates.WhiteOn: Lights.BlackOn(); break; case LightStates.BlackOn: Lights.Off(); break; default: Lights.Off(); break; } } if (!Buttons.MainButtons[0].isOn && buttonHandled) { Thread.Sleep(30); buttonHandled = false; } if (!Buttons.MainButtons[0].isOn && !buttonHandled) { //This should never occur under normal circumstances Console.WriteLine("*****************************************************************"); Console.WriteLine("A fatal error occurred when attempting to read the button state"); Console.WriteLine("This program will now close"); Console.WriteLine("*****************************************************************"); break; } } } Buttons.Dispose(); Lights.Dispose(); Console.ReadLine(); }