-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLedClient.cs
62 lines (50 loc) · 1.31 KB
/
LedClient.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
using System;
using System.Device.Gpio;
namespace AspNetCore3LedOnOff
{
public class LedClient : IDisposable
{
private const int LedPin = 17;
private GpioController _controller = new GpioController();
private bool disposedValue = false;
private object _locker = new object();
public LedClient()
{
_controller.OpenPin(LedPin, PinMode.Output);
_controller.Write(LedPin, PinValue.Low);
IsLedOn = false;
}
public bool IsLedOn { get; private set; }
public void LedOn()
{
lock (_locker)
{
_controller.Write(LedPin, PinValue.High);
IsLedOn = true;
}
}
public void LedOff()
{
lock (_locker)
{
_controller.Write(LedPin, PinValue.Low);
IsLedOn = false;
}
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
_controller.Dispose();
}
disposedValue = true;
}
}
public void Dispose()
{
Dispose(true);
}
}
}