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

Names are now used to find characteristics instead of UUIDs

parent 52c1ac04
No related branches found
No related tags found
1 merge request!1App now has a basic structure and BLE support
......@@ -19,6 +19,7 @@ using System.Reflection.PortableExecutable;
using Plugin.BLE.Windows;
using System.Text;
using System.Windows.Documents;
using Robobin.Interfaces;
namespace RobobinApp.ViewModels
{
......@@ -43,6 +44,10 @@ namespace RobobinApp.ViewModels
public const string SendReceiveServiceUUID = "00000001-710e-4a5b-8d75-3e5b444bc3cf";
public const string rxUUID = "00000002-710e-4a5b-8d75-3e5b444bc3cf";
public const string wxUUID = "00000003-710e-4a5b-8d75-3e5b444bc3cf";
public const string readCharacteristicName = "CPU Temperature";
public const string writeCharacteristicName = "Temperature Units (F or C)";
public string tempUnit = "C";
public bool IsConnected
......@@ -52,7 +57,7 @@ namespace RobobinApp.ViewModels
{
_isConnected = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ConnectButtonText)); // Update button text when connection state changes
OnPropertyChanged(nameof(ConnectButtonText));
}
}
private ICharacteristic _readCharacteristic;
......@@ -109,6 +114,11 @@ namespace RobobinApp.ViewModels
public ConnectionPageViewModel()
{
_bluetoothLE = CrossBluetoothLE.Current;
_adapter = CrossBluetoothLE.Current.Adapter;
BluetoothDevices = new ObservableCollection<BluetoothDevice>();
WifiNetworks = new ObservableCollection<WifiNetwork>();
ConnectCommand = new Command(OnConnect);
......@@ -119,8 +129,8 @@ namespace RobobinApp.ViewModels
SendWifiInfoCommand = new Command(OnSendWifiInfo);
TestWriteOperation = new Command(async() => await PingPiASync());
_bluetoothLE = CrossBluetoothLE.Current;
_adapter = _bluetoothLE.Adapter;
_adapter.DeviceDiscovered += OnDeviceDiscovered;
IsWifiNetworkSelectionVisible = false;
......@@ -154,7 +164,7 @@ namespace RobobinApp.ViewModels
Debug.WriteLine("Retrieving Wifi networks from readCharacteristic");
//Delay 5 seconds
await Task.Delay(5000);
await Task.Delay(2500);
//var networks = await ReadOperationAsync();
var networks = "Network1\nNetwork2\nNetwork3"; // For testing
......@@ -347,15 +357,22 @@ namespace RobobinApp.ViewModels
foreach (var characteristic in characteristics)
{
var descriptor = await characteristic.GetDescriptorsAsync();
Debug.WriteLine($"{characteristic.Uuid} | {characteristic.Name} | {descriptor}");
if (characteristic.Uuid.Equals(rxUUID))
var descriptors = await characteristic.GetDescriptorsAsync();
foreach (var descriptor in descriptors)
{
var descriptorValue = await descriptor.ReadAsync();
var descriptorValueString = Encoding.UTF8.GetString(descriptorValue);
Debug.WriteLine($"Descriptor: {descriptor.Id} | Value: {descriptorValueString}");
}
Debug.WriteLine($"{characteristic.Uuid} |{characteristic.Name}");
if (characteristic.Name.Equals(readCharacteristicName))
{
ReadCharacteristic = characteristic;
var result = await ReadOperationAsync();
}
else if (characteristic.Uuid.Equals(wxUUID))
else if (characteristic.Name.Equals(writeCharacteristicName))
{
WriteCharacteristic = characteristic;
const string command = "SCAN";
......@@ -485,8 +502,8 @@ namespace RobobinApp.ViewModels
IsWifiNetworkSelectionVisible = false;
// Dispose of the device reference
if (_connectedDevice != null)
_connectedDevice.Dispose();
_connectedDevice = null;
// _connectedDevice.Dispose();
_connectedDevice = null;
IsConnected = false;
ScanDevices();
await Application.Current.MainPage.DisplayAlert("Disconnected", "Device disconnected successfully.", "OK");
......
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