private void Run(string[] args) { var led = ProcessorPin.Pin18 .Output() .Name("LED") .Revert() .Enable(); using (var connection = new GpioConnection(led)) { var button = ProcessorPin.Pin2 .Input() .Name("Button") .Revert() .Switch() .Enable() .OnStatusChanged(b => { Console.WriteLine("Button/LED switched {0}", b ? "On" : "Off"); connection.Pins["LED"].Toggle(); }); connection.Add(button); Console.WriteLine("Press Enter to quit..."); Console.ReadLine(); } }
public GpioInterface() { LogHelper.LogMessage("GpioInterface initialization started: {0}", DateTime.Now); gpioConnection = new GpioConnection(new List <PinConfiguration> { //configure output pins MapOutputPin(OutputPin.O1).Input(), MapOutputPin(OutputPin.O2).Input(), MapOutputPin(OutputPin.O3).Input(), MapOutputPin(OutputPin.O4).Input(), MapOutputPin(OutputPin.O5).Input(), MapOutputPin(OutputPin.O6).Input(), MapOutputPin(OutputPin.O7).Input(), MapOutputPin(OutputPin.O8).Input(), MapOutputPin(OutputPin.O9).Input(), MapOutputPin(OutputPin.O10).Input(), //configure input pins MapInputPin(InputPin.I1).Input(), MapInputPin(InputPin.I2).Input(), MapInputPin(InputPin.I3).Input(), MapInputPin(InputPin.I4).Input(), MapInputPin(InputPin.I5).Input(), MapInputPin(InputPin.I6).Input(), MapInputPin(InputPin.I7).Input(), MapInputPin(InputPin.I8).Input(), MapInputPin(InputPin.I9).Input(), MapInputPin(InputPin.I10).Input(), }); gpioConnection.PinStatusChanged += PinStatusChanged; LogHelper.LogMessage("GpioInterface initialization finished"); }
private void Run(string[] args) { Console.WriteLine("Press any key to exit..."); var led = ProcessorPin.Pin23 .Output(); using (var connection = new GpioConnection(led)) { while (!Console.KeyAvailable) { connection.Toggle(led); System.Threading.Thread.Sleep(250); } } // Another approach using a behavior with finite number of blinks (10) //BlinkBehavior behavior = new BlinkBehavior(new PinConfiguration[] { led }) { Interval = new TimeSpan(0, 0, seconds: 1), Count = 10 }; //connection.Start(behavior); //while (!Console.KeyAvailable) //{ // System.Threading.Thread.Sleep(200); //} //connection.Stop(behavior); }
public RaspberryPiPinProvider() { inputPins = new List <PinConfiguration>() { ConnectorPin.P1Pin16.Input().PullDown(), ConnectorPin.P1Pin18.Input().PullDown() }; outputPins = new List <PinConfiguration>() { ConnectorPin.P1Pin11.Output(), ConnectorPin.P1Pin12.Output(), ConnectorPin.P1Pin13.Output(), ConnectorPin.P1Pin15.Output() }; connection = new GpioConnection(); inputPins.ForEach(x => { x.OnStatusChanged(state => { if (InputPinStateChange != null) { InputPinStateChange(inputPins.IndexOf(x), state); } }); connection.Add(x); }); outputPins.ForEach(x => connection.Add(x)); }
public void Initialize() { _pinConfiguration = Pin.Input().OnStatusChanged(s => { RaiseOnPressedEvent(null); }); _connection = new GpioConnection(_pinConfiguration); }
static void Main() { conPin = new GpioConnection(ProcessorPin.Gpio18.Output()); Console.WriteLine("Blink Sample"); Console.WriteLine("==============="); Console.WriteLine($"GPIO : {conPin.Pins.First().Configuration.Pin}"); Console.WriteLine(RaspberrySharp.System.Board.Current.Processor); while (true) { // Blink the LED Console.WriteLine("LED On"); conPin.Pins.First().Enabled = true; Thread.Sleep(1000); Console.WriteLine("LED Off"); conPin.Pins.First().Enabled = false; Thread.Sleep(1000); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.X: Console.WriteLine("Blink End ..."); Environment.Exit(0); break; } } } }
static bool ConnectPort(string[] args) { //Connect to the right UART port (may be USB in Windows/Unix/Mac or a Raspberry Mainboard) if (g_bIoTBoard) { //Define pins to control baudrate (GPIO2 on Pin21) and force a HW reset of the MWSUB3G (Pin12) OutputPinConfiguration pinGPIO2 = ConnectorPin.P1Pin21.Output(); m_pinConnection = new GpioConnection(pinGPIO2); OutputPinConfiguration pinRESET = ConnectorPin.P1Pin12.Output(); m_pinConnection.Add(pinRESET); //Reset sequence m_pinConnection[pinRESET] = false; Thread.Sleep(100); m_pinConnection[pinGPIO2] = true; //true for 500Kbps, change to false for 2400bps low speed m_pinConnection[pinRESET] = true; Thread.Sleep(2500); //wait for initialization firmware code to finish startup //Open COM port from Raspberry mainboard string sCOMPort = "/dev/ttyAMA0"; g_objRFE.ConnectPort(sCOMPort, g_nBaudrate, true); Console.WriteLine("Connected to port " + sCOMPort); } else if (args.Contains("/p:AUTO", StringComparer.Ordinal)) { //This is any non-IoT platform with a single device connected to USB if (g_objRFE.GetConnectedPorts()) { if (g_objRFE.ValidCP2101Ports.Length == 1) { bool bForceBaudrate = (RFECommunicator.IsRaspberry() && g_nBaudrate > 115200); g_objRFE.ConnectPort(g_objRFE.ValidCP2101Ports[0], g_nBaudrate, RFECommunicator.IsUnixLike() && !RFECommunicator.IsMacOS(), bForceBaudrate); } } if (g_objRFE.PortConnected) { Console.WriteLine("Connected to port " + g_objRFE.ValidCP2101Ports[0]); } else { Console.WriteLine("ERROR: no port available, please review your connection"); return(false); } } else { //Use specified port from command line int nPos = Array.FindIndex(args, x => x.StartsWith("/p:")); if (nPos >= 0) { string sCOMPort = args[nPos].Replace("/p:", ""); Console.WriteLine("Trying manual port: " + sCOMPort); g_objRFE.ConnectPort(sCOMPort, g_nBaudrate, RFECommunicator.IsUnixLike() && !RFECommunicator.IsMacOS()); Console.WriteLine("Connected to port " + sCOMPort); } } return(g_objRFE.PortConnected); }
public void Setup() { redLed = ConnectorPin.P1Pin12.Output(); yellowLed = ConnectorPin.P1Pin16.Output(); greenLed = ConnectorPin.P1Pin18.Output(); leds = new OutputPinConfiguration[] { redLed, greenLed, yellowLed }; conn = new GpioConnection(leds); }
public static void CloseGpio() { if (gpio != null) { gpio.Close(); gpio = null; } }
public IOFactory(DataServerWebClient d, GpioConnection g) { log4net.Config.XmlConfigurator.Configure(); log = LogManager.GetLogger("Device"); dataServer = d; gpio = g; driver = GpioConnectionSettings.DefaultDriver; }
internal void Start(GpioConnection connection) { Connection = connection; foreach (var pinConfiguration in Configurations) connection[pinConfiguration] = false; currentStep = GetFirstStep(); timer.Start(TimeSpan.Zero); }
static void Main(string[] args) { log4net.Config.XmlConfigurator.Configure(); ILog log = LogManager.GetLogger("GPIO"); log.Debug("Start"); PinConfiguration output = ConnectorPin.P1Pin36.Output().Name("Output1"); PinConfiguration[] outputs = new PinConfiguration[] { output }; GpioConnection gpio = new GpioConnection(outputs); //gpio.Open(); ElectricPotential referenceVoltage = ElectricPotential.FromVolts(3.3); var driver = new MemoryGpioConnectionDriver(); //GpioConnectionSettings.DefaultDriver; Mcp3008SpiConnection spi = new Mcp3008SpiConnection( driver.Out(adcClock), driver.Out(adcCs), driver.In(adcMiso), driver.Out(adcMosi)); IInputAnalogPin inputPin = spi.In(Mcp3008Channel.Channel0); gpio.Open(); ElectricPotential volts = ElectricPotential.FromVolts(0); while (!Console.KeyAvailable) { var v = referenceVoltage * (double)inputPin.Read().Relative; Console.WriteLine("{0} mV", v.Millivolts); if ((Math.Abs(v.Millivolts - volts.Millivolts) > 100)) { volts = ElectricPotential.FromMillivolts(v.Millivolts); Console.WriteLine("Voltage ch0: {0}", volts.Millivolts.ToString()); } gpio.Toggle("Output1"); Thread.Sleep(2000); } gpio.Close(); //bool bShutdown = false; //while(!bShutdown) //{ // gpio.Toggle(output); // log.Debug("Toggle output"); // Thread.Sleep(5000); //} }
public void AddButton(string name, ProcessorPin pin) { var p = pin.Input(); p.Resistor = PinResistor.PullDown; var gpioConnection = new GpioConnection(p); Buttons.Add(name, gpioConnection); }
private static void Start() { var _settings = new GpioConnectionSettings(); _settings.PollInterval = TimeSpan.FromSeconds(1);//.FromMilliseconds(50); _conPin = new GpioConnection(_settings); _conPin.Add(testPin.Input()); //_conPin.Toggle(testPin); _conPin.PinStatusChanged += _conPin_PinStatusChanged; }
/// <summary> /// Close specific serial port and finish /// </summary> static void ClosePort() { if (m_pinConnection != null) { m_pinConnection.Close(); m_pinConnection = null; } g_objRFE.Close(); g_objRFE.Dispose(); //g_objRFE = null; }
internal void Start(GpioConnection connection) { Connection = connection; foreach (var pinConfiguration in Configurations) { connection[pinConfiguration] = false; } currentStep = GetFirstStep(); timer.Start(TimeSpan.Zero); }
static void Main(string[] args) { var led1 = ConnectorPin.P1Pin11.Output(); var connection = new GpioConnection(led1); for (var i = 0; i < 100; i++) { connection.Toggle(led1); System.Threading.Thread.Sleep(250); } connection.Close(); }
public void Setup() { _redLed = ConnectorPin.P1Pin12.Output(); _yellowLed = ConnectorPin.P1Pin16.Output(); _greenLed = ConnectorPin.P1Pin18.Output(); _leds = new OutputPinConfiguration[] { _redLed, _greenLed, _yellowLed }; _conn = new GpioConnection(_leds); _conn[_greenLed] = true; _conn[_yellowLed] = true; _conn[_redLed] = true; }
/// <summary> /// Starts the specified behavior on the connection. /// </summary> /// <param name="connection">The connection.</param> /// <param name="behavior">The behavior.</param> public static void Start(this GpioConnection connection, PinsBehavior behavior) { foreach (var configuration in behavior.Configurations) { if (!connection.Contains(configuration)) { connection.Add(configuration); } } behavior.Start(connection); }
public clsDialHookListener(InputPinConfiguration HookInput, InputPinConfiguration PulseDialInput) { HookIO = HookInput; DialIO = PulseDialInput; var config = new GpioConnectionSettings() { PollInterval = 5, }; GPIO = new GpioConnection(config, HookIO, DialIO); GPIO.PinStatusChanged += (object sender, PinStatusEventArgs e) => { //switch change event handler if (e.Configuration.Pin == HookIO.Pin) { if (GPIO[HookIO]) { HookPulseCount++; } HookWaitEvent.Set(); } else if (e.Configuration.Pin == DialIO.Pin) { if (GPIO[DialIO]) { DialPulseCount++; DialWaitEvent.Set(); } } else { Console.WriteLine("Huh?! Wrong IO: " + e.Configuration.Name); } }; DialListenerThread = new Thread(ListenDial) { Name = "DialListener", IsBackground = true, }; DialListenerThread.Start(); HookListenerThread = new Thread(ListenHookSwitch) { Name = "HookListener", IsBackground = true, }; HookListenerThread.Start(); }
public Lighting(ConfigurationObject.DevicesConfig.LightingConfig config, GpioConnection gpioConnection) : base(gpioConnection) { Description = config.Description; Floor = config.Floor; _timerEnabled = config.TimerEnabled; _offTime = config.OffTime; _onTime = config.OnTime; _switchPin = config.SwitchPin.Output().Disable(); _switchPin.Name = config.Description; _deviceStatus = config.DeviceStatus; Disabled = config.Disabled; }
static GpioGlobalConnection() { // if (!CommonHelper.IsBoard) // return; _settings = new GpioConnectionSettings { //Interval between pin checks. This is *really* important - higher values lead to missed values/borking. Lower //values are apparently possible, but may have 'severe' performance impact. Further testing needed. PollInterval = TimeSpan.FromMilliseconds(500) }; _gpioConnectionGlobalPin = new GpioConnection(_settings); _blinkPins = new ConcurrentDictionary <ProcessorPin, TimeSpan>(); }
public DeviceController(IConfigurationController configController, IDeviceScheduler scheduler = null) { _gpioConnection = new GpioConnection(); if (_gpioConnection.IsOpened) { InitializeDevices(configController.Config.Devices); } if (scheduler != null) { _deviceScheduler = scheduler; RegisterDevicesToScheduler(); } }
private void InitializeGpio() { var allShutterPins = (from x in _configController.Config.Devices.Shutters let onPin = x.OpenPin let offPin = x.ClosePin select new[] { onPin, offPin }).SelectMany(x => x).ToList(); var allLightingPins = (from x in _configController.Config.Devices.Lightings select x.SwitchPin); var allPins = allShutterPins.Concat(allLightingPins); _allOutputPins = allPins.Select(pin => pin.Output().Enable()); _gpioConnection = new GpioConnection(_allOutputPins); }
private static void TestDrive() { Console.WriteLine("Testing arrows with car driving"); ConsoleKeyInfo cki; var connection = new GpioConnection(driveForward, driveBackward, driveTurnLeft, driveTurnRight); Console.WriteLine("Press the Escape (Esc) key to quit: \n"); do { cki = Console.ReadKey(); Console.Write(" --- You pressed "); Console.WriteLine(cki.Key.ToString()); switch (cki.Key) { case ConsoleKey.UpArrow: //connection.Blink(driveForward, new TimeSpan(0, 0, 0, 0, 300)); //Hack as we don't have immediate mode in managed code //Blink appears to have issues as it uses Timer connection.Toggle(driveForward); System.Threading.Thread.Sleep(300); connection.Toggle(driveForward); break; case ConsoleKey.DownArrow: connection.Toggle(driveBackward); System.Threading.Thread.Sleep(300); connection.Toggle(driveBackward); break; case ConsoleKey.LeftArrow: connection.Toggle(driveForward); connection.Toggle(driveTurnLeft); System.Threading.Thread.Sleep(400); connection.Toggle(driveForward); connection.Toggle(driveTurnLeft); break; case ConsoleKey.RightArrow: connection.Toggle(driveForward); connection.Toggle(driveTurnRight); System.Threading.Thread.Sleep(400); connection.Toggle(driveForward); connection.Toggle(driveTurnRight); break; default: break; } } while (cki.Key != ConsoleKey.Escape); connection.Close(); }
protected void turnOffAllPumps(object sender, EventArgs e) { var ssr1 = ConnectorPin.P1Pin36.Output(); var ssr2 = ConnectorPin.P1Pin22.Output(); var connection1 = new GpioConnection(ssr1); var connection2 = new GpioConnection(ssr2); connection1.Close(); connection2.Close(); Pump1Status.Text = "Off"; Pump2Status.Text = "Off"; }
public HardwareService() { //initialize logging log4net.Config.XmlConfigurator.Configure(); log = LogManager.GetLogger("Device"); //initialize hardware gpio = new GpioConnection(); gpioDriver = new MemoryGpioConnectionDriver(); Solenoids = new List <ISolenoid>(); Alarms = new List <IAlarm>(); Analogs = new List <IAnalog>(); Spis = new List <ISpi>(); }
static void Main(string[] args) { OutputPinConfiguration pin12 = ConnectorPin.P1Pin12.Output(); pin12.Enabled = false; using (GpioConnection connection = new GpioConnection(pin12)) { while (!Console.KeyAvailable) { connection.Toggle(pin12); Thread.Sleep(250); } } }
public static void Main() { var application = new Application(); application.RenderException += (_, args) => Console.WriteLine(args.Exception); using (var timerFactory = new TimerFactory()) using (var gpioConnectionDriverFactory = new GpioConnectionDriverFactory(true)) { var(textDisplayDevice, lcd) = Create(gpioConnectionDriverFactory); using (lcd) { // var textViewNavigator = application.StartRendering(new TextViewRendererFactory(textDisplayDevice, timerFactory)); var menuButton = new PullDownButtonDevice(ConnectorPin.P1Pin13); var playButton = new PullDownButtonDevice(ConnectorPin.P1Pin15); var nextButton = new PullDownButtonDevice(ConnectorPin.P1Pin16); var prevButton = new PullDownButtonDevice(ConnectorPin.P1Pin18); using (var gpioConnection = new GpioConnection(gpioConnectionDriverFactory, menuButton.PinConfiguration, playButton.PinConfiguration, nextButton.PinConfiguration, prevButton.PinConfiguration)) { using (var rfidTransceiver = new Mfrc522Connection("/dev/spidev0.0", ConnectorPin.P1Pin22, gpioConnectionDriverFactory, null, new RfidConnectionLogger())) using (var rotaryEncoder = new Ky040Device(ConnectorPin.P1Pin36, ConnectorPin.P1Pin38, ConnectorPin.P1Pin40, gpioConnectionDriverFactory, new Ky040ConsoleReporter())) { menuButton.Pressed += (sender, eventArgs) => Console.WriteLine("Menu"); playButton.Pressed += (sender, eventArgs) => Console.WriteLine("Play"); nextButton.Pressed += (sender, eventArgs) => Console.WriteLine("Next"); prevButton.Pressed += (sender, eventArgs) => Console.WriteLine("Prev"); rotaryEncoder.Pressed += (sender, args) => Console.WriteLine("Rotary"); rotaryEncoder.Rotated += RotaryEncoder_Rotated; rfidTransceiver.TagDetected += RfidTransceiver_TagDetected; // textViewNavigator.NavigateToAsync(new MainTextView(rfidTransceiver, rotaryEncoder, menuButton, // playButton, nextButton, prevButton)); // application.Run(); var i = 0; var token = new CancellationTokenSource(); Console.CancelKeyPress += (sender, args) => token.Cancel(); while (!token.IsCancellationRequested) { textDisplayDevice.WriteLine(AlignedString.Format("Hello: {0:9, <>}", i++)); Thread.Sleep(100); textDisplayDevice.WriteLine(" "); Thread.Sleep(1000); } } } } } Console.WriteLine("Ending..."); }
private void BlinkTest() { var led1Config = ConnectorPin.P1Pin11.Output(); var led1Con = new GpioConnection(led1Config); led1Con.Open(); for (var i = 0; i < 30; i++) { led1Con.Toggle(led1Config); System.Threading.Thread.Sleep(1000); } led1Con.Close(); }
static void Main(string[] args) { var led1 = ConnectorPin.P1Pin07.Output(); using (var connection = new GpioConnection(led1)) { for (var i = 0; i < 100; i++) { Console.Write("."); connection.Toggle(led1); System.Threading.Thread.Sleep(2000); } connection.Close(); } }