private void CheckInputPins() { var newPinValues = Driver.Read(inputPins); var notifiedConfigurations = new List <PinConfiguration>(); foreach (var processorPin in inputPins.Enumerate()) { var np = (ProcessorPin)processorPin; var oldPinValue = pinRawValues.Get(processorPin); var newPinValue = newPinValues.Get(processorPin); if (oldPinValue != newPinValue) { var pin = (InputPinConfiguration)pinConfigurations[np]; var switchPin = pin as SwitchInputPinConfiguration; if (switchPin != null) { if (pin.GetEffective(newPinValue)) { pinValues[np] = !pinValues[np]; notifiedConfigurations.Add(pin); } } else { pinValues[np] = pin.GetEffective(newPinValue); notifiedConfigurations.Add(pin); } } } pinRawValues = newPinValues; // Only fires events once all states have been modified. foreach (var pin in notifiedConfigurations) { OnPinStatusChanged(new PinStatusEventArgs { Configuration = pin, Enabled = pinValues[pin.Pin] }); } }
/// <summary> /// Enumerates the specified pins. /// </summary> /// <param name="pins">The pins.</param> /// <returns>The pins.</returns> public static IEnumerable <int> Enumerate(this ProcessorPins pins) { return(Enumerable.Range(0, pins.Count) .Where(p => (pins.Get(p))) .ToArray()); }