-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hat.cs
140 lines (105 loc) · 3.82 KB
/
Hat.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using Windows.Devices;
using Windows.System.Threading;
using static Pimoroni.AutomationHat.SN3218LEDDriver;
namespace Pimoroni.AutomationHat
{
public static class Hat
{
private static ThreadPoolTimer _refreshTimer = null;
private static SN3218LEDDriver _ledDriver;
private static ADS1015 _a2dController;
private static Led _power;
private static Led _comms;
private static Led _warn;
public static bool PowerLED
{
get
{
return _power.State;
}
set
{
_power.State = value;
}
}
public static bool CommsLED
{
get
{
return _comms.State;
}
set
{
_comms.State = value;
}
}
public static bool WarnLED
{
get
{
return _warn.State;
}
set
{
_warn.State = value;
}
}
public static Relay Relay1 { get; private set; }
public static Relay Relay2 { get; private set; }
public static Relay Relay3 { get; private set; }
public static Output Output1 { get; private set; }
public static Output Output2 { get; private set; }
public static Output Output3 { get; private set; }
public static Input Input1 { get; private set; }
public static Input Input2 { get; private set; }
public static Input Input3 { get; private set; }
public static AnalogInput AnalogInput1 { get { return _a2dController[0]; } }
public static AnalogInput AnalogInput2 { get { return _a2dController[1]; } }
public static AnalogInput AnalogInput3 { get { return _a2dController[2]; } }
public static AnalogInput AnalogInput4 { get { return _a2dController[3]; } }
public static async void Init()
{
try
{
_power = new Led(17);
_comms = new Led(16);
_warn = new Led(15);
Relay1 = new Relay(13, 6, 7);
Relay2 = new Relay(19, 8, 9);
Relay3 = new Relay(16, 10, 11);
Output1 = new Output(5, 3);
Output2 = new Output(12, 4);
Output3 = new Output(6, 5);
Input1 = new Input(26, 14, true, Controllers.GPIOController);
Input2 = new Input(20, 13, true, Controllers.GPIOController);
Input3 = new Input(21, 12, true, Controllers.GPIOController);
_a2dController[0] = new AnalogInput(0, 25.85, new Led(0)); ;
_a2dController[1] = new AnalogInput(1, 25.85, new Led(1)); ;
_a2dController[2] = new AnalogInput(2, 25.85, new Led(2)); ;
_a2dController[3] = new AnalogInput(3, 3.3, null);
// Turn the power light on
_ledDriver = await SN3218LEDDriver.Open();
_ledDriver.Enable();
_ledDriver.EnableLeds();
_a2dController = await ADS1015.Open();
_refreshTimer = ThreadPoolTimer.CreatePeriodicTimer(x => Tick(), TimeSpan.FromMilliseconds(20));
}
catch (Exception ex)
{
}
}
public static bool IsGPIOSupported
{
get
{
return Controllers.GPIOController != null;
}
}
private static void Tick()
{
_ledDriver.Refresh();
_a2dController.ReadVoltages();
}
}
}