-
Notifications
You must be signed in to change notification settings - Fork 0
/
GpioHandler.cs
51 lines (38 loc) · 1.25 KB
/
GpioHandler.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Device.Gpio;
namespace Pillowsoft.GhostKeys
{
public abstract class GpioHandler
{
private readonly GpioController controller;
public GpioHandler()
{
//This workaround is needed on some Pis
var assembly = typeof(GpioDriver).Assembly;
var driverType = assembly.GetType("System.Device.Gpio.Drivers.RaspberryPi3LinuxDriver");
var ctor = driverType.GetConstructor(new Type[] { });
var driver = ctor.Invoke(null) as GpioDriver;
this.controller = new GpioController(PinNumberingScheme.Board, driver);
// this.controller = new MockGpioController();
}
protected void OpenOutputPin(int pin, PinValue initialValue)
{
if (!controller.IsPinOpen(pin))
{
controller.OpenPin(pin, PinMode.Output, initialValue);
}
else
{
WriteOutputPin(pin, initialValue);
}
}
protected void WriteOutputPin(int pin, PinValue pinValue)
{
controller.Write(pin, pinValue);
}
}
}