/// <summary> /// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.IO.SPI.MCP3008"/> object. /// </summary> /// <remarks> /// Call <see cref="Dispose"/> when you are finished using the <see cref="CyrusBuilt.MonoPi.IO.SPI.MCP3008"/>. The /// <see cref="Dispose"/> method leaves the <see cref="CyrusBuilt.MonoPi.IO.SPI.MCP3008"/> in an unusable state. After /// calling <see cref="Dispose"/>, you must release all references to the <see cref="CyrusBuilt.MonoPi.IO.SPI.MCP3008"/> /// so the garbage collector can reclaim the memory that the <see cref="CyrusBuilt.MonoPi.IO.SPI.MCP3008"/> was occupying. /// </remarks> public void Dispose() { if (this._isDisposed) { return; } this._channel = AdcChannels.None; if (this._chipSelect != null) { this._chipSelect.Dispose(); this._chipSelect = null; } if (this._clock != null) { this._clock.Dispose(); this._clock = null; } if (this._masterInSlaveOut != null) { this._masterInSlaveOut.Dispose(); this._masterInSlaveOut = null; } if (this._masterOutSlaveIn != null) { this._masterOutSlaveIn.Dispose(); this._masterOutSlaveIn = null; } this._isDisposed = true; }
/// <summary> /// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.Components.Switches.ToggleSwitchComponent"/> /// object. /// </summary> /// <remarks> /// Call <see cref="Dispose"/> when you are finished using the /// <see cref="CyrusBuilt.MonoPi.Components.Switches.ToggleSwitchComponent"/>. The /// <see cref="Dispose"/> method leaves /// the <see cref="CyrusBuilt.MonoPi.Components.Switches.ToggleSwitchComponent"/> in an /// unusable state. After calling <see cref="Dispose"/>, you must release all references /// to the <see cref="CyrusBuilt.MonoPi.Components.Switches.ToggleSwitchComponent"/> so /// the garbage collector can reclaim the memory that the /// <see cref="CyrusBuilt.MonoPi.Components.Switches.ToggleSwitchComponent"/> was occupying. /// </remarks> public override void Dispose() { lock (_syncLock) { this._isPolling = false; } if ((this._pollThread != null) && (this._pollThread.IsAlive)) { try { Thread.Sleep(50); this._pollThread.Abort(); } catch (ThreadAbortException) { Thread.ResetAbort(); } finally { this._pollThread = null; } } if (this._pin != null) { this._pin.Dispose(); this._pin = null; } base.Dispose(); }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.LED.TM16XXBase"/> /// class with the data pin, clock pin, strobe pin, the number of /// supported characters, activation flag, and intensity level. /// </summary> /// <param name="data"> /// The data pin. /// </param> /// <param name="clock"> /// The clock pin. /// </param> /// <param name="strobe"> /// The strobe pin. /// </param> /// <param name="displays"> /// The number of characters to display. /// </param> /// <param name="activate"> /// Set true to activate the display. /// </param> /// <param name="intensity"> /// The display intensity (brightness) level. /// </param> public TM16XXBase(IRaspiGpio data, IRaspiGpio clock, IRaspiGpio strobe, Int32 displays, Boolean activate, Int32 intensity) { this._data = data; this._data.Provision(); this._clock = clock; this._clock.Provision(); this._strobe = strobe; this._strobe.Provision(); // TODO What is the acceptable range? this._displays = displays; this._strobe.Write(PinState.High); this._clock.Write(PinState.High); // TODO What is the acceptable range of "intensity"? this.SendCommand(0x40); this.SendCommand((Byte)(0x80 | (activate ? 0x08 : 0x00) | Math.Min(7, intensity))); this._strobe.Write(PinState.Low); this.Send(0xC0); for (Int32 i = 0; i < 16; i++) { this.Send(0x00); } this._strobe.Write(PinState.High); }
/// <summary> /// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.RTC.DS1302"/> /// object. /// </summary> /// <remarks>Call <see cref="Dispose"/> when you are finished using the /// <see cref="CyrusBuilt.MonoPi.RTC.DS1302"/>. The <see cref="Dispose"/> /// method leaves the <see cref="CyrusBuilt.MonoPi.RTC.DS1302"/> in an /// unusable state. After calling <see cref="Dispose"/>, you must release /// all references to the <see cref="CyrusBuilt.MonoPi.RTC.DS1302"/> /// so the garbage collector can reclaim the memory that the /// <see cref="CyrusBuilt.MonoPi.RTC.DS1302"/> was occupying. /// </remarks> public void Dispose() { if (this._isDisposed) { return; } if (this._clockPin != null) { this._clockPin.Write(PinState.Low); this._clockPin.Dispose(); this._clockPin = null; } if (this._dataPin != null) { this._dataPin.Write(PinState.Low); this._dataPin.Dispose(); this._dataPin = null; } if (this._csPin != null) { this._csPin.Write(PinState.Low); this._csPin.Dispose(); this._csPin = null; } this._isDisposed = true; }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Switches.ToggleSwitchComponent"/> /// class with the pin the switch is wired to. /// </summary> /// <param name="pin"> /// The input pin to check switch state on. /// </param> public ToggleSwitchComponent(IRaspiGpio pin) : base() { if (pin == null) { throw new ArgumentNullException("pin"); } this._pin = pin; this._pin.Provision(); this._pin.StateChanged += this.OnStateChanged; }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Devices.RCSwitch.RCSwitchDevice"/> /// class with the pin to use to transmit codes with. /// </summary> /// <param name="transmitPin"> /// The native pin to use to transmit codes. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="transmitPin"/> cannot be null. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="transmitPin"/> is not an output pin. /// </exception> public RCSwitchDevice(IRaspiGpio transmitPin) : base() { if (transmitPin == null) { throw new ArgumentNullException("pin"); } if (transmitPin.Mode != PinMode.OUT) { throw new ArgumentException("The specified pin is not an output.", "pin"); } this._txPin = transmitPin; this._txPin.Write(PinState.Low); }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.RTC.DS1302"/> /// class with the clock, data, and chip-select pins. /// </summary> /// <param name="clockPin"> /// The GPIO pin to use for the clock. /// </param> /// <param name="dataPin"> /// The GPIO pin to use for data. /// </param> /// <param name="csPin"> /// The GPIO pin to use for chip-select. /// </param> public DS1302(IRaspiGpio clockPin, IRaspiGpio dataPin, IRaspiGpio csPin) { this._clockPin = clockPin; this._clockPin.Provision(); this._dataPin = dataPin; this._dataPin.Provision(); this._csPin = csPin; this._csPin.Provision(); UnsafeNativeMethods.ds1302setup((Int32)this._clockPin.InnerPin, (Int32)this._dataPin.InnerPin, (Int32)this._csPin.InnerPin); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <filterpriority>2</filterpriority> /// <remarks>Call <see cref="Dispose"/> when you are finished using the /// <see cref="CyrusBuilt.MonoPi.Devices.RCSwitch.RCSwitchDevice"/>. The <see cref="Dispose"/> method leaves the /// <see cref="CyrusBuilt.MonoPi.Devices.RCSwitch.RCSwitchDevice"/> in an unusable state. After calling /// <see cref="Dispose"/>, you must release all references to the /// <see cref="CyrusBuilt.MonoPi.Devices.RCSwitch.RCSwitchDevice"/> so the garbage collector can reclaim the memory /// that the <see cref="CyrusBuilt.MonoPi.Devices.RCSwitch.RCSwitchDevice"/> was occupying.</remarks> public override void Dispose() { if (base.IsDisposed) { return; } if (this._txPin != null) { this._txPin.Dispose(); this._txPin = null; } base.Dispose(); }
/// <summary> /// Initializes a new instance of the /// <see cref="CyrusBuilt.MonoPi.Devices.CrystalFontzSerialLCD.CrystalFontz63xSerial"/> /// class with the GPIO pin to control the backlight with /// and the BAUD rate to negotiate with the display. /// </summary> /// <param name="backlightPin"> /// The GPIO pin to use to control the backlight. /// </param> /// <param name="baud"> /// The BAUD rate. /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// BAUD rate cannot be less than 2400 or greater than 19200. /// </exception> public CrystalFontz63xSerial(IRaspiGpio backlightPin, BaudRates baud) { this._baud = baud; if ((Int32)baud < 2400) { throw new ArgumentOutOfRangeException("baud", "Cannot be less than 2400 baud."); } if ((Int32)baud > 19200) { throw new ArgumentOutOfRangeException("baud", "Cannot be greater than 19200 baud."); } this._lcd = new Rs232SerialPort(baud); this._backlightPin = backlightPin; }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <filterpriority>2</filterpriority> /// <remarks>Call <see cref="Dispose"/> when you are finished using the /// <see cref="CyrusBuilt.MonoPi.Components.Power.GpioPowerComponent"/>. The <see cref="Dispose"/> method leaves the /// <see cref="CyrusBuilt.MonoPi.Components.Power.GpioPowerComponent"/> in an unusable state. After calling /// <see cref="Dispose"/>, you must release all references to the /// <see cref="CyrusBuilt.MonoPi.Components.Power.GpioPowerComponent"/> so the garbage collector can reclaim the /// memory that the <see cref="CyrusBuilt.MonoPi.Components.Power.GpioPowerComponent"/> was occupying.</remarks> public override void Dispose() { if (base.IsDisposed) { return; } if (this._output != null) { this._output.Dispose(); this._output = null; } base.Dispose(); }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.SPI.MCP3008"/> /// class the analog-to-digital channel, clock pin, SPI Master Output/ /// Slave Input (MOSI), SPI Master Input/Slave Output (MISO), and SPI /// chip select pin. /// </summary> /// <param name="channel"> /// MCP3008 channel number 0 - 7 (pin 1 -8 on chip). /// </param> /// <param name="spiclk"> /// SPI clock pin. /// </param> /// <param name="mosi"> /// Master Output, Slave Input (MOSI). /// </param> /// <param name="miso"> /// Master Input, Slave Output (MISO). /// </param> /// <param name="cs"> /// Chip Select pin. /// </param> public MCP3008(AdcChannels channel, IRaspiGpio spiclk, IRaspiGpio mosi, IRaspiGpio miso, IRaspiGpio cs) { this._channel = channel; this._clock = spiclk; this._clock.Provision(); this._masterOutSlaveIn = mosi; this._masterOutSlaveIn.Provision(); this._masterInSlaveOut = miso; this._masterInSlaveOut.Provision(); this._chipSelect = cs; this._chipSelect.Provision(); }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Servos.RPIServoBlasterDriver"/> /// class with the servo pin, the index of the pin in the servo provider's pin map, /// The name of the pin, and the servo provider. /// </summary> /// <param name="pin"> /// The pin the servo is attached to. /// </param> /// <param name="index"> /// The index of the pin in the servo provider's pin map. /// </param> /// <param name="pinName"> /// The name of the pin. /// </param> /// <param name="provider"> /// The servo provider. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="pin"/> cannot be null - or - /// <paramref name="pinName"/> cannot be null or empty - or - /// <paramref name="provider"/> cannot be null. /// </exception> public RPIServoBlasterDriver(IRaspiGpio pin, Int32 index, String pinName, RPIServoBlasterProvider provider) { if (pin == null) { throw new ArgumentNullException("pin"); } if (String.IsNullOrEmpty(pinName)) { throw new ArgumentNullException("pinName"); } if (provider == null) { throw new ArgumentNullException("provider"); } this._pin = pin; this._index = index; this._pinString = pinName; this._provider = provider; }
/// <summary> /// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.LED.TM16XXBase"/> object. /// </summary> /// <remarks> /// Call <see cref="Dispose"/> when you are finished using the <see cref="CyrusBuilt.MonoPi.LED.TM16XXBase"/>. The /// <see cref="Dispose"/> method leaves the <see cref="CyrusBuilt.MonoPi.LED.TM16XXBase"/> in an unusable state. After /// calling <see cref="Dispose"/>, you must release all references to the /// <see cref="CyrusBuilt.MonoPi.LED.TM16XXBase"/> so the garbage collector can reclaim the memory that the /// <see cref="CyrusBuilt.MonoPi.LED.TM16XXBase"/> was occupying. /// </remarks> public void Dispose() { this.ActivateDisplay(false); if (this._clock != null) { this._clock.Dispose(); this._clock = null; } if (this._data != null) { this._data.Dispose(); this._data = null; } if (this._strobe != null) { this._strobe.Dispose(); this._strobe = null; } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <filterpriority>2</filterpriority> /// <remarks>Call <see cref="Dispose"/> when you are finished using the /// <see cref="CyrusBuilt.MonoPi.Components.Servos.RPIServoBlasterDriver"/>. The <see cref="Dispose"/> method leaves /// the <see cref="CyrusBuilt.MonoPi.Components.Servos.RPIServoBlasterDriver"/> in an unusable state. After calling /// <see cref="Dispose"/>, you must release all references to the /// <see cref="CyrusBuilt.MonoPi.Components.Servos.RPIServoBlasterDriver"/> so the garbage collector can reclaim the /// memory that the <see cref="CyrusBuilt.MonoPi.Components.Servos.RPIServoBlasterDriver"/> was occupying.</remarks> public void Dispose() { if (this._isDisposed) { return; } if (this._provider != null) { this._provider.Dispose(); this._provider = null; } if (this._pin != null) { this._pin.Dispose(); this._pin = null; } this._isDisposed = true; }
/// <summary> /// Releases all resource used by the /// <see cref="CyrusBuilt.MonoPi.Devices.CrystalFontzSerialLCD.CrystalFontz63xSerial"/> object. /// </summary> /// <param name="disposing"> /// If set to <c>true</c> disposing. /// </param> private void Dispose(Boolean disposing) { if (this._isDisposed) { return; } if (disposing) { if (this._lcd != null) { this._lcd.Dispose(); this._lcd = null; } if (this._backlightPin != null) { this._backlightPin.Dispose(); this._backlightPin = null; } } this._isDisposed = true; }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Power.GpioPowerComponent"/> /// class with the GPIO pin that will be used to control the component /// and the pin states that will be used to consider the device on or off. /// </summary> /// <param name="pin"> /// The GPIO pin that will be used to control the component. /// </param> /// <param name="onState"> /// The pin state to consider the device "on". /// </param> /// <param name="offState"> /// The pin state to consider the device "off". /// </param> public GpioPowerComponent(IRaspiGpio pin, PinState onState, PinState offState) : this(pin) { this._onState = onState; this._offState = offState; }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Power.GpioPowerComponent"/> /// class with the GPIO pin that will be used to control the component. /// </summary> /// <param name="pin"> /// The GPIO pin that will be used to control the component. /// </param> public GpioPowerComponent(IRaspiGpio pin) : base() { this._output = pin; this._output.StateChanged += Output_StateChanged; }
/// <summary> /// Helper method for adding pins to the pin maps. /// </summary> /// <param name="pin"> /// The pin to add to both pin maps. /// </param> /// <param name="name"> /// The pin name. /// </param> private static void DefinePin(IRaspiGpio pin, String name) { PIN_MAP.Add(pin, name); REVERSE_PIN_MAP.Add(name, pin); }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.LED.TM1638"/> /// class with the data pin, clock pin, strobe pin, a flag to set the /// display active, and the display intensity (brightness). /// </summary> /// <param name="data"> /// The data pin. /// </param> /// <param name="clock"> /// The clock pin. /// </param> /// <param name="strobe"> /// The strobe pin. /// </param> /// <param name="active"> /// Set true to activate the display. /// </param> /// <param name="intensity"> /// The display intensity (brightness). /// </param> public TM1638(IRaspiGpio data, IRaspiGpio clock, IRaspiGpio strobe, Boolean active, Byte intensity) : base(data, clock, strobe, 8, active, intensity) { }
/// <summary> /// Initializes a new instance of the /// <see cref="CyrusBuilt.MonoPi.Devices.CrystalFontzSerialLCD.CrystalFontz63xSerial"/> /// class with a GPIO pin to use to control the backlight. /// </summary> /// <param name="backlightPin"> /// The GPIO pin to use to control the backlight. /// </param> public CrystalFontz63xSerial(IRaspiGpio backlightPin) { this._lcd = new Rs232SerialPort(this._baud); this._backlightPin = backlightPin; }
/// <summary> /// Gets a list of servo pins from the config and validates them /// against the pin map. /// </summary> /// <returns> /// A list of servo pins read from the config. /// </returns> /// <exception cref="IOException"> /// An error occurred while trying to read the device config. /// </exception> private List <IPin> GetServoPinsFromConfig() { // Open the config for read access. List <IPin> servoPins = new List <IPin>(); using (StreamReader sr = new StreamReader(File.OpenRead(this._servoBlasterDevCfg.FullName))) { Int32 i = 0; Int32 index = -1; String pin = String.Empty; String p1pins = String.Empty; String p5pins = String.Empty; IRaspiGpio gpio = null; Boolean mappingStarted = false; // Process each line of the config. String line = sr.ReadLine(); while (line != null) { // Basically what we are doing here is reading // each of the pin definitions in the ServoBlaster // config to make sure the config matches our // pin map. If we find a pin that is not in the // pin map, then we throw an exception. if (mappingStarted) { line = line.Trim(); i = line.IndexOf(" on "); if (i > 0) { if (Int32.TryParse(line.Substring(0, i), out index)) { pin = line.Substring(i + 4).Trim(); i = pin.IndexOf(' '); pin = pin.Substring(0, i); if (REVERSE_PIN_MAP.TryGetValue(pin, out gpio)) { if (index == servoPins.Count) { servoPins.Add(gpio); } else if (index > servoPins.Count) { while (servoPins.Count < index) { servoPins.Add(null); } servoPins.Add(gpio); } else { servoPins[index] = gpio; } } else { this.OnUnrecognizedPinFound(new UnrecognizedPinFoundEventArgs("Unrecognized pin in ServoBlaster config: " + pin)); } } } } else { if ((line.StartsWith("p1pins=")) || (line.StartsWith("p5pins="))) { p1pins = line.Substring(7); } mappingStarted = line.Trim().Equals("Servo mapping:"); } line = sr.ReadLine(); } } return(servoPins); }