-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDummyHeartRateSource.cs
More file actions
41 lines (36 loc) · 1.13 KB
/
Copy pathDummyHeartRateSource.cs
File metadata and controls
41 lines (36 loc) · 1.13 KB
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
using ILogger = MetroLog.ILogger;
using LoggerFactory = MetroLog.LoggerFactory;
namespace CardioMeter;
public class DummyHeartRateSource : IHeartRateProvider
{
private static readonly ILogger Log = LoggerFactory.GetLogger(nameof(DummyHeartRateSource));
private PeriodicTimer _timer;
private Task _task;
public DummyHeartRateSource()
{
KeepAlive();
}
public void KeepAlive()
{
if (_task == null || _task.IsCompleted)
{
_task = Task.Run(async () =>
{
_timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
while (true)
{
var ticked = await _timer.WaitForNextTickAsync();
if (ticked)
HeartRateReceived?.Invoke(this, HeartRateEventArgs.FromDummy(DateTime.Now));
}
});
}
}
public void Dispose()
{
_timer.Dispose();
}
public event EventHandler<HeartRateEventArgs> HeartRateReceived;
public event EventHandler OnConnectionLost;
public event EventHandler OnConnectionEstablished;
}