Skip to content
Snippets Groups Projects
Commit ef2fea87 authored by Paul-Winpenny's avatar Paul-Winpenny
Browse files

Added a bit of code in lab (No raspberry pi so have to go home)

parent a2f655a2
No related branches found
No related tags found
No related merge requests found
......@@ -140,9 +140,9 @@ namespace RobobinApp.ViewModels
TestReadOperation = new Command(async () => await ReadOperationAsync());
SendWifiInfoCommand = new Command(OnSendWifiInfo);
TestWriteOperation = new Command(async() => await PingPiASync());
TestWriteOperation = new Command(() => PingPiASyncAsync());
_adapter.DeviceDiscovered += OnDeviceDiscovered;
IsWifiNetworkSelectionVisible = false;
......@@ -165,16 +165,17 @@ namespace RobobinApp.ViewModels
}
}
private async Task PingPiASync()
private async Task PingPiASyncAsync()
{
if (tempUnit.Equals("C"))
{
tempUnit = "F";
} else
}
else
{
tempUnit = "C";
}
WriteOperationAsync(tempUnit);
await WriteOperationAsync(tempUnit);
}
......@@ -183,7 +184,9 @@ namespace RobobinApp.ViewModels
WifiNetworks.Clear();
Debug.WriteLine("Retrieving Wifi networks from readCharacteristic");
const string command = "SCAN";
await WriteOperationAsync(command);
var networks = await ReadOperationAsync();
//var networks = "Network1\nNetwork2\nNetwork3"; // For testing
......@@ -300,7 +303,7 @@ namespace RobobinApp.ViewModels
}
}
private void OnDeviceDiscovered(object sender, DeviceEventArgs e)
private void OnDeviceDiscovered(object? sender, DeviceEventArgs e)
{
Debug.WriteLine($"Discovered device: {e.Device.Name ?? e.Device.Id.ToString()}");
......@@ -462,11 +465,12 @@ namespace RobobinApp.ViewModels
private async Task<string> ReadOperationAsync(int retryCount = 3)
{
if (ReadCharacteristic == null || !IsConnected)
if (ReadWriteService == null || !IsConnected)
{
Debug.WriteLine("Read characteristic is not set or device is not connected.");
return "Failure";
}
ReadCharacteristic = await ReadWriteService.GetCharacteristicAsync(Guid.Parse(rxUUID));
Debug.WriteLine($"READ COMMAND : {ReadCharacteristic.Uuid}");
for (int attempt = 1; attempt <= retryCount; attempt++)
{
......@@ -496,11 +500,13 @@ namespace RobobinApp.ViewModels
private async Task<string> WriteOperationAsync(string command, string arguments="", int retryCount = 3)
{
if (WriteCharacteristic == null)
if (ReadWriteService == null)
{
Debug.WriteLine("Write characteristic is not set.");
return "Failure";
}
//Get Characteristic
WriteCharacteristic = await ReadWriteService.GetCharacteristicAsync(Guid.Parse(wxUUID));
string joinedData = command + ":" + arguments;
Debug.WriteLine($"WRITE COMMAND {joinedData}, UUID: {WriteCharacteristic}");
byte[] data = System.Text.Encoding.UTF8.GetBytes(joinedData);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment