Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check connection state for i2c devices #120

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/BME280I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ BME280I2C::BME280I2C
):BME280(settings),
m_settings(settings)
{
Wire.begin();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is on the user, per previous issue

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My investigations showed that Wire.begin() is necessary to have a non blocking behaviour for Wire.endTransmission().
I just tested it here again.

}


/****************************************************************/
bool BME280I2C::Initialize()
{
bool success(false);
Wire.beginTransmission(m_settings.bme280Addr);
if(0 == Wire.endTransmission())
success = true;

if(success)
{
success = BME280::Initialize();
}

return success;
}


Expand Down
9 changes: 9 additions & 0 deletions src/BME280I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ class BME280I2C: public BME280
BME280I2C(
const Settings& settings = Settings());

/*****************************************************************/
/* CONSTRUCTOR INIT FUNCTIONS */
/*****************************************************************/

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


/*****************************************************************/
/* ACCESSOR FUNCTIONS */
Expand Down
18 changes: 18 additions & 0 deletions src/BME280I2C_BRZO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ BME280I2C_BRZO::BME280I2C_BRZO
{
}


/****************************************************************/
bool BME280I2C_BRZO::Initialize()
{
bool success(false);
brzo_i2c_start_transaction(m_settings.bme280Addr, m_settings.i2cClockRate);
if(0 == brzo_i2c_end_transaction())
success = true;

if(success)
{
success = BME280::Initialize();
}

return success;
}


/****************************************************************/
void BME280I2C_BRZO::setSettings
(
Expand Down
9 changes: 9 additions & 0 deletions src/BME280I2C_BRZO.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ class BME280I2C_BRZO : public BME280I2C
BME280I2C_BRZO(
const Settings& settings = Settings());

/*****************************************************************/
/* CONSTRUCTOR INIT FUNCTIONS */
/*****************************************************************/

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


/*****************************************************************/
/* ACCESSOR FUNCTIONS */
Expand Down