clang some more, add a humidity object

This commit is contained in:
Lady Ada 2019-12-29 03:01:52 -05:00
parent 9c75a42a5c
commit 610d7292df
2 changed files with 66 additions and 1 deletions

View File

@ -545,6 +545,15 @@ Adafruit_Sensor *Adafruit_BME280::getPressureSensor(void) {
return pressure_sensor;
}
/*!
@brief Gets an Adafruit Unified Sensor object for the humidity sensor
component
@return Adafruit_Sensor pointer to humidity sensor
*/
Adafruit_Sensor *Adafruit_BME280::getHumiditySensor(void) {
return humidity_sensor;
}
/**************************************************************************/
/*!
@brief Gets the sensor_t data for the BME280's temperature sensor
@ -624,3 +633,43 @@ bool Adafruit_BME280_Pressure::getEvent(sensors_event_t *event) {
event->pressure = _theBME280->readPressure() / 100; // convert Pa to hPa
return true;
}
/**************************************************************************/
/*!
@brief Gets the sensor_t data for the BME280's humidity sensor
*/
/**************************************************************************/
void Adafruit_BME280_Humidity::getSensor(sensor_t *sensor) {
/* Clear the sensor_t object */
memset(sensor, 0, sizeof(sensor_t));
/* Insert the sensor name in the fixed length char array */
strncpy(sensor->name, "BME280", sizeof(sensor->name) - 1);
sensor->name[sizeof(sensor->name) - 1] = 0;
sensor->version = 1;
sensor->sensor_id = _sensorID;
sensor->type = SENSOR_TYPE_RELATIVE_HUMIDITY;
sensor->min_delay = 0;
sensor->min_value = 0;
sensor->max_value = 100; /* 0 - 100 % */
sensor->resolution = 3; /* 3% accuracy */
}
/**************************************************************************/
/*!
@brief Gets the humidity as a standard sensor event
@param event Sensor event object that will be populated
@returns True
*/
/**************************************************************************/
bool Adafruit_BME280_Humidity::getEvent(sensors_event_t *event) {
/* Clear the event */
memset(event, 0, sizeof(sensors_event_t));
event->version = sizeof(sensors_event_t);
event->sensor_id = _sensorID;
event->type = SENSOR_TYPE_RELATIVE_HUMIDITY;
event->timestamp = millis();
event->relative_humidity = _theBME280->readHumidity();
return true;
}

View File

@ -135,6 +135,20 @@ private:
Adafruit_BME280 *_theBME280 = NULL;
};
/** Adafruit Unified Sensor interface for humidity component of BME280 */
class Adafruit_BME280_Humidity : public Adafruit_Sensor {
public:
/** @brief Create an Adafruit_Sensor compatible object for the humidity sensor
@param parent A pointer to the BME280 class */
Adafruit_BME280_Humidity(Adafruit_BME280 *parent) { _theBME280 = parent; }
bool getEvent(sensors_event_t *);
void getSensor(sensor_t *);
private:
int _sensorID = 0;
Adafruit_BME280 *_theBME280 = NULL;
};
/**************************************************************************/
/*!
@brief Class that stores state and functions for interacting with BME280 IC
@ -222,6 +236,7 @@ public:
Adafruit_Sensor *getTemperatureSensor(void);
Adafruit_Sensor *getPressureSensor(void);
Adafruit_Sensor *getHumiditySensor(void);
protected:
TwoWire *_wire; //!< pointer to a TwoWire object
@ -229,6 +244,7 @@ protected:
Adafruit_BME280_Temp *temp_sensor = NULL;
Adafruit_BME280_Pressure *pressure_sensor = NULL;
Adafruit_BME280_Humidity *humidity_sensor = NULL;
void readCoefficients(void);
bool isReadingCalibration(void);