提交 6262d353 编写于 作者: G Greg Ingram 提交者: Krzysztof Wicher

Updated throughout to use new SpiDevice.Create (#531)

* Updated throughout to use new SpiDevice.Create

* Added the GenAPI package back

* Updated from feedback

* Updated a few I2C related changes for Create
上级 3007425b
......@@ -15,7 +15,7 @@ public class Volume : IDisposable
var connection = new SpiConnectionSettings(0,0);
connection.ClockFrequency = 1000000;
connection.Mode = SpiMode.Mode0;
var spi = new UnixSpiDevice(connection);
var spi = SpiDevice.Create(connection);
var mcp3008 = new Mcp3008(spi);
var volume = new Volume(mcp3008);
volume.Init();
......
......@@ -12,13 +12,8 @@ SpiConnectionSettings settings = new SpiConnectionSettings(0, 0)
Mode = Adxl345.SpiMode
};
// get SpiDevice(In Linux)
UnixSpiDevice device = new UnixSpiDevice(settings);
var device = SpiDevice.Create(settings);
// get SpiDevice(In Win10)
// Windows10SpiDevice device = new Windows10SpiDevice(settings);
// pass in a SpiDevice
// set gravity measurement range ±4G
using (Adxl345 sensor = new Adxl345(device, GravityRange.Range04))
{
......
......@@ -20,12 +20,9 @@ namespace Adxl345.Samples
ClockFrequency = Iot.Device.Adxl345.Adxl345.SpiClockFrequency,
Mode = Iot.Device.Adxl345.Adxl345.SpiMode
};
// get SpiDevice(In Linux)
UnixSpiDevice device = new UnixSpiDevice(settings);
// get SpiDevice(In Win10)
// Windows10SpiDevice device = new Windows10SpiDevice(settings);
// pass in a SpiDevice
var device = SpiDevice.Create(settings);
// set gravity measurement range ±4G
using (Iot.Device.Adxl345.Adxl345 sensor = new Iot.Device.Adxl345.Adxl345(device, GravityRange.Range04))
{
......
......@@ -21,11 +21,9 @@ SpiConnectionSettings settings = new SpiConnectionSettings(0, 0)
ClockFrequency = Adxl345.SpiClockFrequency,
Mode = Adxl345.SpiMode
};
// get SpiDevice(In Linux)
UnixSpiDevice device = new UnixSpiDevice(settings);
var device = SpiDevice.Create(settings);
// pass in a SpiDevice
// set gravity measurement range ±4G
// Set gravity measurement range ±4G
using (Adxl345 sensor = new Adxl345(device, GravityRange.Range04))
{
// loop
......
......@@ -78,7 +78,7 @@ namespace Iot.Device.BrickPi3
// as the SPI is a static, checking if it has already be initialised
if (_brickPiSPI == null)
{
_brickPiSPI = new UnixSpiDevice(settings);
_brickPiSPI = SpiDevice.Create(settings);
}
BrickPi3Info = new BrickPiInfo();
BrickPi3Info.Manufacturer = GetManufacturer();
......
......@@ -55,7 +55,7 @@ var settings = new SpiConnectionSettings(0, 1)
Mode = SpiMode.Mode0,
DataBitLength = 8
};
_goPiGo3 = new GoPiGo(new UnixSpiDevice(settings));
_goPiGo3 = new GoPiGo(SpiDevice.Create(settings));
// Do whatever you want, read sensors, set motors, etc
// once finished, and class will be disposed, all motors will be floated and sensors reinitialized
// The SpiDevice will the disposed when GoPiGo will be disposed
......
......@@ -28,7 +28,7 @@ namespace GoPiGo3.sample
Mode = SpiMode.Mode0,
DataBitLength = 8
};
_goPiGo3 = new GoPiGo(new UnixSpiDevice(settings));
_goPiGo3 = new GoPiGo(SpiDevice.Create(settings));
Console.WriteLine("Choose a test by entering the number and press enter:");
Console.WriteLine(" 1. Basic GoPiGo3 info and embedded led test");
Console.WriteLine(" 2. Control left motor from motor right position");
......
......@@ -49,7 +49,7 @@ var settings = new SpiConnectionSettings(0, 1)
Mode = SpiMode.Mode0,
DataBitLength = 8
};
GoPiGo _goPiGo3 = new GoPiGo(new UnixSpiDevice(settings));
GoPiGo _goPiGo3 = new GoPiGo(SpiDevice.Create(settings));
SoundSensor soundSensor = new SoundSensor(_goPiGo3, GrovePort.Grove1);
Console.WriteLine($"Test {soundSensor.SensorName} on port {soundSensor.Port}. Press a key to finish the test");
while (!Console.KeyAvailable)
......
......@@ -41,7 +41,7 @@ namespace Iot.Device.Samples
ClockFrequency = Max7219.SpiClockFrequency,
Mode = Max7219.SpiMode
};
var spi = new UnixSpiDevice(connectionSettings);
var spi = SpiDevice.Create(connectionSettings);
using (var devices = new Max7219(spi, cascadedDevices: 4))
{
//initialize the devices
......
......@@ -16,7 +16,7 @@ var connectionSettings = new SpiConnectionSettings(0, 0)
ClockFrequency = 10_000_000,
Mode = SpiMode.Mode0
};
var spi = new UnixSpiDevice(connectionSettings);
var spi = SpiDevice.Create(connectionSettings);
var devices = new Max7219(spi, cascadedDevices: 4);
```
......
......@@ -33,7 +33,7 @@ var connectionSettings = new SpiConnectionSettings(0, 0)
Mode = SpiMode.Mode0
};
var spiDevice = new UnixSpiDevice(connectionSettings);
var spiDevice = SpiDevice.Create(connectionSettings);
// 0x20 is the device address in this example.
var mcp23S17 = new Mcp23S17(spiDevice, 0x20);
......
......@@ -75,7 +75,7 @@ namespace Iot.Device.Mcp23xxx.Samples
Mode = SpiMode.Mode0
};
var spiDevice = new UnixSpiDevice(spiConnectionSettings);
var spiDevice = SpiDevice.Create(spiConnectionSettings);
// SPI.
switch (mcp23xxxDevice)
......
......@@ -44,7 +44,7 @@ namespace Iot.Device.Mcp25xxx.Samples
private static Mcp25xxx GetMcp25xxxDevice()
{
var spiConnectionSettings = new SpiConnectionSettings(0, 0);
var spiDevice = new UnixSpiDevice(spiConnectionSettings);
var spiDevice = SpiDevice.Create(spiConnectionSettings);
return new Mcp25625(spiDevice);
}
......
......@@ -32,7 +32,7 @@ namespace Iot.Device.Samples
Mode = SpiMode.Mode0
};
var spi = new UnixSpiDevice(connection);
var spi = SpiDevice.Create(connection);
var mcp3008 = new Mcp3008.Mcp3008(spi);
return mcp3008;
}
......
......@@ -14,7 +14,7 @@ You can use the following code to [access the MCP3008 via SPI](Mcp3008.Sample.cs
var connection = new SpiConnectionSettings(0,0);
connection.ClockFrequency = 1000000;
connection.Mode = SpiMode.Mode0;
var spi = new UnixSpiDevice(connection);
var spi = SpiDevice.Create(connection);
var mcp = new Mcp3008(spi);
```
......
......@@ -12,7 +12,7 @@ SpiConnectionSettings settings = new SpiConnectionSettings(0, 0)
ClockFrequency = Nrf24l01.SpiClockFrequency,
Mode = Nrf24l01.SpiMode
};
UnixSpiDevice device = new UnixSpiDevice(settings);
var device = SpiDevice.Create(settings);
// Creates a new instance of the nRF24L01
using (Nrf24l01 sensor = new Nrf24l01(receiverDevice, 5, 6, 20))
......@@ -53,4 +53,4 @@ private static void Receiver_ReceivedData(object sender, DataReceivedEventArgs e
```
## References
https://cdn.datasheetspdf.com/pdf-down/N/R/F/NRF24L01-Nordic.pdf
\ No newline at end of file
https://cdn.datasheetspdf.com/pdf-down/N/R/F/NRF24L01-Nordic.pdf
......@@ -26,8 +26,8 @@ namespace Iot.Device.Nrf24l01.Samples
ClockFrequency = Nrf24l01.SpiClockFrequency,
Mode = Nrf24l01.SpiMode
};
UnixSpiDevice senderDevice = new UnixSpiDevice(senderSettings);
UnixSpiDevice receiverDevice = new UnixSpiDevice(receiverSettings);
var senderDevice = SpiDevice.Create(senderSettings);
var receiverDevice = SpiDevice.Create(receiverSettings);
// SPI Device, CE Pin, IRQ Pin, Receive Packet Size
using (Nrf24l01 sender = new Nrf24l01(senderDevice, 23, 24, 20))
......
......@@ -53,8 +53,8 @@ SpiConnectionSettings receiverSettings = new SpiConnectionSettings(1, 2)
ClockFrequency = Nrf24l01.SpiClockFrequency,
Mode = Nrf24l01.SpiMode
};
UnixSpiDevice senderDevice = new UnixSpiDevice(senderSettings);
UnixSpiDevice receiverDevice = new UnixSpiDevice(receiverSettings);
var senderDevice = SpiDevice.Create(senderSettings);
var receiverDevice = SpiDevice.Create(receiverSettings);
// SPI Device, CE Pin, IRQ Pin, Receive Packet Size
using (Nrf24l01 sender = new Nrf24l01(senderDevice, 23, 24, 20))
......
......@@ -23,7 +23,7 @@ namespace Iot.Device.Ws28xx.Samples
};
// Create a Neo Pixel x8 stick on spi 0.0
var spi = new UnixSpiDevice(settings);
var spi = SpiDevice.Create(settings);
#if WS2808
var neo = new Ws2808(spi, count);
......
......@@ -24,7 +24,7 @@ namespace DeviceApiTester.Commands.I2c
/// <remarks>
/// NOTE: This test app uses the base class's <see cref="CreateI2cDevice"/> method to create a device.<br/>
/// Real-world usage would simply create an instance of an <see cref="I2cDevice"/> implementation:
/// <code>using (var i2cDevice = new UnixI2cDevice(connectionSettings))</code>
/// <code>using (var i2cDevice = I2cDevice.Create(connectionSettings))</code>
/// </remarks>
public int Execute()
{
......
......@@ -27,7 +27,7 @@ namespace DeviceApiTester.Commands.I2c
/// <remarks>
/// NOTE: This test app uses the base class's <see cref="CreateI2cDevice"/> method to create a device.<br/>
/// Real-world usage would simply create an instance of an <see cref="I2cDevice"/> implementation:
/// <code>using (var i2cDevice = new UnixI2cDevice(connectionSettings))</code>
/// <code>using (var i2cDevice = I2cDevice.Create(connectionSettings))</code>
/// </remarks>
public int Execute()
{
......@@ -52,7 +52,7 @@ namespace DeviceApiTester.Commands.I2c
stringBuilder.Append(Environment.NewLine);
var connectionSettings = new I2cConnectionSettings(BusId, DeviceAddress);
using (var i2cDevice = new System.Device.I2c.Drivers.UnixI2cDevice(connectionSettings))
using (var i2cDevice = I2cDevice.Create(connectionSettings))
{
for (int startingRowAddress = 0; startingRowAddress < 255; startingRowAddress += 16)
{
......
......@@ -26,7 +26,7 @@ namespace DeviceApiTester.Commands.I2c
/// <remarks>
/// NOTE: This test app uses the base class's <see cref="CreateI2cDevice"/> method to create a device.<br/>
/// Real-world usage would simply create an instance of an <see cref="I2cDevice"/> implementation:
/// <code>using (var i2cDevice = new UnixI2cDevice(connectionSettings))</code>
/// <code>using (var i2cDevice = I2cDevice.Create(connectionSettings))</code>
/// </remarks>
public int Execute()
{
......
......@@ -23,7 +23,7 @@ namespace DeviceApiTester.Commands.I2c
/// <remarks>
/// NOTE: This test app uses the base class's <see cref="CreateI2cDevice"/> method to create a device.<br/>
/// Real-world usage would simply create an instance of an <see cref="I2cDevice"/> implementation:
/// <code>using (var i2cDevice = new UnixI2cDevice(connectionSettings))</code>
/// <code>using (var i2cDevice = I2cDevice.Create(connectionSettings))</code>
/// </remarks>
public int Execute()
{
......
......@@ -23,7 +23,7 @@ namespace DeviceApiTester.Commands.I2c
/// <remarks>
/// NOTE: This test app uses the base class's <see cref="CreateI2cDevice"/> method to create a device.<br/>
/// Real-world usage would simply create an instance of an <see cref="I2cDevice"/> implementation:
/// <code>using (var i2cDevice = new UnixI2cDevice(connectionSettings))</code>
/// <code>using (var i2cDevice = I2cDevice.Create(connectionSettings))</code>
/// </remarks>
public int Execute()
{
......
......@@ -17,7 +17,7 @@ namespace DeviceApiTester.Commands.Spi
/// <remarks>
/// NOTE: This test app uses the base class's <see cref="CreateSpiDevice"/> method to create a device.<br/>
/// Real-world usage would simply create an instance of a <see cref="SpiDevice"/> implementation:
/// <code>using (var spi = new UnixSpiDevice(connectionSettings))</code>
/// <code>using (var spi = SpiDevice.Create(connectionSettings))</code>
/// </remarks>
public int Execute()
{
......
......@@ -20,7 +20,7 @@ namespace DeviceApiTester.Commands.Spi
/// <remarks>
/// NOTE: This test app uses the base class's <see cref="CreateSpiDevice"/> method to create a device.<br/>
/// Real-world usage would simply create an instance of a <see cref="SpiDevice"/> implementation:
/// <code>using (var spi = new UnixSpiDevice(connectionSettings))</code>
/// <code>using (var spi = SpiDevice.Create(connectionSettings))</code>
/// </remarks>
public int Execute()
{
......
......@@ -17,7 +17,7 @@ namespace DeviceApiTester.Commands.Spi
/// <remarks>
/// NOTE: This test app uses the base class's <see cref="CreateSpiDevice"/> method to create a device.<br/>
/// Real-world usage would simply create an instance of a <see cref="SpiDevice"/> implementation:
/// <code>using (var spi = new UnixSpiDevice(connectionSettings))</code>
/// <code>using (var spi = SpiDevice.Create(connectionSettings))</code>
/// </remarks>
public int Execute()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册