Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Robobin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plw1g21
Robobin
Commits
8a848bbb
Commit
8a848bbb
authored
5 months ago
by
Paul-Winpenny
Browse files
Options
Downloads
Patches
Plain Diff
Names are now used to find characteristics instead of UUIDs
parent
52c1ac04
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
App now has a basic structure and BLE support
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
App/RobobinApp/ViewModels/ConnectionPageViewModel.cs
+27
-10
27 additions, 10 deletions
App/RobobinApp/ViewModels/ConnectionPageViewModel.cs
with
27 additions
and
10 deletions
App/RobobinApp/ViewModels/ConnectionPageViewModel.cs
+
27
−
10
View file @
8a848bbb
...
...
@@ -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
(
5
0
00
);
await
Task
.
Delay
(
2
500
);
//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
(
w
xUUID
))
else
if
(
characteristic
.
Name
.
Equals
(
w
riteCharacteristicName
))
{
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"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment