Skip to content

Commit

Permalink
Merge pull request #81 from finitespace/filtering
Browse files Browse the repository at this point in the history
Filtering
  • Loading branch information
finitespace committed Mar 18, 2018
2 parents 40fdb74 + 335a562 commit 9900b50
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/BME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ bool BME280::Initialize()
if(success)
{
success &= ReadTrim();

if(m_settings.filter != Filter_Off)
{
InitializeFilter();
}

WriteSettings();
}

Expand All @@ -61,6 +67,24 @@ bool BME280::Initialize()
return m_initialized;
}


/****************************************************************/
bool BME280::InitializeFilter()
{
// Force an unfiltered measurement to populate the filter buffer.
// This fixes a bug that causes the first read to always be 28.82 °C 81732.34 hPa.
Filter filter = m_settings.filter;
m_settings.filter = Filter_Off;

WriteSettings();

float dummy;
read(dummy, dummy, dummy);

m_settings.filter = filter;
}


/****************************************************************/
bool BME280::ReadChipID()
{
Expand Down
8 changes: 7 additions & 1 deletion src/BME280.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,16 @@ class BME280
/* CONSTRUCTOR INIT FUNCTIONS */
/*****************************************************************/

//////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/// Write configuration to BME280, return true if successful.
/// Must be called from any child classes.
virtual bool Initialize();

///////////////////////////////////////////////////////////////
/// Force a unfiltered measurement to populate the filter
/// buffer.
bool InitializeFilter();


/*****************************************************************/
/* ACCESSOR FUNCTIONS */
Expand Down
3 changes: 2 additions & 1 deletion src/BME280SpiSw.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class BME280SpiSw: public BME280{
protected:

////////////////////////////////////////////////////////////////
/// Method used at start up to initialize the class. Starts the I2C interface.
/// Method used at start up to initialize the class. Starts the
/// software SPI interface.
virtual bool Initialize();

private:
Expand Down

0 comments on commit 9900b50

Please sign in to comment.