fix nullable
This commit is contained in:
parent
2dd113a9d8
commit
c78348324a
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using Swan;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Camera {
|
||||
|
@ -1,7 +1,9 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Swan;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
using Swan;
|
||||
using Swan;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Camera {
|
||||
/// <summary>
|
||||
|
@ -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)}");
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ namespace Unosquare.RaspberryIO.Camera {
|
||||
/// <summary>
|
||||
/// Specifies the path to save video files.
|
||||
/// </summary>
|
||||
public String? VideoFileName {
|
||||
public String VideoFileName {
|
||||
get; set;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace Unosquare.RaspberryIO.Camera {
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Camera {
|
||||
/// <summary>
|
||||
/// Defines the available encoding formats for the Raspberry Pi camera module.
|
||||
/// </summary>
|
||||
|
@ -62,7 +62,8 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// <returns>
|
||||
/// A <see cref="String" /> that represents the audio state.
|
||||
/// </returns>
|
||||
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" +
|
||||
|
@ -36,7 +36,7 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// The brightness.
|
||||
/// </value>
|
||||
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));
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Computer {
|
||||
/// <summary>
|
||||
@ -9,35 +9,35 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// <summary>
|
||||
/// Gets the name.
|
||||
/// </summary>
|
||||
public String? Name {
|
||||
public String Name {
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the IP V4 address.
|
||||
/// </summary>
|
||||
public IPAddress? IPv4 {
|
||||
public IPAddress IPv4 {
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the IP V6 address.
|
||||
/// </summary>
|
||||
public IPAddress? IPv6 {
|
||||
public IPAddress IPv6 {
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the access point.
|
||||
/// </summary>
|
||||
public String? AccessPointName {
|
||||
public String AccessPointName {
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the MAC (Physical) address.
|
||||
/// </summary>
|
||||
public String? MacAddress {
|
||||
public String MacAddress {
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
|
@ -34,10 +34,10 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// </summary>
|
||||
/// <param name="adapters">The adapters.</param>
|
||||
/// <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>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -103,7 +101,7 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// <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>
|
||||
/// <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
|
||||
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.
|
||||
/// </summary>
|
||||
/// <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 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");
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -8,42 +8,42 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// <summary>
|
||||
/// System name.
|
||||
/// </summary>
|
||||
public String? SysName {
|
||||
public String SysName {
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Node name.
|
||||
/// </summary>
|
||||
public String? NodeName {
|
||||
public String NodeName {
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release level.
|
||||
/// </summary>
|
||||
public String? Release {
|
||||
public String Release {
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Version level.
|
||||
/// </summary>
|
||||
public String? Version {
|
||||
public String Version {
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hardware level.
|
||||
/// </summary>
|
||||
public String? Machine {
|
||||
public String Machine {
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Domain name.
|
||||
/// </summary>
|
||||
public String? DomainName {
|
||||
public String DomainName {
|
||||
get; set;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
/// <summary>
|
||||
/// Gets the library version.
|
||||
/// </summary>
|
||||
public Version? LibraryVersion {
|
||||
public Version LibraryVersion {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// <value>
|
||||
/// The os information.
|
||||
/// </value>
|
||||
public OsInfo? OperatingSystem {
|
||||
public OsInfo OperatingSystem {
|
||||
get; set;
|
||||
}
|
||||
|
||||
@ -135,63 +135,63 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// <summary>
|
||||
/// Gets the CPU model name.
|
||||
/// </summary>
|
||||
public String? ModelName {
|
||||
public String ModelName {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of supported CPU features.
|
||||
/// </summary>
|
||||
public String[]? Features {
|
||||
public String[] Features {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the CPU implementer hex code.
|
||||
/// </summary>
|
||||
public String? CpuImplementer {
|
||||
public String CpuImplementer {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the CPU architecture code.
|
||||
/// </summary>
|
||||
public String? CpuArchitecture {
|
||||
public String CpuArchitecture {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the CPU variant code.
|
||||
/// </summary>
|
||||
public String? CpuVariant {
|
||||
public String CpuVariant {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the CPU part code.
|
||||
/// </summary>
|
||||
public String? CpuPart {
|
||||
public String CpuPart {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the CPU revision code.
|
||||
/// </summary>
|
||||
public String? CpuRevision {
|
||||
public String CpuRevision {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hardware model number.
|
||||
/// </summary>
|
||||
public String? Hardware {
|
||||
public String Hardware {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hardware revision number.
|
||||
/// </summary>
|
||||
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).
|
||||
/// </summary>
|
||||
/// /// <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>
|
||||
/// Gets processor model (accordingly to new-style revision codes).
|
||||
@ -229,7 +229,7 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// <summary>
|
||||
/// Gets the serial number.
|
||||
/// </summary>
|
||||
public String? Serial {
|
||||
public String Serial {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
@ -271,7 +271,7 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// <summary>
|
||||
/// Placeholder for processor index.
|
||||
/// </summary>
|
||||
private String? Processor {
|
||||
private String Processor {
|
||||
get; set;
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
List<String> propertyValues2 = new List<String> {
|
||||
"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<ISystemInfo>();
|
||||
|
||||
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;
|
||||
|
@ -8,14 +8,14 @@ namespace Unosquare.RaspberryIO.Computer {
|
||||
/// <summary>
|
||||
/// Gets the ESSID of the Wireless network.
|
||||
/// </summary>
|
||||
public String? Name {
|
||||
public String Name {
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the network quality.
|
||||
/// </summary>
|
||||
public String? Quality {
|
||||
public String Quality {
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
internal static class Standard {
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unosquare.RaspberryIO.Native {
|
||||
/// <summary>
|
||||
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes static members of the <see cref="Pi" /> class.
|
||||
|
@ -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>
|
||||
<PackageTags>Raspberry Pi GPIO Camera SPI I2C Embedded IoT Mono C# .NET</PackageTags>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user