public static ReservePin ( |
||
pin | ||
fReserve | bool | |
Результат | bool |
/// <summary> /// Build an instance of the PWM type /// </summary> /// <param name="channel">The channel</param> /// <param name="period">The period of the pulse</param> /// <param name="duration">The duration of the pulse. The value should be a fraction of the period</param> /// <param name="scale">The scale factor for the period/duration (nS, uS, mS)</param> /// <param name="invert">Whether the output should be inverted or not</param> public PWM(Cpu.PWMChannel channel, uint period, uint duration, ScaleFactor scale, bool invert) { HardwareProvider hwProvider = HardwareProvider.HwProvider; if (hwProvider == null) { throw new InvalidOperationException(); } m_pin = hwProvider.GetPwmPinForChannel(channel); m_channel = channel; //--// m_period = period; m_duration = duration; m_scale = scale; m_invert = invert; //--// try { Init(); Commit(); Port.ReservePin(m_pin, true); } catch { Dispose(false); } }
//--// /// <summary> /// Build an instance of the PWM type /// </summary> /// <param name="channel">The channel to use</param> /// <param name="frequency_Hz">The frequency of the pulse in Hz</param> /// <param name="dutyCycle">The duty cycle of the pulse as a fraction of unity. Value should be between 0.0 and 1.0</param> /// <param name="invert">Whether the output should be inverted or not</param> public PWM(Cpu.PWMChannel channel, double frequency_Hz, double dutyCycle, bool invert) { HardwareProvider hwProvider = HardwareProvider.HwProvider; if (hwProvider == null) { throw new InvalidOperationException(); } m_pin = hwProvider.GetPwmPinForChannel(channel); m_channel = channel; //--// m_period = PeriodFromFrequency(frequency_Hz, out m_scale); m_duration = DurationFromDutyCycleAndPeriod(dutyCycle, m_period); m_invert = invert; //--// try { Init(); Commit(); Port.ReservePin(m_pin, true); } catch { Dispose(false); } }
//--// public I2CDevice(Configuration config) { this.Config = config; HardwareProvider hwProvider = HardwareProvider.HwProvider; if (hwProvider != null) { Cpu.Pin scl; Cpu.Pin sda; hwProvider.GetI2CPins(out scl, out sda); if (scl != Cpu.Pin.GPIO_NONE) { Port.ReservePin(scl, true); } if (sda != Cpu.Pin.GPIO_NONE) { Port.ReservePin(sda, true); } } Initialize(); m_disposed = false; }
private void Dispose(bool fDisposing) { if (!m_disposed) { try { HardwareProvider hwProvider = HardwareProvider.HwProvider; if (hwProvider != null) { Cpu.Pin scl; Cpu.Pin sda; hwProvider.GetI2CPins(out scl, out sda); if (scl != Cpu.Pin.GPIO_NONE) { Port.ReservePin(scl, false); } if (sda != Cpu.Pin.GPIO_NONE) { Port.ReservePin(sda, false); } } } finally { m_disposed = true; } } }
//--// /// <summary> /// Builds an instance of AnalogOutput type for the specified channel /// </summary> /// <param name="channel">The channel for the AnalogOutput</param> /// <param name="scale">A multiplicative factor to apply to the value written to the sensor</param> /// <param name="offset">A constant factor to add to the value written to the sensor</param> /// <param name="precisionInBits">The desired bit precision for the D/A conversion. A value of -1 indicates default precision.</param> public AnalogOutput(Cpu.AnalogOutputChannel channel, double scale, double offset, int precisionInBits) { m_channel = channel; HardwareProvider hwProvider = HardwareProvider.HwProvider; if (hwProvider == null) { throw new InvalidOperationException(); } m_pin = hwProvider.GetAnalogOutputPinForChannel(channel); m_scale = scale; m_offset = offset; int[] availablePrecisions = hwProvider.GetAvailableAnalogOutputPrecisionInBitsForChannel(channel); if (precisionInBits == -1) { if (availablePrecisions.Length == 0) { throw new InvalidOperationException(); } m_precision = availablePrecisions[0]; } else { bool found = false; foreach (int precision in availablePrecisions) { if (precisionInBits == precision) { m_precision = precision; found = true; break; } } if (!found) { throw new ArgumentException(); } } bool fReserved = false; try { lock (s_syncRoot) { fReserved = Port.ReservePin(m_pin, true); Initialize(channel, m_precision); } } catch { if (fReserved) { Port.ReservePin(m_pin, false); } throw; } }
//--// protected void Dispose(bool disposing) { try { Stop(); } catch { // hide all exceptions... } finally { Uninit(); Port.ReservePin(m_pin, false); } }
private void Dispose(bool fDisposing) { if (!m_disposed) { try { HardwareProvider hwProvider = HardwareProvider.HwProvider; if (hwProvider != null) { Cpu.Pin msk; Cpu.Pin miso; Cpu.Pin mosi; hwProvider.GetSpiPins(m_config.SPI_mod, out msk, out miso, out mosi); if (msk != Cpu.Pin.GPIO_NONE) { Port.ReservePin(msk, false); } if (miso != Cpu.Pin.GPIO_NONE) { Port.ReservePin(miso, false); } if (mosi != Cpu.Pin.GPIO_NONE) { Port.ReservePin(mosi, false); } } if (m_config.ChipSelect_Port != Cpu.Pin.GPIO_NONE) { m_cs.Dispose(); } } finally { m_disposed = true; } } }
//--// public SPI(Configuration config) { HardwareProvider hwProvider = HardwareProvider.HwProvider; if (hwProvider != null) { Cpu.Pin msk; Cpu.Pin miso; Cpu.Pin mosi; hwProvider.GetSpiPins(config.SPI_mod, out msk, out miso, out mosi); if (msk != Cpu.Pin.GPIO_NONE) { Port.ReservePin(msk, true); } if (miso != Cpu.Pin.GPIO_NONE) { Port.ReservePin(miso, true); } if (mosi != Cpu.Pin.GPIO_NONE) { Port.ReservePin(mosi, true); } } //if (config.ChipSelect_Port != Cpu.Pin.GPIO_NONE) //{ // //m_cs = new OutputPort(config.ChipSelect_Port, !config.ChipSelect_ActiveState); // Port.ReservePin(config.ChipSelect_Port, true); //} if (config.ChipSelect_Port != Cpu.Pin.GPIO_NONE) { Port.ReservePin(config.ChipSelect_Port, true); } m_config = config; m_disposed = false; }
private void Dispose(bool fDisposing) { Port.ReservePin(m_pin, false); Uninitialize(m_channel); }
private void Dispose(bool fDisposing) { Port.ReservePin(m_pin, false); }