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

Softwarewire #82

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Adding SoftwareWire files.
  • Loading branch information
finitespace committed Mar 14, 2018
commit a32f579b12b57fc9b28dc512f98a31de58a00cf8
90 changes: 90 additions & 0 deletions src/BME280I2CSoftwareWire.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
BME280I2CSoftwareWireI2C.cpp
This code records data from the BME280I2CSoftwareWire sensor and provides an API.
This file is part of the Arduino BME280I2CSoftwareWire library.
Copyright (C) 2016 Tyler Glenn

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http:https://www.gnu.org/licenses/>.

Written: Dec 30 2015.
Last Updated: Jan 1 2016. - Happy New year!

This header must be included in any derived code or copies of the code.

Based on the data sheet provided by Bosch for the BME280I2CSoftwareWire environmental sensor,
calibration code based on algorithms providedBosch, some unit conversations courtesy
of www.endmemo.com, altitude equation courtesy of NOAA, and dew point equation
courtesy of Brian McNoldy at http:https://andrew.rsmas.miami.edu.
*/

#include "config.h"

#ifdef USING_SOFTWARE_WIRE

#include "SoftwareWire.h"

#include "BME280I2CSoftwareWire.h"


/****************************************************************/
BME280I2CSoftwareWire::BME280I2CSoftwareWire
(
SoftwareWire& softwareWire,
const Settings& settings
):BME280I2C(settings),
m_softwareWire(softwareWire)
{
}

/****************************************************************/
bool BME280I2CSoftwareWire::WriteRegister
(
uint8_t addr,
uint8_t data
)
{
m_softwareWire.beginTransmission(getSettings().bme280Addr);
m_softwareWire.write(addr);
m_softwareWire.write(data);
m_softwareWire.endTransmission();

return true; // TODO: Chech return values from wire calls.
}


/****************************************************************/
bool BME280I2CSoftwareWire::ReadRegister
(
uint8_t addr,
uint8_t data[],
uint8_t length
)
{
uint8_t ord(0);

m_softwareWire.beginTransmission(getSettings().bme280Addr);
m_softwareWire.write(addr);
m_softwareWire.endTransmission();

m_softwareWire.requestFrom(static_cast<uint8_t>(getSettings().bme280Addr), length);

while(m_softwareWire.available())
{
data[ord++] = m_softwareWire.read();
}

return ord == length;
}

#endif
69 changes: 69 additions & 0 deletions src/BME280I2CSoftwareWire.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
BME280I2CSoftwareWire.h
This code records data from the BME280 sensor and provides an API.
This file is part of the Arduino BME280 library.
Copyright (C) 2016 Tyler Glenn

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http:https://www.gnu.org/licenses/>.

Written: Mar 13 2018.

This code is licensed under the GNU LGPL and is open for distrbution
and copying in accordance with the license.
This header must be included in any derived code or copies of the code.

Based on the data sheet provided by Bosch for the Bme280 environmental sensor.
*/

#ifndef TG_BME_280_I2C_SOFTWARE_WIRE_H
#define TG_BME_280_I2C_SOFTWARE_WIRE_H

#include "BME280I2C.h"

class SoftwareWire;

//////////////////////////////////////////////////////////////////
/// BME280I2CSoftwareWire - SoftwareWire I2C Implementation of BME280.
class BME280I2CSoftwareWire: public BME280I2C
{

public:

///////////////////////////////////////////////////////////////
/// Constructor used to create the class. All parameters have
/// default values.
BME280I2CSoftwareWire(
SoftwareWire& softwareWire,
const BME280I2C::Settings& settings = BME280I2C::Settings());


protected:
private:
SoftwareWire& m_softwareWire;

//////////////////////////////////////////////////////////////////
/// Write values to BME280 registers.
virtual bool WriteRegister(
uint8_t addr,
uint8_t data);

/////////////////////////////////////////////////////////////////
/// Read values from BME280 registers.
virtual bool ReadRegister(
uint8_t addr,
uint8_t data[],
uint8_t length);

};
#endif // TG_BME_280_I2C_H