/
Mcp23xxx.DigitalOutputPort.cs
50 lines (46 loc) · 1.63 KB
/
Mcp23xxx.DigitalOutputPort.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
using Meadow.Hardware;
namespace Meadow.Foundation.ICs.IOExpanders
{
public partial class Mcp23xxx
{
/// <summary>
/// Represents an Mcp23xxx DigitalOutputPort
/// </summary>
public class DigitalOutputPort : DigitalOutputPortBase
{
/// <summary>
/// Enable the caller to receive pin state updates
/// </summary>
/// <param name="pin"></param>
/// <param name="state"></param>
public delegate void SetPinStateDelegate(IPin pin, bool state);
/// <summary>
/// The SetPinState delegate
/// </summary>
public SetPinStateDelegate SetPinState = default!;
/// <summary>
/// The port state
/// True for high, false for low
/// </summary>
public override bool State
{
get => state;
set => SetPinState?.Invoke(Pin, state = value);
}
bool state;
/// <summary>
/// Create a new DigitalOutputPort
/// </summary>
/// <param name="pin">The pin representing the port</param>
/// <param name="initialState">The initial port state</param>
/// <param name="outputType">An IPin instance</param>
public DigitalOutputPort(
IPin pin,
bool initialState = false,
OutputType outputType = OutputType.OpenDrain)
: base(pin, (IDigitalChannelInfo)pin.SupportedChannels![0], initialState, outputType)
{
}
}
}
}