|
18 | 18 | CONSTRUCTOR
|
19 | 19 | ***************************************************************************/
|
20 | 20 | // default
|
21 |
| -Adafruit_LSM9DS0::Adafruit_LSM9DS0() { |
| 21 | +Adafruit_LSM9DS0::Adafruit_LSM9DS0( int32_t sensorID ) { |
22 | 22 | _i2c = true;
|
| 23 | + _lsm9dso_sensorid_accel = sensorID + 1; |
| 24 | + _lsm9dso_sensorid_mag = sensorID + 2; |
| 25 | + _lsm9dso_sensorid_gyro = sensorID + 3; |
| 26 | + _lsm9dso_sensorid_temp = sensorID + 4; |
23 | 27 | }
|
24 | 28 |
|
25 |
| -Adafruit_LSM9DS0::Adafruit_LSM9DS0(int8_t xmcs, int8_t gcs) { |
| 29 | +Adafruit_LSM9DS0::Adafruit_LSM9DS0(int8_t xmcs, int8_t gcs, int32_t sensorID ) { |
26 | 30 | _i2c = false;
|
27 | 31 | // hardware SPI!
|
28 | 32 | _csg = gcs;
|
29 | 33 | _csxm = xmcs;
|
30 | 34 | _mosi = _miso = _clk = -1;
|
| 35 | + _lsm9dso_sensorid_accel = sensorID + 1; |
| 36 | + _lsm9dso_sensorid_mag = sensorID + 2; |
| 37 | + _lsm9dso_sensorid_gyro = sensorID + 3; |
| 38 | + _lsm9dso_sensorid_temp = sensorID + 4; |
31 | 39 | }
|
32 | 40 |
|
33 |
| -Adafruit_LSM9DS0::Adafruit_LSM9DS0(int8_t clk, int8_t miso, int8_t mosi, int8_t xmcs, int8_t gcs) { |
| 41 | +Adafruit_LSM9DS0::Adafruit_LSM9DS0(int8_t clk, int8_t miso, int8_t mosi, int8_t xmcs, int8_t gcs, int32_t sensorID ) { |
34 | 42 | _i2c = false;
|
35 | 43 | // software SPI!
|
36 | 44 | _csg = gcs;
|
37 | 45 | _csxm = xmcs;
|
38 | 46 | _mosi = mosi;
|
39 | 47 | _miso = miso;
|
40 | 48 | _clk = clk;
|
| 49 | + _lsm9dso_sensorid_accel = sensorID + 1; |
| 50 | + _lsm9dso_sensorid_mag = sensorID + 2; |
| 51 | + _lsm9dso_sensorid_gyro = sensorID + 3; |
| 52 | + _lsm9dso_sensorid_temp = sensorID + 4; |
41 | 53 | }
|
42 | 54 |
|
43 | 55 | bool Adafruit_LSM9DS0::begin()
|
@@ -277,6 +289,124 @@ void Adafruit_LSM9DS0::setupGyro ( lsm9ds0GyroScale_t scale )
|
277 | 289 | }
|
278 | 290 | }
|
279 | 291 |
|
| 292 | +/*************************************************************************** |
| 293 | + UNIFIED SENSOR FUNCTIONS |
| 294 | + ***************************************************************************/ |
| 295 | + |
| 296 | +/**************************************************************************/ |
| 297 | +/*! |
| 298 | + @brief Gets the most recent accel sensor event |
| 299 | +*/ |
| 300 | +/**************************************************************************/ |
| 301 | +void Adafruit_LSM9DS0::getEvent(sensors_event_t *accelEvent, |
| 302 | + sensors_event_t *magEvent, |
| 303 | + sensors_event_t *gyroEvent, |
| 304 | + sensors_event_t *tempEvent ) |
| 305 | +{ |
| 306 | + /* Clear the events */ |
| 307 | + memset(accelEvent, 0, sizeof(sensors_event_t)); |
| 308 | + memset(magEvent, 0, sizeof(sensors_event_t)); |
| 309 | + memset(gyroEvent, 0, sizeof(sensors_event_t)); |
| 310 | + memset(tempEvent, 0, sizeof(sensors_event_t)); |
| 311 | + |
| 312 | + /* update the sensor data */ |
| 313 | + read(); |
| 314 | + uint32_t timestamp = millis(); |
| 315 | + |
| 316 | + /* Update the accelerometer data */ |
| 317 | + accelEvent->version = sizeof(sensors_event_t); |
| 318 | + accelEvent->sensor_id = _lsm9dso_sensorid_accel; |
| 319 | + accelEvent->type = SENSOR_TYPE_ACCELEROMETER; |
| 320 | + accelEvent->timestamp = timestamp; |
| 321 | + accelEvent->acceleration.x = accelData.x; |
| 322 | + accelEvent->acceleration.y = accelData.y; |
| 323 | + accelEvent->acceleration.z = accelData.z; |
| 324 | + |
| 325 | + /* Update the magnetometer data */ |
| 326 | + magEvent->version = sizeof(sensors_event_t); |
| 327 | + magEvent->sensor_id = _lsm9dso_sensorid_mag; |
| 328 | + magEvent->type = SENSOR_TYPE_MAGNETIC_FIELD; |
| 329 | + magEvent->timestamp = timestamp; |
| 330 | + magEvent->magnetic.x = magData.x; |
| 331 | + magEvent->magnetic.y = magData.y; |
| 332 | + magEvent->magnetic.z = magData.z; |
| 333 | + |
| 334 | + /* Update the gyroscope data */ |
| 335 | + gyroEvent->version = sizeof(sensors_event_t); |
| 336 | + gyroEvent->sensor_id = _lsm9dso_sensorid_accel; |
| 337 | + gyroEvent->type = SENSOR_TYPE_GYROSCOPE; |
| 338 | + gyroEvent->timestamp = timestamp; |
| 339 | + gyroEvent->gyro.x = gyroData.x; |
| 340 | + gyroEvent->gyro.y = gyroData.y; |
| 341 | + gyroEvent->gyro.z = gyroData.z; |
| 342 | + |
| 343 | + /* Update the temperature data */ |
| 344 | + tempEvent->version = sizeof(sensors_event_t); |
| 345 | + tempEvent->sensor_id = _lsm9dso_sensorid_temp; |
| 346 | + tempEvent->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; |
| 347 | + tempEvent->timestamp = timestamp; |
| 348 | + tempEvent->temperature = temperature; |
| 349 | +} |
| 350 | + |
| 351 | +/**************************************************************************/ |
| 352 | +/*! |
| 353 | + @brief Gets the sensor_t data |
| 354 | +*/ |
| 355 | +/**************************************************************************/ |
| 356 | +void Adafruit_LSM9DS0::getSensor(sensor_t *accel, sensor_t *mag, |
| 357 | + sensor_t *gyro, sensor_t *temp ) |
| 358 | +{ |
| 359 | + /* Clear the sensor_t objects */ |
| 360 | + memset(accel, 0, sizeof(sensor_t)); |
| 361 | + memset(mag, 0, sizeof(sensor_t)); |
| 362 | + memset(gyro, 0, sizeof(sensor_t)); |
| 363 | + memset(temp, 0, sizeof(sensor_t)); |
| 364 | + |
| 365 | + /* Insert the sensor name in the fixed length char array */ |
| 366 | + strncpy (accel->name, "LSM9DS0_A", sizeof(accel->name) - 1); |
| 367 | + accel->name[sizeof(accel->name)- 1] = 0; |
| 368 | + accel->version = 1; |
| 369 | + accel->sensor_id = _lsm9dso_sensorid_accel; |
| 370 | + accel->type = SENSOR_TYPE_ACCELEROMETER; |
| 371 | + accel->min_delay = 0; |
| 372 | + accel->max_value = 0.0; // ToDo |
| 373 | + accel->min_value = 0.0; // ToDo |
| 374 | + accel->resolution = 0.0; // ToDo |
| 375 | + |
| 376 | + /* Insert the sensor name in the fixed length char array */ |
| 377 | + strncpy (mag->name, "LSM9DS0_M", sizeof(mag->name) - 1); |
| 378 | + mag->name[sizeof(mag->name)- 1] = 0; |
| 379 | + mag->version = 1; |
| 380 | + mag->sensor_id = _lsm9dso_sensorid_mag; |
| 381 | + mag->type = SENSOR_TYPE_MAGNETIC_FIELD; |
| 382 | + mag->min_delay = 0; |
| 383 | + mag->max_value = 0.0; // ToDo |
| 384 | + mag->min_value = 0.0; // ToDo |
| 385 | + mag->resolution = 0.0; // ToDo |
| 386 | + |
| 387 | + /* Insert the sensor name in the fixed length char array */ |
| 388 | + strncpy (gyro->name, "LSM9DS0_G", sizeof(gyro->name) - 1); |
| 389 | + gyro->name[sizeof(gyro->name)- 1] = 0; |
| 390 | + gyro->version = 1; |
| 391 | + gyro->sensor_id = _lsm9dso_sensorid_gyro; |
| 392 | + gyro->type = SENSOR_TYPE_GYROSCOPE; |
| 393 | + gyro->min_delay = 0; |
| 394 | + gyro->max_value = 0.0; // ToDo |
| 395 | + gyro->min_value = 0.0; // ToDo |
| 396 | + gyro->resolution = 0.0; // ToDo |
| 397 | + |
| 398 | + /* Insert the sensor name in the fixed length char array */ |
| 399 | + strncpy (temp->name, "LSM9DS0_T", sizeof(temp->name) - 1); |
| 400 | + temp->name[sizeof(temp->name)- 1] = 0; |
| 401 | + temp->version = 1; |
| 402 | + temp->sensor_id = _lsm9dso_sensorid_temp; |
| 403 | + temp->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; |
| 404 | + temp->min_delay = 0; |
| 405 | + temp->max_value = 0.0; // ToDo |
| 406 | + temp->min_value = 0.0; // ToDo |
| 407 | + temp->resolution = 0.0; // ToDo |
| 408 | +} |
| 409 | + |
280 | 410 | /***************************************************************************
|
281 | 411 | PRIVATE FUNCTIONS
|
282 | 412 | ***************************************************************************/
|
|
0 commit comments