public void On() { if (!_outputPin.Read()) { _outputPin.Write(true); } }
private void UpdateLineStatus(IGpioPin line, bool newStatus) { var oldStatus = line.Read(); // on when false , off when true if (oldStatus == newStatus) { line.Write(!newStatus); } }
/// <summary> /// Reads the current state of the given pin. /// </summary> /// <param name="pin">The pin to read.</param> /// <returns>True if high, false is low.</returns> public static bool ReadDigital(IGpioPin gpioPin) { if (gpioPin.PinMode != GpioPinDriveMode.Input) { gpioPin.PinMode = GpioPinDriveMode.Input; } return(gpioPin.Read() == true); }
public IRIN(int pin) { Pi.Init <BootstrapWiringPi>(); mPin = pin; gpio = Pi.Gpio[mPin]; gpio.PinMode = GpioPinDriveMode.Input; mSignalVal = gpio.Read(); IRSensor = new InfraredSensor(gpio, true); }
private void HandleInterrupt() { if (_gpioPin.Read()) { HandleButtonPressed(); } else { HandleButtonReleased(); } }
public void wait_until_idle() { // The python loop is "while(epdconfig.digital_read(self.busy_pin) == 0): # 0: idle, 1: busy" // Which doesn't make sense if you loop while it's idle ??? //Console.WriteLine($"[Waituntilidle] Pin Number B{busypin.BcmPinNumber}/{busypin.PhysicalPinNumber} Status : {busypin.Read()} "); while (busypin.Read() != true) { System.Threading.Thread.Sleep(100); //delay(100); } //Console.WriteLine($"[Waituntilidle] no longer busy"); }
private void HandleInterrupt() { var val = _gpioPin.Read(); if ((val && _gpioPin.InputPullMode == GpioPinResistorPullMode.PullDown) || (!val && _gpioPin.InputPullMode == GpioPinResistorPullMode.PullUp)) { HandleButtonPressed(); } else { HandleButtonReleased(); } }
private UInt32 ExpectPulse(GpioPinValue level) { UInt32 count = 0; while (_dataPin.Read() == (level == GpioPinValue.High)) { count++; //WaitMicroseconds(1); if (count == 10000) { return(0); } } return(count); }
private byte RecvByte() { byte @byte = 0x00; for (var i = 0; i < 8; i++) { ClkPin.Write(true); @byte = unchecked ((Byte)(@byte << 1)); if (MisoPin.Read()) { @byte = (byte)(@byte | 0x1); } ClkPin.Write(false); } return(@byte); }
public static void InvertLedSignal() { if (_initDone == false) { Init(); } var isOn = _blinkingPin.Read(); if (isOn) { _blinkingPin.Write(false); } else { _blinkingPin.Write(true); } }
/// <summary> /// Initializes a new instance of the <see cref="LogicProbe"/> class. /// </summary> /// <param name="inputPin">The input pin.</param> public LogicProbe(IGpioPin inputPin) { _inputPin = inputPin; _inputPin.PinMode = GpioPinDriveMode.Input; _inputPin.InputPullMode = GpioPinResistorPullMode.PullUp; _inputPin.RegisterInterruptCallback(EdgeDetection.FallingAndRisingEdge, () => { if (_timer.IsRunning == false) { return; } var value = _inputPin.Read(); var elapsed = _timer.ElapsedMicroseconds; var data = new ProbeDataEventArgs(elapsed, value); ProbeDataAvailable?.Invoke(this, data); }); }
public bool GetLineStatus(int lineNr) { switch (lineNr) { case 1: return(!_line1.Read()); case 2: return(!_line2.Read()); case 3: return(!_line3.Read()); case 4: return(!_line4.Read()); default: throw new Exception($"Not implemented line {lineNr}"); } }
public void updateSignal() { mSignalVal = gpio.Read(); }
public async void ReadGPIO() { try { if (DeviceReady) { GpioPinValue pin17Status = pin17.Read(); if (pin17Status.ToString() != oldStatusPin17) { stateChange++; if (stateChange == 1) { dt1 = DateTime.Now; //Nouveau front //Console.WriteLine("dt1 : " + dt1.ToString()); } oldStatusPin17 = pin17Status.ToString(); //Console.WriteLine("GPIO 17 state change : " + pin17Status.ToString()); if (stateChange == 2) //on a eu un retour d'état donc un Low High Low (ou High Low High) { DateTime dt2 = DateTime.Now; //Console.WriteLine("dt2 : " + dt2.ToString()); TimeSpan spanElapsed = dt2.Subtract(dt1); //Console.WriteLine("Time elapsed between states : " + spanElapsed.TotalMilliseconds.ToString()); if (spanElapsed.TotalMilliseconds > antiRebond) { Console.WriteLine("GPIO 17 counter +1. signal duration : " + spanElapsed.TotalMilliseconds.ToString() + "ms"); counter++; await connection.InvokeAsync("CounterUpdate", counter.ToString()); } else { Console.WriteLine("GPIO 17 bounce detected " + spanElapsed.TotalMilliseconds.ToString() + "ms < " + antiRebond.ToString() + "ms"); } stateChange = 0; //init dt1 = DateTime.Now; //init } } } else { Console.WriteLine("Device is not ready"); } } catch (Exception ex) { Console.WriteLine("ReadGPIO Error : " + ex.Message); } // finally // { // if(pin17 != null) // pin17.Dispose(); // if(pin22 != null) // pin22.Dispose(); // } }
private double ReadTemp(int pidId) { var csPin = pidId == 0 ? CsPin1 : CsPin2; // // b10000000 = 0x80 // 0x8x to specify 'write register value' // 0xx0 to specify 'configuration register' // // 0b10110010 = 0xB2 // Config Register // --------------- // bit 7: Vbias -> 1 (ON) // bit 6: Conversion Mode -> 0 (MANUAL) // bit5: 1-shot ->1 (ON) // bit4: 3-wire select -> 1 (3 wire config) // bits 3-2: fault detection cycle -> 0 (none) // bit 1: fault status clear -> 1 (clear any fault) // bit 0: 50/60 Hz filter select -> 0 (60Hz) // // 0b11010010 or 0xD2 for continuous auto conversion // at 60Hz (faster conversion) // //one shot WriteRegister(0x00, 0xB2, csPin); // conversion time is less than 100ms Thread.Sleep(100); // read all registers var myOut = ReadRegisters(0, 8, csPin); string[] b = myOut.Select(x => Convert.ToString(x, 2).PadLeft(8, '0')).ToArray(); var conf_reg = myOut[0]; //_logger.LogInformation("config register byte: %x%", conf_reg); var rtd_msb = myOut[1]; var rtd_lsb = myOut[2]; var rtd_ADC_Code = ((rtd_msb << 8) | rtd_lsb) >> 1; var temp_C = CalcPT100Temp(rtd_ADC_Code); var hft_msb = myOut[3]; var hft_lsb = myOut[4]; var hft = ((hft_msb << 8) | hft_lsb) >> 1; //_logger.LogInformation("high fault threshold: %d", hft); var lft_msb = myOut[5]; var lft_lsb = myOut[6]; var lft = ((lft_msb << 8) | lft_lsb) >> 1; //_logger.LogInformation("low fault threshold:{0}", lft); var status = myOut[7]; // // 10 Mohm resistor is on breakout board to help // detect cable faults // bit 7: RTD High Threshold / cable fault open // bit 6: RTD Low Threshold / cable fault short // bit 5: REFIN- > 0.85 x VBias -> must be requested // bit 4: REFIN- < 0.85 x VBias (FORCE- open) -> must be requested // bit 3: RTDIN- < 0.85 x VBias (FORCE- open) -> must be requested // bit 2: Overvoltage / undervoltage fault // bits 1,0 don't care //print "Status byte: %x" % status if ((status & 0x80) == 1) { throw new Exception("High threshold limit (Cable fault/open)"); } if ((status & 0x40) == 1) { throw new Exception("Low threshold limit (Cable fault/short)"); } if ((status & 0x04) == 1) { throw new Exception("Overvoltage or Undervoltage Error"); } _logger.LogInformation($"Temp: {temp_C}°C"); TempReadHeartbeat.Write(!TempReadHeartbeat.Read()); return(temp_C); }
private static async Task <(double humidity, double tempature)> ReadSensorData(IGpioPin dataPin, CancellationToken token) { dataPin.PinMode = GpioPinDriveMode.Output; dataPin.Write(GpioPinValue.High); await Task.Delay(25, token); dataPin.Write(GpioPinValue.Low); dataPin.PinMode = GpioPinDriveMode.Input; dataPin.InputPullMode = GpioPinResistorPullMode.PullUp; await Task.Delay(27, token); if (dataPin.Read() == false) // make sure the sensor is there { while (!dataPin.Read()) // Wait for data high { } uint data = 0; byte crc = 0; for (int i = 0; i < 32; i++) { while (dataPin.Read()) // Data Clock Start { } while (!dataPin.Read()) // Data Start { } await Task.Delay(32, token); data *= 2; if (dataPin.Read()) { data++; } } for (int i = 0; i < 8; i++) { while (dataPin.Read()) // Data Clock Start { } while (!dataPin.Read()) // Data Start { } await Task.Delay(32, token); crc *= 2; if (dataPin.Read()) { crc++; } } return((double)(data >> 16) / 256, (double)(data & 0xffff) / 256); } else { return(default, default);