diff --git a/src/devices/Ads1115/README.md b/src/devices/Ads1115/README.md index 65fc0d50a2..06c43a7c60 100644 --- a/src/devices/Ads1115/README.md +++ b/src/devices/Ads1115/README.md @@ -9,10 +9,7 @@ ADS1115 is an Analog-to-Digital converter (ADC) with 16 bits of resolution. // set I2C bus ID: 1 // ADS1115 Addr Pin connect to GND I2cConnectionSettings settings = new I2cConnectionSettings(1, (int)I2cAddress.GND); -// get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); -// get I2cDevice (in Win10) -//Windows10I2cDevice device = new Windows10I2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); // pass in I2cDevice // measure the voltage AIN0 diff --git a/src/devices/Ads1115/samples/Program.cs b/src/devices/Ads1115/samples/Program.cs index 32d4b36ac2..097a12fb9b 100644 --- a/src/devices/Ads1115/samples/Program.cs +++ b/src/devices/Ads1115/samples/Program.cs @@ -18,9 +18,7 @@ static void Main(string[] args) // ADS1115 Addr Pin connect to GND I2cConnectionSettings settings = new I2cConnectionSettings(1, (int)I2cAddress.GND); // get I2cDevice (in Linux) - UnixI2cDevice device = new UnixI2cDevice(settings); - // get I2cDevice (in Win10) - //Windows10I2cDevice device = new Windows10I2cDevice(settings); + I2cDevice device = I2cDevice.Create(settings); // pass in I2cDevice // measure the voltage AIN0 diff --git a/src/devices/Ads1115/samples/README.md b/src/devices/Ads1115/samples/README.md index 7e93a16349..8ff926eff0 100644 --- a/src/devices/Ads1115/samples/README.md +++ b/src/devices/Ads1115/samples/README.md @@ -26,8 +26,7 @@ Rotary Potentiometer // set I2C bus ID: 1 // ADS1115 Addr Pin connect to GND I2cConnectionSettings settings = new I2cConnectionSettings(1, (int)I2cAddress.GND); -// get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); // pass in I2cDevice // measure the voltage AIN0 diff --git a/src/devices/Ags01db/README.md b/src/devices/Ags01db/README.md index 1f81437e71..97a9e4bc7e 100644 --- a/src/devices/Ags01db/README.md +++ b/src/devices/Ags01db/README.md @@ -1,5 +1,5 @@ # AGS01DB - MEMS VOC Gas Sensor -AGS01DB is a MEMS VOC gas sensor with calibrated digital signal output. It uses special digital module acquisition technology and gas sensing technology to ensure that the product has high reliability and excellent long-term stability. +AGS01DB is a MEMS VOC gas sensor with calibrated digital signal output. It uses special digital module acquisition technology and gas sensing technology to ensure that the product has high reliability and excellent long-term stability. ## Sensor Image ![](sensor.jpg) @@ -8,7 +8,7 @@ AGS01DB is a MEMS VOC gas sensor with calibrated digital signal output. It uses ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Ags01db.DefaultI2cAddress); // get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); // get I2cDevice (in Win10) //Windows10I2cDevice device = new Windows10I2cDevice(settings); diff --git a/src/devices/Ags01db/samples/Program.cs b/src/devices/Ags01db/samples/Program.cs index df33b9c2d3..32adc1d610 100644 --- a/src/devices/Ags01db/samples/Program.cs +++ b/src/devices/Ags01db/samples/Program.cs @@ -10,7 +10,7 @@ class Program static void Main(string[] args) { I2cConnectionSettings settings = new I2cConnectionSettings(1, Ags01db.DefaultI2cAddress); - UnixI2cDevice device = new UnixI2cDevice(settings); + I2cDevice device = I2cDevice.Create(settings); using (Ags01db sensor = new Ags01db(device)) { diff --git a/src/devices/Ags01db/samples/README.md b/src/devices/Ags01db/samples/README.md index 75b4a2e881..89f9387571 100644 --- a/src/devices/Ags01db/samples/README.md +++ b/src/devices/Ags01db/samples/README.md @@ -18,7 +18,7 @@ SDA, SCL need pull-up resistance. ## Code ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Ags01db.DefaultI2cAddress); -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Ags01db sensor = new Ags01db(device)) { diff --git a/src/devices/Bh1750fvi/README.md b/src/devices/Bh1750fvi/README.md index 722e9365ff..b8a45efd11 100644 --- a/src/devices/Bh1750fvi/README.md +++ b/src/devices/Bh1750fvi/README.md @@ -7,10 +7,7 @@ BH1750FVI is an digital Ambient Light Sensor IC for I2C bus interface. This IC i ## Usage ```C# I2cConnectionSettings settings = new I2cConnectionSettings(busId: 1, (int)I2cAddress.AddPinLow); -// get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); -// get I2cDevice (in Win10) -//Windows10I2cDevice device = new Windows10I2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Bh1750fvi sensor = new Bh1750fvi(device)) { @@ -21,4 +18,4 @@ using (Bh1750fvi sensor = new Bh1750fvi(device)) ``` ## References -https://cdn.datasheetspdf.com/pdf-down/B/H/1/BH1750FVI_Rohm.pdf \ No newline at end of file +https://cdn.datasheetspdf.com/pdf-down/B/H/1/BH1750FVI_Rohm.pdf diff --git a/src/devices/Bh1750fvi/samples/Program.cs b/src/devices/Bh1750fvi/samples/Program.cs index ac18e3feb9..fbab94307e 100644 --- a/src/devices/Bh1750fvi/samples/Program.cs +++ b/src/devices/Bh1750fvi/samples/Program.cs @@ -14,7 +14,7 @@ class Program static void Main(string[] args) { I2cConnectionSettings settings = new I2cConnectionSettings(busId: 1, (int)I2cAddress.AddPinLow); - UnixI2cDevice device = new UnixI2cDevice(settings); + I2cDevice device = I2cDevice.Create(settings); using (Bh1750fvi sensor = new Bh1750fvi(device)) { diff --git a/src/devices/Bh1750fvi/samples/README.md b/src/devices/Bh1750fvi/samples/README.md index f9bd27e2ea..368c55f179 100644 --- a/src/devices/Bh1750fvi/samples/README.md +++ b/src/devices/Bh1750fvi/samples/README.md @@ -16,7 +16,7 @@ ## Code ```C# I2cConnectionSettings settings = new I2cConnectionSettings(busId: 1, (int)I2cAddress.AddPinLow); -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Bh1750fvi sensor = new Bh1750fvi(device)) { diff --git a/src/devices/Bmp180/samples/Bmp180.Sample.cs b/src/devices/Bmp180/samples/Bmp180.Sample.cs index b4026b3697..bc34831e29 100644 --- a/src/devices/Bmp180/samples/Bmp180.Sample.cs +++ b/src/devices/Bmp180/samples/Bmp180.Sample.cs @@ -21,8 +21,8 @@ static void Main(string[] args) const int busId = 1; var i2cSettings = new I2cConnectionSettings(busId, Bmp180.DefaultI2cAddress); - var i2cDevice = new UnixI2cDevice(i2cSettings); - var i2cBmp280 = new Bmp180(i2cDevice); + var i2cDevice = I2cDevice.Create(i2cSettings); + var i2cBmp280 = new Bmp180(i2cDevice); using (i2cBmp280) { @@ -31,7 +31,7 @@ static void Main(string[] args) //read values Temperature tempValue = i2cBmp280.ReadTemperature(); - Console.WriteLine($"Temperature {tempValue.Celsius} °C"); + Console.WriteLine($"Temperature {tempValue.Celsius} °C"); double preValue = i2cBmp280.ReadPressure(); Console.WriteLine($"Pressure {preValue} Pa"); double altValue = i2cBmp280.ReadAltitude(); @@ -47,7 +47,7 @@ static void Main(string[] args) preValue = i2cBmp280.ReadPressure(); Console.WriteLine($"Pressure {preValue} Pa"); altValue = i2cBmp280.ReadAltitude(); - Console.WriteLine($"Altitude {altValue:0.##} m"); + Console.WriteLine($"Altitude {altValue:0.##} m"); } } } diff --git a/src/devices/Bmx280/samples/Bme280.sample.cs b/src/devices/Bmx280/samples/Bme280.sample.cs index 15e3561bbe..1906ffe355 100644 --- a/src/devices/Bmx280/samples/Bme280.sample.cs +++ b/src/devices/Bmx280/samples/Bme280.sample.cs @@ -24,7 +24,7 @@ static async Task Main(string[] args) const double defaultSeaLevelPressure = 1033.00; var i2cSettings = new I2cConnectionSettings(busId, Bme280.DefaultI2cAddress); - var i2cDevice = new UnixI2cDevice(i2cSettings); + var i2cDevice = I2cDevice.Create(i2cSettings); var i2CBmpe80 = new Bme280(i2cDevice); using (i2CBmpe80) diff --git a/src/devices/Bmx280/samples/Bmp280.sample.cs b/src/devices/Bmx280/samples/Bmp280.sample.cs index f6d5b18771..703d80d1e5 100644 --- a/src/devices/Bmx280/samples/Bmp280.sample.cs +++ b/src/devices/Bmx280/samples/Bmp280.sample.cs @@ -24,7 +24,7 @@ static async Task Main(string[] args) const double defaultSeaLevelPressure = 1033.00; var i2cSettings = new I2cConnectionSettings(busId, Bmp280.DefaultI2cAddress); - var i2cDevice = new UnixI2cDevice(i2cSettings); + var i2cDevice = I2cDevice.Create(i2cSettings); var i2CBmp280 = new Bmp280(i2cDevice); using (i2CBmp280) diff --git a/src/devices/Bno055/README.md b/src/devices/Bno055/README.md index 028a0cb3a0..0f3bf16fe5 100644 --- a/src/devices/Bno055/README.md +++ b/src/devices/Bno055/README.md @@ -19,7 +19,7 @@ You will find this device as ["Inertial Measurement Unit"](https://www.dexterind Create a ```Bno055Sensor``` class and pass the I2C device. The default I2C address is provided in the class. ```csharp -I2cDevice i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(1, Bno055Sensor.DefaultI2cAddress)); +I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(1, Bno055Sensor.DefaultI2cAddress)); Bno055Sensor bno055Sensor = new Bno055Sensor(i2cDevice); Console.WriteLine($"Id: {bno055Sensor.Info.ChipId}, AccId: {bno055Sensor.Info.AcceleratorId}, GyroId: {bno055Sensor.Info.GyroscopeId}, MagId: {bno055Sensor.Info.MagnetometerId}"); Console.WriteLine($"Firmware version: {bno055Sensor.Info.FirmwareVersion}, Bootloader: {bno055Sensor.Info.BootloaderVersion}"); diff --git a/src/devices/Bno055/samples/Bno055.sample.cs b/src/devices/Bno055/samples/Bno055.sample.cs index e7346309f0..33606dc45a 100644 --- a/src/devices/Bno055/samples/Bno055.sample.cs +++ b/src/devices/Bno055/samples/Bno055.sample.cs @@ -16,7 +16,7 @@ class Program static void Main(string[] args) { Console.WriteLine("Hello BNO055!"); - I2cDevice i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(1, Bno055Sensor.DefaultI2cAddress)); + I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(1, Bno055Sensor.DefaultI2cAddress)); Bno055Sensor bno055Sensor = new Bno055Sensor(i2cDevice); Console.WriteLine($"Id: {bno055Sensor.Info.ChipId}, AccId: {bno055Sensor.Info.AcceleratorId}, GyroId: {bno055Sensor.Info.GyroscopeId}, MagId: {bno055Sensor.Info.MagnetometerId}"); Console.WriteLine($"Firmware version: {bno055Sensor.Info.FirmwareVersion}, Bootloader: {bno055Sensor.Info.BootloaderVersion}"); diff --git a/src/devices/CharacterLcd/README.md b/src/devices/CharacterLcd/README.md index 7cf0cc5ad4..e9e73ae680 100644 --- a/src/devices/CharacterLcd/README.md +++ b/src/devices/CharacterLcd/README.md @@ -25,8 +25,8 @@ Grove LCD RGB Backlight uses two i2c devices: Here is a Hello World example of how to consume Grove LCD RGB Backlight binding: ```c# -var i2cLcdDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); -var i2cRgbDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); +var i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); +var i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); using (var lcd = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice)) { lcd.Write("Hello World!"); @@ -37,14 +37,14 @@ using (var lcd = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice)) PCF8574T/PCF8574AT Sample The I2C backpack based on the PCF8574T/AT IC uses specific pin mapping, to consume this device binding on this backpack use like so ```c# -var i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: 0x27)); +var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x27)); var controller = new Pcf8574(i2cDevice); var lcd = new Lcd1602(registerSelectPin: 0, enablePin: 2, dataPins: new int[] { 4, 5, 6, 7}, backlightPin: 3, readWritePin: 1, controller: controller); ``` there is a full working example in the samples directory called Pcf8574tSample.cs For PCF8574T i2c addresses can be between 0x27 and 0x20 depending on bridged solder jumpers and for PCF8574AT i2c addresses can be between 0x3f and 0x38 depending on bridged solder jumpers -## References +## References - Very complete tutorial on how to connect and work with one of these displays: https://learn.adafruit.com/drive-a-16x2-lcd-directly-with-a-raspberry-pi/overview - Good guide explaining how the device works internally: http://www.site2241.net/november2014.htm - Seeedstudio, Grove - LCD RGB Backlight library: https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight diff --git a/src/devices/CharacterLcd/samples/CharacterLcd.Sample.cs b/src/devices/CharacterLcd/samples/CharacterLcd.Sample.cs index 65ad7eed03..487ee7a316 100644 --- a/src/devices/CharacterLcd/samples/CharacterLcd.Sample.cs +++ b/src/devices/CharacterLcd/samples/CharacterLcd.Sample.cs @@ -30,7 +30,7 @@ static void Main(string[] args) /// static void UsingMcp() { - UnixI2cDevice i2CDevice = new UnixI2cDevice(new I2cConnectionSettings(1, 0x21)); + I2cDevice i2CDevice = I2cDevice.Create(new I2cConnectionSettings(1, 0x21)); Mcp23008 mcpDevice = new Mcp23008(i2CDevice); int[] dataPins = { 3, 4, 5, 6 }; int registerSelectPin = 1; diff --git a/src/devices/CharacterLcd/samples/Hd44780.ExtendedSample.cs b/src/devices/CharacterLcd/samples/Hd44780.ExtendedSample.cs index 0c071c7132..39b07e2316 100644 --- a/src/devices/CharacterLcd/samples/Hd44780.ExtendedSample.cs +++ b/src/devices/CharacterLcd/samples/Hd44780.ExtendedSample.cs @@ -25,12 +25,12 @@ public static void Test() Console.WriteLine("Starting..."); #if USEI2C - var i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: 0x21)); + var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x21)); var controller = new Mcp23008(i2cDevice); var lcd = new Lcd1602(registerSelectPin: 1, enablePin: 2, dataPins: new int[] { 3, 4, 5, 6 }, backlightPin: 7, controller: controller); #elif USERGB - var i2cLcdDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); - var i2cRgbDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); + var i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); + var i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); var lcd = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice); #else Hd44780 lcd = new Hd44780(new Size(20, 4), LcdInterface.CreateGpio(12, 26, new int[] { 16, 17, 18, 19, 20, 21, 22, 23 }, readWritePin: 13)); @@ -359,4 +359,3 @@ static void CreateTensCharacters(Hd44780 lcd) } } } - diff --git a/src/devices/CharacterLcd/samples/Pcf8574tSample.cs b/src/devices/CharacterLcd/samples/Pcf8574tSample.cs index 17b621a406..1b62be7776 100644 --- a/src/devices/CharacterLcd/samples/Pcf8574tSample.cs +++ b/src/devices/CharacterLcd/samples/Pcf8574tSample.cs @@ -26,7 +26,7 @@ public static void SampleEntryPoint() Console.WriteLine("Starting..."); //for PCF8574T i2c addresses can be between 0x27 and 0x20 depending on bridged solder jumpers //for PCF8574AT i2c addresses can be between 0x3f and 0x38 depending on bridged solder jumpers - var i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: 0x27)); + var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x27)); var controller = new Pcf8574(i2cDevice); var lcd = new Lcd1602(registerSelectPin: 0, enablePin: 2, dataPins: new int[] { 4, 5, 6, 7 }, backlightPin: 3, readWritePin: 1, controller: controller); diff --git a/src/devices/Dhtxx/README.md b/src/devices/Dhtxx/README.md index bc1c604dba..84cf2a5b5b 100644 --- a/src/devices/Dhtxx/README.md +++ b/src/devices/Dhtxx/README.md @@ -21,7 +21,7 @@ Only DHT12 can use I2C protocol. ```csharp I2cConnectionSettings settings = new I2cConnectionSettings(1, DhtSensor.DefaultI2cAddressDht12); -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (DhtSensor dht = new DhtSensor(device)) { @@ -35,4 +35,4 @@ using (DhtSensor dht = new DhtSensor(device)) * **DHT11** [datasheet](https://cdn.datasheetspdf.com/pdf-down/D/H/T/DHT11-Aosong.pdf) * **DHT12** [datasheet](https://cdn.datasheetspdf.com/pdf-down/D/H/T/DHT12-Aosong.pdf) * **DHT21** [datasheet](https://cdn.datasheetspdf.com/pdf-down/A/M/2/AM2301-Aosong.pdf) -* **DHT22** [datasheet](https://cdn-shop.adafruit.com/datasheets/DHT22.pdf) \ No newline at end of file +* **DHT22** [datasheet](https://cdn-shop.adafruit.com/datasheets/DHT22.pdf) diff --git a/src/devices/Dhtxx/samples/DhtSensor.sample.cs b/src/devices/Dhtxx/samples/DhtSensor.sample.cs index b7e1a0311c..060ce7e774 100644 --- a/src/devices/Dhtxx/samples/DhtSensor.sample.cs +++ b/src/devices/Dhtxx/samples/DhtSensor.sample.cs @@ -15,7 +15,7 @@ static void Main(string[] args) // Init DHT12 through I2C //I2cConnectionSettings settings = new I2cConnectionSettings(1, DhtSensor.Dht12DefaultI2cAddress); - //UnixI2cDevice device = new UnixI2cDevice(settings); + //I2cDevice device = I2cDevice.Create(settings); //DhtSensor dht = new DhtSensor(device); using (DhtSensor dht = new DhtSensor(4, DhtType.Dht11)) diff --git a/src/devices/Ds1307/README.md b/src/devices/Ds1307/README.md index 35ed041215..debc7c72b9 100644 --- a/src/devices/Ds1307/README.md +++ b/src/devices/Ds1307/README.md @@ -1,5 +1,5 @@ # DS1307 - Realtime Clock -The DS1307 serial real-time clock (RTC) is a lowpower, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus. +The DS1307 serial real-time clock (RTC) is a lowpower, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus. ## Sensor Image ![](sensor.jpg) @@ -7,10 +7,7 @@ The DS1307 serial real-time clock (RTC) is a lowpower, full binary-coded decimal ## Usage ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds1307.DefaultI2cAddress); -// get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); -// get I2cDevice (in Win10) -//Windows10I2cDevice device = new Windows10I2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Ds1307 rtc = new Ds1307(device)) { diff --git a/src/devices/Ds1307/samples/Program.cs b/src/devices/Ds1307/samples/Program.cs index 4ee9a2071d..312e04f450 100644 --- a/src/devices/Ds1307/samples/Program.cs +++ b/src/devices/Ds1307/samples/Program.cs @@ -16,10 +16,7 @@ static void Main(string[] args) Console.WriteLine("Hello, Realtime Clock DS1307!"); I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds1307.DefaultI2cAddress); - // get I2cDevice (in Linux) - UnixI2cDevice device = new UnixI2cDevice(settings); - // get I2cDevice (in Win10) - //Windows10I2cDevice device = new Windows10I2cDevice(settings); + I2cDevice device = I2cDevice.Create(settings); using (Ds1307 rtc = new Ds1307(device)) { diff --git a/src/devices/Ds1307/samples/README.md b/src/devices/Ds1307/samples/README.md index 38a323ecfa..e30a1f1a98 100644 --- a/src/devices/Ds1307/samples/README.md +++ b/src/devices/Ds1307/samples/README.md @@ -17,7 +17,7 @@ Console.WriteLine("Hello, Realtime Clock DS1307!"); I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds1307.DefaultI2cAddress); -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Ds1307 rtc = new Ds1307(device)) { diff --git a/src/devices/Ds3231/README.md b/src/devices/Ds3231/README.md index 7b763a04fe..3dd92018c8 100644 --- a/src/devices/Ds3231/README.md +++ b/src/devices/Ds3231/README.md @@ -7,10 +7,7 @@ DS3231 is a low-cost, extremely accurate I2C realtime clock (RTC) with an integr ## Usage ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds3231.DefaultI2cAddress); -// get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); -// get I2cDevice (in Win10) -//Windows10I2cDevice device = new Windows10I2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Ds3231 rtc = new Ds3231(device)) { diff --git a/src/devices/Ds3231/samples/Program.cs b/src/devices/Ds3231/samples/Program.cs index 3e36f738a0..cd58311371 100644 --- a/src/devices/Ds3231/samples/Program.cs +++ b/src/devices/Ds3231/samples/Program.cs @@ -14,10 +14,7 @@ class Program static void Main(string[] args) { I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds3231.DefaultI2cAddress); - // get I2cDevice (in Linux) - UnixI2cDevice device = new UnixI2cDevice(settings); - // get I2cDevice (in Win10) - //Windows10I2cDevice device = new Windows10I2cDevice(settings); + I2cDevice device = I2cDevice.Create(settings); using (Ds3231 rtc = new Ds3231(device)) { diff --git a/src/devices/Ds3231/samples/README.md b/src/devices/Ds3231/samples/README.md index 3b163e45c1..47b534bf2a 100644 --- a/src/devices/Ds3231/samples/README.md +++ b/src/devices/Ds3231/samples/README.md @@ -15,8 +15,7 @@ ## Code ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds3231.DefaultI2cAddress); -// get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Ds3231 rtc = new Ds3231(device)) { diff --git a/src/devices/GrovePi/README.md b/src/devices/GrovePi/README.md index 8dc8a524f4..367445e454 100644 --- a/src/devices/GrovePi/README.md +++ b/src/devices/GrovePi/README.md @@ -35,7 +35,7 @@ This version include a pure driver so you can directly access to the raw results High level classes has been built for those sensors. Generic Digital Input, Digital Output, Analogic Input, PWM Output has been built as well. You can build your own classes looking at the sensors provided in the [Sensors folder](./Sensors). -More sensors are supported and being tested like the Grove Led Bar. Note that this sensor as the Ultrasonic sensor have native support and accessing their data is different than for the other sensors. +More sensors are supported and being tested like the Grove Led Bar. Note that this sensor as the Ultrasonic sensor have native support and accessing their data is different than for the other sensors. ## How to use the driver @@ -45,7 +45,7 @@ Create a ```GrovePi``` class. ```csharp I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.GrovePiSefaultI2cAddress); -grovePi = new GrovePi(new UnixI2cDevice(i2CConnectionSettings)); +grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); // Do something with the sensors // At the end, the IEC Device will be disposed ``` @@ -60,7 +60,7 @@ The GrovePiInfo class offers information like the firmware version, manufacturer ```csharp I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.GrovePiSefaultI2cAddress); -grovePi = new GrovePi(new UnixI2cDevice(i2CConnectionSettings)); +grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); Console.WriteLine($"Manufacturer :{grovePi.GrovePiInfo.Manufacturer}"); Console.WriteLine($"Board: {grovePi.GrovePiInfo.Board}"); Console.WriteLine($"Firmware version: {grovePi.GrovePiInfo.SoftwareVersion}"); @@ -82,7 +82,7 @@ Their usage is very similar to Arduino usage. For example, if you want to read a ```csharp // Set the pin as Input, should be done only once but you -// can change it as well over time +// can change it as well over time grovePi.PinMode(GrovePort.Grove1, PinMode.Input); // Then read results, you can do it as much as you want var result = grovePi.AnalogRead(GrovePort.Grove1); @@ -102,16 +102,16 @@ Note that Analogic pins can be used for both analogic and digital sensors. In ca There are high level classes to handle directly sensors like analogic sensors, buzzers, leds, buttons. All the sensors are using only 1 pin out of the 2 available. There is nothing presenting you to use the 2 pins if you have a sensor using 2 pins. Just make sue you won't use the adjacent Grove plug in this case. -Using the sensor classes is straight forward. Just reference a class and initialized it. Access properties which are common to all sensors, ```Value``` and ```ToString()```. +Using the sensor classes is straight forward. Just reference a class and initialized it. Access properties which are common to all sensors, ```Value``` and ```ToString()```. Example creating an Ultrasonic sensor on Grove1 port: ```csharp UltrasonicSensor ultrasonic = new UltrasonicSensor(grovePi, GrovePort.DigitalPin6); while (!Console.KeyAvailable) -{ - Console.WriteLine($"Ultrasonic: {ultrasonic}"); - Thread.Sleep(2000); +{ + Console.WriteLine($"Ultrasonic: {ultrasonic}"); + Thread.Sleep(2000); } ``` @@ -123,7 +123,7 @@ A series of hardware tests for sensors are available in [GrovePi.samples](./samp Console.WriteLine("Hello GrovePi!"); PinLevel relay = PinLevel.Low; I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.GrovePiSefaultI2cAddress); -grovePi = new GrovePi(new UnixI2cDevice(i2CConnectionSettings)); +grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); Console.WriteLine($"Manufacturer :{grovePi.GrovePiInfo.Manufacturer}"); Console.WriteLine($"Board: {grovePi.GrovePiInfo.Board}"); Console.WriteLine($"Firmware version: {grovePi.GrovePiInfo.SoftwareVersion}"); @@ -147,11 +147,8 @@ while (!Console.KeyAvailable) dhtSensor.ReadSensor(); Console.WriteLine($"{dhtSensor.DhtType}: {dhtSensor}"); Thread.Sleep(2000); - Console.CursorTop -= 5; + Console.CursorTop -= 5; } Console.CursorTop += 5; ``` - - - diff --git a/src/devices/GrovePi/samples/Program.cs b/src/devices/GrovePi/samples/Program.cs index 7d3baf183b..bbbd196bb3 100644 --- a/src/devices/GrovePi/samples/Program.cs +++ b/src/devices/GrovePi/samples/Program.cs @@ -21,7 +21,7 @@ static void Main(string[] args) Console.WriteLine("Hello GrovePi!"); PinValue relay = PinValue.Low; I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); - grovePi = new GrovePi(new UnixI2cDevice(i2CConnectionSettings)); + grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); Console.WriteLine($"Manufacturer :{grovePi.GrovePiInfo.Manufacturer}"); Console.WriteLine($"Board: {grovePi.GrovePiInfo.Board}"); Console.WriteLine($"Firmware version: {grovePi.GrovePiInfo.SoftwareVersion}"); @@ -42,13 +42,13 @@ static void Main(string[] args) relay = (relay == PinValue.Low) ? PinValue.High : PinValue.Low; grovePi.DigitalWrite(GrovePort.DigitalPin2, relay); Console.WriteLine($"Relay: {relay}"); - grovePi.AnalogWrite(GrovePort.DigitalPin3, (byte)(poten * 100 / 1023)); + grovePi.AnalogWrite(GrovePort.DigitalPin3, (byte)(poten * 100 / 1023)); Console.WriteLine($"Button: {grovePi.DigitalRead(GrovePort.DigitalPin4)}"); Console.WriteLine($"Ultrasonic: {ultrasonic}"); dhtSensor.Read(); Console.WriteLine($"{dhtSensor.DhtType}: {dhtSensor}"); - Thread.Sleep(2000); - } + Thread.Sleep(2000); + } } } } diff --git a/src/devices/Hmc5883l/README.md b/src/devices/Hmc5883l/README.md index 21e18d7f10..a69c48bc52 100644 --- a/src/devices/Hmc5883l/README.md +++ b/src/devices/Hmc5883l/README.md @@ -8,7 +8,7 @@ HMC5883L is a surface-mount, multi-chip module designed for low-field magnetic s ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Hmc5883l.DefaultI2cAddress); // get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); // get I2cDevice (in Win10) //Windows10I2cDevice device = new Windows10I2cDevice(settings); diff --git a/src/devices/Hmc5883l/samples/Program.cs b/src/devices/Hmc5883l/samples/Program.cs index cd7439dab4..0ff06fd76e 100644 --- a/src/devices/Hmc5883l/samples/Program.cs +++ b/src/devices/Hmc5883l/samples/Program.cs @@ -14,10 +14,7 @@ class Program static void Main(string[] args) { I2cConnectionSettings settings = new I2cConnectionSettings(1, Hmc5883l.DefaultI2cAddress); - // get I2cDevice (in Linux) - UnixI2cDevice device = new UnixI2cDevice(settings); - // get I2cDevice (in Win10) - //Windows10I2cDevice device = new Windows10I2cDevice(settings); + I2cDevice device = I2cDevice.Create(settings); using (Hmc5883l sensor = new Hmc5883l(device)) { diff --git a/src/devices/Hmc5883l/samples/README.md b/src/devices/Hmc5883l/samples/README.md index 04a6cd70a9..c757a684ec 100644 --- a/src/devices/Hmc5883l/samples/README.md +++ b/src/devices/Hmc5883l/samples/README.md @@ -15,8 +15,7 @@ ## Code ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Hmc5883l.DefaultI2cAddress); -// get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Hmc5883l sensor = new Hmc5883l(device)) { diff --git a/src/devices/Hts221/samples/Hts221.Sample.cs b/src/devices/Hts221/samples/Hts221.Sample.cs index cacf704ea3..54ab134a35 100644 --- a/src/devices/Hts221/samples/Hts221.Sample.cs +++ b/src/devices/Hts221/samples/Hts221.Sample.cs @@ -29,7 +29,7 @@ public static void Main(string[] args) private static I2cDevice CreateI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } } diff --git a/src/devices/Hts221/samples/README.md b/src/devices/Hts221/samples/README.md index 6b13b2bf55..a2eff33d6f 100644 --- a/src/devices/Hts221/samples/README.md +++ b/src/devices/Hts221/samples/README.md @@ -19,7 +19,7 @@ class Program private static I2cDevice CreateI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } ``` diff --git a/src/devices/Lm75/README.md b/src/devices/Lm75/README.md index 6f24b857b9..5f35815670 100644 --- a/src/devices/Lm75/README.md +++ b/src/devices/Lm75/README.md @@ -7,10 +7,7 @@ The LM75 is a temperature sensor, Delta-Sigma analog-to-digital converter, and d ## Usage ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Lm75.DefaultI2cAddress); -// get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); -// get I2cDevice (in Win10) -//Windows10I2cDevice device = new Windows10I2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using(Lm75 sensor = new Lm75(device)) { diff --git a/src/devices/Lm75/samples/Program.cs b/src/devices/Lm75/samples/Program.cs index 6c6f8cda40..e5f21c60b8 100644 --- a/src/devices/Lm75/samples/Program.cs +++ b/src/devices/Lm75/samples/Program.cs @@ -14,7 +14,7 @@ class Program static void Main(string[] args) { I2cConnectionSettings settings = new I2cConnectionSettings(1, Lm75.DefaultI2cAddress); - UnixI2cDevice device = new UnixI2cDevice(settings); + I2cDevice device = I2cDevice.Create(settings); using (Lm75 sensor = new Lm75(device)) { diff --git a/src/devices/Lm75/samples/README.md b/src/devices/Lm75/samples/README.md index 512447ad4b..3272ec2d6c 100644 --- a/src/devices/Lm75/samples/README.md +++ b/src/devices/Lm75/samples/README.md @@ -15,7 +15,7 @@ ## Code ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Lm75.DefaultI2cAddress); -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using(Lm75 sensor = new Lm75(device)) { diff --git a/src/devices/Lps25h/samples/Lps25h.Sample.cs b/src/devices/Lps25h/samples/Lps25h.Sample.cs index fd6adc128f..1fec41cd81 100644 --- a/src/devices/Lps25h/samples/Lps25h.Sample.cs +++ b/src/devices/Lps25h/samples/Lps25h.Sample.cs @@ -29,7 +29,7 @@ public static void Main(string[] args) private static I2cDevice CreateI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } } diff --git a/src/devices/Lps25h/samples/README.md b/src/devices/Lps25h/samples/README.md index 3745a39025..4a4ef6e44a 100644 --- a/src/devices/Lps25h/samples/README.md +++ b/src/devices/Lps25h/samples/README.md @@ -21,7 +21,7 @@ class Program private static I2cDevice CreateI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } ``` diff --git a/src/devices/Lsm9Ds1/samples/Lsm9Ds1.AccelerometerAndGyroscope.Sample.cs b/src/devices/Lsm9Ds1/samples/Lsm9Ds1.AccelerometerAndGyroscope.Sample.cs index 1400cdef4d..9db697ca4b 100644 --- a/src/devices/Lsm9Ds1/samples/Lsm9Ds1.AccelerometerAndGyroscope.Sample.cs +++ b/src/devices/Lsm9Ds1/samples/Lsm9Ds1.AccelerometerAndGyroscope.Sample.cs @@ -19,7 +19,7 @@ public static void Run() { while (true) { - Console.WriteLine($"Acceleration={ag.Acceleration}"); + Console.WriteLine($"Acceleration={ag.Acceleration}"); Console.WriteLine($"AngularRate={ag.AngularRate}"); Thread.Sleep(100); } @@ -29,7 +29,7 @@ public static void Run() private static I2cDevice CreateI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } } diff --git a/src/devices/Lsm9Ds1/samples/Lsm9Ds1.Magnetometer.Sample.cs b/src/devices/Lsm9Ds1/samples/Lsm9Ds1.Magnetometer.Sample.cs index b793e65a96..227d36b812 100644 --- a/src/devices/Lsm9Ds1/samples/Lsm9Ds1.Magnetometer.Sample.cs +++ b/src/devices/Lsm9Ds1/samples/Lsm9Ds1.Magnetometer.Sample.cs @@ -85,7 +85,7 @@ public static void Run() private static I2cDevice CreateI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } } diff --git a/src/devices/Lsm9Ds1/samples/README.md b/src/devices/Lsm9Ds1/samples/README.md index ebcd38967e..bc8b6c0683 100644 --- a/src/devices/Lsm9Ds1/samples/README.md +++ b/src/devices/Lsm9Ds1/samples/README.md @@ -13,7 +13,7 @@ class Program { while (true) { - Console.WriteLine($"Acceleration={ag.Acceleration}"); + Console.WriteLine($"Acceleration={ag.Acceleration}"); Console.WriteLine($"AngularRate={ag.AngularRate}"); Thread.Sleep(100); } @@ -23,7 +23,7 @@ class Program private static I2cDevice CreateI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } ``` @@ -34,7 +34,7 @@ class Program class Magnetometer { public const int I2cAddress = 0x1C; - + public static void Run() { using (var m = new Lsm9Ds1Magnetometer(CreateI2cDevice())) @@ -95,7 +95,7 @@ class Magnetometer private static I2cDevice CreateI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } -``` \ No newline at end of file +``` diff --git a/src/devices/Max44009/README.md b/src/devices/Max44009/README.md index f59cc391d2..da887967f1 100644 --- a/src/devices/Max44009/README.md +++ b/src/devices/Max44009/README.md @@ -7,10 +7,7 @@ The MAX44009 ambient light sensor features an I2C digital output that is ideal f ## Usage ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Max44009.DefaultI2cAddress); -// get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); -// get I2cDevice (in Win10) -//Windows10I2cDevice device = new Windows10I2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); // integration time is 100ms using (Max44009 sensor = new Max44009(device, IntegrationTime.Time100)) diff --git a/src/devices/Max44009/samples/Program.cs b/src/devices/Max44009/samples/Program.cs index 71c19db167..a1eeee2832 100644 --- a/src/devices/Max44009/samples/Program.cs +++ b/src/devices/Max44009/samples/Program.cs @@ -14,7 +14,7 @@ class Program static void Main(string[] args) { I2cConnectionSettings settings = new I2cConnectionSettings(1, Max44009.DefaultI2cAddress); - UnixI2cDevice device = new UnixI2cDevice(settings); + I2cDevice device = I2cDevice.Create(settings); // integration time is 100ms using (Max44009 sensor = new Max44009(device, IntegrationTime.Time100)) @@ -30,4 +30,4 @@ static void Main(string[] args) } } } -} \ No newline at end of file +} diff --git a/src/devices/Max44009/samples/README.md b/src/devices/Max44009/samples/README.md index 46b865aa4d..3556d24128 100644 --- a/src/devices/Max44009/samples/README.md +++ b/src/devices/Max44009/samples/README.md @@ -11,11 +11,11 @@ * SDA - SDA * VCC - 5V * GND - GND - + ## Code ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Max44009.DefaultI2cAddress); -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); // integration time is 100ms using (Max44009 sensor = new Max44009(device, IntegrationTime.Time100)) diff --git a/src/devices/Mcp23xxx/README.md b/src/devices/Mcp23xxx/README.md index 7f65700502..f7fce61dab 100644 --- a/src/devices/Mcp23xxx/README.md +++ b/src/devices/Mcp23xxx/README.md @@ -21,7 +21,7 @@ This binding includes an `Mcp23xxx` abstract class and derived abstract classes ```csharp // 0x20 is the device address in this example. var connectionSettings = new I2cConnectionSettings(1, 0x20); -var i2cDevice = new UnixI2cDevice(connectionSettings); +var i2cDevice = I2cDevice.Create(connectionSettings); var mcp23S17 = new Mcp23017(i2cDevice); ``` @@ -88,6 +88,6 @@ PinValue interruptA = mcp23S17.ReadInterruptA(); PinValue interruptB = mcp23S17.ReadInterruptB(); ``` -## References +## References https://www.adafruit.com/product/732 https://learn.adafruit.com/using-mcp23008-mcp23017-with-circuitpython/overview diff --git a/src/devices/Mcp23xxx/samples/Mcp23xxx.Sample.cs b/src/devices/Mcp23xxx/samples/Mcp23xxx.Sample.cs index 4dd1d2c039..80506359f2 100644 --- a/src/devices/Mcp23xxx/samples/Mcp23xxx.Sample.cs +++ b/src/devices/Mcp23xxx/samples/Mcp23xxx.Sample.cs @@ -54,7 +54,7 @@ private enum Mcp23xxxDevice private static Mcp23xxx GetMcp23xxxDevice(Mcp23xxxDevice mcp23xxxDevice) { var i2cConnectionSettings = new I2cConnectionSettings(1, s_deviceAddress); - var i2cDevice = new UnixI2cDevice(i2cConnectionSettings); + var i2cDevice = I2cDevice.Create(i2cConnectionSettings); // I2C. switch (mcp23xxxDevice) diff --git a/src/devices/Mpr121/README.md b/src/devices/Mpr121/README.md index f1a2dacbe1..e24e90c634 100644 --- a/src/devices/Mpr121/README.md +++ b/src/devices/Mpr121/README.md @@ -15,7 +15,7 @@ The binding provides different options of device configuration. The device can b #### Default configuration with manually updating of channel statuses ```csharp -var i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: Mpr121.DefaultI2cAddress)); +var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: Mpr121.DefaultI2cAddress)); var mpr121 = new Mpr121(device: i2cDevice); var statuses = mpr121.ReadChannelStatuses(); @@ -29,7 +29,7 @@ Console.WriteLine($"The 1st channel is {status}"); #### Channel statuses auto refresh ```csharp -var i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: Mpr121.DefaultI2cAddress)); +var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: Mpr121.DefaultI2cAddress)); // Initialize controller with default configuration and auto-refresh the channel statuses every 100 ms. var mpr121 = new Mpr121(device: i2cDevice, periodRefresh: 100); @@ -45,7 +45,7 @@ mpr121.ChannelStatusesChanged += (object sender, ChannelStatusesChangedEventArgs #### Custom MPR121 registers configuration ```csharp -var i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: Mpr121.DefaultI2cAddress)); +var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: Mpr121.DefaultI2cAddress)); var config = new Mpr121Configuration { MaxHalfDeltaRising = 0x01, @@ -63,4 +63,4 @@ var config = new Mpr121Configuration }; var mpr121 = new Mpr121(device: i2cDevice, configuration: config); -``` \ No newline at end of file +``` diff --git a/src/devices/Mpr121/samples/Mpr121.Sample.cs b/src/devices/Mpr121/samples/Mpr121.Sample.cs index 6b05f21bbe..a2c469a6bd 100644 --- a/src/devices/Mpr121/samples/Mpr121.Sample.cs +++ b/src/devices/Mpr121/samples/Mpr121.Sample.cs @@ -12,7 +12,7 @@ class Program { static void Main(string[] args) { - var i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: Mpr121.DefaultI2cAddress)); + var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: Mpr121.DefaultI2cAddress)); // Initialize controller with default configuration and auto-refresh the channel statuses every 100 ms. var mpr121 = new Mpr121(device: i2cDevice, periodRefresh: 100); diff --git a/src/devices/Pca95x4/samples/Pca95x4.Sample.cs b/src/devices/Pca95x4/samples/Pca95x4.Sample.cs index d8196f9df3..962245af9f 100644 --- a/src/devices/Pca95x4/samples/Pca95x4.Sample.cs +++ b/src/devices/Pca95x4/samples/Pca95x4.Sample.cs @@ -29,7 +29,7 @@ static void Main(string[] args) private static Pca95x4 GetPca95x4Device() { var i2cConnectionSettings = new I2cConnectionSettings(1, s_deviceAddress); - var i2cDevice = new UnixI2cDevice(i2cConnectionSettings); + var i2cDevice = I2cDevice.Create(i2cConnectionSettings); return new Pca95x4(i2cDevice); } diff --git a/src/devices/Pca9685/samples/Pca9685.Sample.cs b/src/devices/Pca9685/samples/Pca9685.Sample.cs index a7938cca0d..bb16c824ee 100644 --- a/src/devices/Pca9685/samples/Pca9685.Sample.cs +++ b/src/devices/Pca9685/samples/Pca9685.Sample.cs @@ -22,7 +22,7 @@ static void Main(string[] args) var deviceAddress = deviceAddress_fixed | deviceAddress_selectable; var settings = new I2cConnectionSettings(busId, deviceAddress); - var device = new UnixI2cDevice(settings); + var device = I2cDevice.Create(settings); using (var pca9685 = new Pca9685(device)) { diff --git a/src/devices/Pcx857x/README.md b/src/devices/Pcx857x/README.md index a912d01ada..4c0acb3068 100644 --- a/src/devices/Pcx857x/README.md +++ b/src/devices/Pcx857x/README.md @@ -19,7 +19,6 @@ This binding includes an `Pcx857x` abstract base class and derived abstract clas ```csharp // 0x20 is the device address in this example. var connectionSettings = new I2cConnectionSettings(1, 0x20); -var i2cDevice = new UnixI2cDevice(connectionSettings); +var i2cDevice = I2cDevice.Create(connectionSettings); var pcf8574 = new Pcf8574(i2cDevice); ``` - diff --git a/src/devices/SenseHat/SenseHatAccelerometerAndGyroscope.cs b/src/devices/SenseHat/SenseHatAccelerometerAndGyroscope.cs index 78b32271fa..e4754b4028 100644 --- a/src/devices/SenseHat/SenseHatAccelerometerAndGyroscope.cs +++ b/src/devices/SenseHat/SenseHatAccelerometerAndGyroscope.cs @@ -25,7 +25,7 @@ public SenseHatAccelerometerAndGyroscope( private static I2cDevice CreateDefaultI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } } diff --git a/src/devices/SenseHat/SenseHatJoystick.cs b/src/devices/SenseHat/SenseHatJoystick.cs index e9a4a31601..3d8161f174 100644 --- a/src/devices/SenseHat/SenseHatJoystick.cs +++ b/src/devices/SenseHat/SenseHatJoystick.cs @@ -44,7 +44,7 @@ public void Read() private static I2cDevice CreateDefaultI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } public void Dispose() diff --git a/src/devices/SenseHat/SenseHatLedMatrixI2c.cs b/src/devices/SenseHat/SenseHatLedMatrixI2c.cs index d6ca6ff41b..b4fe46c413 100644 --- a/src/devices/SenseHat/SenseHatLedMatrixI2c.cs +++ b/src/devices/SenseHat/SenseHatLedMatrixI2c.cs @@ -139,7 +139,7 @@ private static int PositionToAddress(int x, int y) private static I2cDevice CreateDefaultI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } public override void Dispose() diff --git a/src/devices/SenseHat/SenseHatMagnetometer.cs b/src/devices/SenseHat/SenseHatMagnetometer.cs index b19e597f14..fc6860bbf8 100644 --- a/src/devices/SenseHat/SenseHatMagnetometer.cs +++ b/src/devices/SenseHat/SenseHatMagnetometer.cs @@ -24,7 +24,7 @@ public SenseHatMagnetometer( private static I2cDevice CreateDefaultI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } } diff --git a/src/devices/SenseHat/SenseHatPressureAndTemperature.cs b/src/devices/SenseHat/SenseHatPressureAndTemperature.cs index 087122805c..543885338f 100644 --- a/src/devices/SenseHat/SenseHatPressureAndTemperature.cs +++ b/src/devices/SenseHat/SenseHatPressureAndTemperature.cs @@ -21,7 +21,7 @@ public SenseHatPressureAndTemperature(I2cDevice i2cDevice = null) private static I2cDevice CreateDefaultI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } } diff --git a/src/devices/SenseHat/SenseHatTemperatureAndHumidity.cs b/src/devices/SenseHat/SenseHatTemperatureAndHumidity.cs index af11135809..9024273bf9 100644 --- a/src/devices/SenseHat/SenseHatTemperatureAndHumidity.cs +++ b/src/devices/SenseHat/SenseHatTemperatureAndHumidity.cs @@ -21,7 +21,7 @@ public SenseHatTemperatureAndHumidity(I2cDevice i2cDevice = null) private static I2cDevice CreateDefaultI2cDevice() { var settings = new I2cConnectionSettings(1, I2cAddress); - return new UnixI2cDevice(settings); + return I2cDevice.Create(settings); } } } diff --git a/src/devices/Sht3x/README.md b/src/devices/Sht3x/README.md index 605da9695c..cc27b8d124 100644 --- a/src/devices/Sht3x/README.md +++ b/src/devices/Sht3x/README.md @@ -8,7 +8,7 @@ SHT3x is the next generation of Sensirion’s temperature and humidity sensors. ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, (byte)I2cAddress.AddrLow); // get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); // get I2cDevice (in Win10) //Windows10I2cDevice device = new Windows10I2cDevice(settings); diff --git a/src/devices/Sht3x/samples/Program.cs b/src/devices/Sht3x/samples/Program.cs index 37caad4414..3af7d4e4d4 100644 --- a/src/devices/Sht3x/samples/Program.cs +++ b/src/devices/Sht3x/samples/Program.cs @@ -14,7 +14,7 @@ class Program static void Main(string[] args) { I2cConnectionSettings settings = new I2cConnectionSettings(1, (byte)I2cAddress.AddrLow); - UnixI2cDevice device = new UnixI2cDevice(settings); + I2cDevice device = I2cDevice.Create(settings); using (Sht3x sensor = new Sht3x(device)) { diff --git a/src/devices/Sht3x/samples/README.md b/src/devices/Sht3x/samples/README.md index 65a237c8d0..40b017a27d 100644 --- a/src/devices/Sht3x/samples/README.md +++ b/src/devices/Sht3x/samples/README.md @@ -16,7 +16,7 @@ ## Code ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, (byte)I2cAddress.AddrLow); -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Sht3x sensor = new Sht3x(device)) { diff --git a/src/devices/Si7021/README.md b/src/devices/Si7021/README.md index e2e8d8726c..004ac6a9cd 100644 --- a/src/devices/Si7021/README.md +++ b/src/devices/Si7021/README.md @@ -7,10 +7,7 @@ The Si7021 device provides temperature and humidity sensor readings with an I2C ## Usage ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Si7021.DefaultI2cAddress); -// get I2cDevice (in Linux) -UnixI2cDevice device = new UnixI2cDevice(settings); -// get I2cDevice (in Win10) -//Windows10I2cDevice device = new Windows10I2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Si7021 sensor = new Si7021(device, Resolution.Resolution1)) { diff --git a/src/devices/Si7021/samples/Program.cs b/src/devices/Si7021/samples/Program.cs index 1d49f7b52d..7f4931801b 100644 --- a/src/devices/Si7021/samples/Program.cs +++ b/src/devices/Si7021/samples/Program.cs @@ -14,7 +14,7 @@ class Program static void Main(string[] args) { I2cConnectionSettings settings = new I2cConnectionSettings(1, Si7021.DefaultI2cAddress); - UnixI2cDevice device = new UnixI2cDevice(settings); + I2cDevice device = I2cDevice.Create(settings); using (Si7021 sensor = new Si7021(device, Resolution.Resolution1)) { diff --git a/src/devices/Si7021/samples/README.md b/src/devices/Si7021/samples/README.md index 85a3f3a95c..97afb5b8b9 100644 --- a/src/devices/Si7021/samples/README.md +++ b/src/devices/Si7021/samples/README.md @@ -15,7 +15,7 @@ ## Code ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Si7021.DefaultI2cAddress); -UnixI2cDevice device = new UnixI2cDevice(settings); +I2cDevice device = I2cDevice.Create(settings); using (Si7021 sensor = new Si7021(device, Resolution.Resolution1)) { diff --git a/src/devices/Ssd13xx/samples/Ssd13xx.Sample.cs b/src/devices/Ssd13xx/samples/Ssd13xx.Sample.cs index ccc2006a77..72b4da63ad 100644 --- a/src/devices/Ssd13xx/samples/Ssd13xx.Sample.cs +++ b/src/devices/Ssd13xx/samples/Ssd13xx.Sample.cs @@ -50,11 +50,12 @@ static void Main(string[] args) #endif } - private static UnixI2cDevice GetI2CDevice(){ + private static I2cDevice GetI2CDevice() + { Console.WriteLine("Using I2C protocol"); var connectionSettings = new I2cConnectionSettings(1, 0x3C); - return new UnixI2cDevice(connectionSettings); + return I2cDevice.Create(connectionSettings); } private static Ssd1327 GetSsd1327WithI2c() @@ -66,7 +67,7 @@ private static Ssd1306 GetSsd1306WithI2c() { return new Ssd1306(GetI2CDevice()); } - + // Display size 128x32. private static void Initialize(Ssd1306 device) { @@ -91,7 +92,7 @@ private static void Initialize(Ssd1306 device) } // Display size 96x96. - private static void Initialize(Ssd1327 device) + private static void Initialize(Ssd1327 device) { device.SendCommand(new Ssd1327Cmnds.SetUnlockDriver(true)); device.SendCommand(new SetDisplayOff()); @@ -187,8 +188,8 @@ private static string DisplayIpAddress() } private static void DisplayImages(Ssd1306 ssd1306) - { - Console.WriteLine("Display Images"); + { + Console.WriteLine("Display Images"); foreach(var image_name in Directory.GetFiles("images", "*.bmp").OrderBy(f => f)) { using (Image image = Image.Load(image_name)) @@ -208,7 +209,7 @@ private static void DisplayClock(Ssd1306 ssd1306) var y = 0; foreach(var i in Enumerable.Range(0,100)) - { + { using (Image image = new Image(128, 32)) { image.Mutate(ctx => ctx @@ -225,11 +226,11 @@ private static void DisplayClock(Ssd1306 ssd1306) if(y >= image.Height) y = 0; Thread.Sleep(100); - } + } } } - - // Referencing https://stackoverflow.com/questions/6803073/get-local-ip-address + + // Referencing https://stackoverflow.com/questions/6803073/get-local-ip-address private static string GetIpAddress() { // Get a list of all network interfaces (usually one per network card, dialup, and VPN connection). @@ -268,8 +269,8 @@ private static string GetIpAddress() public static void DisplayImage(this Ssd1306 s, Image image) { Int16 width = 128; - Int16 pages = 4; - List buffer = new List(); + Int16 pages = 4; + List buffer = new List(); for (int page = 0; page < pages; page++) { @@ -277,15 +278,15 @@ public static void DisplayImage(this Ssd1306 s, Image image) { int bits = 0; for (byte bit = 0; bit < 8; bit++) - { + { bits = bits << 1; - bits |= image[x, page * 8 + 7 - bit].PackedValue > 0 ? 1 : 0; - } + bits |= image[x, page * 8 + 7 - bit].PackedValue > 0 ? 1 : 0; + } - buffer.Add((byte)bits); + buffer.Add((byte)bits); } } - + int chunk_size = 16; for(int i = 0; i < buffer.Count; i += chunk_size) { diff --git a/src/devices/Tcs3472x/README.md b/src/devices/Tcs3472x/README.md index f1596ce017..36888e1d03 100644 --- a/src/devices/Tcs3472x/README.md +++ b/src/devices/Tcs3472x/README.md @@ -12,7 +12,7 @@ Device Family contains TCS34721, TCS34723, TCS34725 and TCS34727. You will find this device as ["Light and Color Sensor" at Dexter Industries"](https://www.dexterindustries.com/product/light-color-sensor/) or ["RGB Color Sensor with IR filter and White LED - TCS34725"](https://www.adafruit.com/product/1334) -Note: TCS34721 and TCS34723 have a default I2C address which is 0x39 while TCS34725 and TCS34727 have 0x29. +Note: TCS34721 and TCS34723 have a default I2C address which is 0x39 while TCS34725 and TCS34727 have 0x29. ## Usage @@ -20,7 +20,7 @@ Create a ```Tcs3472xSensor``` class and pass the I2C device. Please see above fo ```csharp var i2cSettings = new I2cConnectionSettings(1, Tcs3472xSensor.DefaultAddress); -I2cDevice i2cDevice = new UnixI2cDevice(i2cSettings); +I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); Tcs3472xSensor tcs3472X = new Tcs3472xSensor(i2cDevice); while(!Console.KeyAvailable) { @@ -32,6 +32,6 @@ while(!Console.KeyAvailable) } ``` -You can as well adjust the time for integration, so the time needed to read the data either in the constructor either later one. Minimum time is 0.0024 seconds and maximum time is 7.4 seconds. This is not a linear function and it will be set to the closest lower value supported by the chip. +You can as well adjust the time for integration, so the time needed to read the data either in the constructor either later one. Minimum time is 0.0024 seconds and maximum time is 7.4 seconds. This is not a linear function and it will be set to the closest lower value supported by the chip. -when calling ```tcs3472X.GetColor()``` you get a ```Color``` type with RGB as the normal RGB. A contains the *Clear* value of the sensor. \ No newline at end of file +when calling ```tcs3472X.GetColor()``` you get a ```Color``` type with RGB as the normal RGB. A contains the *Clear* value of the sensor. diff --git a/src/devices/Tcs3472x/samples/README.md b/src/devices/Tcs3472x/samples/README.md index 508608585f..b0d13e11d8 100644 --- a/src/devices/Tcs3472x/samples/README.md +++ b/src/devices/Tcs3472x/samples/README.md @@ -8,7 +8,7 @@ Create a ```Tcs3472xSensor``` class and pass the I2C device. Please see above fo ```csharp var i2cSettings = new I2cConnectionSettings(1, Tcs3472xSensor.DefaultAddress); -I2cDevice i2cDevice = new UnixI2cDevice(i2cSettings); +I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); Tcs3472xSensor tcs3472X = new Tcs3472xSensor(i2cDevice); while(!Console.KeyAvailable) { @@ -20,6 +20,6 @@ while(!Console.KeyAvailable) } ``` -You can as well adjust the time for integration, so the time needed to read the data either in the constructor either later one. Minimum time is 0.0024 seconds and maximum time is 7.4 seconds. This is not a linear function and it will be set to the closest lower value supported byt the system. +You can as well adjust the time for integration, so the time needed to read the data either in the constructor either later one. Minimum time is 0.0024 seconds and maximum time is 7.4 seconds. This is not a linear function and it will be set to the closest lower value supported byt the system. -when calling ```tcs3472X.GetColor()``` you get a ```Color``` type with RGB as the normal RGB. A contains the *Clear* value of the sensor. \ No newline at end of file +when calling ```tcs3472X.GetColor()``` you get a ```Color``` type with RGB as the normal RGB. A contains the *Clear* value of the sensor. diff --git a/src/devices/Tcs3472x/samples/Tcs3472x.sample.cs b/src/devices/Tcs3472x/samples/Tcs3472x.sample.cs index 50d3e92a3b..1503b3fae0 100644 --- a/src/devices/Tcs3472x/samples/Tcs3472x.sample.cs +++ b/src/devices/Tcs3472x/samples/Tcs3472x.sample.cs @@ -16,7 +16,7 @@ static void Main(string[] args) { Console.WriteLine("Hello TCS3472x!"); var i2cSettings = new I2cConnectionSettings(1, Tcs3472x.DefaultI2cAddress); - I2cDevice i2cDevice = new UnixI2cDevice(i2cSettings); + I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); using(Tcs3472x tcs3472X = new Tcs3472x(i2cDevice)) { while(!Console.KeyAvailable) @@ -27,7 +27,7 @@ static void Main(string[] args) Console.WriteLine($"Valid data: {tcs3472X.IsValidData} Clear Interrupt: {tcs3472X.IsClearInterrupt}"); Thread.Sleep(1000); } - + } } } diff --git a/src/devices/Vl53L0X/README.md b/src/devices/Vl53L0X/README.md index 9c3626886d..5c2131c5a4 100644 --- a/src/devices/Vl53L0X/README.md +++ b/src/devices/Vl53L0X/README.md @@ -17,12 +17,12 @@ You will find this device as ["Distance Sensor"](https://www.dexterindustries.co All calibration and all setup of the sensor is done fully transparently for you. Just create a class and read either once the distance, either using the continuous measurement method. ```csharp -Vl53L0X vL53L0X = new Vl53L0X(new UnixI2cDevice(new I2cConnectionSettings(1, Vl53L0X.DefaultI2cAddress))); +Vl53L0X vL53L0X = new Vl53L0X(I2cDevice.Create(new I2cConnectionSettings(1, Vl53L0X.DefaultI2cAddress))); Console.WriteLine($"Rev: {vL53L0X.Info.Revision}, Prod: {vL53L0X.Info.ProductId}, Mod: {vL53L0X.Info.ModuleId}"); while (!Console.KeyAvailable) { try - { + { Console.WriteLine($"Distance: {vL53L0X.Distance}"); } catch (Exception ex) @@ -37,7 +37,7 @@ Be aware that when reading a distance using the Continuous or Single measurement You can as well get a single measurement, in this case, the precision can be lower. Use the property ```MeasurementMode``` to change the mode. -You can adjust the type of measurement you want. By default, the sensor is put into long range. This does allow to have a quite accurate (+-5%) precision within 2 meters but still can measure distances up to 8 meters (accuracy much less correct). You can switch to short range using the ```SetPrecision``` function. If you want to setup your own mode, you should use in conjunction the ```SetSignalRateLimit``` and the ```SetVcselPulsePeriod``` functions plus the ```HighResolution``` property like in the below example: +You can adjust the type of measurement you want. By default, the sensor is put into long range. This does allow to have a quite accurate (+-5%) precision within 2 meters but still can measure distances up to 8 meters (accuracy much less correct). You can switch to short range using the ```SetPrecision``` function. If you want to setup your own mode, you should use in conjunction the ```SetSignalRateLimit``` and the ```SetVcselPulsePeriod``` functions plus the ```HighResolution``` property like in the below example: ```csharp HighResolution = false; @@ -46,4 +46,4 @@ SetVcselPulsePeriod(VcselType.VcselPeriodPreRange, PeriodPulse.Period14); SetVcselPulsePeriod(VcselType.VcselPeriodFinalRange, PeriodPulse.Period10); ``` -Please refer to the documentation to understand the impact of changing the various pulses as well as using the high resolution precision measurement. The sensor can't be precise in long range and in general, the longer it can see, the less precise are the data. High resolution will return a more precise measurement but mainly in short distance. \ No newline at end of file +Please refer to the documentation to understand the impact of changing the various pulses as well as using the high resolution precision measurement. The sensor can't be precise in long range and in general, the longer it can see, the less precise are the data. High resolution will return a more precise measurement but mainly in short distance. diff --git a/src/devices/Vl53L0X/samples/README.md b/src/devices/Vl53L0X/samples/README.md index a43fb8c762..71d9de1ba1 100644 --- a/src/devices/Vl53L0X/samples/README.md +++ b/src/devices/Vl53L0X/samples/README.md @@ -11,7 +11,7 @@ This sensor is an I2C sensor. So you need to connect the pins of your board to t The usage is straight forward, just initiate a class and start reading the data. Calibration is done automatically in the background. Be aware that first data may not be valid. ```csharp -Vl53L0X vL53L0X = new Vl53L0X(new UnixI2cDevice(new I2cConnectionSettings(1, Vl53L0X.DefaultI2cAddress))); +Vl53L0X vL53L0X = new Vl53L0X(I2cDevice.Create(new I2cConnectionSettings(1, Vl53L0X.DefaultI2cAddress))); Console.WriteLine($"Rev: {vL53L0X.Info.Revision}, Prod: {vL53L0X.Info.ProductId}, Mod: {vL53L0X.Info.ModuleId}"); // Set high precision mode vL53L0X.Precision = Precision.HighPrecision; @@ -37,4 +37,4 @@ while (!Console.KeyAvailable) } Thread.Sleep(500); } -``` \ No newline at end of file +``` diff --git a/src/devices/Vl53L0X/samples/Vl53L0X.sample.cs b/src/devices/Vl53L0X/samples/Vl53L0X.sample.cs index d69a965432..3442aa67f6 100644 --- a/src/devices/Vl53L0X/samples/Vl53L0X.sample.cs +++ b/src/devices/Vl53L0X/samples/Vl53L0X.sample.cs @@ -15,7 +15,7 @@ class Program static void Main(string[] args) { Console.WriteLine("Hello VL53L0X!"); - Vl53L0X vL53L0X = new Vl53L0X(new UnixI2cDevice(new I2cConnectionSettings(1, Vl53L0X.DefaultI2cAddress))); + Vl53L0X vL53L0X = new Vl53L0X(I2cDevice.Create(new I2cConnectionSettings(1, Vl53L0X.DefaultI2cAddress))); Console.WriteLine($"Rev: {vL53L0X.Information.Revision}, Prod: {vL53L0X.Information.ProductId}, Mod: {vL53L0X.Information.ModuleId}"); Console.WriteLine($"Offset in µm: {vL53L0X.Information.OffsetMicrometers}, Signal rate fixed 400 µm: {vL53L0X.Information.SignalRateMeasuementFixed400Micrometers}"); vL53L0X.MeasurementMode = MeasurementMode.Continuous;