fix nullable

This commit is contained in:
BlubbFish 2019-12-08 12:34:43 +01:00
parent 2dd113a9d8
commit c78348324a
17 changed files with 60 additions and 63 deletions

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Linq; using System.Linq;
using Swan; using Swan;
namespace Unosquare.RaspberryIO.Camera { namespace Unosquare.RaspberryIO.Camera {

View File

@ -1,3 +1,5 @@
#nullable enable
using System; using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;

View File

@ -1,3 +1,5 @@
#nullable enable
using System; using System;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
@ -298,8 +300,7 @@ namespace Unosquare.RaspberryIO.Camera {
} }
if(this.ImageColorEffectU >= 0 && this.ImageColorEffectV >= 0) { if(this.ImageColorEffectU >= 0 && this.ImageColorEffectV >= 0) {
_ = sb.Append( _ = sb.Append($" -cfx {this.ImageColorEffectU.Clamp(0, 255).ToString(Ci)}:{this.ImageColorEffectV.Clamp(0, 255).ToString(Ci)}");
$" -cfx {this.ImageColorEffectU.Clamp(0, 255).ToString(Ci)}:{this.ImageColorEffectV.Clamp(0, 255).ToString(Ci)}");
} }
if(this.CaptureMeteringMode != CameraMeteringMode.Average) { if(this.CaptureMeteringMode != CameraMeteringMode.Average) {
@ -330,8 +331,7 @@ namespace Unosquare.RaspberryIO.Camera {
_ = sb.Append($" -drc {this.CaptureDynamicRangeCompensation.ToString().ToLowerInvariant()}"); _ = sb.Append($" -drc {this.CaptureDynamicRangeCompensation.ToString().ToLowerInvariant()}");
} }
if(this.CaptureWhiteBalanceControl == CameraWhiteBalanceMode.Off && if(this.CaptureWhiteBalanceControl == CameraWhiteBalanceMode.Off && (this.CaptureWhiteBalanceGainBlue != 0M || this.CaptureWhiteBalanceGainRed != 0M)) {
(this.CaptureWhiteBalanceGainBlue != 0M || this.CaptureWhiteBalanceGainRed != 0M)) {
_ = sb.Append($" -awbg {this.CaptureWhiteBalanceGainBlue.ToString(Ci)},{this.CaptureWhiteBalanceGainRed.ToString(Ci)}"); _ = sb.Append($" -awbg {this.CaptureWhiteBalanceGainBlue.ToString(Ci)},{this.CaptureWhiteBalanceGainRed.ToString(Ci)}");
} }

View File

@ -63,7 +63,7 @@ namespace Unosquare.RaspberryIO.Camera {
/// <summary> /// <summary>
/// Specifies the path to save video files. /// Specifies the path to save video files.
/// </summary> /// </summary>
public String? VideoFileName { public String VideoFileName {
get; set; get; set;
} }

View File

@ -1,6 +1,6 @@
namespace Unosquare.RaspberryIO.Camera { using System;
using System;
namespace Unosquare.RaspberryIO.Camera {
/// <summary> /// <summary>
/// Defines the available encoding formats for the Raspberry Pi camera module. /// Defines the available encoding formats for the Raspberry Pi camera module.
/// </summary> /// </summary>

View File

@ -62,7 +62,8 @@ namespace Unosquare.RaspberryIO.Computer {
/// <returns> /// <returns>
/// A <see cref="String" /> that represents the audio state. /// A <see cref="String" /> that represents the audio state.
/// </returns> /// </returns>
public override String ToString() => "Device information: \n" + public override String ToString() =>
"Device information: \n" +
$">> Name: {this.ControlName}\n" + $">> Name: {this.ControlName}\n" +
$">> Card number: {this.CardNumber}\n" + $">> Card number: {this.CardNumber}\n" +
$">> Volume (%): {this.Level}%\n" + $">> Volume (%): {this.Level}%\n" +

View File

@ -36,7 +36,7 @@ namespace Unosquare.RaspberryIO.Computer {
/// The brightness. /// The brightness.
/// </value> /// </value>
public Byte 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 { set {
if(this.IsPresent) { if(this.IsPresent) {
File.WriteAllText(BrightnessFilename, value.ToString(CultureInfo.InvariantCulture)); File.WriteAllText(BrightnessFilename, value.ToString(CultureInfo.InvariantCulture));

View File

@ -9,35 +9,35 @@ namespace Unosquare.RaspberryIO.Computer {
/// <summary> /// <summary>
/// Gets the name. /// Gets the name.
/// </summary> /// </summary>
public String? Name { public String Name {
get; internal set; get; internal set;
} }
/// <summary> /// <summary>
/// Gets the IP V4 address. /// Gets the IP V4 address.
/// </summary> /// </summary>
public IPAddress? IPv4 { public IPAddress IPv4 {
get; internal set; get; internal set;
} }
/// <summary> /// <summary>
/// Gets the IP V6 address. /// Gets the IP V6 address.
/// </summary> /// </summary>
public IPAddress? IPv6 { public IPAddress IPv6 {
get; internal set; get; internal set;
} }
/// <summary> /// <summary>
/// Gets the name of the access point. /// Gets the name of the access point.
/// </summary> /// </summary>
public String? AccessPointName { public String AccessPointName {
get; internal set; get; internal set;
} }
/// <summary> /// <summary>
/// Gets the MAC (Physical) address. /// Gets the MAC (Physical) address.
/// </summary> /// </summary>
public String? MacAddress { public String MacAddress {
get; internal set; get; internal set;
} }

View File

@ -34,10 +34,10 @@ namespace Unosquare.RaspberryIO.Computer {
/// </summary> /// </summary>
/// <param name="adapters">The adapters.</param> /// <param name="adapters">The adapters.</param>
/// <returns>A list of WiFi networks.</returns> /// <returns>A list of WiFi networks.</returns>
public async Task<List<WirelessNetworkInfo>> RetrieveWirelessNetworks(String[]? adapters = null) { public async Task<List<WirelessNetworkInfo>> RetrieveWirelessNetworks(String[] adapters = null) {
List<WirelessNetworkInfo> result = new List<WirelessNetworkInfo>(); List<WirelessNetworkInfo> result = new List<WirelessNetworkInfo>();
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 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(); 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 return result.OrderBy(x => x.Name).ToList();
.OrderBy(x => x.Name)
.ToList();
} }
/// <summary> /// <summary>
@ -103,7 +101,7 @@ namespace Unosquare.RaspberryIO.Computer {
/// <param name="password">The password (8 characters as minimum length).</param> /// <param name="password">The password (8 characters as minimum length).</param>
/// <param name="countryCode">The 2-letter country code in uppercase. Default is US.</param> /// <param name="countryCode">The 2-letter country code in uppercase. Default is US.</param>
/// <returns>True if successful. Otherwise, false.</returns> /// <returns>True if successful. Otherwise, false.</returns>
public async Task<Boolean> SetupWirelessNetwork(String adapterName, String networkSsid, String? password = null, String countryCode = "US") { public async Task<Boolean> 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 // 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"; 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."); throw new InvalidOperationException("The password must be at least 8 characters length.");
} }
payload += String.IsNullOrEmpty(password) 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";
? $"network={{\n\tssid=\"{networkSsid}\"\n\tkey_mgmt=NONE\n\t}}\n"
: $"network={{\n\tssid=\"{networkSsid}\"\n\tpsk=\"{password}\"\n\t}}\n";
try { try {
File.WriteAllText("/etc/wpa_supplicant/wpa_supplicant.conf", payload); File.WriteAllText("/etc/wpa_supplicant/wpa_supplicant.conf", payload);
_ = await ProcessRunner.GetProcessOutputAsync("pkill", "-f wpa_supplicant"); _ = await ProcessRunner.GetProcessOutputAsync("pkill", "-f wpa_supplicant");
@ -212,7 +208,7 @@ namespace Unosquare.RaspberryIO.Computer {
/// Retrieves the current network adapter. /// Retrieves the current network adapter.
/// </summary> /// </summary>
/// <returns>The name of the current network adapter.</returns> /// <returns>The name of the current network adapter.</returns>
public static async Task<String?> GetCurrentAdapterName() { public static async Task<String> GetCurrentAdapterName() {
String result = await ProcessRunner.GetProcessOutputAsync("route").ConfigureAwait(false); String result = await ProcessRunner.GetProcessOutputAsync("route").ConfigureAwait(false);
String defaultLine = result.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(l => l.StartsWith("default", StringComparison.OrdinalIgnoreCase)); 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<String> GetWirelessNetworkName() => ProcessRunner.GetProcessOutputAsync("iwgetid", "-r"); public Task<String> GetWirelessNetworkName() => ProcessRunner.GetProcessOutputAsync("iwgetid", "-r");
private static void GetIPv4(String indentedLine, NetworkAdapterInfo adapter) { 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) { if(addressText == null) {
return; return;
@ -238,7 +234,7 @@ namespace Unosquare.RaspberryIO.Computer {
} }
private static void GetIPv6(String indentedLine, NetworkAdapterInfo adapter) { 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) { if(addressText == null) {
return; 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) { if(indentedLine.IndexOf(tagName, StringComparison.Ordinal) < 0) {
return null; return null;
} }

View File

@ -8,42 +8,42 @@ namespace Unosquare.RaspberryIO.Computer {
/// <summary> /// <summary>
/// System name. /// System name.
/// </summary> /// </summary>
public String? SysName { public String SysName {
get; set; get; set;
} }
/// <summary> /// <summary>
/// Node name. /// Node name.
/// </summary> /// </summary>
public String? NodeName { public String NodeName {
get; set; get; set;
} }
/// <summary> /// <summary>
/// Release level. /// Release level.
/// </summary> /// </summary>
public String? Release { public String Release {
get; set; get; set;
} }
/// <summary> /// <summary>
/// Version level. /// Version level.
/// </summary> /// </summary>
public String? Version { public String Version {
get; set; get; set;
} }
/// <summary> /// <summary>
/// Hardware level. /// Hardware level.
/// </summary> /// </summary>
public String? Machine { public String Machine {
get; set; get; set;
} }
/// <summary> /// <summary>
/// Domain name. /// Domain name.
/// </summary> /// </summary>
public String? DomainName { public String DomainName {
get; set; get; set;
} }

View File

@ -84,7 +84,7 @@ namespace Unosquare.RaspberryIO.Computer {
/// <summary> /// <summary>
/// Gets the library version. /// Gets the library version.
/// </summary> /// </summary>
public Version? LibraryVersion { public Version LibraryVersion {
get; private set; get; private set;
} }
@ -94,7 +94,7 @@ namespace Unosquare.RaspberryIO.Computer {
/// <value> /// <value>
/// The os information. /// The os information.
/// </value> /// </value>
public OsInfo? OperatingSystem { public OsInfo OperatingSystem {
get; set; get; set;
} }
@ -135,63 +135,63 @@ namespace Unosquare.RaspberryIO.Computer {
/// <summary> /// <summary>
/// Gets the CPU model name. /// Gets the CPU model name.
/// </summary> /// </summary>
public String? ModelName { public String ModelName {
get; private set; get; private set;
} }
/// <summary> /// <summary>
/// Gets a list of supported CPU features. /// Gets a list of supported CPU features.
/// </summary> /// </summary>
public String[]? Features { public String[] Features {
get; private set; get; private set;
} }
/// <summary> /// <summary>
/// Gets the CPU implementer hex code. /// Gets the CPU implementer hex code.
/// </summary> /// </summary>
public String? CpuImplementer { public String CpuImplementer {
get; private set; get; private set;
} }
/// <summary> /// <summary>
/// Gets the CPU architecture code. /// Gets the CPU architecture code.
/// </summary> /// </summary>
public String? CpuArchitecture { public String CpuArchitecture {
get; private set; get; private set;
} }
/// <summary> /// <summary>
/// Gets the CPU variant code. /// Gets the CPU variant code.
/// </summary> /// </summary>
public String? CpuVariant { public String CpuVariant {
get; private set; get; private set;
} }
/// <summary> /// <summary>
/// Gets the CPU part code. /// Gets the CPU part code.
/// </summary> /// </summary>
public String? CpuPart { public String CpuPart {
get; private set; get; private set;
} }
/// <summary> /// <summary>
/// Gets the CPU revision code. /// Gets the CPU revision code.
/// </summary> /// </summary>
public String? CpuRevision { public String CpuRevision {
get; private set; get; private set;
} }
/// <summary> /// <summary>
/// Gets the hardware model number. /// Gets the hardware model number.
/// </summary> /// </summary>
public String? Hardware { public String Hardware {
get; private set; get; private set;
} }
/// <summary> /// <summary>
/// Gets the hardware revision number. /// Gets the hardware revision number.
/// </summary> /// </summary>
public String? Revision { public String Revision {
get; private set; get; private set;
} }
@ -206,7 +206,7 @@ namespace Unosquare.RaspberryIO.Computer {
/// Gets the board model (accordingly to new-style revision codes). /// Gets the board model (accordingly to new-style revision codes).
/// </summary> /// </summary>
/// /// <exception cref="InvalidOperationException">This board does not support new-style revision codes. Use {nameof(RaspberryPiVersion)}.</exception> /// /// <exception cref="InvalidOperationException">This board does not support new-style revision codes. Use {nameof(RaspberryPiVersion)}.</exception>
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.");
/// <summary> /// <summary>
/// Gets processor model (accordingly to new-style revision codes). /// Gets processor model (accordingly to new-style revision codes).
@ -229,7 +229,7 @@ namespace Unosquare.RaspberryIO.Computer {
/// <summary> /// <summary>
/// Gets the serial number. /// Gets the serial number.
/// </summary> /// </summary>
public String? Serial { public String Serial {
get; private set; get; private set;
} }
@ -271,7 +271,7 @@ namespace Unosquare.RaspberryIO.Computer {
/// <summary> /// <summary>
/// Placeholder for processor index. /// Placeholder for processor index.
/// </summary> /// </summary>
private String? Processor { private String Processor {
get; set; get; set;
} }
@ -288,7 +288,7 @@ namespace Unosquare.RaspberryIO.Computer {
List<String> propertyValues2 = new List<String> { List<String> propertyValues2 = new List<String> {
"System Information", "System Information",
$"\t{nameof(this.LibraryVersion),-22}: {this.LibraryVersion}", $"\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) { foreach(PropertyInfo property in properties) {
@ -324,7 +324,7 @@ namespace Unosquare.RaspberryIO.Computer {
Boolean hasSysInfo = DependencyContainer.Current.CanResolve<ISystemInfo>(); Boolean hasSysInfo = DependencyContainer.Current.CanResolve<ISystemInfo>();
try { 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; this.RaspberryPiVersion = PiVersion.Unknown;
if(Enum.IsDefined(typeof(PiVersion), boardVersion)) { if(Enum.IsDefined(typeof(PiVersion), boardVersion)) {
this.RaspberryPiVersion = (PiVersion)boardVersion; this.RaspberryPiVersion = (PiVersion)boardVersion;

View File

@ -8,14 +8,14 @@ namespace Unosquare.RaspberryIO.Computer {
/// <summary> /// <summary>
/// Gets the ESSID of the Wireless network. /// Gets the ESSID of the Wireless network.
/// </summary> /// </summary>
public String? Name { public String Name {
get; internal set; get; internal set;
} }
/// <summary> /// <summary>
/// Gets the network quality. /// Gets the network quality.
/// </summary> /// </summary>
public String? Quality { public String Quality {
get; internal set; get; internal set;
} }

View File

@ -16,7 +16,7 @@ namespace Unosquare.RaspberryIO {
private const String MissingDependenciesMessage = "You need to load a valid assembly (WiringPi or PiGPIO)."; private const String MissingDependenciesMessage = "You need to load a valid assembly (WiringPi or PiGPIO).";
private static readonly Object SyncLock = new Object(); private static readonly Object SyncLock = new Object();
private static Boolean _isInit; private static Boolean _isInit;
private static SystemInfo? _info; private static SystemInfo _info;
/// <summary> /// <summary>
/// Initializes static members of the <see cref="Pi" /> class. /// Initializes static members of the <see cref="Pi" /> class.

View File

@ -16,7 +16,6 @@ This library enables developers to use the various Raspberry Pi's hardware modul
<PackageLicenseUrl>https://raw.githubusercontent.com/unosquare/raspberryio/master/LICENSE</PackageLicenseUrl> <PackageLicenseUrl>https://raw.githubusercontent.com/unosquare/raspberryio/master/LICENSE</PackageLicenseUrl>
<PackageTags>Raspberry Pi GPIO Camera SPI I2C Embedded IoT Mono C# .NET</PackageTags> <PackageTags>Raspberry Pi GPIO Camera SPI I2C Embedded IoT Mono C# .NET</PackageTags>
<LangVersion>8.0</LangVersion> <LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>