forked from dotnet/iot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigurableFirmata.ino
223 lines (181 loc) · 5.24 KB
/
ConfigurableFirmata.ino
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* CommonFirmataFeatures.ino generated by FirmataBuilder
*/
// Use these defines to easily enable or disable certain modules
/* Note 1: Currently no client support by dotnet/iot for the following modules, so they're disabled by default */
/* Enabling all modules on the smaller Arduino boards (such as the UNO or the Nano) won't work anyway, as there is both
* not enough flash as well as not enough RAM.
*
* Note 2: If you get compiler errors or want to test experimental features, it might be better to use the example
* file in the ConfigurableFirmata library (default path C:\Users\<UserName>\Documents\Arduino\libraries\ConfigurableFirmata\examples\ConfigurableFirmata)
*/
//#define ENABLE_ONE_WIRE
//#define ENABLE_SERVO
//#define ENABLE_ACCELSTEPPER
//#define ENABLE_BASIC_SCHEDULER
//#define ENABLE_SERIAL
// Support for analog in and analog out (PWM or real DACs, if available)
#define ENABLE_ANALOG
// Support for digital in and digital out
#define ENABLE_DIGITAL
// I2C support (most boards have just one channel)
#define ENABLE_I2C
// SPI support. This feature requires a non-standard module compiled into the firmware
// #define ENABLE_SPI
// Native reading of DHTXX sensors. Reading a DHT11 directly using GPIO methods from a remote PC will not work, because of the very tight timing requirements of these sensors
// This feature requires a non-standard module compiled into the firmware (see Readme.md). In addition, the "DHT Sensor library" from Adafruit is required.
// #define ENABLE_DHT
#include <ConfigurableFirmata.h>
#ifdef ENABLE_DIGITAL
#include <DigitalInputFirmata.h>
DigitalInputFirmata digitalInput;
#include <DigitalOutputFirmata.h>
DigitalOutputFirmata digitalOutput;
#endif
#ifdef ENABLE_ANALOG
#include <AnalogInputFirmata.h>
AnalogInputFirmata analogInput;
#include <AnalogOutputFirmata.h>
AnalogOutputFirmata analogOutput;
#endif
#ifdef ENABLE_I2C
#include <Wire.h>
#include <I2CFirmata.h>
I2CFirmata i2c;
#endif
#ifdef ENABLE_ONE_WIRE
#include <OneWireFirmata.h>
OneWireFirmata oneWire;
#endif
#ifdef ENABLE_SERIAL
#include <SerialFirmata.h>
SerialFirmata serial;
#endif
#include <FirmataExt.h>
FirmataExt firmataExt;
#ifdef ENABLE_SPI
#include <SpiFirmata.h>
SpiFirmata spi;
#endif
#ifdef ENABLE_SERVO
#include <Servo.h>
#include <ServoFirmata.h>
ServoFirmata servo;
#endif
#include <AnalogWrite.h>
#ifdef ENABLE_BASIC_SCHDULER
// The scheduler allows to store scripts on the board, however this requires a kind of compiler on the client side.
// When running dotnet/iot on the client side, prefer using the FirmataIlExecutor module instead
#include <FirmataScheduler.h>
FirmataScheduler scheduler;
#endif
#include <FirmataReporting.h>
FirmataReporting reporting;
#ifdef ENABLE_ACCELSTEPPER
#include <AccelStepperFirmata.h>
AccelStepperFirmata accelStepper;
#endif
#ifdef ENABLE_DHT
#include <DhtFirmata.h>
DhtFirmata dhtFirmata;
#endif
void systemResetCallback()
{
for (byte i = 0; i < TOTAL_PINS; i++) {
if (IS_PIN_ANALOG(i)) {
Firmata.setPinMode(i, ANALOG);
} else if (IS_PIN_DIGITAL(i)) {
Firmata.setPinMode(i, OUTPUT);
}
}
firmataExt.reset();
}
void initTransport()
{
// Uncomment to save a couple of seconds by disabling the startup blink sequence.
// Firmata.disableBlinkVersion();
Firmata.begin(115200);
}
void initFirmata()
{
// Set firmware name and version. The name is automatically derived from the name of this file.
// Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
// The usage of the above shortcut is not recommended, since it stores the full path of the file name in a
// string constant, using both flash and ram.
Firmata.setFirmwareNameAndVersion("ConfigurableFirmata", FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
#ifdef ENABLE_DIGITAL
firmataExt.addFeature(digitalInput);
firmataExt.addFeature(digitalOutput);
#endif
#ifdef ENABLE_ANALOG
firmataExt.addFeature(analogInput);
firmataExt.addFeature(analogOutput);
#endif
#ifdef ENABLE_SERVO
firmataExt.addFeature(servo);
#endif
#ifdef ENABLE_I2C
firmataExt.addFeature(i2c);
#endif
#ifdef ENABLE_ONE_WIRE
firmataExt.addFeature(oneWire);
#endif
#ifdef ENABLE_SERIAL
firmataExt.addFeature(serial);
#endif
#ifdef ENABLE_BASIC_SCHEDULER
firmataExt.addFeature(scheduler);
#endif
firmataExt.addFeature(reporting);
#ifdef ENABLE_SPI
firmataExt.addFeature(spi);
#endif
#ifdef ENABLE_ACCELSTEPPER
firmataExt.addFeature(accelStepper);
#endif
#ifdef ENABLE_DHT
firmataExt.addFeature(dhtFirmata);
#endif
Firmata.attach(SYSTEM_RESET, systemResetCallback);
}
void setup()
{
initFirmata();
initTransport();
Firmata.parse(SYSTEM_RESET);
}
void loop()
{
while(Firmata.available()) {
Firmata.processInput();
if (!Firmata.isParsingMessage()) {
goto runtasks;
}
}
if (!Firmata.isParsingMessage())
{
runtasks:
#ifdef ENABLE_BASIC_SCHEDULER
scheduler.runTasks();
#else
0 == 0; // Do something useless (to prevent a compiler error)
#endif
}
if (reporting.elapsed()) {
#ifdef ENABLE_ANALOG
analogInput.report();
#endif
#ifdef ENABLE_I2C
i2c.report();
#endif
}
#ifdef ENABLE_DIGITAL
digitalInput.report();
#endif
#ifdef ENABLE_ACCELSTEPPER
accelStepper.update();
#endif
#ifdef ENABLE_SERIAL
serial.update();
#endif
}