From eae8a70bc253f7573176ed803d6e3461d0fdabeb Mon Sep 17 00:00:00 2001 From: Patrick Grawehr Date: Thu, 29 Sep 2022 17:39:45 +0200 Subject: [PATCH] The call to Dns.GetHostEntry() may fail on MacOS (#1927) * The call to Dns.GetHostEntry() may fail on MacOS ... only ever seen there. * Build on one CPU only Maybe this avoids the concurrency problems? * Revert "Build on one CPU only" This reverts commit 7ee8124b4ceb5e31df7f74d7da4e908ad96aaac3. * Make sure there's only one .csproj per directory Therefore split up sample folders containing multiple projects into subfolders. This fixes the macOS build and also some weird issues on other operating systems (such as the debugger getting confused about which one to execute) * Also update the solution files --- src/devices/Arduino/Arduino.sln | 4 +- .../{ => ApiChecker}/Arduino.sample.cs | 0 .../{ => ApiChecker}/Arduino.sample.csproj | 9 +- .../ArduinoCompilerSampleMethods.cs | 0 .../{ => ApiChecker}/DebugLogStream.cs | 0 .../samples/{ => ApiChecker}/RgbLedTest.cs | 0 .../samples/{ => ApiChecker}/TestCases.cs | 0 .../samples/{ => Monitor}/Arduino.Monitor.cs | 0 .../{ => Monitor}/Arduino.Monitor.csproj | 15 +- .../samples/{ => Monitor}/CharacterDisplay.cs | 0 .../Arduino/tests/Arduino.Tests.csproj | 2 +- src/devices/Bh1745/Bh1745.sln | 4 +- .../samples/{ => BH1745}/Bh1745.Sample.csproj | 4 +- .../samples/{Program.cs => BH1745/Bh1745.cs} | 0 .../Bh1745.CustomConfiguration.cs} | 0 .../Bh1745CustomConfiguration.Sample.csproj} | 8 +- src/devices/Bmxx80/Bmxx80.sln | 6 +- .../samples/{ => Bme280}/Bme280.sample.cs | 0 .../samples/Bme280/Bme280.sample.csproj} | 4 +- .../samples/{ => Bme680}/Bme680.sample.cs | 188 +++++++++--------- .../samples/{ => Bme680}/Bme680.sample.csproj | 6 +- .../samples/{ => Bmp280}/Bmp280.sample.cs | 0 .../samples/{ => Bmp280}/Bmp280.sample.csproj | 6 +- src/devices/LiquidLevel/LiquidLevel.sln | 4 +- .../LiquidLevelSwitch.Sample.csproj | 6 +- .../LiquidLevelSwitch.sample.cs | 0 .../{ => Llc200d3sh}/Llc200d3sh.Sample.csproj | 6 +- .../{ => Llc200d3sh}/Llc200d3sh.sample.cs | 0 src/devices/Nmea0183/NmeaUdpServer.cs | 18 +- src/devices/Seesaw/Seesaw.sln | 8 +- .../Seesaw.Sample.BlinkingLights.cs | 0 .../Seesaw.Sample.BlinkingLights.csproj | 4 +- .../samples/{ => BlinkingLights}/Volume.cs | 0 .../Seesaw.Sample.Capabilities.cs | 0 .../Seesaw.Sample.Capabilities.csproj | 2 +- .../{ => Encoder}/Seesaw.Sample.Encoder.cs | 0 .../Seesaw.Sample.Encoder.csproj | 2 +- .../Seesaw.Sample.SoilSensor.cs | 0 .../Seesaw.Sample.SoilSensor.csproj | 2 +- tools/ArduinoCsCompiler/ArduinoCsCompiler.sln | 2 +- .../Frontend/Frontend.csproj | 2 +- 41 files changed, 149 insertions(+), 163 deletions(-) rename src/devices/Arduino/samples/{ => ApiChecker}/Arduino.sample.cs (100%) rename src/devices/Arduino/samples/{ => ApiChecker}/Arduino.sample.csproj (72%) rename src/devices/Arduino/samples/{ => ApiChecker}/ArduinoCompilerSampleMethods.cs (100%) rename src/devices/Arduino/samples/{ => ApiChecker}/DebugLogStream.cs (100%) rename src/devices/Arduino/samples/{ => ApiChecker}/RgbLedTest.cs (100%) rename src/devices/Arduino/samples/{ => ApiChecker}/TestCases.cs (100%) rename src/devices/Arduino/samples/{ => Monitor}/Arduino.Monitor.cs (100%) rename src/devices/Arduino/samples/{ => Monitor}/Arduino.Monitor.csproj (50%) rename src/devices/Arduino/samples/{ => Monitor}/CharacterDisplay.cs (100%) rename src/devices/Bh1745/samples/{ => BH1745}/Bh1745.Sample.csproj (75%) rename src/devices/Bh1745/samples/{Program.cs => BH1745/Bh1745.cs} (100%) rename src/devices/Bh1745/samples/{Program.CustomConfiguration.cs => CustomConfiguration/Bh1745.CustomConfiguration.cs} (100%) rename src/devices/{Bmxx80/samples/Bme280.sample.csproj => Bh1745/samples/CustomConfiguration/Bh1745CustomConfiguration.Sample.csproj} (57%) rename src/devices/Bmxx80/samples/{ => Bme280}/Bme280.sample.cs (100%) rename src/devices/{Bh1745/samples/Bh1745CustomConfiguration.Sample.csproj => Bmxx80/samples/Bme280/Bme280.sample.csproj} (72%) rename src/devices/Bmxx80/samples/{ => Bme680}/Bme680.sample.cs (97%) rename src/devices/Bmxx80/samples/{ => Bme680}/Bme680.sample.csproj (66%) rename src/devices/Bmxx80/samples/{ => Bmp280}/Bmp280.sample.cs (100%) rename src/devices/Bmxx80/samples/{ => Bmp280}/Bmp280.sample.csproj (66%) rename src/devices/LiquidLevel/samples/{ => LiquidLevelSwitch}/LiquidLevelSwitch.Sample.csproj (66%) rename src/devices/LiquidLevel/samples/{ => LiquidLevelSwitch}/LiquidLevelSwitch.sample.cs (100%) rename src/devices/LiquidLevel/samples/{ => Llc200d3sh}/Llc200d3sh.Sample.csproj (66%) rename src/devices/LiquidLevel/samples/{ => Llc200d3sh}/Llc200d3sh.sample.cs (100%) rename src/devices/Seesaw/samples/{ => BlinkingLights}/Seesaw.Sample.BlinkingLights.cs (100%) rename src/devices/Seesaw/samples/{ => BlinkingLights}/Seesaw.Sample.BlinkingLights.csproj (70%) rename src/devices/Seesaw/samples/{ => BlinkingLights}/Volume.cs (100%) rename src/devices/Seesaw/samples/{ => Capabilities}/Seesaw.Sample.Capabilities.cs (100%) rename src/devices/Seesaw/samples/{ => Capabilities}/Seesaw.Sample.Capabilities.csproj (87%) rename src/devices/Seesaw/samples/{ => Encoder}/Seesaw.Sample.Encoder.cs (100%) rename src/devices/Seesaw/samples/{ => Encoder}/Seesaw.Sample.Encoder.csproj (86%) rename src/devices/Seesaw/samples/{ => SoilSensor}/Seesaw.Sample.SoilSensor.cs (100%) rename src/devices/Seesaw/samples/{ => SoilSensor}/Seesaw.Sample.SoilSensor.csproj (84%) diff --git a/src/devices/Arduino/Arduino.sln b/src/devices/Arduino/Arduino.sln index aa8429b200..cb9737aa3e 100644 --- a/src/devices/Arduino/Arduino.sln +++ b/src/devices/Arduino/Arduino.sln @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arduino", "Arduino.csproj", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Device.Gpio", "..\..\System.Device.Gpio\System.Device.Gpio.csproj", "{0B90F9D4-7353-4172-A317-714471A06781}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arduino.sample", "samples\Arduino.sample.csproj", "{2670F7BF-A7C8-49EB-9A99-1719A90D0C67}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arduino.sample", "samples\ApiChecker\Arduino.sample.csproj", "{2670F7BF-A7C8-49EB-9A99-1719A90D0C67}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bmxx80", "..\Bmxx80\Bmxx80.csproj", "{EEEB0FB8-E1ED-4970-BDF6-DA3D5E2ED074}" EndProject @@ -21,7 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CpuTemperature", "..\CpuTem EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{9E5A25ED-9839-4C1A-9B27-993437D1CB31}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arduino.Monitor", "samples\Arduino.Monitor.csproj", "{23B4B60C-9594-42BB-9D25-C54983B0F809}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arduino.Monitor", "samples\Monitor\Arduino.Monitor.csproj", "{23B4B60C-9594-42BB-9D25-C54983B0F809}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CA26B999-4C0E-4E82-A46E-A68AC1B85C10}" EndProject diff --git a/src/devices/Arduino/samples/Arduino.sample.cs b/src/devices/Arduino/samples/ApiChecker/Arduino.sample.cs similarity index 100% rename from src/devices/Arduino/samples/Arduino.sample.cs rename to src/devices/Arduino/samples/ApiChecker/Arduino.sample.cs diff --git a/src/devices/Arduino/samples/Arduino.sample.csproj b/src/devices/Arduino/samples/ApiChecker/Arduino.sample.csproj similarity index 72% rename from src/devices/Arduino/samples/Arduino.sample.csproj rename to src/devices/Arduino/samples/ApiChecker/Arduino.sample.csproj index ec2a7420f3..ce567cab24 100644 --- a/src/devices/Arduino/samples/Arduino.sample.csproj +++ b/src/devices/Arduino/samples/ApiChecker/Arduino.sample.csproj @@ -16,10 +16,9 @@ - - - - - + + + + \ No newline at end of file diff --git a/src/devices/Arduino/samples/ArduinoCompilerSampleMethods.cs b/src/devices/Arduino/samples/ApiChecker/ArduinoCompilerSampleMethods.cs similarity index 100% rename from src/devices/Arduino/samples/ArduinoCompilerSampleMethods.cs rename to src/devices/Arduino/samples/ApiChecker/ArduinoCompilerSampleMethods.cs diff --git a/src/devices/Arduino/samples/DebugLogStream.cs b/src/devices/Arduino/samples/ApiChecker/DebugLogStream.cs similarity index 100% rename from src/devices/Arduino/samples/DebugLogStream.cs rename to src/devices/Arduino/samples/ApiChecker/DebugLogStream.cs diff --git a/src/devices/Arduino/samples/RgbLedTest.cs b/src/devices/Arduino/samples/ApiChecker/RgbLedTest.cs similarity index 100% rename from src/devices/Arduino/samples/RgbLedTest.cs rename to src/devices/Arduino/samples/ApiChecker/RgbLedTest.cs diff --git a/src/devices/Arduino/samples/TestCases.cs b/src/devices/Arduino/samples/ApiChecker/TestCases.cs similarity index 100% rename from src/devices/Arduino/samples/TestCases.cs rename to src/devices/Arduino/samples/ApiChecker/TestCases.cs diff --git a/src/devices/Arduino/samples/Arduino.Monitor.cs b/src/devices/Arduino/samples/Monitor/Arduino.Monitor.cs similarity index 100% rename from src/devices/Arduino/samples/Arduino.Monitor.cs rename to src/devices/Arduino/samples/Monitor/Arduino.Monitor.cs diff --git a/src/devices/Arduino/samples/Arduino.Monitor.csproj b/src/devices/Arduino/samples/Monitor/Arduino.Monitor.csproj similarity index 50% rename from src/devices/Arduino/samples/Arduino.Monitor.csproj rename to src/devices/Arduino/samples/Monitor/Arduino.Monitor.csproj index 19efba6131..920a46e43a 100644 --- a/src/devices/Arduino/samples/Arduino.Monitor.csproj +++ b/src/devices/Arduino/samples/Monitor/Arduino.Monitor.csproj @@ -14,13 +14,12 @@ - - - - - - - - + + + + + + + \ No newline at end of file diff --git a/src/devices/Arduino/samples/CharacterDisplay.cs b/src/devices/Arduino/samples/Monitor/CharacterDisplay.cs similarity index 100% rename from src/devices/Arduino/samples/CharacterDisplay.cs rename to src/devices/Arduino/samples/Monitor/CharacterDisplay.cs diff --git a/src/devices/Arduino/tests/Arduino.Tests.csproj b/src/devices/Arduino/tests/Arduino.Tests.csproj index 4713c06f45..fbcbe758c2 100644 --- a/src/devices/Arduino/tests/Arduino.Tests.csproj +++ b/src/devices/Arduino/tests/Arduino.Tests.csproj @@ -10,7 +10,7 @@ true - + diff --git a/src/devices/Bh1745/Bh1745.sln b/src/devices/Bh1745/Bh1745.sln index 261619ebe6..2193c4ba02 100644 --- a/src/devices/Bh1745/Bh1745.sln +++ b/src/devices/Bh1745/Bh1745.sln @@ -5,9 +5,9 @@ VisualStudioVersion = 16.0.31205.134 MinimumVisualStudioVersion = 15.0.26124.0 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{EA121A48-7916-4D9D-94C8-8E59BCDE3A96}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bh1745.Sample", "samples\Bh1745.Sample.csproj", "{24A728CA-F4EF-4DB0-B13F-65FFD772352B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bh1745.Sample", "samples\BH1745\Bh1745.Sample.csproj", "{24A728CA-F4EF-4DB0-B13F-65FFD772352B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bh1745CustomConfiguration.Sample", "samples\Bh1745CustomConfiguration.Sample.csproj", "{F6ED35EA-2FDE-4056-8165-0FAB6CE5DD5E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bh1745CustomConfiguration.Sample", "samples\CustomConfiguration\Bh1745CustomConfiguration.Sample.csproj", "{F6ED35EA-2FDE-4056-8165-0FAB6CE5DD5E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bh1745", "Bh1745.csproj", "{C572C86D-5BB2-4610-84EA-768257758933}" EndProject diff --git a/src/devices/Bh1745/samples/Bh1745.Sample.csproj b/src/devices/Bh1745/samples/BH1745/Bh1745.Sample.csproj similarity index 75% rename from src/devices/Bh1745/samples/Bh1745.Sample.csproj rename to src/devices/Bh1745/samples/BH1745/Bh1745.Sample.csproj index 5fabc82c70..53767eb6ee 100644 --- a/src/devices/Bh1745/samples/Bh1745.Sample.csproj +++ b/src/devices/Bh1745/samples/BH1745/Bh1745.Sample.csproj @@ -5,9 +5,9 @@ false - + - + \ No newline at end of file diff --git a/src/devices/Bh1745/samples/Program.cs b/src/devices/Bh1745/samples/BH1745/Bh1745.cs similarity index 100% rename from src/devices/Bh1745/samples/Program.cs rename to src/devices/Bh1745/samples/BH1745/Bh1745.cs diff --git a/src/devices/Bh1745/samples/Program.CustomConfiguration.cs b/src/devices/Bh1745/samples/CustomConfiguration/Bh1745.CustomConfiguration.cs similarity index 100% rename from src/devices/Bh1745/samples/Program.CustomConfiguration.cs rename to src/devices/Bh1745/samples/CustomConfiguration/Bh1745.CustomConfiguration.cs diff --git a/src/devices/Bmxx80/samples/Bme280.sample.csproj b/src/devices/Bh1745/samples/CustomConfiguration/Bh1745CustomConfiguration.Sample.csproj similarity index 57% rename from src/devices/Bmxx80/samples/Bme280.sample.csproj rename to src/devices/Bh1745/samples/CustomConfiguration/Bh1745CustomConfiguration.Sample.csproj index 9537053a0e..dc4478238a 100644 --- a/src/devices/Bmxx80/samples/Bme280.sample.csproj +++ b/src/devices/Bh1745/samples/CustomConfiguration/Bh1745CustomConfiguration.Sample.csproj @@ -5,13 +5,9 @@ false - - + - - - - + \ No newline at end of file diff --git a/src/devices/Bmxx80/Bmxx80.sln b/src/devices/Bmxx80/Bmxx80.sln index 9565f70efc..d705975193 100644 --- a/src/devices/Bmxx80/Bmxx80.sln +++ b/src/devices/Bmxx80/Bmxx80.sln @@ -5,11 +5,11 @@ VisualStudioVersion = 16.0.30011.22 MinimumVisualStudioVersion = 15.0.26124.0 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{3810A23A-DF9E-4956-961F-10272B731209}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bme280.sample", "samples\Bme280.sample.csproj", "{5F20AA65-F5E2-4CD9-8847-1508DA362092}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bme280.sample", "samples\Bme280\Bme280.sample.csproj", "{5F20AA65-F5E2-4CD9-8847-1508DA362092}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bme680.sample", "samples\Bme680.sample.csproj", "{0583C743-4EE5-4150-8886-AABC1EB6A339}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bme680.sample", "samples\Bme680\Bme680.sample.csproj", "{0583C743-4EE5-4150-8886-AABC1EB6A339}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bmp280.sample", "samples\Bmp280.sample.csproj", "{99456915-2483-4C22-8F63-8817A097F2E2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bmp280.sample", "samples\Bmp280\Bmp280.sample.csproj", "{99456915-2483-4C22-8F63-8817A097F2E2}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bmxx80", "Bmxx80.csproj", "{D0AA8380-159F-445B-A081-D750B9062ADA}" EndProject diff --git a/src/devices/Bmxx80/samples/Bme280.sample.cs b/src/devices/Bmxx80/samples/Bme280/Bme280.sample.cs similarity index 100% rename from src/devices/Bmxx80/samples/Bme280.sample.cs rename to src/devices/Bmxx80/samples/Bme280/Bme280.sample.cs diff --git a/src/devices/Bh1745/samples/Bh1745CustomConfiguration.Sample.csproj b/src/devices/Bmxx80/samples/Bme280/Bme280.sample.csproj similarity index 72% rename from src/devices/Bh1745/samples/Bh1745CustomConfiguration.Sample.csproj rename to src/devices/Bmxx80/samples/Bme280/Bme280.sample.csproj index 8941e80c5d..769549cbba 100644 --- a/src/devices/Bh1745/samples/Bh1745CustomConfiguration.Sample.csproj +++ b/src/devices/Bmxx80/samples/Bme280/Bme280.sample.csproj @@ -5,9 +5,9 @@ false - + - + \ No newline at end of file diff --git a/src/devices/Bmxx80/samples/Bme680.sample.cs b/src/devices/Bmxx80/samples/Bme680/Bme680.sample.cs similarity index 97% rename from src/devices/Bmxx80/samples/Bme680.sample.cs rename to src/devices/Bmxx80/samples/Bme680/Bme680.sample.cs index 91ed456533..74aa928a07 100644 --- a/src/devices/Bmxx80/samples/Bme680.sample.cs +++ b/src/devices/Bmxx80/samples/Bme680/Bme680.sample.cs @@ -1,94 +1,94 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Device.I2c; -using System.Threading; -using Iot.Device.Bmxx80; -using Iot.Device.Common; -using UnitsNet; - -Console.WriteLine("Hello BME680!"); - -// The I2C bus ID on the Raspberry Pi 3. -const int busId = 1; -// set this to the current sea level pressure in the area for correct altitude readings -Pressure defaultSeaLevelPressure = WeatherHelper.MeanSeaLevel; - -I2cConnectionSettings i2cSettings = new(busId, Bme680.DefaultI2cAddress); -I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); - -using Bme680 bme680 = new Bme680(i2cDevice, Temperature.FromDegreesCelsius(20.0)); - -while (true) -{ - // reset will change settings back to default - bme680.Reset(); - - // 10 consecutive measurement with default settings - for (var i = 0; i < 10; i++) - { - // Perform a synchronous measurement - var readResult = bme680.Read(); - - // Print out the measured data - Console.WriteLine($"Gas resistance: {readResult.GasResistance?.Ohms:0.##}Ohm"); - Console.WriteLine($"Temperature: {readResult.Temperature?.DegreesCelsius:0.#}\u00B0C"); - Console.WriteLine($"Pressure: {readResult.Pressure?.Hectopascals:0.##}hPa"); - Console.WriteLine($"Relative humidity: {readResult.Humidity?.Percent:0.#}%"); - - if (readResult.Temperature.HasValue && readResult.Pressure.HasValue) - { - var altValue = WeatherHelper.CalculateAltitude(readResult.Pressure.Value, defaultSeaLevelPressure, readResult.Temperature.Value); - Console.WriteLine($"Altitude: {altValue.Meters:0.##}m"); - } - - if (readResult.Temperature.HasValue && readResult.Humidity.HasValue) - { - // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity. - Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(readResult.Temperature.Value, readResult.Humidity.Value).DegreesCelsius:0.#}\u00B0C"); - Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(readResult.Temperature.Value, readResult.Humidity.Value).DegreesCelsius:0.#}\u00B0C"); - } - - // when measuring the gas resistance on each cycle it is important to wait a certain interval - // because a heating plate is activated which will heat up the sensor without sleep, this can - // falsify all readings coming from the sensor - Thread.Sleep(1000); - } - - // change the settings - bme680.TemperatureSampling = Sampling.HighResolution; - bme680.HumiditySampling = Sampling.UltraHighResolution; - bme680.PressureSampling = Sampling.Skipped; - - bme680.ConfigureHeatingProfile(Bme680HeaterProfile.Profile2, Temperature.FromDegreesCelsius(280), Duration.FromMilliseconds(80), Temperature.FromDegreesCelsius(24)); - bme680.HeaterProfile = Bme680HeaterProfile.Profile2; - - // 10 consecutive measurements with custom settings - for (int i = 0; i < 10; i++) - { - // Perform an asynchronous measurement - var readResult = await bme680.ReadAsync(); - - // Print out the measured data - Console.WriteLine($"Gas resistance: {readResult.GasResistance?.Ohms:0.##}Ohm"); - Console.WriteLine($"Temperature: {readResult.Temperature?.DegreesCelsius:0.#}\u00B0C"); - Console.WriteLine($"Pressure: {readResult.Pressure?.Hectopascals:0.##}hPa"); - Console.WriteLine($"Relative humidity: {readResult.Humidity?.Percent:0.#}%"); - - if (readResult.Temperature.HasValue && readResult.Pressure.HasValue) - { - var altValue = WeatherHelper.CalculateAltitude(readResult.Pressure.Value, defaultSeaLevelPressure, readResult.Temperature.Value); - Console.WriteLine($"Altitude: {altValue.Meters:0.##}m"); - } - - if (readResult.Temperature.HasValue && readResult.Humidity.HasValue) - { - // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity. - Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(readResult.Temperature.Value, readResult.Humidity.Value).DegreesCelsius:0.#}\u00B0C"); - Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(readResult.Temperature.Value, readResult.Humidity.Value).DegreesCelsius:0.#}\u00B0C"); - } - - Thread.Sleep(1000); - } -} +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Device.I2c; +using System.Threading; +using Iot.Device.Bmxx80; +using Iot.Device.Common; +using UnitsNet; + +Console.WriteLine("Hello BME680!"); + +// The I2C bus ID on the Raspberry Pi 3. +const int busId = 1; +// set this to the current sea level pressure in the area for correct altitude readings +Pressure defaultSeaLevelPressure = WeatherHelper.MeanSeaLevel; + +I2cConnectionSettings i2cSettings = new(busId, Bme680.DefaultI2cAddress); +I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); + +using Bme680 bme680 = new Bme680(i2cDevice, Temperature.FromDegreesCelsius(20.0)); + +while (true) +{ + // reset will change settings back to default + bme680.Reset(); + + // 10 consecutive measurement with default settings + for (var i = 0; i < 10; i++) + { + // Perform a synchronous measurement + var readResult = bme680.Read(); + + // Print out the measured data + Console.WriteLine($"Gas resistance: {readResult.GasResistance?.Ohms:0.##}Ohm"); + Console.WriteLine($"Temperature: {readResult.Temperature?.DegreesCelsius:0.#}\u00B0C"); + Console.WriteLine($"Pressure: {readResult.Pressure?.Hectopascals:0.##}hPa"); + Console.WriteLine($"Relative humidity: {readResult.Humidity?.Percent:0.#}%"); + + if (readResult.Temperature.HasValue && readResult.Pressure.HasValue) + { + var altValue = WeatherHelper.CalculateAltitude(readResult.Pressure.Value, defaultSeaLevelPressure, readResult.Temperature.Value); + Console.WriteLine($"Altitude: {altValue.Meters:0.##}m"); + } + + if (readResult.Temperature.HasValue && readResult.Humidity.HasValue) + { + // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity. + Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(readResult.Temperature.Value, readResult.Humidity.Value).DegreesCelsius:0.#}\u00B0C"); + Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(readResult.Temperature.Value, readResult.Humidity.Value).DegreesCelsius:0.#}\u00B0C"); + } + + // when measuring the gas resistance on each cycle it is important to wait a certain interval + // because a heating plate is activated which will heat up the sensor without sleep, this can + // falsify all readings coming from the sensor + Thread.Sleep(1000); + } + + // change the settings + bme680.TemperatureSampling = Sampling.HighResolution; + bme680.HumiditySampling = Sampling.UltraHighResolution; + bme680.PressureSampling = Sampling.Skipped; + + bme680.ConfigureHeatingProfile(Bme680HeaterProfile.Profile2, Temperature.FromDegreesCelsius(280), Duration.FromMilliseconds(80), Temperature.FromDegreesCelsius(24)); + bme680.HeaterProfile = Bme680HeaterProfile.Profile2; + + // 10 consecutive measurements with custom settings + for (int i = 0; i < 10; i++) + { + // Perform an asynchronous measurement + var readResult = await bme680.ReadAsync(); + + // Print out the measured data + Console.WriteLine($"Gas resistance: {readResult.GasResistance?.Ohms:0.##}Ohm"); + Console.WriteLine($"Temperature: {readResult.Temperature?.DegreesCelsius:0.#}\u00B0C"); + Console.WriteLine($"Pressure: {readResult.Pressure?.Hectopascals:0.##}hPa"); + Console.WriteLine($"Relative humidity: {readResult.Humidity?.Percent:0.#}%"); + + if (readResult.Temperature.HasValue && readResult.Pressure.HasValue) + { + var altValue = WeatherHelper.CalculateAltitude(readResult.Pressure.Value, defaultSeaLevelPressure, readResult.Temperature.Value); + Console.WriteLine($"Altitude: {altValue.Meters:0.##}m"); + } + + if (readResult.Temperature.HasValue && readResult.Humidity.HasValue) + { + // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity. + Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(readResult.Temperature.Value, readResult.Humidity.Value).DegreesCelsius:0.#}\u00B0C"); + Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(readResult.Temperature.Value, readResult.Humidity.Value).DegreesCelsius:0.#}\u00B0C"); + } + + Thread.Sleep(1000); + } +} diff --git a/src/devices/Bmxx80/samples/Bme680.sample.csproj b/src/devices/Bmxx80/samples/Bme680/Bme680.sample.csproj similarity index 66% rename from src/devices/Bmxx80/samples/Bme680.sample.csproj rename to src/devices/Bmxx80/samples/Bme680/Bme680.sample.csproj index a3797e9c00..87d88e44bc 100644 --- a/src/devices/Bmxx80/samples/Bme680.sample.csproj +++ b/src/devices/Bmxx80/samples/Bme680/Bme680.sample.csproj @@ -4,14 +4,10 @@ $(DefaultSampleTfms) false - - - - - + \ No newline at end of file diff --git a/src/devices/Bmxx80/samples/Bmp280.sample.cs b/src/devices/Bmxx80/samples/Bmp280/Bmp280.sample.cs similarity index 100% rename from src/devices/Bmxx80/samples/Bmp280.sample.cs rename to src/devices/Bmxx80/samples/Bmp280/Bmp280.sample.cs diff --git a/src/devices/Bmxx80/samples/Bmp280.sample.csproj b/src/devices/Bmxx80/samples/Bmp280/Bmp280.sample.csproj similarity index 66% rename from src/devices/Bmxx80/samples/Bmp280.sample.csproj rename to src/devices/Bmxx80/samples/Bmp280/Bmp280.sample.csproj index f741a4a804..8eb90052ab 100644 --- a/src/devices/Bmxx80/samples/Bmp280.sample.csproj +++ b/src/devices/Bmxx80/samples/Bmp280/Bmp280.sample.csproj @@ -4,14 +4,10 @@ $(DefaultSampleTfms) false - - - - - + \ No newline at end of file diff --git a/src/devices/LiquidLevel/LiquidLevel.sln b/src/devices/LiquidLevel/LiquidLevel.sln index 2835d50570..f5d2ab1481 100644 --- a/src/devices/LiquidLevel/LiquidLevel.sln +++ b/src/devices/LiquidLevel/LiquidLevel.sln @@ -10,9 +10,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{499A samples\README.md = samples\README.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Llc200d3sh.Sample", "samples\Llc200d3sh.Sample.csproj", "{6A38157B-7F9E-4003-A346-D898C86AE8FA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Llc200d3sh.Sample", "samples\Llc200d3sh\Llc200d3sh.Sample.csproj", "{6A38157B-7F9E-4003-A346-D898C86AE8FA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiquidLevelSwitch.Sample", "samples\LiquidLevelSwitch.Sample.csproj", "{2675D556-74B1-40DA-B1F8-4CE2733463CF}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiquidLevelSwitch.Sample", "samples\LiquidLevelSwitch\LiquidLevelSwitch.Sample.csproj", "{2675D556-74B1-40DA-B1F8-4CE2733463CF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/devices/LiquidLevel/samples/LiquidLevelSwitch.Sample.csproj b/src/devices/LiquidLevel/samples/LiquidLevelSwitch/LiquidLevelSwitch.Sample.csproj similarity index 66% rename from src/devices/LiquidLevel/samples/LiquidLevelSwitch.Sample.csproj rename to src/devices/LiquidLevel/samples/LiquidLevelSwitch/LiquidLevelSwitch.Sample.csproj index 8c2652cd50..9403810c07 100644 --- a/src/devices/LiquidLevel/samples/LiquidLevelSwitch.Sample.csproj +++ b/src/devices/LiquidLevel/samples/LiquidLevelSwitch/LiquidLevelSwitch.Sample.csproj @@ -4,14 +4,10 @@ $(DefaultSampleTfms) false - - - - - + \ No newline at end of file diff --git a/src/devices/LiquidLevel/samples/LiquidLevelSwitch.sample.cs b/src/devices/LiquidLevel/samples/LiquidLevelSwitch/LiquidLevelSwitch.sample.cs similarity index 100% rename from src/devices/LiquidLevel/samples/LiquidLevelSwitch.sample.cs rename to src/devices/LiquidLevel/samples/LiquidLevelSwitch/LiquidLevelSwitch.sample.cs diff --git a/src/devices/LiquidLevel/samples/Llc200d3sh.Sample.csproj b/src/devices/LiquidLevel/samples/Llc200d3sh/Llc200d3sh.Sample.csproj similarity index 66% rename from src/devices/LiquidLevel/samples/Llc200d3sh.Sample.csproj rename to src/devices/LiquidLevel/samples/Llc200d3sh/Llc200d3sh.Sample.csproj index 43c232d11e..34fa18e9d3 100644 --- a/src/devices/LiquidLevel/samples/Llc200d3sh.Sample.csproj +++ b/src/devices/LiquidLevel/samples/Llc200d3sh/Llc200d3sh.Sample.csproj @@ -4,14 +4,10 @@ $(DefaultSampleTfms) false - - - - - + \ No newline at end of file diff --git a/src/devices/LiquidLevel/samples/Llc200d3sh.sample.cs b/src/devices/LiquidLevel/samples/Llc200d3sh/Llc200d3sh.sample.cs similarity index 100% rename from src/devices/LiquidLevel/samples/Llc200d3sh.sample.cs rename to src/devices/LiquidLevel/samples/Llc200d3sh/Llc200d3sh.sample.cs diff --git a/src/devices/Nmea0183/NmeaUdpServer.cs b/src/devices/Nmea0183/NmeaUdpServer.cs index bc94294b9f..9cf671ee81 100644 --- a/src/devices/Nmea0183/NmeaUdpServer.cs +++ b/src/devices/Nmea0183/NmeaUdpServer.cs @@ -255,14 +255,22 @@ public override int Read(byte[] buffer, int offset, int count) } // Check whether the given address is ours (new IPs can be added at runtime, if interfaces go up) - var host = Dns.GetHostEntry(Dns.GetHostName()); - if (host.AddressList.Contains(pt.Address)) + try { - _knownSenders.Add(pt.Address, true); + var host = Dns.GetHostEntry(Dns.GetHostName()); + if (host.AddressList.Contains(pt.Address)) + { + _knownSenders.Add(pt.Address, true); + } + else + { + _knownSenders.Add(pt.Address, false); + } } - else + catch (SocketException x) { - _knownSenders.Add(pt.Address, false); + // Dns.GetHostEntry() sometimes throws a SocketException, but only on MacOS. + _parent.FireOnParserError($"Unable to get DNS entry for Host, possibly disconnected?. Error: {x.Message}", NmeaError.None); } } diff --git a/src/devices/Seesaw/Seesaw.sln b/src/devices/Seesaw/Seesaw.sln index 4bc2754356..297cb12bdf 100644 --- a/src/devices/Seesaw/Seesaw.sln +++ b/src/devices/Seesaw/Seesaw.sln @@ -5,15 +5,15 @@ VisualStudioVersion = 17.2.32505.173 MinimumVisualStudioVersion = 15.0.26124.0 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{A15390DB-F07B-4014-9840-5F792089E026}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Seesaw.Sample.BlinkingLights", "samples\Seesaw.Sample.BlinkingLights.csproj", "{413D2811-7A97-44AC-9D82-099209920BBE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Seesaw.Sample.BlinkingLights", "samples\BlinkingLights\Seesaw.Sample.BlinkingLights.csproj", "{413D2811-7A97-44AC-9D82-099209920BBE}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Seesaw.Sample.Capabilities", "samples\Seesaw.Sample.Capabilities.csproj", "{5807BB95-184F-47CC-A8A4-63519079B525}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Seesaw.Sample.Capabilities", "samples\Capabilities\Seesaw.Sample.Capabilities.csproj", "{5807BB95-184F-47CC-A8A4-63519079B525}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Seesaw.Sample.SoilSensor", "samples\Seesaw.Sample.SoilSensor.csproj", "{164336C0-7E90-4082-B98D-0AEBB60717E3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Seesaw.Sample.SoilSensor", "samples\SoilSensor\Seesaw.Sample.SoilSensor.csproj", "{164336C0-7E90-4082-B98D-0AEBB60717E3}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Seesaw", "Seesaw.csproj", "{F87E6203-1DA1-4648-9A1C-AB39C0CDE7E7}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Seesaw.Sample.Encoder", "samples\Seesaw.Sample.Encoder.csproj", "{2AF6BC30-E051-45A3-AA35-9CBB7E6352BA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Seesaw.Sample.Encoder", "samples\Encoder\Seesaw.Sample.Encoder.csproj", "{2AF6BC30-E051-45A3-AA35-9CBB7E6352BA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/devices/Seesaw/samples/Seesaw.Sample.BlinkingLights.cs b/src/devices/Seesaw/samples/BlinkingLights/Seesaw.Sample.BlinkingLights.cs similarity index 100% rename from src/devices/Seesaw/samples/Seesaw.Sample.BlinkingLights.cs rename to src/devices/Seesaw/samples/BlinkingLights/Seesaw.Sample.BlinkingLights.cs diff --git a/src/devices/Seesaw/samples/Seesaw.Sample.BlinkingLights.csproj b/src/devices/Seesaw/samples/BlinkingLights/Seesaw.Sample.BlinkingLights.csproj similarity index 70% rename from src/devices/Seesaw/samples/Seesaw.Sample.BlinkingLights.csproj rename to src/devices/Seesaw/samples/BlinkingLights/Seesaw.Sample.BlinkingLights.csproj index 2fb46c979e..df7e95a78e 100644 --- a/src/devices/Seesaw/samples/Seesaw.Sample.BlinkingLights.csproj +++ b/src/devices/Seesaw/samples/BlinkingLights/Seesaw.Sample.BlinkingLights.csproj @@ -5,9 +5,9 @@ false - + - + \ No newline at end of file diff --git a/src/devices/Seesaw/samples/Volume.cs b/src/devices/Seesaw/samples/BlinkingLights/Volume.cs similarity index 100% rename from src/devices/Seesaw/samples/Volume.cs rename to src/devices/Seesaw/samples/BlinkingLights/Volume.cs diff --git a/src/devices/Seesaw/samples/Seesaw.Sample.Capabilities.cs b/src/devices/Seesaw/samples/Capabilities/Seesaw.Sample.Capabilities.cs similarity index 100% rename from src/devices/Seesaw/samples/Seesaw.Sample.Capabilities.cs rename to src/devices/Seesaw/samples/Capabilities/Seesaw.Sample.Capabilities.cs diff --git a/src/devices/Seesaw/samples/Seesaw.Sample.Capabilities.csproj b/src/devices/Seesaw/samples/Capabilities/Seesaw.Sample.Capabilities.csproj similarity index 87% rename from src/devices/Seesaw/samples/Seesaw.Sample.Capabilities.csproj rename to src/devices/Seesaw/samples/Capabilities/Seesaw.Sample.Capabilities.csproj index 66cebc018c..788616e8b3 100644 --- a/src/devices/Seesaw/samples/Seesaw.Sample.Capabilities.csproj +++ b/src/devices/Seesaw/samples/Capabilities/Seesaw.Sample.Capabilities.csproj @@ -5,7 +5,7 @@ false - + diff --git a/src/devices/Seesaw/samples/Seesaw.Sample.Encoder.cs b/src/devices/Seesaw/samples/Encoder/Seesaw.Sample.Encoder.cs similarity index 100% rename from src/devices/Seesaw/samples/Seesaw.Sample.Encoder.cs rename to src/devices/Seesaw/samples/Encoder/Seesaw.Sample.Encoder.cs diff --git a/src/devices/Seesaw/samples/Seesaw.Sample.Encoder.csproj b/src/devices/Seesaw/samples/Encoder/Seesaw.Sample.Encoder.csproj similarity index 86% rename from src/devices/Seesaw/samples/Seesaw.Sample.Encoder.csproj rename to src/devices/Seesaw/samples/Encoder/Seesaw.Sample.Encoder.csproj index 656c4af816..ac123f8f4a 100644 --- a/src/devices/Seesaw/samples/Seesaw.Sample.Encoder.csproj +++ b/src/devices/Seesaw/samples/Encoder/Seesaw.Sample.Encoder.csproj @@ -8,6 +8,6 @@ - + diff --git a/src/devices/Seesaw/samples/Seesaw.Sample.SoilSensor.cs b/src/devices/Seesaw/samples/SoilSensor/Seesaw.Sample.SoilSensor.cs similarity index 100% rename from src/devices/Seesaw/samples/Seesaw.Sample.SoilSensor.cs rename to src/devices/Seesaw/samples/SoilSensor/Seesaw.Sample.SoilSensor.cs diff --git a/src/devices/Seesaw/samples/Seesaw.Sample.SoilSensor.csproj b/src/devices/Seesaw/samples/SoilSensor/Seesaw.Sample.SoilSensor.csproj similarity index 84% rename from src/devices/Seesaw/samples/Seesaw.Sample.SoilSensor.csproj rename to src/devices/Seesaw/samples/SoilSensor/Seesaw.Sample.SoilSensor.csproj index 5f1f0f709e..4124915f83 100644 --- a/src/devices/Seesaw/samples/Seesaw.Sample.SoilSensor.csproj +++ b/src/devices/Seesaw/samples/SoilSensor/Seesaw.Sample.SoilSensor.csproj @@ -5,7 +5,7 @@ false - + \ No newline at end of file diff --git a/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln b/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln index 2a766a92d9..2c1c2fdcce 100644 --- a/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln +++ b/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln @@ -31,7 +31,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{B096 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeatherStation", "samples\WeatherStation\WeatherStation.csproj", "{599172D6-F472-4D53-BA77-044C0A32A2B3}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arduino.sample", "..\..\src\devices\Arduino\samples\Arduino.sample.csproj", "{C6C5ABC7-8A2C-4127-92A4-6D2471AEB3AA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arduino.sample", "..\..\src\devices\Arduino\samples\ApiChecker\Arduino.sample.csproj", "{C6C5ABC7-8A2C-4127-92A4-6D2471AEB3AA}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mcp3xxx", "..\..\src\devices\Mcp3xxx\Mcp3xxx.csproj", "{A9978931-850E-4E46-9029-1BD82DE4FD6E}" EndProject diff --git a/tools/ArduinoCsCompiler/Frontend/Frontend.csproj b/tools/ArduinoCsCompiler/Frontend/Frontend.csproj index 94ead4a3eb..f3c064bc37 100644 --- a/tools/ArduinoCsCompiler/Frontend/Frontend.csproj +++ b/tools/ArduinoCsCompiler/Frontend/Frontend.csproj @@ -22,7 +22,7 @@ - +