diff --git a/Unosquare.RaspberryIO/Camera/CameraColor.cs b/Unosquare.RaspberryIO/Camera/CameraColor.cs index bb6cc65..bcdb8ec 100644 --- a/Unosquare.RaspberryIO/Camera/CameraColor.cs +++ b/Unosquare.RaspberryIO/Camera/CameraColor.cs @@ -1,6 +1,5 @@ using System; using System.Linq; - using Swan; namespace Unosquare.RaspberryIO.Camera { diff --git a/Unosquare.RaspberryIO/Camera/CameraController.cs b/Unosquare.RaspberryIO/Camera/CameraController.cs index dad55b2..d3bc2b8 100644 --- a/Unosquare.RaspberryIO/Camera/CameraController.cs +++ b/Unosquare.RaspberryIO/Camera/CameraController.cs @@ -1,7 +1,9 @@ +#nullable enable + using System; using System.IO; using System.Threading; -using System.Threading.Tasks; +using System.Threading.Tasks; using Swan; diff --git a/Unosquare.RaspberryIO/Camera/CameraRect.cs b/Unosquare.RaspberryIO/Camera/CameraRect.cs index 55a3479..6a01589 100644 --- a/Unosquare.RaspberryIO/Camera/CameraRect.cs +++ b/Unosquare.RaspberryIO/Camera/CameraRect.cs @@ -1,7 +1,7 @@ using System; using System.Globalization; -using Swan; +using Swan; namespace Unosquare.RaspberryIO.Camera { /// diff --git a/Unosquare.RaspberryIO/Camera/CameraSettingsBase.cs b/Unosquare.RaspberryIO/Camera/CameraSettingsBase.cs index 40ecab5..c3c7831 100644 --- a/Unosquare.RaspberryIO/Camera/CameraSettingsBase.cs +++ b/Unosquare.RaspberryIO/Camera/CameraSettingsBase.cs @@ -1,3 +1,5 @@ +#nullable enable + using System; using System.Globalization; using System.Text; @@ -298,8 +300,7 @@ namespace Unosquare.RaspberryIO.Camera { } if(this.ImageColorEffectU >= 0 && this.ImageColorEffectV >= 0) { - _ = sb.Append( - $" -cfx {this.ImageColorEffectU.Clamp(0, 255).ToString(Ci)}:{this.ImageColorEffectV.Clamp(0, 255).ToString(Ci)}"); + _ = sb.Append($" -cfx {this.ImageColorEffectU.Clamp(0, 255).ToString(Ci)}:{this.ImageColorEffectV.Clamp(0, 255).ToString(Ci)}"); } if(this.CaptureMeteringMode != CameraMeteringMode.Average) { @@ -330,8 +331,7 @@ namespace Unosquare.RaspberryIO.Camera { _ = sb.Append($" -drc {this.CaptureDynamicRangeCompensation.ToString().ToLowerInvariant()}"); } - if(this.CaptureWhiteBalanceControl == CameraWhiteBalanceMode.Off && - (this.CaptureWhiteBalanceGainBlue != 0M || this.CaptureWhiteBalanceGainRed != 0M)) { + if(this.CaptureWhiteBalanceControl == CameraWhiteBalanceMode.Off && (this.CaptureWhiteBalanceGainBlue != 0M || this.CaptureWhiteBalanceGainRed != 0M)) { _ = sb.Append($" -awbg {this.CaptureWhiteBalanceGainBlue.ToString(Ci)},{this.CaptureWhiteBalanceGainRed.ToString(Ci)}"); } diff --git a/Unosquare.RaspberryIO/Camera/CameraVideoSettings.cs b/Unosquare.RaspberryIO/Camera/CameraVideoSettings.cs index 6a80899..c0ec8a9 100644 --- a/Unosquare.RaspberryIO/Camera/CameraVideoSettings.cs +++ b/Unosquare.RaspberryIO/Camera/CameraVideoSettings.cs @@ -63,7 +63,7 @@ namespace Unosquare.RaspberryIO.Camera { /// /// Specifies the path to save video files. /// - public String? VideoFileName { + public String VideoFileName { get; set; } diff --git a/Unosquare.RaspberryIO/Camera/Enums.cs b/Unosquare.RaspberryIO/Camera/Enums.cs index 0c49868..f1d8f43 100644 --- a/Unosquare.RaspberryIO/Camera/Enums.cs +++ b/Unosquare.RaspberryIO/Camera/Enums.cs @@ -1,6 +1,6 @@ -namespace Unosquare.RaspberryIO.Camera { - using System; +using System; +namespace Unosquare.RaspberryIO.Camera { /// /// Defines the available encoding formats for the Raspberry Pi camera module. /// diff --git a/Unosquare.RaspberryIO/Computer/AudioState.cs b/Unosquare.RaspberryIO/Computer/AudioState.cs index 62d302e..1ea5068 100644 --- a/Unosquare.RaspberryIO/Computer/AudioState.cs +++ b/Unosquare.RaspberryIO/Computer/AudioState.cs @@ -62,7 +62,8 @@ namespace Unosquare.RaspberryIO.Computer { /// /// A that represents the audio state. /// - public override String ToString() => "Device information: \n" + + public override String ToString() => + "Device information: \n" + $">> Name: {this.ControlName}\n" + $">> Card number: {this.CardNumber}\n" + $">> Volume (%): {this.Level}%\n" + diff --git a/Unosquare.RaspberryIO/Computer/DsiDisplay.cs b/Unosquare.RaspberryIO/Computer/DsiDisplay.cs index 7583336..b605f54 100644 --- a/Unosquare.RaspberryIO/Computer/DsiDisplay.cs +++ b/Unosquare.RaspberryIO/Computer/DsiDisplay.cs @@ -36,7 +36,7 @@ namespace Unosquare.RaspberryIO.Computer { /// The brightness. /// public Byte Brightness { - get => this.IsPresent ? System.Byte.TryParse(File.ReadAllText(BrightnessFilename).Trim(), out Byte brightness) ? brightness : (Byte)0 : (Byte)0; + get => this.IsPresent ? Byte.TryParse(File.ReadAllText(BrightnessFilename).Trim(), out Byte brightness) ? brightness : (Byte)0 : (Byte)0; set { if(this.IsPresent) { File.WriteAllText(BrightnessFilename, value.ToString(CultureInfo.InvariantCulture)); diff --git a/Unosquare.RaspberryIO/Computer/NetworkAdapterInfo.cs b/Unosquare.RaspberryIO/Computer/NetworkAdapterInfo.cs index 7b1c801..f85193d 100644 --- a/Unosquare.RaspberryIO/Computer/NetworkAdapterInfo.cs +++ b/Unosquare.RaspberryIO/Computer/NetworkAdapterInfo.cs @@ -1,5 +1,5 @@ using System; -using System.Net; +using System.Net; namespace Unosquare.RaspberryIO.Computer { /// @@ -9,35 +9,35 @@ namespace Unosquare.RaspberryIO.Computer { /// /// Gets the name. /// - public String? Name { + public String Name { get; internal set; } /// /// Gets the IP V4 address. /// - public IPAddress? IPv4 { + public IPAddress IPv4 { get; internal set; } /// /// Gets the IP V6 address. /// - public IPAddress? IPv6 { + public IPAddress IPv6 { get; internal set; } /// /// Gets the name of the access point. /// - public String? AccessPointName { + public String AccessPointName { get; internal set; } /// /// Gets the MAC (Physical) address. /// - public String? MacAddress { + public String MacAddress { get; internal set; } diff --git a/Unosquare.RaspberryIO/Computer/NetworkSettings.cs b/Unosquare.RaspberryIO/Computer/NetworkSettings.cs index 00f4480..58580d0 100644 --- a/Unosquare.RaspberryIO/Computer/NetworkSettings.cs +++ b/Unosquare.RaspberryIO/Computer/NetworkSettings.cs @@ -34,10 +34,10 @@ namespace Unosquare.RaspberryIO.Computer { /// /// The adapters. /// A list of WiFi networks. - public async Task> RetrieveWirelessNetworks(String[]? adapters = null) { + public async Task> RetrieveWirelessNetworks(String[] adapters = null) { List result = new List(); - foreach(String? networkAdapter in adapters ?? (await this.RetrieveAdapters()).Where(x => x.IsWireless).Select(x => x.Name)) { + foreach(String networkAdapter in adapters ?? (await this.RetrieveAdapters()).Where(x => x.IsWireless).Select(x => x.Name)) { String wirelessOutput = await ProcessRunner.GetProcessOutputAsync("iwlist", $"{networkAdapter} scanning").ConfigureAwait(false); String[] outputLines = wirelessOutput.Split('\n').Select(x => x.Trim()).Where(x => String.IsNullOrWhiteSpace(x) == false).ToArray(); @@ -90,9 +90,7 @@ namespace Unosquare.RaspberryIO.Computer { } } - return result - .OrderBy(x => x.Name) - .ToList(); + return result.OrderBy(x => x.Name).ToList(); } /// @@ -103,7 +101,7 @@ namespace Unosquare.RaspberryIO.Computer { /// The password (8 characters as minimum length). /// The 2-letter country code in uppercase. Default is US. /// True if successful. Otherwise, false. - public async Task SetupWirelessNetwork(String adapterName, String networkSsid, String? password = null, String countryCode = "US") { + public async Task SetupWirelessNetwork(String adapterName, String networkSsid, String password = null, String countryCode = "US") { // TODO: Get the country where the device is located to set 'country' param in payload var String payload = $"country={countryCode}\nctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\nupdate_config=1\n"; @@ -111,9 +109,7 @@ namespace Unosquare.RaspberryIO.Computer { throw new InvalidOperationException("The password must be at least 8 characters length."); } - payload += String.IsNullOrEmpty(password) - ? $"network={{\n\tssid=\"{networkSsid}\"\n\tkey_mgmt=NONE\n\t}}\n" - : $"network={{\n\tssid=\"{networkSsid}\"\n\tpsk=\"{password}\"\n\t}}\n"; + payload += String.IsNullOrEmpty(password) ? $"network={{\n\tssid=\"{networkSsid}\"\n\tkey_mgmt=NONE\n\t}}\n" : $"network={{\n\tssid=\"{networkSsid}\"\n\tpsk=\"{password}\"\n\t}}\n"; try { File.WriteAllText("/etc/wpa_supplicant/wpa_supplicant.conf", payload); _ = await ProcessRunner.GetProcessOutputAsync("pkill", "-f wpa_supplicant"); @@ -212,7 +208,7 @@ namespace Unosquare.RaspberryIO.Computer { /// Retrieves the current network adapter. /// /// The name of the current network adapter. - public static async Task GetCurrentAdapterName() { + public static async Task GetCurrentAdapterName() { String result = await ProcessRunner.GetProcessOutputAsync("route").ConfigureAwait(false); String defaultLine = result.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(l => l.StartsWith("default", StringComparison.OrdinalIgnoreCase)); @@ -226,7 +222,7 @@ namespace Unosquare.RaspberryIO.Computer { public Task GetWirelessNetworkName() => ProcessRunner.GetProcessOutputAsync("iwgetid", "-r"); private static void GetIPv4(String indentedLine, NetworkAdapterInfo adapter) { - String? addressText = ParseOutputTagFromLine(indentedLine, "inet addr:") ?? ParseOutputTagFromLine(indentedLine, "inet "); + String addressText = ParseOutputTagFromLine(indentedLine, "inet addr:") ?? ParseOutputTagFromLine(indentedLine, "inet "); if(addressText == null) { return; @@ -238,7 +234,7 @@ namespace Unosquare.RaspberryIO.Computer { } private static void GetIPv6(String indentedLine, NetworkAdapterInfo adapter) { - String? addressText = ParseOutputTagFromLine(indentedLine, "inet6 addr:") ?? ParseOutputTagFromLine(indentedLine, "inet6 "); + String addressText = ParseOutputTagFromLine(indentedLine, "inet6 addr:") ?? ParseOutputTagFromLine(indentedLine, "inet6 "); if(addressText == null) { return; @@ -249,7 +245,7 @@ namespace Unosquare.RaspberryIO.Computer { } } - private static String? ParseOutputTagFromLine(String indentedLine, String tagName) { + private static String ParseOutputTagFromLine(String indentedLine, String tagName) { if(indentedLine.IndexOf(tagName, StringComparison.Ordinal) < 0) { return null; } diff --git a/Unosquare.RaspberryIO/Computer/OsInfo.cs b/Unosquare.RaspberryIO/Computer/OsInfo.cs index 6675393..578a41e 100644 --- a/Unosquare.RaspberryIO/Computer/OsInfo.cs +++ b/Unosquare.RaspberryIO/Computer/OsInfo.cs @@ -8,42 +8,42 @@ namespace Unosquare.RaspberryIO.Computer { /// /// System name. /// - public String? SysName { + public String SysName { get; set; } /// /// Node name. /// - public String? NodeName { + public String NodeName { get; set; } /// /// Release level. /// - public String? Release { + public String Release { get; set; } /// /// Version level. /// - public String? Version { + public String Version { get; set; } /// /// Hardware level. /// - public String? Machine { + public String Machine { get; set; } /// /// Domain name. /// - public String? DomainName { + public String DomainName { get; set; } diff --git a/Unosquare.RaspberryIO/Computer/SystemInfo.cs b/Unosquare.RaspberryIO/Computer/SystemInfo.cs index 0f65de5..38d16b2 100644 --- a/Unosquare.RaspberryIO/Computer/SystemInfo.cs +++ b/Unosquare.RaspberryIO/Computer/SystemInfo.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Reflection; using Swan; -using Swan.DependencyInjection; +using Swan.DependencyInjection; using Unosquare.RaspberryIO.Abstractions; using Unosquare.RaspberryIO.Native; @@ -84,7 +84,7 @@ namespace Unosquare.RaspberryIO.Computer { /// /// Gets the library version. /// - public Version? LibraryVersion { + public Version LibraryVersion { get; private set; } @@ -94,7 +94,7 @@ namespace Unosquare.RaspberryIO.Computer { /// /// The os information. /// - public OsInfo? OperatingSystem { + public OsInfo OperatingSystem { get; set; } @@ -135,63 +135,63 @@ namespace Unosquare.RaspberryIO.Computer { /// /// Gets the CPU model name. /// - public String? ModelName { + public String ModelName { get; private set; } /// /// Gets a list of supported CPU features. /// - public String[]? Features { + public String[] Features { get; private set; } /// /// Gets the CPU implementer hex code. /// - public String? CpuImplementer { + public String CpuImplementer { get; private set; } /// /// Gets the CPU architecture code. /// - public String? CpuArchitecture { + public String CpuArchitecture { get; private set; } /// /// Gets the CPU variant code. /// - public String? CpuVariant { + public String CpuVariant { get; private set; } /// /// Gets the CPU part code. /// - public String? CpuPart { + public String CpuPart { get; private set; } /// /// Gets the CPU revision code. /// - public String? CpuRevision { + public String CpuRevision { get; private set; } /// /// Gets the hardware model number. /// - public String? Hardware { + public String Hardware { get; private set; } /// /// Gets the hardware revision number. /// - public String? Revision { + public String Revision { get; private set; } @@ -206,7 +206,7 @@ namespace Unosquare.RaspberryIO.Computer { /// Gets the board model (accordingly to new-style revision codes). /// /// /// This board does not support new-style revision codes. Use {nameof(RaspberryPiVersion)}. - public BoardModel BoardModel => this.NewStyleRevisionCodes ? this._boardModel : throw new InvalidOperationException($"This board does not support new-style revision codes. Use {nameof(this.RaspberryPiVersion)} property instead."); + public BoardModel BoardModel => this.NewStyleRevisionCodes ? this._boardModel : throw new InvalidOperationException($"This board does not support new-style revision codes. Use {nameof(this.RaspberryPiVersion)} property instead."); /// /// Gets processor model (accordingly to new-style revision codes). @@ -229,7 +229,7 @@ namespace Unosquare.RaspberryIO.Computer { /// /// Gets the serial number. /// - public String? Serial { + public String Serial { get; private set; } @@ -271,7 +271,7 @@ namespace Unosquare.RaspberryIO.Computer { /// /// Placeholder for processor index. /// - private String? Processor { + private String Processor { get; set; } @@ -288,7 +288,7 @@ namespace Unosquare.RaspberryIO.Computer { List propertyValues2 = new List { "System Information", $"\t{nameof(this.LibraryVersion),-22}: {this.LibraryVersion}", - $"\t{nameof(this.RaspberryPiVersion),-22}: {this.RaspberryPiVersion}" + $"\t{nameof(this.RaspberryPiVersion),-22}: {this.RaspberryPiVersion}", }; foreach(PropertyInfo property in properties) { @@ -324,7 +324,7 @@ namespace Unosquare.RaspberryIO.Computer { Boolean hasSysInfo = DependencyContainer.Current.CanResolve(); try { - if(String.IsNullOrWhiteSpace(this.Revision) == false && Int32.TryParse(this.Revision != null ? this.Revision.ToUpperInvariant() : "", NumberStyles.HexNumber, CultureInfo.InvariantCulture, out Int32 boardVersion)) { + if(String.IsNullOrWhiteSpace(this.Revision) == false && Int32.TryParse(this.Revision.ToUpperInvariant(), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out Int32 boardVersion)) { this.RaspberryPiVersion = PiVersion.Unknown; if(Enum.IsDefined(typeof(PiVersion), boardVersion)) { this.RaspberryPiVersion = (PiVersion)boardVersion; diff --git a/Unosquare.RaspberryIO/Computer/WirelessNetworkInfo.cs b/Unosquare.RaspberryIO/Computer/WirelessNetworkInfo.cs index ca8659b..f766065 100644 --- a/Unosquare.RaspberryIO/Computer/WirelessNetworkInfo.cs +++ b/Unosquare.RaspberryIO/Computer/WirelessNetworkInfo.cs @@ -8,14 +8,14 @@ namespace Unosquare.RaspberryIO.Computer { /// /// Gets the ESSID of the Wireless network. /// - public String? Name { + public String Name { get; internal set; } /// /// Gets the network quality. /// - public String? Quality { + public String Quality { get; internal set; } diff --git a/Unosquare.RaspberryIO/Native/Standard.cs b/Unosquare.RaspberryIO/Native/Standard.cs index 359e8a0..13c4091 100644 --- a/Unosquare.RaspberryIO/Native/Standard.cs +++ b/Unosquare.RaspberryIO/Native/Standard.cs @@ -1,5 +1,5 @@ -using System; -using System.Runtime.InteropServices; +using System; +using System.Runtime.InteropServices; namespace Unosquare.RaspberryIO.Native { internal static class Standard { diff --git a/Unosquare.RaspberryIO/Native/SystemName.cs b/Unosquare.RaspberryIO/Native/SystemName.cs index bd11a31..795a3d5 100644 --- a/Unosquare.RaspberryIO/Native/SystemName.cs +++ b/Unosquare.RaspberryIO/Native/SystemName.cs @@ -1,5 +1,5 @@ -using System; -using System.Runtime.InteropServices; +using System; +using System.Runtime.InteropServices; namespace Unosquare.RaspberryIO.Native { /// diff --git a/Unosquare.RaspberryIO/Pi.cs b/Unosquare.RaspberryIO/Pi.cs index 11252f2..e0edd44 100644 --- a/Unosquare.RaspberryIO/Pi.cs +++ b/Unosquare.RaspberryIO/Pi.cs @@ -1,5 +1,5 @@ using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Swan; using Swan.DependencyInjection; @@ -16,7 +16,7 @@ namespace Unosquare.RaspberryIO { private const String MissingDependenciesMessage = "You need to load a valid assembly (WiringPi or PiGPIO)."; private static readonly Object SyncLock = new Object(); private static Boolean _isInit; - private static SystemInfo? _info; + private static SystemInfo _info; /// /// Initializes static members of the class. diff --git a/Unosquare.RaspberryIO/Unosquare.RaspberryIO.csproj b/Unosquare.RaspberryIO/Unosquare.RaspberryIO.csproj index d6d4e66..5638c85 100644 --- a/Unosquare.RaspberryIO/Unosquare.RaspberryIO.csproj +++ b/Unosquare.RaspberryIO/Unosquare.RaspberryIO.csproj @@ -16,7 +16,6 @@ This library enables developers to use the various Raspberry Pi's hardware modul https://raw.githubusercontent.com/unosquare/raspberryio/master/LICENSE Raspberry Pi GPIO Camera SPI I2C Embedded IoT Mono C# .NET 8.0 - enable