static void set(int pin) { if (Controller == null || PinController == null) { return; } Pin?pinStatus = PinController.GetDriver()?.GetPinConfig(pin); if (pinStatus == null) { return; } if (pinStatus.IsPinOn) { PinController.GetDriver()?.SetGpioValue(pin, GpioPinMode.Output, GpioPinState.Off); Logger.Log($"Successfully set {pin} pin to OFF.", LogLevels.Green); } else { PinController.GetDriver()?.SetGpioValue(pin, GpioPinMode.Output, GpioPinState.On); Logger.Log($"Successfully set {pin} pin to ON.", LogLevels.Green); } }
public bool SetGpioValue(int pin, GpioPinState state) { if (!PinController.IsValidPin(pin)) { return(false); } try { GpioPin GpioPin = (GpioPin)Pi.Gpio[pin]; if (GpioPin.PinMode == GpioPinDriveMode.Output) { GpioPin.Write((GpioPinValue)state); CastDriver <IGpioControllerDriver>(this).Logger.Trace($"Configured ({pin}) gpio pin to ({state.ToString()}) state."); CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(new Pin(pin, state)); return(true); } return(false); } finally { Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }
public bool GpioDigitalRead(int pin) { if (!IsWiringPiInstalled()) { return(false); } if (!PiGpioController.IsAllowedToExecute || !IsDriverProperlyInitialized) { return(false); } if (!PinController.IsValidPin(pin)) { CastDriver <IGpioControllerDriver>(this)?.Logger.Log("The specified pin is invalid."); return(false); } try { return(ReadState(pin) == Enums.GpioPinState.Off ? false : true); } finally { Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }
public bool SetGpioValue(int pin, Enums.GpioPinMode mode, Enums.GpioPinState state) { if (!IsWiringPiInstalled()) { return(false); } if (!PiGpioController.IsAllowedToExecute || !IsDriverProperlyInitialized) { return(false); } if (!PinController.IsValidPin(pin)) { CastDriver <IGpioControllerDriver>(this)?.Logger.Log("The specified pin is invalid."); return(false); } try { if (SetMode(pin, mode)) { return(WriteValue(pin, state)); } return(false); } finally { Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }
public Connector(NodeLink displayedLink, Pin?source, Pin?destination) { DisplayedLink = displayedLink; Source = source; Destination = destination; FillColor = DataCache.IconAverageColor(displayedLink.Item.Icon); }
private async Task FinishDrag(MouseButtonEventArgs args) { Debug.Assert(sourcePin != null); var viewModel = AssociatedObject.DataContext as ProductionGraphViewModel; if (viewModel == null) { return; } Pin source = sourcePin; Pin?target = targetPin; if (target == null) { var position = args.GetPosition(AssociatedObject); var canvasPos = AssociatedObject.PointToCanvas(position); var screenPos = AssociatedObject.PointToScreen(position); try { Reset(keepAdorner: true); await viewModel.SuggestConnect(source, canvasPos, screenPos); } finally { Reset(); } } else { Reset(); viewModel.Connect(source, target); } }
private void PrepareDrag(Pin source) { if (state != DragState.None) { Reset(); } sourcePin = source; startPosition = sourcePin.Hotspot; state = DragState.Preparing; if (!AssociatedObject.CaptureMouse()) { Reset(); } }
public bool SetGpioValue(int pin, GpioPinMode mode, GpioPinState state) { if (!PinController.IsValidPin(pin) || !IsDriverProperlyInitialized) { return(false); } try { if (DriverController == null) { return(false); } if (!DriverController.IsPinModeSupported(pin, (PinMode)mode)) { return(false); } DriverController.OpenPin(pin); if (!DriverController.IsPinOpen(pin)) { return(false); } DriverController.SetPinMode(pin, (PinMode)mode); DriverController.Write(pin, state == GpioPinState.Off ? PinValue.High : PinValue.Low); CastDriver <IGpioControllerDriver>(this)?.Logger.Trace($"Configured ({pin}) gpio pin to ({state.ToString()}) state with ({mode.ToString()}) mode."); CastDriver <IGpioControllerDriver>(this)?.UpdatePinConfig(new Pin(pin, state, mode)); return(true); } finally { if (DriverController != null) { if (DriverController.IsPinOpen(pin)) { DriverController.ClosePin(pin); } } Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }
private static bool IsValidTarget(Pin source, Pin?target) { if (target == null) { return(true); } if (source == target) { return(false); } bool compatibleKinds = (source.Kind == PinKind.Input && target.Kind == PinKind.Output) || (source.Kind == PinKind.Output && target.Kind == PinKind.Input); return(compatibleKinds && source.Item == target.Item); }
private void SetEvents() { if (!IsAllowedToExecute) { Logger.Warning("Running OS platform is unsupported."); return; } var driver = PinController.GetDriver(); if (driver == null || !driver.IsDriverProperlyInitialized) { Logger.Warning("Failed to set events as drivers are not loaded."); return; } List <Pin> pinConfigs = new List <Pin>(); for (int i = 0; i < Constants.BcmGpioPins.Length; i++) { Pin?config = PinController.GetDriver()?.GetPinConfig(Constants.BcmGpioPins[i]); if (config == null) { continue; } pinConfigs.Add(config); Logger.Trace($"Generated pin config for {Pi.Gpio[i].PhysicalPinNumber} gpio pin."); } ConfigManager = new PinConfigManager().Init(new PinConfig(pinConfigs)); for (int i = 0; i < AvailablePins.OutputPins.Length; i++) { EventManager?.RegisterEvent(new EventConfig(AvailablePins.OutputPins[i], GpioPinMode.Output, GpioPinEventStates.ALL, OutputPinEvents)); Logger.Trace($"Event registered for {AvailablePins.OutputPins[i]} gpio pin with Output state."); } for (int i = 0; i < AvailablePins.InputPins.Length; i++) { EventManager?.RegisterEvent(new EventConfig(AvailablePins.InputPins[i], GpioPinMode.Input, GpioPinEventStates.ALL, InputPinEvents)); Logger.Trace($"Event registered for {AvailablePins.InputPins[i]} gpio pin with Input state."); } }
public bool SetGpioValue(int pin, Enums.GpioPinState state) { if (!IsWiringPiInstalled()) { return(false); } if (!PiGpioController.IsAllowedToExecute || !IsDriverProperlyInitialized) { return(false); } if (!PinController.IsValidPin(pin)) { CastDriver <IGpioControllerDriver>(this)?.Logger.Log("The specified pin is invalid."); return(false); } try { Pin?pinConfig = GetPinConfig(pin); if (pinConfig == null) { return(false); } if (pinConfig.Mode != Enums.GpioPinMode.Output) { CastDriver <IGpioControllerDriver>(this)?.Logger.Warning($"Pin cannot be configured to {state.ToString()} as it is not in output mode."); return(false); } return(WriteValue(pin, state)); } finally { Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }
public bool GpioDigitalRead(int pin) { if (!PinController.IsValidPin(pin) || !IsDriverProperlyInitialized) { CastDriver <IGpioControllerDriver>(this)?.Logger.Log("The specified pin is invalid."); return(false); } try { GpioPin gpioPin = (GpioPin)Pi.Gpio[pin]; return(gpioPin.Read()); } finally { Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }
public bool GpioDigitalRead(int pin) { if (!PinController.IsValidPin(pin) || !IsDriverProperlyInitialized) { CastDriver <IGpioControllerDriver>(this)?.Logger.Log("The specified pin is invalid."); return(false); } try { if (DriverController == null) { return(false); } DriverController.OpenPin(pin); if (!DriverController.IsPinOpen(pin)) { return(false); } return(!(DriverController.Read(pin) == PinValue.High)); } finally { if (DriverController != null) { if (DriverController.IsPinOpen(pin)) { DriverController.ClosePin(pin); } } Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }
public bool SetGpioValue(int pin, GpioPinMode mode) { if (!PinController.IsValidPin(pin)) { return(false); } try { GpioPin GpioPin = (GpioPin)Pi.Gpio[pin]; GpioPin.PinMode = (GpioPinDriveMode)mode; CastDriver <IGpioControllerDriver>(this)?.Logger.Trace($"Configured ({pin}) gpio pin with ({mode.ToString()}) mode."); CastDriver <IGpioControllerDriver>(this)?.UpdatePinConfig(new Pin(pin, mode)); return(true); } finally { Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }
private void Update(Point position, Point canvasPos) { Debug.Assert(sourcePin != null); Debug.Assert(connectorAdorner != null); var connector = (ConnectorShape)((Canvas)connectorAdorner.Child).Children[0]; if (sourcePin.Kind == PinKind.Output) { connector.Points = new PointCollection { startPosition, canvasPos } } ; else { connector.Points = new PointCollection { canvasPos, startPosition } }; Pin?candidatePin = FindPin(position); if (targetPin != candidatePin && IsValidTarget(sourcePin, candidatePin)) { if (targetPin != null) { targetPin.IsHighlighted = false; } targetPin = candidatePin; if (targetPin != null) { targetPin.IsHighlighted = true; } } }
private void Reset(bool keepAdorner = false) { state = DragState.None; startPosition = new Point(); sourcePin = null; if (targetPin != null) { targetPin.IsHighlighted = false; targetPin = null; } if (!keepAdorner) { var layer = AdornerLayer.GetAdornerLayer(AssociatedObject); if (connectorAdorner != null) { layer.Remove(connectorAdorner); } connectorAdorner = null; } AssociatedObject.ReleaseMouseCapture(); }