-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
59 lines (54 loc) · 1.87 KB
/
Program.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
using m4rcus.HatchBaby.Rest;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.UI;
namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
// output debugging info to console
Trace.Listeners.Add(new ConsoleTraceListener());
if (args.Length == 1)
{
// connect directly without discovery if address is known, ex "CBBABE52631F"
var bluetoothAddress = ulong.Parse(args[0], System.Globalization.NumberStyles.HexNumber);
using (var rest = new RestDevice("My Device", bluetoothAddress))
{
Task.WaitAll(DoTest(rest));
}
}
else
{
foreach (var rest in RestDevice.Discover().Result)
{
using (rest) // dispose of the device when done with "using" or .Dispose()
{
Task.WaitAll(DoTest(rest));
}
}
}
}
static async Task DoTest(RestDevice rest)
{
// reset to red/quiet
await rest.SetAudioTrack(AudioTrack.TRACK_NONE);
await rest.SetColor(Colors.Red);
await rest.SetPower(true);
await Task.Delay(1000);
// toggle on and off, green and blue
await rest.SetPower(!rest.Data.Power);
await Task.Delay(1000);
await rest.SetColor(Colors.Green);
await rest.SetPower(!rest.Data.Power);
await Task.Delay(1000);
await rest.SetColor(Colors.Blue);
// set volume, audio track
await rest.SetVolume(60);
await rest.SetAudioTrack(AudioTrack.TRACK_STREAM);
await Task.Delay(6000);
await rest.SetVolume(10);
}
}
}