Skip to content

Commit

Permalink
feat(properties): add barometric pressure property
Browse files Browse the repository at this point in the history
  • Loading branch information
malokhvii-eduard committed Nov 29, 2021
1 parent 5ef8c12 commit b610203
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/airly/I18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ extern const char* UptimePropertyDescription;
extern const char* UptimePropertyTitle;

#if defined(THING_HAS_BME280)
extern const char* BarometricPressurePropertyDescription;
extern const char* BarometricPressurePropertyTitle;
extern const char* HumidityPropertyDescription;
extern const char* HumidityPropertyTitle;
extern const char* TemperaturePropertyDescription;
Expand Down
13 changes: 13 additions & 0 deletions include/airly/properties/BarometricPressure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef AIRLY_INCLUDE_AIRLY_PROPERTIES_BAROMETRIC_PRESSURE_H_
#define AIRLY_INCLUDE_AIRLY_PROPERTIES_BAROMETRIC_PRESSURE_H_

/* Config for WebThings framework */
#include <WebThingConfig.h>

/* WebThings framework */
#include <Thing.h>

void describeBarometricPressureProperty(ThingDevice* device);
void setBarometricPressureProperty(const float barometricPressure);

#endif // AIRLY_INCLUDE_AIRLY_PROPERTIES_BAROMETRIC_PRESSURE_H_
5 changes: 4 additions & 1 deletion src/airly/Device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

#if defined(THING_HAS_BME280)
/* Properties for Bosch Sensortec BME280 */
#include <airly/properties/BarometricPressure.h>
#include <airly/properties/Humidity.h>
#include <airly/properties/Temperature.h>

#define BME280_CAPABILITIES "TemperatureSensor", "HumiditySensor",
#define BME280_CAPABILITIES \
"TemperatureSensor", "HumiditySensor", "BarometricPressureSensor",
#else
#define BME280_CAPABILITIES
#endif
Expand All @@ -23,6 +25,7 @@ void describeDevice(WebThingAdapter* adapter) {
#if defined(THING_HAS_BME280)
describeTemperatureProperty(&device);
describeHumidityProperty(&device);
describeBarometricPressureProperty(&device);
#endif

describeUptimeProperty(&device);
Expand Down
2 changes: 2 additions & 0 deletions src/airly/I18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const char* UptimePropertyDescription = "";
const char* UptimePropertyTitle = "";

#if defined(THING_HAS_BME280)
const char* BarometricPressurePropertyDescription = "";
const char* BarometricPressurePropertyTitle = "";
const char* HumidityPropertyDescription = "";
const char* HumidityPropertyTitle = "";
const char* TemperaturePropertyDescription = "";
Expand Down
3 changes: 3 additions & 0 deletions src/airly/Thing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <Bme280.h>

/* Properties */
#include <airly/properties/BarometricPressure.h>
#include <airly/properties/Humidity.h>
#include <airly/properties/Temperature.h>

Expand All @@ -53,9 +54,11 @@ static void beginBme280() {
static bool pollBme280(void *) {
auto temperature = bme280.getTemperature();
auto humidity = bme280.getHumidity();
auto barometricPressure = bme280.getPressure();

setTemperatureProperty(temperature);
setHumidityProperty(humidity);
setBarometricPressureProperty(barometricPressure);

return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/airly/locales/en-US.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const char* UptimePropertyDescription PROGMEM =
const char* UptimePropertyTitle PROGMEM = "Uptime";

#if defined(THING_HAS_BME280)
const char* BarometricPressurePropertyDescription PROGMEM =
"The pressure within the atmosphere of Earth";
const char* BarometricPressurePropertyTitle PROGMEM = "Barometric pressure";
const char* HumidityPropertyDescription PROGMEM =
"The concentration of water vapor present in the air";
const char* HumidityPropertyTitle PROGMEM = "Humidity";
Expand Down
35 changes: 35 additions & 0 deletions src/airly/properties/BarometricPressure.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <airly/properties/Humidity.h>

/* AVR low-level */
#include <avr/pgmspace.h>

/* Preprocessor-based localization */
#include <airly/I18n.h>

// -------------------------------------------------------------------------- //
// Property: Barometric pressure (hPa)
// -------------------------------------------------------------------------- //
#if defined(THING_HAS_BME280)

static const char* propertyId PROGMEM = "barometricPressure";
static ThingProperty property(propertyId,
i18n::BarometricPressurePropertyDescription,
NUMBER, "BarometricPressureProperty");

void describeBarometricPressureProperty(ThingDevice* device) {
property.title = i18n::BarometricPressurePropertyTitle;
property.unit = "hectopascal";
property.minimum = 300;
property.maximum = 1100;
property.readOnly = true;

device->addProperty(&property);
}

void setBarometricPressureProperty(const float barometricPressure) {
auto hectopascals = barometricPressure / 100;
property.setValue({.number = hectopascals});
}

#endif
// -------------------------------------------------------------------------- //

0 comments on commit b610203

Please sign in to comment.