Skip to content

Commit bb79446

Browse files
committed
added imperial quantities support
Added support for imperial quanties for pressure and IMU sensor
1 parent d8e0105 commit bb79446

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/EnvClass.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ float EnvClass::readTemperature(int units /*= CELSIUS*/)
102102
{
103103
if (_revision == BOARD_REVISION_2) {
104104
while(!iaqSensor->run()){ }
105-
return iaqSensor->temperature;
105+
float reading = iaqSensor->temperature;
106+
if (units == FAHRENHEIT){
107+
reading = iaqSensor->temperature;
108+
return (reading * 9.0 / 5.0) + 32.0;
109+
} else {
110+
return reading;
111+
}
106112
}
107113
return HTS221->readTemperature(units);
108114
}

src/PressureClass.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,29 @@ float PressureClass::readPressure(int units)
101101
{
102102
if (_revision == BOARD_REVISION_2) {
103103
while(!iaqSensor->run()){ }
104-
return iaqSensor->pressure/1000;
104+
float reading = iaqSensor->pressure/1000;
105+
if (units == MILLIBAR) { // 1 kPa = 10 millibar
106+
return reading * 10;
107+
} else if (units == PSI) { // 1 kPa = 0.145038 PSI
108+
return reading * 0.145038;
109+
} else {
110+
return reading;
111+
}
105112
}
106113
return LPS22HB->readPressure(units);
107114
}
108115

109-
float PressureClass::readTemperature()
116+
float PressureClass::readTemperature(int units /*= CELSIUS*/)
110117
{
111118
if (_revision == BOARD_REVISION_2) {
112119
while(!iaqSensor->run()){}
113-
return iaqSensor->temperature;
120+
float reading = iaqSensor->temperature;
121+
if (units == FAHRENHEIT){
122+
reading = iaqSensor->temperature;
123+
return (reading * 9.0 / 5.0) + 32.0;
124+
} else {
125+
return reading;
126+
}
114127
}
115128
return LPS22HB->readTemperature();
116129
}

src/PressureClass.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PressureClass {
1313
void end();
1414

1515
float readPressure(int units = KILOPASCAL);
16-
float readTemperature(void);
16+
float readTemperature(int units = CELSIUS);
1717

1818
private:
1919
// Helper functions declarations

0 commit comments

Comments
 (0)