public ButtonConnection(IController contoller) { log.Debug(m => m("Init button connection")); var toggleBtn = ConnectorPin.P1Pin12.Input().PullDown(); var backBtn = ConnectorPin.P1Pin16.Input().PullDown(); var nextBtn = ConnectorPin.P1Pin18.Input().PullDown(); // toggle toggleBtn.OnStatusChanged(state => { if (state) contoller.TogglePlay(); }); // next nextBtn.OnStatusChanged(state => { if (state) contoller.PlayNext(); }); // previous backBtn.OnStatusChanged(state => { if (state) contoller.PlayPrevious(); }); // open connection _gpioConnection = new GpioConnection(toggleBtn, backBtn, nextBtn); }
public void Initialize() { _pinConfiguration = Pin.Input().OnStatusChanged(s => { RaiseOnPressedEvent(null); }); _connection = new GpioConnection(_pinConfiguration); }
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 RaspiAtxConnection(IController controller, IGpioConnectionDriver driver) { // set boot ok pin _bookOkPin = ConnectorPin.P1Pin11.Output().Revert(); // listen to shutdown gpio var shutdownPin = ConnectorPin.P1Pin13 .Input() .PullDown() .OnStatusChanged(state => { if (state) { log.Info(m => m("Shutdown triggered by RaspiAtx")); controller.Shutdown(); } }); // connect on/off button trigger pin _triggerOnOffButtonPin = driver.Out(ConnectorPin.P1Pin32); // open connection _gpioConnection = new GpioConnection(_bookOkPin, shutdownPin); }
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); }
static void Main(string[] args) { var left1 = ConnectorPin.P1Pin26.Output(); var left2 = ConnectorPin.P1Pin21.Output(); var right1 = ConnectorPin.P1Pin24.Output(); var right2 = ConnectorPin.P1Pin19.Output(); var ultrasonic = ConnectorPin.P1Pin08.Input(); var servoBase = ConnectorPin.P1Pin22.Output(); var servoPitch = ConnectorPin.P1Pin18.Output(); var leftMotor = ConnectorPin.P1Pin07.Input().OnStatusChanged(b => Evt("Left Motor", b)); var rightMotor = ConnectorPin.P1Pin11.Input().OnStatusChanged(b => Evt("Right Motor", b)); var irLeft = ConnectorPin.P1Pin12.Input().OnStatusChanged(b => Evt("Left IR", b)); var irRight = ConnectorPin.P1Pin13.Input().OnStatusChanged(b => Evt("Right IR", b)); var lineLeft = ConnectorPin.P1Pin16.Input().OnStatusChanged(b => Evt("Left Line", b)); var lineRight = ConnectorPin.P1Pin15.Input().OnStatusChanged(b => Evt("Right Line", b)); var connection = new GpioConnection(left1, left2, right1, right2, irLeft, irRight, lineLeft, lineRight, leftMotor, rightMotor, servoBase, servoPitch, ultrasonic); connection.Open(); var p = Process.Start("/usr/bin/servod", "--pcm --p1pins=22,18 --min=50 --max=250 --idle-timeout=500ms"); p.WaitForExit(); var cmd = Process.Start("/bin/bash", "-c 'echo 0=125 > /dev/servoblaster'"); if (cmd != null) { cmd.WaitForExit(); } var cmd2 = new Process(); cmd2.StartInfo.FileName = "/usr/bin/python"; cmd2.StartInfo.Arguments = "Ultrasonic.py"; cmd2.StartInfo.RedirectStandardOutput = true; cmd2.StartInfo.UseShellExecute = false; cmd2.Start(); cmd2.WaitForExit(); Console.WriteLine(cmd2.StandardOutput.ReadToEnd()); /*connection[left1] = true; connection[left2] = false; connection[right1] = true; connection[right2] = false;*/ Thread.Sleep(5000); /*connection[left1] = false; connection[left2] = false; connection[right1] = false; connection[right2] = false;*/ connection.Close(); Process.Start("/usr/bin/killall", "servod"); }
public LedsController() { pins = new Dictionary<ushort, OutputPinConfiguration> { { 23, ProcessorPin.Pin23.Output() }, { 24, ProcessorPin.Pin24.Output() } }; connection = new GpioConnection(pins[23], pins[24]); }
public AmplifierConnection() { log.Debug(m => m("Init amplifier connection")); // connect volume via i2c _i2cDriver = new I2cDriver(ProcessorPin.Pin2, ProcessorPin.Pin3); _connection = _i2cDriver.Connect(0x4b); // connect shutdown via gpio _shutdownPin = ConnectorPin.P1Pin36.Output().Revert(); _gpioConnection = new GpioConnection(_shutdownPin); }
static void Main(string[] args) { var led1 = ConnectorPin.P1Pin18.Output(); //This is Pin 24 on the Pi var connection = new GpioConnection(led1); for(var i=0; i<100; i++) { Console.WriteLine(i); connection.Toggle(led1); System.Threading.Thread.Sleep(250); } connection.Close(); }
public clsRinger(OutputPinConfiguration RingerPower, OutputPinConfiguration RingerOscillator, float[] RingPattern = null) { if (RingPattern==null) RingPattern = ringPattern_UK; ringPattern = RingPattern; RingerPowerPin = RingerPower; RingerOscillatorPin = RingerOscillator; var GPIOconfig = new GpioConnectionSettings(); GPIO = new GpioConnection(GPIOconfig,RingerPowerPin,RingerOscillatorPin); RingerThread = new Thread(Ring); RingerThread.IsBackground = true; RingerThread.Name = "Ringer Thread"; }
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(); }
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(); } }
static StatusLED() { try { RED_PIN = ConnectorPin.P1Pin12.Output(); GREEN_PIN = ConnectorPin.P1Pin16.Output(); BLUE_PIN = ConnectorPin.P1Pin21.Output(); pins = new OutputPinConfiguration[3]; pins [0] = RED_PIN; pins [1] = GREEN_PIN; pins [2] = BLUE_PIN; cnx = new GpioConnection(pins); cnx.Open(); } catch { } }
public CommandExecuter(Settings setting) { this.setting = setting; servo = new ProcessStartInfo("/bin/bash"); servo.UseShellExecute = false; servo.CreateNoWindow = true; servo.RedirectStandardOutput = true; servo.RedirectStandardError = true; #if !DEBUG pin1 = ConnectorPin.P1Pin38.Output(); pin2 = ConnectorPin.P1Pin40.Output(); connection = new GpioConnection(pin1, pin2); #endif }
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(); }
public FlowMeter(InputPinConfiguration pin) { pinChange = lastPinChange; flowSensorPin = pin; try { cn = new GpioConnection(pin); cn.PinStatusChanged += PinStatusChanged; } catch (Exception ex) { Console.WriteLine("Failed To Create FlowController"); Console.WriteLine(ex.ToString()); } }
public RaspPiGpioNode() { // GPIO init hardware interface gpioPinsConnection = new GpioConnection(); foreach (var x in GpioToPin) { gpioPinsConnection.Add(x.Value.Output()); } if (!gpioPinsConnection.IsOpened) { gpioPinsConnection.Open(); } // Done DebugEx.TraceLog("RaspberryPIGPIO plugin up and running !! "); }
public Sda5708Connection(ProcessorPin load, ProcessorPin data, ProcessorPin sdclk, ProcessorPin reset) { this._load = load; this._data = data; this._sdclk = sdclk; this._reset = reset; this._baseConnection = new GpioConnection ( load.Output (), data.Output (), sdclk.Output (), reset.Output ()); this._baseConnection [reset] = false; this._baseConnection [reset] = false; Thread.Sleep (50); this._baseConnection [reset] = true; this.Clear(); }
static void Main(string[] args) { var pin1 = ConnectorPin.P1Pin22.Input(); var driver = new GpioConnectionDriver(); var settings = new GpioConnectionSettings(); settings.Driver = driver; using (var hans = new GpioConnection(settings)) { hans.Add(pin1); while (true) { Console.WriteLine(settings.Driver.Read(pin1.Pin)); Thread.Sleep(100); } } }
static void Main(string[] args) { try { var driver = args.GetDriver(); var mainboard = Board.Current; if (!mainboard.IsRaspberryPi) { Console.WriteLine("'{0}' is not a valid processor for a Raspberry Pi.", mainboard.Processor); return; } // Declare outputs (leds) var leds = new PinConfiguration[] { ConnectorPin.P1Pin26.Output().Name("Led1").Enable(), ConnectorPin.P1Pin24.Output().Name("Led2"), ConnectorPin.P1Pin22.Output().Name("Led3").Enable(), ConnectorPin.P1Pin15.Output().Name("Led4"), ConnectorPin.P1Pin13.Output().Name("Led5").Enable(), ConnectorPin.P1Pin11.Output().Name("Led6") }; // Assign a behavior to the leds var behavior = new ChaserBehavior(leds) { Loop = args.GetLoop(), RoundTrip = args.GetRoundTrip(), Width = args.GetWidth(), Interval = args.GetSpeed() }; // Alternate behaviors... /* var random = new Random(); var behavior = new PatternBehavior(leds, Enumerable.Range(0, 5).Select(i => random.Next(511))) { Loop = Helpers.GetLoop(args), RoundTrip = Helpers.GetRoundTrip(args), Interval = Helpers.GetSpeed(args) };*/ /* var behavior = new BlinkBehavior(leds) { Count = args.GetWidth(), Interval = args.GetSpeed() };*/ // Declare input (switchButton) interacting with the leds behavior var switchButton = ConnectorPin.P1Pin03.Input() .Name("Switch") .Revert() .Switch() .Enable() .OnStatusChanged(b => { behavior.RoundTrip = !behavior.RoundTrip; Console.WriteLine("Button switched {0}", b ? "on" : "off"); }); // Create connection Console.WriteLine("Running on Raspberry firmware rev{0}, board rev{1}, processor {2}", mainboard.Firmware, mainboard.Revision, mainboard.Processor); var settings = new GpioConnectionSettings {Driver = driver}; using (var connection = new GpioConnection(settings, leds)) { Console.WriteLine("Using {0}, frequency {1:0.##}hz", settings.Driver.GetType().Name, 1000.0/args.GetSpeed()); Thread.Sleep(1000); connection.Add(switchButton); connection.Start(behavior); // Starting the behavior automatically registers the pins to the connection, if needed. Console.ReadKey(true); connection.Stop(behavior); } } catch(Exception ex) { var currentException = ex; while (currentException != null) { Console.WriteLine("{0}: {1}", currentException.GetType().Name, currentException.Message); currentException = currentException.InnerException; } } }
private static void TestLEDs() { Console.WriteLine("Test GPIO"); var led1 = ConnectorPin.P1Pin31.Output(); var led2 = ConnectorPin.P1Pin33.Output(); var led3 = ConnectorPin.P1Pin35.Output(); var led4 = ConnectorPin.P1Pin37.Output(); var connection = new GpioConnection(led1, led2, led3, led4); for (int i = 0; i < 5; i++) { connection.Blink(led1, new TimeSpan(0, 0, 1)); connection.Blink(led2, new TimeSpan(0, 0, 1)); connection.Blink(led3, new TimeSpan(0, 0, 1)); connection.Blink(led4, new TimeSpan(0, 0, 1)); } connection.Close(); }
public FridgeController(int sensorPin, OutputPinConfiguration fridgePin, float lt, float ht) { HighTemp = ht; LowTemp = lt; this._fridgePin = fridgePin; try { _cnFridge = new GpioConnection(fridgePin); } catch (Exception ex) { Console.WriteLine("Failed To Create FridgeController"); Console.WriteLine(ex.ToString()); } }
static void Main(string[] args) { const ConnectorPin led1Pin = ConnectorPin.P1Pin26; const ConnectorPin led2Pin = ConnectorPin.P1Pin24; const ConnectorPin led3Pin = ConnectorPin.P1Pin22; const ConnectorPin led4Pin = ConnectorPin.P1Pin15; const ConnectorPin led5Pin = ConnectorPin.P1Pin13; const ConnectorPin led6Pin = ConnectorPin.P1Pin11; const ConnectorPin buttonPin = ConnectorPin.P1Pin03; Console.WriteLine("Chaser Sample: Sample a LED chaser with a switch to change behavior"); Console.WriteLine(); Console.WriteLine("\tLed 1: {0}", led1Pin); Console.WriteLine("\tLed 2: {0}", led2Pin); Console.WriteLine("\tLed 3: {0}", led3Pin); Console.WriteLine("\tLed 4: {0}", led4Pin); Console.WriteLine("\tLed 5: {0}", led5Pin); Console.WriteLine("\tLed 6: {0}", led6Pin); Console.WriteLine("\tSwitch: {0}", buttonPin); Console.WriteLine(); var driver = args.GetDriver(); // Declare outputs (leds) var leds = new PinConfiguration[] { led1Pin.Output().Name("Led1").Enable(), led2Pin.Output().Name("Led2"), led3Pin.Output().Name("Led3").Enable(), led4Pin.Output().Name("Led4"), led5Pin.Output().Name("Led5").Enable(), led6Pin.Output().Name("Led6") }; // Assign a behavior to the leds var behavior = new ChaserBehavior(leds) { Loop = args.GetLoop(), RoundTrip = args.GetRoundTrip(), Width = args.GetWidth(), Interval = TimeSpan.FromMilliseconds(args.GetSpeed()) }; // Alternate behaviors... /* var random = new Random(); var behavior = new PatternBehavior(leds, Enumerable.Range(0, 5).Select(i => random.Next(511))) { Loop = Helpers.GetLoop(args), RoundTrip = Helpers.GetRoundTrip(args), Interval = Helpers.GetSpeed(args) };*/ /* var behavior = new BlinkBehavior(leds) { Count = args.GetWidth(), Interval = args.GetSpeed() };*/ // Declare input (switchButton) interacting with the leds behavior var switchButton = buttonPin.Input() .Name("Switch") .Revert() .Switch() .Enable() .OnStatusChanged(b => { behavior.RoundTrip = !behavior.RoundTrip; Console.WriteLine("Button switched {0}", b ? "on" : "off"); }); // Create connection var settings = new GpioConnectionSettings {Driver = driver}; using (var connection = new GpioConnection(settings, leds)) { Console.WriteLine("Using {0}, frequency {1:0.##}hz", settings.Driver.GetType().Name, 1000.0/args.GetSpeed()); Thread.Sleep(1000); connection.Add(switchButton); connection.Start(behavior); // Starting the behavior automatically registers the pins to the connection, if needed. Console.ReadKey(true); connection.Stop(behavior); } }
private static void TestDriveCommands(string[] args) { Console.WriteLine("Testing drive commands"); if (args.Length <= 1) { Console.WriteLine("No commands provided"); } var connection = new GpioConnection(driveForward, driveBackward, driveTurnLeft, driveTurnRight); var command = ""; for (int i = 1; i < args.Length-1; i++) { command = args[i]; switch (command) { case "U": connection.Toggle(driveForward); System.Threading.Thread.Sleep(300); connection.Toggle(driveForward); break; case "D": connection.Toggle(driveBackward); System.Threading.Thread.Sleep(300); connection.Toggle(driveBackward); break; case "UL": connection.Toggle(driveForward); connection.Toggle(driveTurnLeft); System.Threading.Thread.Sleep(400); connection.Toggle(driveForward); connection.Toggle(driveTurnLeft); break; case "UR": connection.Toggle(driveForward); connection.Toggle(driveTurnRight); System.Threading.Thread.Sleep(400); connection.Toggle(driveForward); connection.Toggle(driveTurnRight); break; case "DL": connection.Toggle(driveBackward); connection.Toggle(driveTurnLeft); System.Threading.Thread.Sleep(400); connection.Toggle(driveBackward); connection.Toggle(driveTurnLeft); break; case "DR": connection.Toggle(driveBackward); connection.Toggle(driveTurnRight); System.Threading.Thread.Sleep(400); connection.Toggle(driveBackward); connection.Toggle(driveTurnRight); break; default: Console.WriteLine("Unknown command {0} Expected command to be one of U D UL UR DL DR", command); break; } } connection.Close(); }
internal ConnectedPin(GpioConnection connection, PinConfiguration pinConfiguration) { this.connection = connection; Configuration = pinConfiguration; }
internal ConnectedPins(GpioConnection connection) { this.connection = connection; }
public RaspNode(Transport transport) { // Hardware interface gpioPinsConnection = new GpioConnection(); foreach (var x in LedToPin) { gpioPinsConnection.Add(x.Value.Output()); } if (!gpioPinsConnection.IsOpened) { gpioPinsConnection.Open(); } // Node transport this.Transport = (transport != Transport.None) ? transport : Transport.YPCHANNEL; }
public static void Main() { Console.Title = "Raspberry-LED Domotica client"; if (!Helpers.IsLinux) { Console.WriteLine("Sorry, almost everything in this script can only run on the Raspberry Pi."); Console.WriteLine("Press enter to close the script."); Console.Read(); Environment.Exit(0); } Console.CancelKeyPress += delegate { Console.WriteLine("Stopping the program"); HubConnection.Closed -= StartHubConnection; HubConnection.Closed += null; HubConnection.Stop(); Console.WriteLine("Stopped SignalR communication"); for (var i = 0; i == 32;) { string str = $"gpio{i}"; if (Directory.Exists(Path.Combine("/sys/class/gpio", str))) { driver.Release((ProcessorPin) i); } i++; } gpio.Close(); Console.WriteLine("Stopped driver allocating"); Thread.Sleep(1000); Environment.Exit(0); }; // Connection to the signalr hub HubConnection = new HubConnection("http://192.168.1.100"); RaspberryHub = HubConnection.CreateHubProxy("Raspberry"); // If the server decides to close the connection we need to start it again HubConnection.Closed += StartHubConnection; // Starts the connection StartHubConnection(); gpio = new GpioConnection(); driver = new GpioConnectionDriver(); I2CDriver = new I2cDriver(ConnectorPin.P1Pin3.ToProcessor(), ConnectorPin.P1Pin5.ToProcessor()); ArduinoConnection = I2CDriver.Connect(0x04); var switchButton = ConnectorPin.P1Pin13.Input().Revert().OnStatusChanged(x => { Console.WriteLine(x); RaspberryHub.Invoke("SendChangedValue", ConnectorPin.P1Pin37, x ? "On" : "Off"); }); var doorSensor = ConnectorPin.P1Pin7.Input().PullUp().OnStatusChanged(x => { RaspberryHub.Invoke("SendChangedValue", ConnectorPin.P1Pin7, x ? "Open" : "Closed"); }); var motionSensor = ConnectorPin.P1Pin13.Input().OnStatusChanged(x => { RaspberryHub.Invoke("SendChangedValue", ConnectorPin.P1Pin11, x ? "Detected" : "Not detected"); Console.WriteLine( DateTime.Now + ":Motion {0}", x ? "Detected" : "Not detected"); }); // gpio.Add(switchButton); // gpio.Add(doorSensor); // gpio.Add(motionSensor); RaspberryHub.On<string>("ChangePiLed", pinnumber => { int ledid = int.Parse(pinnumber); var procpin = ((ConnectorPin) ledid).ToProcessor(); string str = string.Format("gpio{0}",procpin.ToString().Replace("Pin0","").Replace("Pin","")); if (!Directory.Exists(Path.Combine("/sys/class/gpio", str))) { Console.WriteLine($"OutputPin {procpin} is not allocated!\nAllocating now."); driver.Allocate(procpin, PinDirection.Output); Console.WriteLine("Pin allocated"); } driver.Write(procpin, !driver.Read(procpin)); RaspberryHub.Invoke("SendChangedValue", pinnumber, driver.Read(procpin) ? "On" : "Off"); }); RaspberryHub.On<string, string>("SetupConfig", (pinnumber, type) => { int pin = int.Parse(pinnumber); if (pin > 7) { Action<bool> onstatusaction = b => { RaspberryHub.Invoke("SendChangedValue", pin, driver.Read(((ConnectorPin) pin).ToProcessor()) ? "On" : "Off"); }; string str = string.Format("gpio{0}", ((ConnectorPin)pin).ToProcessor().ToString().Replace("Pin0", "").Replace("Pin", "")); Console.WriteLine(str); if (!Directory.Exists(Path.Combine("/sys/class/gpio", str))) { Console.WriteLine("Adding button"); var button = CreatePinConfig.CreateOutputPinConfiguration((ConnectorPin) pin, onstatusaction, "Button"); gpio.Add(button); } } }); RaspberryHub.On<int, string>("GetPinStatus", (pin, type) => { driver.Read(((ConnectorPin) pin).ToProcessor()); string status = string.Empty; if (type.Equals("Button")) { status = driver.Read(((ConnectorPin) pin).ToProcessor()) ? "Pressed" : "Not pressed"; } if (type.Equals("LED")) { status = driver.Read(((ConnectorPin) pin).ToProcessor()) ? "On" : "Off"; } if (type.Equals("Door sensor")) { status = driver.Read(((ConnectorPin)pin).ToProcessor()) ? "Open" : "Closed"; } RaspberryHub.Invoke("SendChangedValue", pin, status); }); ServerWorkThread objThread = new ServerWorkThread(); SendToArduino(1); while (true) { Thread.Sleep(50); ReadFromArduino(); //objThread.HandleConnection(objThread.mySocket.Accept()); } }