/// <summary> /// Create a new ADXL362 object using the specified SPI module. /// </summary> /// <param name="module">SPI module to use.</param> /// <param name="chipSelect">Chip select pin.</param> /// <param name="speed">Speed of the SPI bus.</param> public ADXL362(Spi.SPI_module module, IDigitalPin chipSelect, ushort speed = 10) { // // ADXL362 works in SPI mode 0 (CPOL = 0, CPHA = 0). // _adxl362 = new SPIBus(module, chipSelect, speed); Reset(); Start(); }
/// <summary> /// Turn interrupts on or off and set the conversion trigger count. /// </summary> /// <remarks> /// The conversion count is the number of conversions that must be outside /// of the upper and lower limits before and interrupt is generated. /// See Interrupt Control Register on page 15 and 16 of the datasheet. /// </remarks> /// <param name="mode"></param> /// <param name="conversionCount"> /// Number of conversions that must be outside of the threshold before an interrupt is /// generated. /// </param> /// <param name="pin">GPIO pin connected to the TSL2561 interrupt pin. Set to null to use the previously supplied pin.</param> public void SetInterruptMode(InterruptMode mode, byte conversionCount, IDigitalPin pin = null) { if (conversionCount > 15) { throw new ArgumentOutOfRangeException("conversionCount", "Conversion count must be in the range 0-15 inclusive."); } // // Attach the interrupt event before we turn on interrupts. // if (pin != null) { if (_interruptPin != null) { //Port: TODO check _interruptPin.Dispose(); } _interruptPin = new DigitalInputPort(pin, false, ResistorMode.PullUp); _interruptPin.Changed += InterruptPin_Changed; } else { if (_interruptPin == null) { throw new ArgumentException("Interrupt pin must be supplied"); } } // // Put interrupt control in bits 4 & 5 of the Interrupt Control Register. // Using the enum above makes sure that mode is in the range 0-3 inclusive. // var registerValue = (byte)mode; registerValue <<= 4; // // conversionCount is known to be 0-15, put this in the lower four bits of // the Interrupt Control Register. // registerValue |= conversionCount; // // Clear the interrupt bit before we turn them on. // ClearInterrupt(); _tsl2561.WriteRegister(Registers.InterruptControl, registerValue); }
public PCD8544(IDigitalPin chipSelectPin, IDigitalPin dcPin, IDigitalPin resetPin, Spi.SPI_module spiModule = Spi.SPI_module.SPI1, uint speedKHz = 4000) { spiBuffer = new byte[Width * Height / 8]; dataCommandPort = new DigitalOutputPort(dcPin, true); resetPort = new DigitalOutputPort(resetPin, true); var spiConfig = new Spi.Configuration( SPI_mod: spiModule, ChipSelect_Port: chipSelectPin, ChipSelect_ActiveState: false, ChipSelect_SetupTime: 0, ChipSelect_HoldTime: 0, Clock_IdleState: false, Clock_Edge: true, Clock_RateKHz: speedKHz); spi = new Spi(spiConfig); Initialize(); }
/// <summary> /// Configure the interrupts for the ADXL362. /// </summary> /// <remark> /// Set the interrupt mask for interrupt pins 1 and 2 /// pins to the interrupt pins on the ADXL362 if requested. /// /// Interrupts can be disabled by passing 0 for the interrupt maps. It is also /// possible to disconnect and ADXL362 by setting the interrupt pin /// to GPIO_NONE. /// </remark> /// <param name="interruptMap1">Bit mask for interrupt pin 1</param> /// <param name="interruptPin1">Pin connected to interrupt pin 1 on the ADXL362.</param> /// <param name="interruptMap2">Bit mask for interrupt pin 2</param> /// <param name="interruptPin2">Pin connected to interrupt pin 2 on the ADXL362.</param> public void ConfigureInterrupts(byte interruptMap1, IDigitalPin interruptPin1, byte interruptMap2 = 0, IDigitalPin interruptPin2 = null) // TODO: interrupPin2 = IDigitalPin.GPIO_NONE { _adxl362.WriteBytes(new byte[] { Command.WriteRegister, interruptMap1, interruptMap2 }); //TODO: I changed this from IDigitalPin.GPIO_NONE to null if (interruptPin1 != null) { _digitalInputPort1 = new DigitalInputPort(interruptPin1, false, MapResistorMode((interruptMap1 & 0xf0) > 0)); _digitalInputPort1.Changed += InterruptChanged; } else { _digitalInputPort1 = null; } //TODO: I changed this from IDigitalPin.GPIO_NONE to null if (interruptPin2 != null) { _digitalInputPort2 = new DigitalInputPort(interruptPin2, false, MapResistorMode((interruptMap2 & 0xf0) > 0)); _digitalInputPort2.Changed += InterruptChanged; } else { _digitalInputPort2 = null; } }
public LedControl(IDigitalPin ledPin, IBlockingTimer blinkTimer) { _outputPort = new DigitalOutputPort(ledPin, initialState: false); _blinkTimer = blinkTimer; }
/// <summary> /// Create a new DS18B20 temperature sensor object with the specified configuration. /// </summary> /// <param name="oneWirePin">GPIO pin the DS18B20 is connected to.</param> /// <param name="deviceID">Address of the DS18B20 device.</param> /// <param name="updateInterval">Update period in milliseconds. Note that this most be greater than the conversion period for the sensor.</param> /// <param name="temperatureChangeNotificationThreshold">Threshold for temperature changes that will generate an interrupt.</param> public DS18B20(IDigitalPin oneWirePin, UInt64 deviceID = 0, ushort updateInterval = MinimumPollingPeriod, float temperatureChangeNotificationThreshold = 0.001F) { if (oneWirePin == null) { throw new ArgumentException("OneWire pin cannot be null.", nameof(oneWirePin)); } lock (OneWireBus.Instance) { Sensor = OneWireBus.Add(oneWirePin); if (Sensor.DeviceBus.TouchReset() == 0) { throw new Exception("Cannot find DS18B20 sensor on the OneWire interface."); } if (Sensor.DeviceIDs.Count == 1) { BusMode = BusModeType.SingleDevice; } else { if (deviceID == 0) { throw new ArgumentException("Device deviceID cannot be 0 on a OneWireBus with multiple devices.", nameof(deviceID)); } BusMode = BusModeType.MultimpleDevices; } // // Check for the ROM ID in the list of devices connected to the bus. // if (deviceID != 0) { bool found = false; foreach (UInt64 id in Sensor.DeviceIDs) { if (id == deviceID) { found = true; break; } } if (!found) { throw new Exception("Cannot locate the specified device ID on the OneWire bus."); } } } DeviceID = deviceID; ReadConfiguration(); if ((updateInterval != 0) && (MaximumConversionPeriod > updateInterval)) { throw new ArgumentOutOfRangeException(nameof(updateInterval), "Temperature readings can take " + MaximumConversionPeriod + "ms at this resolution."); } TemperatureChangeNotificationThreshold = temperatureChangeNotificationThreshold; _updateInterval = updateInterval; if (updateInterval > 0) { StartUpdating(); } else { Update(); } }