protected void ChangePinPullMode(int pinNumber, PullMode mode) { GpioPin pin = watcher.Get(pinNumber); if (pin != null) { pin.SetPullMode(mode); WritePinState(pin); } }
public string DeserializeState(string state, out Dictionary <int, string> tagsState) { tagsState = new Dictionary <int, string>(); StringBuilder log = new StringBuilder(); if (state != null) { using (Gpio gpio = new Gpio()) { string[] lines = state.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { string[] fields = line.Split(SEPARATOR); if (fields.Length == 5) { try { int pinNumber = Int32.Parse(fields[0]); PinMode pinMode = (PinMode)Enum.Parse(typeof(PinMode), fields[1]); PinValue pinValue = (PinValue)Enum.Parse(typeof(PinValue), fields[2]); PullMode pullMode = (PullMode)Enum.Parse(typeof(PullMode), fields[3]); string tag = fields[4]; GpioPin pin = gpio.GetPin(pinNumber); pin.Tag = tag; pin.SetMode(pinMode); pin.SetPullMode(pullMode); pin.Write(pinValue); if (tagsState != null) { tagsState.Add(pin.Number, pin.Tag); } log.AppendFormat("Pin {0} set to mode {1}, pull {2}, value {3}, tag {4}", pinNumber, pinMode, pullMode, pinValue, tag); } catch (Exception e) { log.AppendFormat("Error: {0}", e.Message); } log.AppendLine(); } } } } return(log.ToString()); }