-
Notifications
You must be signed in to change notification settings - Fork 2
/
MeadowApp.cs
61 lines (50 loc) · 1.62 KB
/
MeadowApp.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
using Meadow;
using Meadow.Devices;
using Meadow.Hardware;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace WakeOnInterrupt;
/// <summary>
/// This sample illustrates putting the device into low-power (sleep) state until an interrupt occurs
/// </summary>
public class MeadowApp : App<F7FeatherV2>
{
private IDigitalOutputPort _red;
private IDigitalOutputPort _green;
public TimeSpan Timespan { get; private set; }
public override Task Initialize()
{
Resolver.Log.Info("Initializing hardware...");
_red = Device.Pins.OnboardLedRed.CreateDigitalOutputPort(false);
_green = Device.Pins.OnboardLedGreen.CreateDigitalOutputPort(false);
Device.PlatformOS.BeforeSleep += () =>
{
_red.State = true;
Resolver.Log.Info("Sleeping...");
};
Device.PlatformOS.AfterWake += (e, o) =>
{
Thread.Sleep(1000);
_red.State = false;
Resolver.Log.Info("Resuming...");
};
return Task.CompletedTask;
}
public override async Task Run()
{
while (true)
{
Resolver.Log.Info("Waiting...");
for (var i = 0; i < 5; i++)
{
_green.State = true;
await Task.Delay(500);
_green.State = false;
await Task.Delay(500);
}
Device.PlatformOS.Sleep(Device.Pins.D05, InterruptMode.EdgeRising, ResistorMode.InternalPullDown);
Resolver.Log.Info("Continuing...");
}
}
}