-
Notifications
You must be signed in to change notification settings - Fork 586
/
SupportedMode.cs
158 lines (133 loc) · 4.99 KB
/
SupportedMode.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Device.Gpio;
using Iot.Device.Board;
namespace Iot.Device.Arduino
{
/// <summary>
/// Mode bits for the Firmata protocol.
/// These are used both for capability reporting as well as to set a mode
/// </summary>
public record SupportedMode
{
/// <summary>
/// The pin supports digital input
/// </summary>
public static SupportedMode DigitalInput = new SupportedMode(0x00, "Digital Input", PinUsage.Gpio);
/// <summary>
/// The pin supports digital output;
/// </summary>
public static SupportedMode DigitalOutput = new SupportedMode(0x01, "Digital Output", PinUsage.Gpio);
/// <summary>
/// The pin supports analog input
/// </summary>
public static SupportedMode AnalogInput = new SupportedMode(0x02, "Analog Input", PinUsage.AnalogIn);
/// <summary>
/// The pin supports PWM
/// </summary>
public static SupportedMode Pwm = new SupportedMode(0x03, "PWM", PinUsage.AnalogOut);
/// <summary>
/// The pin supports servo motor controls
/// </summary>
public static SupportedMode Servo = new SupportedMode(0x04, "Servo");
/// <summary>
/// Unused
/// </summary>
public static SupportedMode Shift = new SupportedMode(0x05, "Shift registers");
/// <summary>
/// The pin supports I2C data transfer
/// </summary>
public static SupportedMode I2c = new SupportedMode(0x06, "I2C", PinUsage.I2c);
/// <summary>
/// The pin supports one wire communication
/// </summary>
public static SupportedMode OneWire = new SupportedMode(0x07, "One Wire");
/// <summary>
/// The pin can drive a stepper motor
/// </summary>
public static SupportedMode Stepper = new SupportedMode(0x08, "Stepper Motor");
/// <summary>
/// The pin has an encoder
/// </summary>
public static SupportedMode Encoder = new SupportedMode(0x09, "Encoder");
/// <summary>
/// The pin can perform UART (TX or RX)
/// </summary>
public static SupportedMode Serial = new SupportedMode(0x0A, "Serial", PinUsage.Uart);
/// <summary>
/// The pin can be set to input-pullup.
/// </summary>
public static SupportedMode InputPullup = new SupportedMode(0x0B, "Input Pullup", PinUsage.Gpio);
//// Unofficial extensions (only supported by special firmware)
/// <summary>
/// The pin can be used for SPI transfer (Clock, MOSI, MISO and default CS pin)
/// For most Arduinos, MOSI=11, MISO=12 and Clock = 13. The default CS pin is 10.
/// </summary>
public static SupportedMode Spi = new SupportedMode(0x0C, "SPI", PinUsage.Spi);
/// <summary>
/// HC-SR04
/// </summary>
public static SupportedMode Sonar = new SupportedMode(0x0D, "HC-SR04");
/// <summary>
/// Arduino tone library
/// </summary>
public static SupportedMode Tone = new SupportedMode(0x0E, "Tone");
/// <summary>
/// DHT type sensors
/// </summary>
public static SupportedMode Dht = new SupportedMode(0x0F, "DHT");
/// <summary>
/// Frequency measurement
/// </summary>
public static SupportedMode Frequency = new SupportedMode(0x10, "Frequency");
/// <summary>
/// Declares a new pin mode
/// </summary>
/// <param name="value">The pin mode value</param>
/// <param name="name">The user-readable name for the mode</param>
/// <param name="pinUsage">Pin usage for this mode, if applicable</param>
public SupportedMode(byte value, string name, PinUsage pinUsage)
{
Value = value;
Name = name;
PinUsage = pinUsage;
}
/// <summary>
/// Declares a new pin mode
/// </summary>
/// <param name="value">The pin mode value</param>
/// <param name="name">The user-readable name for the mode</param>
public SupportedMode(byte value, string name)
{
Value = value;
Name = name;
PinUsage = PinUsage.Unknown;
}
/// <summary>
/// The value for the pin mode
/// </summary>
public byte Value
{
get;
}
/// <summary>
/// The name of the pin mode
/// </summary>
public string Name
{
get;
}
/// <summary>
/// The <see cref="Device.Board.PinUsage"/> for this internal mode, if applicable
/// </summary>
public PinUsage PinUsage
{
get;
}
/// <inheritdoc />
public override string ToString()
{
return $"{Name} (0x{Value:X2})";
}
}
}