Skip to content

Commit

Permalink
Fix Analyzer Warnings (#159)
Browse files Browse the repository at this point in the history
#42 non-breaking
  • Loading branch information
tthiery committed Apr 1, 2021
1 parent 13be270 commit f768e95
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 68 deletions.
115 changes: 57 additions & 58 deletions examples/SharpBrick.PoweredUp.Examples/ExampleTwoHubsMotorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,64 +32,63 @@ public override async Task DiscoverAsync(bool enableTrace)

public override async Task ExecuteAsync()
{
using (TechnicMediumHub technicMediumHub1 = DirectlyConnectedHub1)
using (TwoPortHub technicMediumHub2 = DirectlyConnectedHub2)
{
await technicMediumHub1.VerifyDeploymentModelAsync(modelBuilder => modelBuilder
.AddHub<TechnicMediumHub>(hubBuilder => hubBuilder
.AddDevice<TechnicXLargeLinearMotor>(technicMediumHub1.A)
)
);
await technicMediumHub2.VerifyDeploymentModelAsync(modelBuilder => modelBuilder
.AddHub<TwoPortHub>(hubBuilder => hubBuilder
.AddDevice<TechnicXLargeLinearMotor>(technicMediumHub2.A)
)
);

var motor1 = technicMediumHub1.A.GetDevice<TechnicXLargeLinearMotor>();
var motor2 = technicMediumHub2.A.GetDevice<TechnicXLargeLinearMotor>();

await motor1.SetAccelerationTimeAsync(3000);
await motor1.SetDecelerationTimeAsync(1000);
await motor2.SetAccelerationTimeAsync(3000);
await motor2.SetDecelerationTimeAsync(1000);

await motor1.StartSpeedForTimeAsync(6000, 90, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile | SpeedProfiles.DecelerationProfile);
await motor2.StartSpeedForTimeAsync(6000, 90, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile | SpeedProfiles.DecelerationProfile);

await Task.Delay(5_000);

await motor1.StartSpeedForDegreesAsync(180, -10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await motor2.StartSpeedForDegreesAsync(180, -10, 100, SpecialSpeed.Brake, SpeedProfiles.None);

await Task.Delay(5_000);

await motor1.StartSpeedAsync(100, 90, SpeedProfiles.None);
await motor2.StartSpeedAsync(100, 90, SpeedProfiles.None);

await Task.Delay(5_000);

await motor1.StartSpeedAsync(-100, 90, SpeedProfiles.None);
await motor2.StartSpeedAsync(-100, 90, SpeedProfiles.None);

await Task.Delay(5_000);

await motor1.StartSpeedAsync(0, 90, SpeedProfiles.None);
await motor2.StartSpeedAsync(0, 90, SpeedProfiles.None);

await Task.Delay(5_000);

await motor1.GotoPositionAsync(45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await motor2.GotoPositionAsync(45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);

await Task.Delay(5_000);

await motor1.GotoPositionAsync(-45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await motor2.GotoPositionAsync(-45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);

await technicMediumHub1.SwitchOffAsync();
await technicMediumHub2.SwitchOffAsync();
}
using TechnicMediumHub technicMediumHub1 = DirectlyConnectedHub1;
using TwoPortHub technicMediumHub2 = DirectlyConnectedHub2;

await technicMediumHub1.VerifyDeploymentModelAsync(modelBuilder => modelBuilder
.AddHub<TechnicMediumHub>(hubBuilder => hubBuilder
.AddDevice<TechnicXLargeLinearMotor>(technicMediumHub1.A)
)
);
await technicMediumHub2.VerifyDeploymentModelAsync(modelBuilder => modelBuilder
.AddHub<TwoPortHub>(hubBuilder => hubBuilder
.AddDevice<TechnicXLargeLinearMotor>(technicMediumHub2.A)
)
);

var motor1 = technicMediumHub1.A.GetDevice<TechnicXLargeLinearMotor>();
var motor2 = technicMediumHub2.A.GetDevice<TechnicXLargeLinearMotor>();

await motor1.SetAccelerationTimeAsync(3000);
await motor1.SetDecelerationTimeAsync(1000);
await motor2.SetAccelerationTimeAsync(3000);
await motor2.SetDecelerationTimeAsync(1000);

await motor1.StartSpeedForTimeAsync(6000, 90, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile | SpeedProfiles.DecelerationProfile);
await motor2.StartSpeedForTimeAsync(6000, 90, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile | SpeedProfiles.DecelerationProfile);

await Task.Delay(5_000);

await motor1.StartSpeedForDegreesAsync(180, -10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await motor2.StartSpeedForDegreesAsync(180, -10, 100, SpecialSpeed.Brake, SpeedProfiles.None);

await Task.Delay(5_000);

await motor1.StartSpeedAsync(100, 90, SpeedProfiles.None);
await motor2.StartSpeedAsync(100, 90, SpeedProfiles.None);

await Task.Delay(5_000);

await motor1.StartSpeedAsync(-100, 90, SpeedProfiles.None);
await motor2.StartSpeedAsync(-100, 90, SpeedProfiles.None);

await Task.Delay(5_000);

await motor1.StartSpeedAsync(0, 90, SpeedProfiles.None);
await motor2.StartSpeedAsync(0, 90, SpeedProfiles.None);

await Task.Delay(5_000);

await motor1.GotoPositionAsync(45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await motor2.GotoPositionAsync(45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);

await Task.Delay(5_000);

await motor1.GotoPositionAsync(-45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await motor2.GotoPositionAsync(-45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);

await technicMediumHub1.SwitchOffAsync();
await technicMediumHub2.SwitchOffAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public async Task<string> GetLogInfosAsync(int indent)
_ = stringToLog.Append($"{indentStr}*** Bluegiga-Adapter-Info ***:" + Environment.NewLine + $"{indentStr}Serial Port Name: {SerialAPI.PortName}" + Environment.NewLine + $"{indentStr}Serial Port Speed: {SerialAPI.BaudRate} baud" + Environment.NewLine);
if (Devices.Count > 0)
if (!Devices.IsEmpty)
{
_ = stringToLog.Append($"{indentStr}I know about the following {Devices.Count} devices connected to me:{Environment.NewLine}");
foreach (var device in Devices)
Expand All @@ -220,7 +220,7 @@ public async Task<string> GetLogInfosAsync(int indent)
_ = stringToLog.Append($"{indentStr}I DON'T know about any devices connected to me!{Environment.NewLine}");
}
if (DevicesInfo.Count > 0)
if (!DevicesInfo.IsEmpty)
{
_ = stringToLog.Append($"{indentStr}I know about the following {Devices.Count} devices which have been found by Discovery (not neccessarily connected):{Environment.NewLine}");
var innerindentStr = indentStr + "\t";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IBlueGigaBluetoothBuilder SetBlueGigaBLEOptions(this IBlueGigaBlue
{
if (builder == null)
{
throw new ArgumentException(nameof(builder));
throw new ArgumentNullException(nameof(builder));
}
_ = builder.Services.Configure<BlueGigaBLEOptions>(o =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace SharpBrick.PoweredUp.Mobile
{
public class XamarinPoweredUpBluetoothCharacteristic : IPoweredUpBluetoothCharacteristic
{
private ICharacteristic _characteristic;
private readonly ICharacteristic _characteristic;

public Guid Uuid => _characteristic.Id;

public XamarinPoweredUpBluetoothCharacteristic(ICharacteristic characteristic)
{
this._characteristic = characteristic;
_characteristic = characteristic;
}

public async Task<bool> NotifyValueChangeAsync(Func<byte[], Task> notificationHandler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using SharpBrick.PoweredUp.Bluetooth;
using Windows.Devices.Bluetooth;
Expand Down Expand Up @@ -30,9 +29,9 @@ public async Task<IPoweredUpBluetoothService> GetServiceAsync(Guid serviceId)
{
var gatt = await _device.GetGattServicesForUuidAsync(serviceId);

if (gatt.Status == GattCommunicationStatus.Success)
if (gatt.Status == GattCommunicationStatus.Success && gatt.Services.Count > 0)
{
var service = gatt.Services.FirstOrDefault();
var service = gatt.Services[0];

return new WinRTPoweredUpBluetoothService(service);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using SharpBrick.PoweredUp.Bluetooth;
using Windows.Devices.Bluetooth.GenericAttributeProfile;
Expand Down Expand Up @@ -30,7 +29,7 @@ public async Task<IPoweredUpBluetoothCharacteristic> GetCharacteristicAsync(Guid

if (characteristics.Status == GattCommunicationStatus.Success && characteristics.Characteristics.Count > 0)
{
var characteristic = characteristics.Characteristics.FirstOrDefault();
var characteristic = characteristics.Characteristics[0];

return new WinRTPoweredUpBluetoothCharacteristic(characteristic);
}
Expand Down

0 comments on commit f768e95

Please sign in to comment.