-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathArdusatSDK.h
610 lines (534 loc) · 17.8 KB
/
ArdusatSDK.h
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/**
* @file ArdusatSDK.h
* @author Ben Peters ([email protected])
* @author Sam Olds ([email protected])
* @date December 3, 2014
* @brief Implements ArdusatSDK generic sensor reading and configuration for Space Kit Sensors.
*
* Provides a unifying wrapper of sensor specific functionality to provide a
* consistent interface to interact with each type of sensor.
*/
#ifndef ARDUSATSDK_H_
#define ARDUSATSDK_H_
#include <Arduino.h>
#include <Wire.h>
#include <utility/drivers.h>
#include <avr/pgmspace.h>
#include <utility/serial.h>
/**
* Allows the user to manually decide in an Arduino sketch if the SDK should
* dynamically check if the SpaceBoard is being used or not.
* Defaults to false
*/
extern boolean MANUAL_CONFIG;
/**
* Used when dynamically checking if the SpaceBoard is being used or not. If
* the SpaceBoard is being used, different addresses might be used for each
* sensor.
*/
extern boolean ARDUSAT_SPACEBOARD;
extern const char spacekit_hardware_name[];
extern const char spaceboard_hardware_name[];
extern const char acceleration_sensor_name[];
extern const char gyro_sensor_name[];
extern const char luminosity_sensor_name[];
extern const char magnetic_sensor_name[];
extern const char orientation_sensor_name[];
extern const char pressure_sensor_name[];
extern const char temperature_sensor_name[];
extern const char irtemperature_sensor_name[];
extern const char rgblight_sensor_name[];
extern const char uvlight_sensor_name[];
extern const char CSV_TIMESTAMP[];
extern const char CSV_CHECKSUM[];
/**
* Unique numeric id for each physical sensor
*/
typedef enum {
SENSORID_NULL = 0x00, // no sensor, or unreliable
SENSORID_TMP102 = 0x01,
SENSORID_TSL2561 = 0x02,
SENSORID_MLX90614 = 0x03,
SENSORID_ADAFRUIT9DOFIMU = 0x04,
SENSORID_SI1132 = 0x05,
SENSORID_ML8511 = 0x06,
SENSORID_BMP180 = 0x07,
SENSORID_ISL29125 = 0x08,
SENSORID_TCS34725 = 0x09,
} sensor_id_t;
/**
* Unit definitions
*/
typedef enum {
DATA_UNIT_NONE = 0,
DATA_UNIT_METER_PER_SECONDSQUARED = 1,
DATA_UNIT_RADIAN_PER_SECOND = 2,
DATA_UNIT_MICROTESLA = 3,
DATA_UNIT_DEGREES_CELSIUS = 4,
DATA_UNIT_DEGREES_FAHRENHEIT = 5,
DATA_UNIT_METER_PER_SECOND = 6,
DATA_UNIT_LUX = 7,
DATA_UNIT_RADIAN = 8,
DATA_UNIT_MILLIWATT_PER_CMSQUARED = 9,
DATA_UNIT_DEGREES = 10,
DATA_UNIT_HECTOPASCAL = 11
} data_unit_t;
/**
* Where all of the sensor data is kept before being printed
*/
extern int OUTPUT_BUF_SIZE;
extern char * _output_buffer;
char * _getOutBuf();
void _resetOutBuf();
/**
* The data header contains generic information about the data record.
*/
struct _data_header_v1 {
unsigned char unit; // unit (standard) of the values (e.g. meter, m/s^2, etc.)
unsigned char sensor_id; // id of the sensor that generated this data
unsigned long timestamp; // millis for timestamping the data
};
typedef struct _data_header_v1 _data_header_t;
/**
* Get a string representation of a unit constant
*/
const char * unit_to_str(unsigned char unit);
/**
* creates a string representation of the data in a CSV format that can be used with
* http://experiments.ardusat.com to visualize and log data.
*/
const char * valuesToCSV(const char *sensorName, unsigned long timestamp, int numValues, ...);
const char * valueToCSV(const char *sensorName, float value, unsigned long timestamp=0);
/**
* creates a string representation of the data in a JSON format that can be used with
* http://experiments.ardusat.com to visualize and log data.
*
* Format is:
* ~{"sensorName": "name", "unit": "C", "value": 35.3}|
*/
const char * valuesToJSON(const char *sensorName, unsigned char unit, int numValues, ...);
const char * valueToJSON(const char *sensorName, unsigned char unit, float value);
class Display : public Adafruit_SSD1306 {
public:
Display() : Adafruit_SSD1306() {}
};
/**************************************************************************//**
* @class Sensor
* @defgroup sensor
* @brief Base Sensor class that all Sensors inherit from
*****************************************************************************/
class Sensor {
protected:
void initializeHeader(sensor_id_t sensor_id, data_unit_t unit, const char name[] PROGMEM);
virtual boolean initialize(void) = 0;
virtual boolean readSensor(void) = 0;
public:
const char * name;
_data_header_t header;
boolean initialized;
boolean begin(void);
boolean read(void);
const char * readToCSV(const char * sensorName);
const char * readToJSON(const char * sensorName);
virtual const char * toCSV(const char * sensorName) = 0;
virtual const char * toJSON(const char * sensorName) = 0;
};
/**************************************************************************//**
* @class Acceleration
* @ingroup sensor
*
* @defgroup acceleration
* @brief Encapsulates all functionality related to the Acceleration Sensor
*
* This class can be used to initialize, further configure, read, and print
* data receieved from the LSM303 on the Adafruit 9 Degrees of Freedom
* Board.
*
* Example Usage:
* @code
* Acceleration accel; // Instantiate sensor object
* accel.begin(); // Initialize sensor
* Serial.println(accel.readToJSON("accel")); // Read and print values in JSON
* @endcode
*****************************************************************************/
class Acceleration: public Sensor {
protected:
lsm303_accel_gain_e gGain;
boolean initialize(void);
boolean readSensor(void);
public:
float x;
float y;
float z;
Acceleration(void);
Acceleration(lsm303_accel_gain_e gain);
const char * toCSV(const char * sensorName);
const char * toJSON(const char * sensorName);
};
/**************************************************************************//**
* @class Gyro
* @ingroup sensor
*
* @defgroup gyro
* @brief Encapsulates all functionality related to the Gyro Sensor
*
* This class can be used to initialize, further configure, read, and print
* data receieved from the L3GD20 on the Adafruit 9 Degrees of Freedom
* Board.
*
* Example Usage:
* @code
* Gyro gyro; // Instantiate sensor object
* gyro.begin(); // Initialize sensor
* Serial.println(gyro.readToJSON("gyro")); // Read and print values in JSON
* @endcode
*****************************************************************************/
class Gyro: public Sensor {
protected:
uint8_t range;
boolean initialize(void);
boolean readSensor(void);
public:
float x;
float y;
float z;
Gyro(void);
Gyro(uint8_t range);
const char * toCSV(const char * sensorName);
const char * toJSON(const char * sensorName);
};
/**************************************************************************//**
* @class Luminosity
* @ingroup sensor
*
* @defgroup luminosity
* @brief Encapsulates all functionality related to the Luminosity Sensor
*
* This class can be used to initialize, further configure, read, and print
* data receieved from the TCS34725 board
*
* Example Usage:
* @code
* Luminosity lum; // Instantiate sensor object
* lum.begin(); // Initialize sensor
* Serial.println(lum.readToJSON("lum")); // Read and print values in JSON
* @endcode
*****************************************************************************/
class Luminosity: public Sensor {
protected:
tcs34725Gain_t gain;
tcs34725IntegrationTime_t intTime;
boolean initialize(void);
boolean readSensor(void);
public:
float lux;
Luminosity(void);
Luminosity(tcs34725IntegrationTime_t intTime, tcs34725Gain_t gain);
Luminosity(tcs34725Gain_t gain, tcs34725IntegrationTime_t intTime);
Luminosity(tcs34725IntegrationTime_t intTime);
Luminosity(tcs34725Gain_t gain);
const char * toCSV(const char * sensorName);
const char * toJSON(const char * sensorName);
};
/**************************************************************************//**
* @class Magnetic
* @ingroup sensor
*
* @defgroup magnetic
* @brief Encapsulates all functionality related to the Magnetic Sensor
*
* This class can be used to initialize, further configure, read, and print
* data receieved from the LSM303 on the Adafruit 9 Degrees of Freedom
* Board.
*
* Example Usage:
* @code
* Magnetic mag; // Instantiate sensor object
* mag.begin(); // Initialize sensor
* Serial.println(mag.readToJSON("mag")); // Read and print values in JSON
* @endcode
*****************************************************************************/
class Magnetic: public Sensor {
protected:
lsm303_mag_scale_e gaussScale;
boolean initialize(void);
boolean readSensor(void);
public:
float x;
float y;
float z;
Magnetic(void);
Magnetic(lsm303_mag_scale_e gaussScale);
const char * toCSV(const char * sensorName);
const char * toJSON(const char * sensorName);
};
/**************************************************************************//**
* @class Orientation
* @ingroup sensor
*
* @defgroup orientation
* @brief Encapsulates all functionality related to the Orientation Calculation
*
* This class can be used to initialize, read, and print data derived from the
* Accelerometer and Magnetometer Sensors
*
* Example Usage:
* @code
* Orientation orient; // Instantiate sensor object
* orient.begin(); // Initialize sensor
* Serial.println(orient.readToJSON("orientation")); // Read and print values in JSON
* @endcode
*****************************************************************************/
class Orientation: public Sensor {
protected:
Acceleration * accel;
Magnetic * mag;
boolean initialize(void);
boolean readSensor(void);
public:
float roll;
float pitch;
float heading;
Orientation(Acceleration & accel, Magnetic & mag);
const char * toCSV(const char * sensorName);
const char * toJSON(const char * sensorName);
};
/**************************************************************************//**
* @class Pressure
* @ingroup sensor
*
* @defgroup pressure
* @brief Encapsulates all functionality related to the Pressure Sensor
*
* This class can be used to initialize, further configure, read, and print
* data receieved from the BMP180 on the Adafruit 9 Degrees of Freedom
* Board.
*
* @note This Sensor is not available on the SpaceBoard
*
* Example Usage:
* @code
* Pressure press; // Instantiate sensor object
* press.begin(); // Initialize sensor
* Serial.println(press.readToJSON("pressure")); // Read and print values in JSON
* @endcode
*****************************************************************************/
class Pressure: public Sensor {
protected:
bmp085_mode_t bmp085_mode;
boolean initialize(void);
boolean readSensor(void);
public:
float pressure;
Pressure(void);
Pressure(bmp085_mode_t mode);
float altitudeFromSeaLevelPressure(float seaLevelPressure);
float seaLevelPressureFromAltitude(float altitude);
const char * toCSV(const char * sensorName);
const char * toJSON(const char * sensorName);
};
/**************************************************************************//**
* @class RGBLight
* @ingroup sensor
*
* @defgroup rgblight
* @brief Encapsulates all functionality related to the RGBLight Sensor
*
* This class can be used to initialize, further configure, read, and print
* data receieved from the either the TCS34725 board (default) or the ISL29125
* board
*
* @note No RGBLight Sensors are provided with the Space Kit
*
* Example Usage:
* @code
* RGBLight rgb; // Instantiate sensor object
* rgb.begin(); // Initialize sensor
* Serial.println(rgb.readToJSON("rgb")); // Read and print values in JSON
* @endcode
* Or
* @code
* RGBLightTCS rgb; // Instantiate sensor object
* rgb.begin(); // Initialize sensor
* Serial.println(rgb.readToJSON("rgb")); // Read and print values in JSON
* @endcode
* Or
* @code
* RGBLightISL rgb; // Instantiate sensor object
* rgb.begin(); // Initialize sensor
* Serial.println(rgb.readToJSON("rgb")); // Read and print values in JSON
* @endcode
*****************************************************************************/
class RGBLight: public Sensor {
protected:
tcs34725IntegrationTime_t tcsIt;
tcs34725Gain_t tcsGain;
boolean initialize(void);
boolean readSensor(void);
RGBLight(tcs34725IntegrationTime_t tcsIt, tcs34725Gain_t tcsGain);
public:
float red;
float green;
float blue;
RGBLight(void);
const char * toCSV(const char * sensorName);
const char * toJSON(const char * sensorName);
};
/**
* @class RGBLightTCS
* @ingroup rgblight
*
* @brief Encapsulates all functionality related to the TCS34725 RGBLight Sensor
*/
class RGBLightTCS: public RGBLight {
public:
RGBLightTCS(void);
RGBLightTCS(tcs34725IntegrationTime_t tcsIt, tcs34725Gain_t tcsGain);
RGBLightTCS(tcs34725Gain_t tcsGain, tcs34725IntegrationTime_t tcsIt);
RGBLightTCS(tcs34725IntegrationTime_t tcsIt);
RGBLightTCS(tcs34725Gain_t tcsGain);
};
/**
* @class RGBLightISL
* @ingroup rgblight
*
* @brief Encapsulates all functionality related to the ISL29125 RGBLight Sensor
*/
class RGBLightISL: public RGBLight {
protected:
uint8_t islIntensity;
boolean initialize(void);
boolean readSensor(void);
public:
RGBLightISL(void);
RGBLightISL(uint8_t islIntensity);
};
/**************************************************************************//**
* @class Temperature
* @ingroup sensor
*
* @defgroup temperature
* @brief Encapsulates all functionality related to the Temperature Sensor
*
* This class can be used to initialize, further configure, read, and print
* data receieved from either the TMP102 board (default) or the MLX90614 board
*
* The TMP102 is an ambient temperature sensor and the MLX90614 is an infrared
* temperature sensor
*
* Example Usage:
* @code
* Temperature temp; // Instantiate sensor object
* temp.begin(); // Initialize sensor
* Serial.println(temp.readToJSON("ambient_temp")); // Read and print values in JSON
* @endcode
* Or
* @code
* TemperatureTMP temp; // Instantiate sensor object
* temp.begin(); // Initialize sensor
* Serial.println(temp.readToJSON("ambient_temp")); // Read and print values in JSON
* @endcode
* Or
* @code
* TemperatureMLX temp; // Instantiate sensor object
* temp.begin(); // Initialize sensor
* Serial.println(temp.readToJSON("infrared_temp")); // Read and print values in JSON
* @endcode
*****************************************************************************/
class Temperature: public Sensor {
protected:
boolean initialize(void);
boolean readSensor(void);
public:
float t;
Temperature(void);
const char * toCSV(const char * sensorName);
const char * toJSON(const char * sensorName);
};
/**
* @class TemperatureTMP
* @ingroup temperature
*
* @brief Encapsulates all functionality related to the TMP102 Ambient Temperature Sensor
*/
class TemperatureTMP: public Temperature {
};
/**
* @class TemperatureMLX
* @ingroup temperature
*
* @brief Encapsulates all functionality related to the MLX90614 Infrared Temperature Sensor
*/
class TemperatureMLX: public Temperature {
protected:
boolean initialize(void);
boolean readSensor(void);
public:
TemperatureMLX(void);
};
/**************************************************************************//**
* @class UVLight
* @ingroup sensor
*
* @defgroup uvlight
* @brief Encapsulates all functionality related to the UVLight Sensor
*
* This class can be used to initialize, further configure, read, and print
* data receieved from either the ML8511 board (default) or the SI1132 board
*
* Example Usage:
* @code
* UVLight uv; // Instantiate sensor object
* uv.begin(); // Initialize sensor
* Serial.println(uv.readToJSON("uv")); // Read and print values in JSON
* @endcode
* Or
* @code
* UVLightML uv; // Instantiate sensor object
* uv.begin(); // Initialize sensor
* Serial.println(uv.readToJSON("uv")); // Read and print values in JSON
* @endcode
* Or
* @code
* UVLightSI uv; // Instantiate sensor object
* uv.begin(); // Initialize senor
* Serial.println(uv.readToJSON("uv")); // Read and print values in JSON
* @endcode
*****************************************************************************/
class UVLight: public Sensor {
protected:
int ML8511_pin;
boolean initialize(void);
boolean readSensor(void);
UVLight(int pin);
public:
float uvindex;
UVLight(void);
const char * toCSV(const char * sensorName);
const char * toJSON(const char * sensorName);
};
/**
* @class UVLightML
* @ingroup uvlight
*
* @brief Encapsulates all functionality related to the ML8511 UVLight Sensor
*/
class UVLightML: public UVLight {
public:
UVLightML(void);
UVLightML(int pin);
};
/**
* @class UVLightSI
* @ingroup uvlight
*
* @brief Encapsulates all functionality related to the SI1132 UVLight Sensor
*/
class UVLightSI: public UVLight {
protected:
boolean initialize(void);
boolean readSensor(void);
public:
UVLightSI(void);
};
#endif /* ARDUSATSDK_H_ */