-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
96 lines (79 loc) · 2.42 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
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
using Microsoft.Identity.Client;
using System;
using System.Device.Gpio;
using System.Threading;
Console.WriteLine("Hello World!");
Console.WriteLine("Blinking LED. Press Ctrl+C to end.");
int upPin = 17;
int downPin = 27;
int sleepTime = 12000;
using var controller = new GpioController();
controller.OpenPin(upPin, PinMode.Output);
controller.OpenPin(downPin, PinMode.Output);
controller.Write(upPin, PinValue.High);
controller.Write(downPin, PinValue.High);
try
{
var settings = Settings.LoadSettings();
// Initialize Graph
InitializeGraph(settings);
//getAccessToken
await DisplayAccessTokenAsync();
while (true)
{
var presence = await GraphHelper.GetUsersPresenceAsync("707fca83-7a84-4d7e-8833-19ddfd7f9d2b");
Console.WriteLine(presence.Activity.ToString());
if (presence != null && (presence.Activity == "InAMeeting" || presence.Activity == "InACall" || presence.Activity == "InAConferenceCall"))
{
TogglePinOnFor(upPin, sleepTime);
// Thread.Sleep(sleepTime);
}
//maybe add conditions for down
Thread.Sleep(sleepTime);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine("Setting both pins to high and exiting.");
controller.Write(upPin, PinValue.High);
controller.Write(downPin, PinValue.High);
}
void TogglePinOnFor(int pin, int milliseconds)
{
if (controller is null)
{
return;
}
Console.WriteLine($"Setting pin {pin} to low");
controller.Write(pin, PinValue.Low);
Console.WriteLine($"Sleeping for {milliseconds} milliseconds");
Thread.Sleep(milliseconds);
Console.WriteLine($"Setting pin {pin} to high");
controller.Write(pin, PinValue.High);
}
void InitializeGraph(Settings settings)
{
GraphHelper.InitializeGraphForUserAuth(settings,
(info, cancel) =>
{
// Display the device code message to
// the user. This tells them
// where to go to sign in and provides the
// code to use.
Console.WriteLine(info.Message);
return Task.FromResult(0);
});
}
async Task DisplayAccessTokenAsync()
{
try
{
var userToken = await GraphHelper.GetUserTokenAsync();
// Console.WriteLine($"User token: {userToken}");
}
catch (Exception ex)
{
Console.WriteLine($"Error getting user access token: {ex.Message}");
}
}