private void LoadEffectSequencesFromFile() { Console.WriteLine("Reading effect file"); StreamReader reader = null; try { reader = new StreamReader(File.OpenRead(SongDataPath)); while (!reader.EndOfStream) { var line = reader.ReadLine(); if (line.StartsWith("\"On") && line.EndsWith(_columnSeparator)) { var lineData = new EffectSequence(); var splitLine = line.Split(_columnSeparator); lineData.EffectName = splitLine[0]; lineData.StartTime = lineData.StringToTimeSpan(splitLine[1]); lineData.EndTime = lineData.StringToTimeSpan(splitLine[2]); lineData.Duration = lineData.StringToTimeSpan(splitLine[3]); lineData.Description = splitLine[4]; lineData.Element = splitLine[5]; lineData.ElementType = splitLine[6]; lineData.Files = splitLine[7]; EffectSequences.Add(lineData); } } } catch (FileNotFoundException) { Console.WriteLine("File was not found"); } finally { reader.Close(); } }
public async Task ControlLights() { LoadEffectSequencesFromFile(); if (EffectSequences.Count < 1) { throw new ApplicationException("Unable to load data file"); } LoadShowSummaryFromFile(); Console.WriteLine("Now playing: {0}", SongDataPath); TimeSpan showTime = new TimeSpan(0, 0, 0, 0, 0); using GpioController gpio = new GpioController(); MinPinNumber = 2; MaxPinNumber = 27; for (int pinNum = MinPinNumber; pinNum <= MaxPinNumber; pinNum++) { Console.WriteLine("Setting up pin " + pinNum); gpio.OpenPin(pinNum, PinMode.Output); } Console.CancelKeyPress += (s, e) => { Console.WriteLine("Emergency shutdown"); ShutOffRelays(gpio); }; ShutOffRelays(gpio); // TODO See if both intervals are needed after testing int sleepInterval = 10; int showTimeInterval = 10; while (showTime < _ShowSummary.TotalTime) { var lights = EffectSequences.Where(x => x.StartTime == showTime || x.EndTime == showTime); foreach (var light in lights) { Console.WriteLine("{1}, Toggle Relay {0}", light.Element, showTime); int pinNumber = PinLookup(light.Element); if (light.StartTime == showTime) { gpio.Write(pinNumber, relayOn); } else { gpio.Write(pinNumber, relayOff); } } showTime = showTime.Add(TimeSpan.FromMilliseconds(showTimeInterval)); Thread.Sleep(sleepInterval); } ShutOffRelays(gpio); }