예제 #1
0
error_t tcs34725GetSensorEvent(sensors_event_t *event)
{
  float maxCount;
  uint16_t r, g, b, c;

  /* Clear the event */
  memset(event, 0, sizeof(sensors_event_t));

  event->version   = sizeof(sensors_event_t);
  event->sensor_id = _tcs34725SensorID;
  event->type      = SENSOR_TYPE_COLOR;
  event->timestamp = delayGetTicks();

  /* Get the raw RGB values */
  ASSERT_STATUS(tcs34725GetRawData(&r, &g, &b, &c));

  /* Convert RGB values to floats */
  maxCount = (256 - _tcs34725IntegrationTime) * 1024;
  event->color.r = r / maxCount;
  event->color.g = g / maxCount;
  event->color.b = b / maxCount;

  /* Convert to a 24-bit ARGB value */
  event->color.rgba = (uint8_t)(event->color.r * 0xFF) << 16|
                      (uint8_t)(event->color.g * 0xFF) << 8 |
                      (uint8_t)(event->color.b * 0xFF) |
                      0xFF000000;

  return ERROR_NONE;
}
예제 #2
0
err_t tsl2561GetSensorEvent(sensors_event_t *event)
{
  uint16_t broadband, ir;

  /* Clear the event */
  memset(event, 0, sizeof(sensors_event_t));

  event->version   = sizeof(sensors_event_t);
  event->sensor_id = _tsl2561SensorID;
  event->type      = SENSOR_TYPE_LIGHT;
  event->timestamp = delayGetTicks();

  /* Calculate the actual lux value */
  ASSERT_STATUS(tsl2561GetLuminosity(&broadband, &ir));
  event->light = tsl2561CalculateLux(broadband, ir);

  return ERROR_NONE;
}
예제 #3
0
error_t lsm303accelGetSensorEvent(sensors_event_t *event)
{
  /* Clear the event */
  memset(event, 0, sizeof(sensors_event_t));

  event->version   = sizeof(sensors_event_t);
  event->sensor_id = _lsm303accelSensorID;
  event->type      = SENSOR_TYPE_ACCELEROMETER;
  event->timestamp = delayGetTicks();

  /* Convert units to m/s^2 */
  ASSERT_STATUS(lsm303accelRead());
  event->acceleration.x = _lsm303accelData.x * _lsm303accel_MG_LSB * SENSORS_GRAVITY_STANDARD;
  event->acceleration.y = _lsm303accelData.y * _lsm303accel_MG_LSB * SENSORS_GRAVITY_STANDARD;
  event->acceleration.z = _lsm303accelData.z * _lsm303accel_MG_LSB * SENSORS_GRAVITY_STANDARD;

  return ERROR_NONE;
}
예제 #4
0
err_t lsm303magGetSensorEvent(sensors_event_t *event)
{
  /* Clear the event */
  memset(event, 0, sizeof(sensors_event_t));

  event->version   = sizeof(sensors_event_t);
  event->sensor_id = _lsm303magSensorID;
  event->type      = SENSOR_TYPE_MAGNETIC_FIELD;
  event->timestamp = delayGetTicks();

  /* Convert units to micro-Tesla (1 Gauss = 1 micro-Tesla) */
  ASSERT_STATUS(lsm303magRead());
  event->magnetic.x = _lsm303magData.x / _lsm303mag_Gauss_LSB_XY * SENSORS_GAUSS_TO_MICROTESLA;
  event->magnetic.y = _lsm303magData.y / _lsm303mag_Gauss_LSB_XY * SENSORS_GAUSS_TO_MICROTESLA;
  event->magnetic.z = _lsm303magData.z / _lsm303mag_Gauss_LSB_Z * SENSORS_GAUSS_TO_MICROTESLA;

  return ERROR_NONE;
}
예제 #5
0
error_t mpl115a2GetSensorEvent(sensors_event_t *event)
{
  float pressure_kPa;

  /* Clear the event */
  memset(event, 0, sizeof(sensors_event_t));

  event->version   = sizeof(sensors_event_t);
  event->sensor_id = _mpl115a2SensorID;
  event->type      = SENSOR_TYPE_PRESSURE;
  event->timestamp = delayGetTicks();

  /* Retrieve values from the sensor */
  ASSERT_STATUS(mpl115a2GetPressure(&pressure_kPa));

  /* The MPL115A2 returns a value from 50..115 kPa using a 10-bit range.
   * To convert this to the hPa value sensor_event_t is expecitng simply
   * multiply by 10. */
  event->pressure = pressure_kPa * 10;

  return ERROR_NONE;
}
예제 #6
0
err_t adxl345GetSensorEvent(sensors_event_t *event)
{
  int16_t x, y, z;

  /* Clear the event */
  memset(event, 0, sizeof(sensors_event_t));

  event->version   = sizeof(sensors_event_t);
  event->sensor_id = _adxl345SensorID;
  event->type      = SENSOR_TYPE_ACCELEROMETER;
  event->timestamp = delayGetTicks();

  /* Retrieve values from the sensor */
  ASSERT_STATUS(adxl345GetXYZ(&x, &y, &z));

  /* The ADXL345 returns a raw value where each lsb represents 4mg.  To
   * convert this to a normal g value, multiply by 0.004 and then convert
   * it to the m/s^2 value that sensors_event_t is expecting. */
  event->acceleration.x = x * ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD;
  event->acceleration.y = y * ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD;
  event->acceleration.z = z * ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD;

  return ERROR_NONE;
}