@@ -39,15 +39,35 @@ void Adafruit_LSM9DS0::initI2C(TwoWire *wireBus, int32_t sensorID) {
39
39
&Adafruit_LSM9DS0::getTempSensor);
40
40
}
41
41
42
- // default
42
+ /* *************************************************************************/
43
+ /* !
44
+ @brief Instantiate with default hardware I2C interface
45
+ @param sensorID Unique identifier you'd like for the sensors
46
+ */
47
+ /* *************************************************************************/
43
48
Adafruit_LSM9DS0::Adafruit_LSM9DS0 (int32_t sensorID) {
44
49
initI2C (&Wire, sensorID);
45
50
}
46
51
52
+ /* *************************************************************************/
53
+ /* !
54
+ @brief Instantiate with hardware I2C interface
55
+ @param wireBus The I2C wire interface you'd like to use
56
+ @param sensorID Unique identifier you'd like for the sensors
57
+ */
58
+ /* *************************************************************************/
47
59
Adafruit_LSM9DS0::Adafruit_LSM9DS0 (TwoWire *wireBus, int32_t sensorID) {
48
60
initI2C (wireBus, sensorID);
49
61
}
50
62
63
+ /* *************************************************************************/
64
+ /* !
65
+ @brief Instantiate with hardware SPI interface
66
+ @param xmcs SPI CS pin for accelerometer/mag subchip
67
+ @param gcs SPI CS pin for gyro subchip
68
+ @param sensorID Unique identifier you'd like for the sensors
69
+ */
70
+ /* *************************************************************************/
51
71
Adafruit_LSM9DS0::Adafruit_LSM9DS0 (int8_t xmcs, int8_t gcs, int32_t sensorID) {
52
72
_i2c = false ;
53
73
// hardware SPI!
@@ -72,6 +92,17 @@ Adafruit_LSM9DS0::Adafruit_LSM9DS0(int8_t xmcs, int8_t gcs, int32_t sensorID) {
72
92
&Adafruit_LSM9DS0::getTempSensor);
73
93
}
74
94
95
+ /* *************************************************************************/
96
+ /* !
97
+ @brief Instantiate with software SPI interface
98
+ @param clk SPI clock pin
99
+ @param miso SPI MISO pin
100
+ @param mosi SPI MOSI pin
101
+ @param xmcs SPI CS pin for accelerometer/mag subchip
102
+ @param gcs SPI CS pin for gyro subchip
103
+ @param sensorID Unique identifier you'd like for the sensors
104
+ */
105
+ /* *************************************************************************/
75
106
Adafruit_LSM9DS0::Adafruit_LSM9DS0 (int8_t clk, int8_t miso, int8_t mosi,
76
107
int8_t xmcs, int8_t gcs, int32_t sensorID) {
77
108
_i2c = false ;
@@ -99,6 +130,12 @@ Adafruit_LSM9DS0::Adafruit_LSM9DS0(int8_t clk, int8_t miso, int8_t mosi,
99
130
&Adafruit_LSM9DS0::getTempSensor);
100
131
}
101
132
133
+ /* *************************************************************************/
134
+ /* !
135
+ @brief Initialize I2C or SPI and detect/initialize subsensors
136
+ @returns True if both subsensors were detected on the desired interface
137
+ */
138
+ /* *************************************************************************/
102
139
bool Adafruit_LSM9DS0::begin () {
103
140
if (_i2c) {
104
141
_wire->begin ();
@@ -162,6 +199,12 @@ bool Adafruit_LSM9DS0::begin() {
162
199
/* **************************************************************************
163
200
PUBLIC FUNCTIONS
164
201
***************************************************************************/
202
+
203
+ /* *************************************************************************/
204
+ /* !
205
+ @brief Read all four sensor subcomponents
206
+ */
207
+ /* *************************************************************************/
165
208
void Adafruit_LSM9DS0::read () {
166
209
/* Read all the sensors. */
167
210
readAccel ();
@@ -170,6 +213,11 @@ void Adafruit_LSM9DS0::read() {
170
213
readTemp ();
171
214
}
172
215
216
+ /* *************************************************************************/
217
+ /* !
218
+ @brief Read the sensor accelerometer sensor component
219
+ */
220
+ /* *************************************************************************/
173
221
void Adafruit_LSM9DS0::readAccel () {
174
222
// Read the accelerometer
175
223
byte buffer[6 ];
@@ -194,6 +242,11 @@ void Adafruit_LSM9DS0::readAccel() {
194
242
accelData.z = zhi;
195
243
}
196
244
245
+ /* *************************************************************************/
246
+ /* !
247
+ @brief Read the sensor magnetometer sensor component
248
+ */
249
+ /* *************************************************************************/
197
250
void Adafruit_LSM9DS0::readMag () {
198
251
// Read the magnetometer
199
252
byte buffer[6 ];
@@ -218,6 +271,11 @@ void Adafruit_LSM9DS0::readMag() {
218
271
magData.z = zhi;
219
272
}
220
273
274
+ /* *************************************************************************/
275
+ /* !
276
+ @brief Read the sensor gyroscope sensor component
277
+ */
278
+ /* *************************************************************************/
221
279
void Adafruit_LSM9DS0::readGyro () {
222
280
// Read gyro
223
281
byte buffer[6 ];
@@ -243,6 +301,11 @@ void Adafruit_LSM9DS0::readGyro() {
243
301
gyroData.z = zhi;
244
302
}
245
303
304
+ /* *************************************************************************/
305
+ /* !
306
+ @brief Read the sensor temperature sensor component
307
+ */
308
+ /* *************************************************************************/
246
309
void Adafruit_LSM9DS0::readTemp () {
247
310
// Read temp sensor
248
311
byte buffer[2 ];
@@ -257,6 +320,13 @@ void Adafruit_LSM9DS0::readTemp() {
257
320
temperature = xhi;
258
321
}
259
322
323
+ /* *************************************************************************/
324
+ /* !
325
+ @brief Configure the accelerometer ranging
326
+ @param range Can be LSM9DS0_ACCELRANGE_2G, LSM9DS0_ACCELRANGE_4G,
327
+ LSM9DS0_ACCELRANGE_6G, LSM9DS0_ACCELRANGE_8G, LSM9DS0_ACCELRANGE_16G
328
+ */
329
+ /* *************************************************************************/
260
330
void Adafruit_LSM9DS0::setupAccel (lsm9ds0AccelRange_t range) {
261
331
uint8_t reg = read8 (XMTYPE, LSM9DS0_REGISTER_CTRL_REG2_XM);
262
332
reg &= ~(0b00111000 );
@@ -282,6 +352,13 @@ void Adafruit_LSM9DS0::setupAccel(lsm9ds0AccelRange_t range) {
282
352
}
283
353
}
284
354
355
+ /* *************************************************************************/
356
+ /* !
357
+ @brief Configure the magnetometer gain
358
+ @param gain Can be LSM9DS0_MAGGAIN_2GAUSS, LSM9DS0_MAGGAIN_4GAUSS,
359
+ LSM9DS0_MAGGAIN_8GAUSS, LSM9DS0_MAGGAIN_12GAUSS
360
+ */
361
+ /* *************************************************************************/
285
362
void Adafruit_LSM9DS0::setupMag (lsm9ds0MagGain_t gain) {
286
363
uint8_t reg = read8 (XMTYPE, LSM9DS0_REGISTER_CTRL_REG6_XM);
287
364
reg &= ~(0b01100000 );
@@ -304,6 +381,13 @@ void Adafruit_LSM9DS0::setupMag(lsm9ds0MagGain_t gain) {
304
381
}
305
382
}
306
383
384
+ /* *************************************************************************/
385
+ /* !
386
+ @brief Configure the gyroscope scaling
387
+ @param scale Can be LSM9DS0_GYROSCALE_245DPS, LSM9DS0_GYROSCALE_500DPS
388
+ or LSM9DS0_GYROSCALE_2000DPS
389
+ */
390
+ /* *************************************************************************/
307
391
void Adafruit_LSM9DS0::setupGyro (lsm9ds0GyroScale_t scale) {
308
392
uint8_t reg = read8 (GYROTYPE, LSM9DS0_REGISTER_CTRL_REG4_G);
309
393
reg &= ~(0b00110000 );
@@ -329,7 +413,15 @@ void Adafruit_LSM9DS0::setupGyro(lsm9ds0GyroScale_t scale) {
329
413
330
414
/* *************************************************************************/
331
415
/* !
332
- @brief Gets the most recent accel sensor event
416
+ @brief Gets the most recent accel sensor events for all 4 sensors
417
+ @param accelEvent The accelerometer event object we will fill, pass NULL to
418
+ skip
419
+ @param magEvent The magnetometer event object we will fill, pass NULL to
420
+ skip
421
+ @param gyroEvent The gyroscope event object we will fill, pass NULL to skip
422
+ @param tempEvent The temperature event object we will fill, pass NULL to
423
+ skip
424
+ @returns True on successful reads
333
425
*/
334
426
/* *************************************************************************/
335
427
bool Adafruit_LSM9DS0::getEvent (sensors_event_t *accelEvent,
@@ -355,7 +447,12 @@ bool Adafruit_LSM9DS0::getEvent(sensors_event_t *accelEvent,
355
447
356
448
/* *************************************************************************/
357
449
/* !
358
- @brief Gets the sensor_t data
450
+ @brief Gets the sensor_t data for all 4 sub-sensors at once call
451
+ @param accel The accelerometer sensor_t object we will fill, pass NULL to
452
+ skip
453
+ @param mag The magnetometer sensor_t object we will fill, pass NULL to skip
454
+ @param gyro The gyroscope sensor_t object we will fill, pass NULL to skip
455
+ @param temp The temperature sensor_t object we will fill, pass NULL to skip
359
456
*/
360
457
/* *************************************************************************/
361
458
void Adafruit_LSM9DS0::getSensor (sensor_t *accel, sensor_t *mag, sensor_t *gyro,
@@ -471,6 +568,13 @@ uint8_t Adafruit_LSM9DS0::spixfer(uint8_t data) {
471
568
}
472
569
}
473
570
571
+ /* *************************************************************************/
572
+ /* !
573
+ @brief Fill in the details about the most recent accelerometer data read
574
+ @param event The sensor_event_t object we will fill!
575
+ @param timestamp Unused
576
+ */
577
+ /* *************************************************************************/
474
578
void Adafruit_LSM9DS0::getAccelEvent (sensors_event_t *event,
475
579
uint32_t timestamp) {
476
580
memset (event, 0 , sizeof (sensors_event_t ));
@@ -489,6 +593,13 @@ void Adafruit_LSM9DS0::getAccelEvent(sensors_event_t *event,
489
593
event->acceleration .z *= SENSORS_GRAVITY_STANDARD;
490
594
}
491
595
596
+ /* *************************************************************************/
597
+ /* !
598
+ @brief Fill in the details about the most recent magnetometer data read
599
+ @param event The sensor_event_t object we will fill!
600
+ @param timestamp Unused
601
+ */
602
+ /* *************************************************************************/
492
603
void Adafruit_LSM9DS0::getMagEvent (sensors_event_t *event, uint32_t timestamp) {
493
604
memset (event, 0 , sizeof (sensors_event_t ));
494
605
event->version = sizeof (sensors_event_t );
@@ -503,6 +614,13 @@ void Adafruit_LSM9DS0::getMagEvent(sensors_event_t *event, uint32_t timestamp) {
503
614
event->magnetic .z /= 1000 ;
504
615
}
505
616
617
+ /* *************************************************************************/
618
+ /* !
619
+ @brief Fill in the details about the most recent gyroscope data read
620
+ @param event The sensor_event_t object we will fill!
621
+ @param timestamp The millis timestamp when the read occured
622
+ */
623
+ /* *************************************************************************/
506
624
void Adafruit_LSM9DS0::getGyroEvent (sensors_event_t *event,
507
625
uint32_t timestamp) {
508
626
memset (event, 0 , sizeof (sensors_event_t ));
@@ -515,6 +633,13 @@ void Adafruit_LSM9DS0::getGyroEvent(sensors_event_t *event,
515
633
event->gyro .z = gyroData.z * _gyro_dps_digit * SENSORS_DPS_TO_RADS;
516
634
}
517
635
636
+ /* *************************************************************************/
637
+ /* !
638
+ @brief Fill in the details about the most recent temperature data read
639
+ @param event The sensor_event_t object we will fill!
640
+ @param timestamp The millis timestamp when the read occured
641
+ */
642
+ /* *************************************************************************/
518
643
void Adafruit_LSM9DS0::getTempEvent (sensors_event_t *event,
519
644
uint32_t timestamp) {
520
645
memset (event, 0 , sizeof (sensors_event_t ));
@@ -527,6 +652,12 @@ void Adafruit_LSM9DS0::getTempEvent(sensors_event_t *event,
527
652
// event->temperature /= LSM9DS0_TEMP_LSB_DEGREE_CELSIUS;
528
653
}
529
654
655
+ /* *************************************************************************/
656
+ /* !
657
+ @brief Fill in the details about the accelerometer sensor component
658
+ @param sensor The sensor_t object we will fill!
659
+ */
660
+ /* *************************************************************************/
530
661
void Adafruit_LSM9DS0::getAccelSensor (sensor_t *sensor) {
531
662
memset (sensor, 0 , sizeof (sensor_t ));
532
663
strncpy (sensor->name , " LSM9DS0_A" , sizeof (sensor->name ) - 1 );
@@ -540,6 +671,12 @@ void Adafruit_LSM9DS0::getAccelSensor(sensor_t *sensor) {
540
671
sensor->resolution = 0.0 ; // ToDo
541
672
}
542
673
674
+ /* *************************************************************************/
675
+ /* !
676
+ @brief Fill in the details about the magnetometer sensor component
677
+ @param sensor The sensor_t object we will fill!
678
+ */
679
+ /* *************************************************************************/
543
680
void Adafruit_LSM9DS0::getMagSensor (sensor_t *sensor) {
544
681
memset (sensor, 0 , sizeof (sensor_t ));
545
682
strncpy (sensor->name , " LSM9DS0_M" , sizeof (sensor->name ) - 1 );
@@ -553,6 +690,12 @@ void Adafruit_LSM9DS0::getMagSensor(sensor_t *sensor) {
553
690
sensor->resolution = 0.0 ; // ToDo
554
691
}
555
692
693
+ /* *************************************************************************/
694
+ /* !
695
+ @brief Fill in the details about the gyroscope sensor component
696
+ @param sensor The sensor_t object we will fill!
697
+ */
698
+ /* *************************************************************************/
556
699
void Adafruit_LSM9DS0::getGyroSensor (sensor_t *sensor) {
557
700
memset (sensor, 0 , sizeof (sensor_t ));
558
701
strncpy (sensor->name , " LSM9DS0_G" , sizeof (sensor->name ) - 1 );
@@ -566,6 +709,12 @@ void Adafruit_LSM9DS0::getGyroSensor(sensor_t *sensor) {
566
709
sensor->resolution = 0.0 ; // ToDo
567
710
}
568
711
712
+ /* *************************************************************************/
713
+ /* !
714
+ @brief Fill in the details about the temperature sensor component
715
+ @param sensor The sensor_t object we will fill!
716
+ */
717
+ /* *************************************************************************/
569
718
void Adafruit_LSM9DS0::getTempSensor (sensor_t *sensor) {
570
719
memset (sensor, 0 , sizeof (sensor_t ));
571
720
strncpy (sensor->name , " LSM9DS0_T" , sizeof (sensor->name ) - 1 );
0 commit comments