public void Initialize(bool isEnabledByDefault) { if (LightningProvider.IsLightningEnabled) { LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); } Gpio = GpioController.GetDefault(); if (Gpio == null) { return; } //set pins d0 and d1 as input data0 = Gpio.OpenPin(_d0); data0.SetDriveMode(GpioPinDriveMode.InputPullUp); data0.DebounceTimeout = debounceTimeout; data1 = Gpio.OpenPin(_d1); data1.SetDriveMode(GpioPinDriveMode.InputPullUp); data1.DebounceTimeout = debounceTimeout; IsEnabledChanged += OnIsEnabledChanged; IsEnabled = isEnabledByDefault; swReadingTimer = new Stopwatch(); Debug.WriteLine("Initialized", DEBUG_CAT); }
public void Set(GpioPin pin, bool state) { EnsurePinFunction(pin, GpioFunction.Output); PinStates[pin] = state; Gpio.Write(pin, state); }
public static void Main(string[] args) { Console.WriteLine("Hello Edison!"); var platform = Mraa.Mraa.GetPlatformType(); Gpio gpio; if (platform == Platform.INTEL_EDISON_FAB_C) { gpio = new Gpio(13); } else { throw new InvalidOperationException("Cannot support platform: " + platform.ToString()); } Console.WriteLine("Welcome to libmraa!\nVersion: {0}\nPlatform: {1}", Mraa.Mraa.GetVersion(), platform); gpio.Dir(Dir.DIR_OUT); var state = false; var value = default(int); while (true) { state = !state; value = Convert.ToInt32(state); gpio.Write(value); Thread.Sleep(1000); } }
private void SetupDemo1() { _ledToggleView = FindViewById <ToggleButton>(Resource.Id.ledToggle); try { _pin26 = _service.OpenGpio("BCM26"); _pin26.SetDirection(Gpio.DirectionOutInitiallyLow); } catch (IOException ex) { Log.Error(TAG, "Error during onCreate!", ex); } try { _ledToggleView.Checked = _pin26.Value; } catch (IOException ex) { Log.Error(TAG, "Error during setChecked!", ex); } _ledToggleView.CheckedChange += (sender, e) => { try { _pin26.Value = e.IsChecked; } catch (IOException ex) { Log.Error(TAG, "Error during onCheckedChanged!", ex); } }; }
public IActionResult View(Models.CreditPost creditPost) { if (creditPost.Key != "THISISKEY") { return(Ok("bad key")); } if (creditPost.Count < 0) { return(Ok("bad cnt")); } if (creditPost.Count > 10) { return(Ok("bad cnt")); } int res = Gpio.Coin(creditPost.Count); if (res == 0) { return(Ok("ok")); } if (res == -1) { return(Ok("in prog")); } throw new Exception("shouldn't be here"); }
public static void Main(string[] args) { Console.WriteLine(FtdiInventory.DeviceListInfo()); var ftDeviceInfo = FtdiInventory.GetDevices(); if (ftDeviceInfo.Length == 0) { Console.WriteLine("No Device"); Console.ReadKey(); return; } var firstSerial = ftDeviceInfo.FirstOrDefault().SerialNumber; MpsseDevice.MpsseParams mpsseParams = new MpsseDevice.MpsseParams { Latency = 16, ReadTimeout = 50, WriteTimeout = 50, clockDevisor = 49 * 6 }; using (MpsseDevice mpsse = new FT232H(firstSerial, mpsseParams)) { Console.WriteLine("MPSSE init success with clock frequency {0:0.0} Hz", mpsse.ClockFrequency); var i2c = new I2cBus(mpsse); var gpio = new Gpio(mpsse); Selector(i2c, gpio); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Log.Info(TAG, "Starting BlinkActivity"); var service = new PeripheralManagerService(); try { string pinName = BoardDefaults.GetGpioForLed(); _ledGpio = service.OpenGpio(pinName); _ledGpio.SetDirection(Gpio.DirectionOutInitiallyLow); Log.Info(TAG, "Start blinking LED GPIO pin"); Task.Run(() => { while (true) { _ledGpio.Value = !_ledGpio.Value; Log.Info(TAG, "State set to " + _ledGpio.Value); Thread.Sleep(100); } }); } catch (Exception e) { Log.Error(TAG, "Error on PeripheralIO API", e); } }
public GpioInterruptMonitor(Gpio gpio) { _gpio = gpio; // Started as pull up. _currentState = GpioState.High; }
public static void Main(string[] args) { using (var gpio = new Gpio(PinNaming.BCM)) { var sn74hc595 = new SN74HC595(gpio, 17, 27, 18); Console.WriteLine("Press any key to exit..."); bool fromHighToLow = false; while (!Console.KeyAvailable) { byte mask = 1; for (var i = 0; i < 8; i++) { sn74hc595.Send(mask, fromHighToLow); Thread.Sleep(500); mask = (byte)(mask << 1); } mask = 0x80; for (var i = 0; i < 8; i++) { sn74hc595.Send(mask, fromHighToLow); Thread.Sleep(500); mask = (byte)(mask >> 1); } for (var i = 0; i < 2; i++) { sn74hc595.Send(0xFF, fromHighToLow); Thread.Sleep(500); sn74hc595.Send(0x00, fromHighToLow); Thread.Sleep(500); } } } }
public BeagleGpioReader(BbbPort pPort, string pLabel = "undef", bool pInitialState = true, bool pInvertPolarity = false) { port = pPort; label = pLabel; oldState = pInitialState ? InputSensorState.High : InputSensorState.Low; invertPolarity = pInvertPolarity; gpio = new Gpio(BbbPort.P8_43, true, true); }
public void Dispose() { I2cDevice?.Dispose(); I2cDevice = null; Pwm?.Dispose(); Pwm = null; Gpio?.Dispose(); Gpio = null; }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the Gpio Settings as a human readable string /// </summary> /// <history> /// 01 Dec 16 Cynic - Started /// </history> public string GpioSettingsAsString() { StringBuilder sb = new StringBuilder(); sb.Append(Gpio.ToString()); sb.Append(", MuxMode=" + GpioMode.ToString()); return(sb.ToString()); }
public GameHandler(IEnumerable <Node> nodes, Gpio gpio, SerialPortStream serial, IController controller, IPathfinder pathfinder, IConfigurationManager configurationManager, HubConnection connection) { _controller = controller; _pathfinder = pathfinder; _configurationManager = configurationManager; _connection = connection; _nodes = nodes; _serial = serial; _gpio = gpio; }
public void LightsOff() { // Ignore if already off if (!IsLightOn) { return; } IsLightOn = false; Gpio.Write(HardwareAccess.RELAY_1, PinValue.Low); }
public void LightsOn() { // Ignore if already on if (IsLightOn) { return; } IsLightOn = true; Gpio.Write(HardwareAccess.RELAY_1, PinValue.High); }
private static void GpioTest(I2cBus i2c, Gpio gpio) { var timer = new System.Timers.Timer(); timer.Interval = 5; timer.Elapsed += (sender, args) => { gpio.Out0 = !gpio.Out0; gpio.Multiplex(); gpio.SetLowGpio(); }; timer.AutoReset = true; timer.Enabled = true; char keyChar = ' '; do { if (Console.KeyAvailable) { keyChar = Console.ReadKey().KeyChar; if (keyChar == '1') { gpio.Out0 = false; } if (keyChar == '2') { gpio.Out0 = true; } if (keyChar == '3') { gpio.Out1 = false; } if (keyChar == '4') { gpio.Out1 = true; } if (keyChar == '5') { gpio.Out2 = false; } if (keyChar == '6') { gpio.Out2 = true; } } Thread.Sleep(2); } while (keyChar != 'x'); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Log.Info(TAG, "Starting AlarmActivity"); var service = new PeripheralManagerService(); _alarm1Gpio = service.OpenGpio("IO8"); _buzzerGpio = service.OpenGpio("IO4"); _buzzerGpio.SetDirection(Gpio.DirectionOutInitiallyLow); ConfigureAlarmInput(); }
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()); }
public override bool OnGpioEdge(Gpio p0) { if (p0.Value) { if (!BuzzerPin.Value) { BuzzerPin.Value = true; Thread.Sleep(1000); BuzzerPin.Value = false; } } return(true); }
static void Main(string[] args) { Gpio gpio = new Gpio(Gpio.NumberingMode.Internal); WiringPi.WiringPiSetup(); while (true) { gpio.Write(PIN, PinValue.High); Thread.Sleep(500); gpio.Write(PIN, PinValue.Low); Thread.Sleep(500); } }
private static void TestInput() { using (var gpio = new Gpio(new ShellGpioInterface())) //using (var gpio = new Gpio(new SshGpioInterface("192.168.0.109"))) { Console.WriteLine("Connected Locally"); for (short i = 0; i < 8; i++) { var pin = gpio.NewInputPin(i); var i1 = i; pin.OnValueChanged += x => Console.WriteLine($"Pin {i1}: Changed to " + x); } Console.ReadKey(); } }
protected async Task <bool> RelaySingle(int pin = 0, int delayInMs = 8000) { if (!Gpio.GetOccupiedPins().output.Contains(pin)) { return(false); } SetGpioValue(pin, GpioPinMode.Output, GpioPinState.On); Logger.Log($"Waiting for {delayInMs} ms to close the relay..."); await Task.Delay(delayInMs).ConfigureAwait(false); SetGpioValue(pin, GpioPinMode.Output, GpioPinState.Off); Logger.Log("Relay closed!"); Logger.Info("Relay single test passed!"); return(true); }
private void SetupDemo2() { try { _pin21 = _service.OpenGpio("BCM21"); _pin21.SetDirection(Gpio.DirectionIn); _pin21.SetActiveType(Gpio.ActiveHigh); _pin21.SetEdgeTriggerType(Gpio.EdgeFalling); _pin21.RegisterGpioCallback(new ButtonCallback() { LedToggleView = _ledToggleView }); } catch (IOException ex) { Log.Error(TAG, "Error during onCreate!", ex); } }
/// <summary> /// Initial setup for RPIDriver /// Creates a copy of GPIO Pins /// </summary> public RPIDriver() { Log = new FileLogger(); try { //Same as WiringPiSetup GPIO = new Gpio(Gpio.NumberingMode.Broadcom); Log.Add($"Sucess! WiringPi setup in {GPIO.PinNumberingMode} mode"); Log.Add("PiBoard rev. = " + WiringPi.PiBoardRev().ToString()); //Export all pins UpdatePinStates(); //Initialize OUTInfos for (int i = 0; i < MAX_OUTPUTS; i++) { OUT[i].Name = $"OUT{i}"; OUT[i].SwitchStatus = 0; } //Initialize LEDInfos for (int i = 0; i < MAX_LEDS; i++) { LED[i].Name = $"LED{i}"; LED[i].LedStatus = 0; } //Initialize InputsInfos for (int i = 0; i < MAX_INPUTS; i++) { IN[i].Name = $"IN{i}"; IN[i].ADValue = new byte[] { 0, 0 }; IN[i].Range = (int)RANGES.V3_0; //Default is Thermistor as seen in c++ } //Initialize HSPInfos for (int i = 0; i < MAX_HSP_COUNTERS; i++) { HSP[i].Name = $"HSP{i}"; HSP[i].HSPValue = new byte[] { 0, 0, 0, 0 }; } } catch (Exception ex) { Log.Add("Error: Failed to initialize WiringPi"); Log.Add(ex.Message, false); throw ex; } }
private static void TestOutput() { using (var gpio = new Gpio(new ShellGpioInterface())) // using (var gpio = new Gpio(new SshGpioInterface("192.168.0.109"))) { Console.WriteLine("Connected"); for (short i = 0; i < 8; i++) { var pin = gpio.NewOutputPin(i); pin.On(); pin.Off(); } //var lcd4Pin = gpio.NewOutputPin(2, PinBase.LCD_D2); //lcd4Pin.On(); //lcd4Pin.Off(); } }
protected void InitializePins(Gpio gpio, bool restoreTags) { GpioPin[] pins = new GpioPin[MainClass.MAX_GPIO_NUMBER + 1]; for (int i = 0; i <= MainClass.MAX_GPIO_NUMBER; i++) { pins[i] = gpio.GetPin(i); if (restoreTags && tagsState.ContainsKey(pins[i].Number)) { pins[i].Tag = tagsState[pins[i].Number]; } WritePinState(pins[i]); } tagsState.Clear(); watcher = new PinWatcher(PIN_START_INTERVAL, pins); watcher.PinsStateChanged += PinsStateUpdate; watcher.Start(); }
public string SerializeState(int firstPin, int lastPin, Dictionary <int, string> tags = null) { List <GpioPin> pins = new List <GpioPin>(); using (Gpio gpio = new Gpio()) { for (int i = firstPin; i <= lastPin; i++) { GpioPin pin = gpio.GetPin(i); if (tags != null && tags.ContainsKey(pin.Number)) { pin.Tag = tags[pin.Number]; } pins.Add(pin); } } return(SerializeState(pins)); }
void EnsurePinFunction(GpioPin pin, GpioFunction function) { GpioFunction oldFunction; if (ConnectedPins.TryGetValue(pin, out oldFunction)) { if (oldFunction == function) { return; } ConnectedPins[pin] = function; } else { ConnectedPins.Add(pin, function); PinStates.Add(pin, false); } Gpio.SetFunction(pin, function); }
/// <summary> /// Basic Circuit with 1 LED /// </summary> private Circuit createTestCircuit01() { PowerSource threeVolt = new PowerSource(); TwoPinLED led = new TwoPinLED(); Gpio gpio = new Gpio(17); threeVolt.On(); // connect threevolt to anode threeVolt.AddRoute(threeVolt.PowerPin.PinId, led.Anode.PinId); // connect cathode to gpio led.AddRoute(led.Cathode.PinId, gpio.GpioPin.PinId); // no route needed at gpio (end node) // run through the circuit and try anurn each pin on return(new Circuit(threeVolt.NodeId, new List <Node> { threeVolt, led, gpio }, "TestCircuit")); }
public void ShutdownDriver() { if (PiController.GracefullShutdown) { foreach (int pin in Gpio.GetOccupiedPins().output) { GpioPinConfig?pinStatus = GetGpioConfig(pin); if (pinStatus == null) { continue; } if (pinStatus.IsPinOn) { SetGpioValue(pin, GpioPinMode.Output, GpioPinState.Off); Logger.Log($"Closed pin {pin} as part of shutdown process."); } } } }