-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeviceSetup.xaml.cs
109 lines (85 loc) · 3.29 KB
/
deviceSetup.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using MbientLab.MetaWear;
using MbientLab.MetaWear.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Devices.Bluetooth;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Net.Sockets;
using System.Net;
using System.Text;
using Windows.Networking;
using Windows.Networking.Sockets;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace StarterApp {
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class DeviceSetup : Page {
private IMetaWearBoard metawear;
TcpClient client;
public DeviceSetup() {
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e) {
base.OnNavigatedTo(e);
metawear = MbientLab.MetaWear.Win10.Application.GetMetaWearBoard(e.Parameter as BluetoothLEDevice);
}
private void back_Click(object sender, RoutedEventArgs e) {
if (!metawear.InMetaBootMode) {
metawear.TearDown();
metawear.GetModule<IDebug>().DisconnectAsync();
}
Frame.GoBack();
}
private async void accStart_Click(object sender, RoutedEventArgs e)
{
var accelerometer = metawear.GetModule<MbientLab.MetaWear.Sensor.IAccelerometer>();
accelerometer.Configure(odr: 25f, range: 2f);
System.Diagnostics.Debug.WriteLine("Accelerometer configured!");
try
{
client = new TcpClient("127.0.0.1", 6066);
NetworkStream stream = client.GetStream();
BinaryWriter w = new BinaryWriter(stream);
ASCIIEncoding asen = new ASCIIEncoding();
System.Diagnostics.Debug.WriteLine("Accelerometer configured!");
await accelerometer.Acceleration.AddRouteAsync(source => source.Stream(data =>
stream.Write(asen.GetBytes(data.Value<MbientLab.MetaWear.Data.Acceleration>().ToString()),0, asen.GetByteCount(data.Value<MbientLab.MetaWear.Data.Acceleration>().ToString()))
));
accelerometer.Acceleration.Start();
accelerometer.Start();
}
catch (Exception error)
{
System.Diagnostics.Debug.WriteLine(error.ToString());
}
finally
{
System.Diagnostics.Debug.WriteLine("Done");
}
}
private void accStop_Click(object sender, RoutedEventArgs e)
{
var accelerometer = metawear.GetModule<MbientLab.MetaWear.Sensor.IAccelerometer>();
client.Close();
accelerometer.Stop();
accelerometer.Acceleration.Stop();
metawear.TearDown();
}
static public string ToReadableByteArray(byte[] bytes)
{
return string.Join(", ", bytes);
}
}
}