-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathGpioDriver.cs
108 lines (94 loc) · 4.6 KB
/
GpioDriver.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Threading;
namespace System.Device.Gpio
{
/// <summary>
/// Base class for Gpio Drivers.
/// A Gpio driver provides methods to read from and write to digital I/O pins.
/// </summary>
public abstract class GpioDriver : IDisposable
{
/// <summary>
/// The number of pins provided by the driver.
/// </summary>
protected abstract int PinCount { get; }
/// <summary>
/// Converts a board pin number to the driver's logical numbering scheme.
/// </summary>
/// <param name="pinNumber">The board pin number to convert.</param>
/// <returns>The pin number in the driver's logical numbering scheme.</returns>
protected abstract int ConvertPinNumberToLogicalNumberingScheme(int pinNumber);
/// <summary>
/// Opens a pin in order for it to be ready to use.
/// The driver attempts to open the pin without changing its mode or value.
/// </summary>
/// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param>
protected abstract void OpenPin(int pinNumber);
/// <summary>
/// Closes an open pin.
/// </summary>
/// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param>
protected abstract void ClosePin(int pinNumber);
/// <summary>
/// Sets the mode to a pin.
/// </summary>
/// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param>
/// <param name="mode">The mode to be set.</param>
protected abstract void SetPinMode(int pinNumber, PinMode mode);
/// <summary>
/// Gets the mode of a pin.
/// </summary>
/// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param>
/// <returns>The mode of the pin.</returns>
protected abstract PinMode GetPinMode(int pinNumber);
/// <summary>
/// Checks if a pin supports a specific mode.
/// </summary>
/// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param>
/// <param name="mode">The mode to check.</param>
/// <returns>The status if the pin supports the mode.</returns>
protected abstract bool IsPinModeSupported(int pinNumber, PinMode mode);
/// <summary>
/// Reads the current value of a pin.
/// </summary>
/// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param>
/// <returns>The value of the pin.</returns>
protected abstract PinValue Read(int pinNumber);
/// <summary>
/// Writes a value to a pin.
/// </summary>
/// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param>
/// <param name="value">The value to be written to the pin.</param>
protected abstract void Write(int pinNumber, PinValue value);
/// <summary>
/// Adds a handler for a pin value changed event.
/// </summary>
/// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param>
/// <param name="eventTypes">The event types to wait for.</param>
/// <param name="callback">Delegate that defines the structure for callbacks when a pin value changed event occurs.</param>
protected abstract void AddCallbackForPinValueChangedEvent(int pinNumber, PinEventTypes eventTypes, PinChangeEventHandler callback);
/// <summary>
/// Removes a handler for a pin value changed event.
/// </summary>
/// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param>
/// <param name="callback">Delegate that defines the structure for callbacks when a pin value changed event occurs.</param>
protected abstract void RemoveCallbackForPinValueChangedEvent(int pinNumber, PinChangeEventHandler callback);
/// <summary>
/// Disposes this instance, closing all open pins
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Disposes this instance
/// </summary>
/// <param name="disposing">True if explicitly disposing, false if in finalizer</param>
protected virtual void Dispose(bool disposing)
{
// Nothing to do in base class.
}
}
}