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