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