Added initial interfaces and some sensors implementing them

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Mihai Stefanescu
2018-06-12 18:46:49 +03:00
committed by Mihai Tudor Panu
parent 6bf21a23e7
commit f035470822
102 changed files with 1183 additions and 182 deletions

View File

@ -58,13 +58,13 @@ MS5611::MS5611(int i2cBus, int address)
i2c->address(address);
prom = new uint16_t[MS5611_PROM_SIZE];
if (i2c->writeByte(MS5611_CMD_RESET != mraa::SUCCESS))
UPM_THROW("Reset failed.");
throw std::runtime_error(std::string(__FUNCTION__) + ": Reset failed.");
delayms(5);
for (int i = 0; i < MS5611_PROM_SIZE; ++i) {
uint8_t buf[2];
int bytesRead = i2c->readBytesReg(MS5611_CMD_READ_PROM + 2*i, buf, 2);
if (bytesRead != 2)
UPM_THROW("PROM address failed.");
throw std::runtime_error(std::string(__FUNCTION__) + ": PROM address failed.");
prom[i] = buf[0] << 8;
prom[i] |= buf[1];
// printf("Read PROM entry %d = %04x\n", i, prom[i]);
@ -72,7 +72,7 @@ MS5611::MS5611(int i2cBus, int address)
// printf("CRC = %X\n", promCrc4());
if (promCrc4() != (prom[7] & 0x000F))
UPM_THROW("PROM checksum error.");
throw std::runtime_error(std::string(__FUNCTION__) + ": PROM checksum error.");
setOverSampling(ULTRA_HIGH_RES);
}
@ -153,11 +153,11 @@ uint32_t MS5611::readADC(int adcReg)
uint32_t value;
uint8_t buf[3];
if (i2c->writeByte(adcReg + osr) != mraa::SUCCESS)
UPM_THROW("Convert D2 failed");
throw std::runtime_error(std::string(__FUNCTION__) + ": Convert D2 failed");
delayms(100);
int bytesRead = i2c->readBytesReg(MS5611_CMD_ADC_READ, buf, 3);
if (bytesRead != 3)
UPM_THROW("ADC read failed");
throw std::runtime_error(std::string(__FUNCTION__) + ": ADC read failed");
// printf("%02X%02X%02X\n", buf[0], buf[1], buf[2]);
value = ((uint32_t)buf[0] << 16) | ((uint32_t)buf[1] << 8) | buf[2];
return value;
@ -181,6 +181,11 @@ int MS5611::getTemperatureCelsius()
return (temp + 50) / 100;
}
float MS5611::getTemperature()
{
return getTemperatureCelsius();
}
int MS5611::getPressurePa()
{
@ -208,3 +213,7 @@ int MS5611::getPressurePa()
return pressure;
}
float MS5611::getPressure()
{
return getPressurePa();
}

View File

@ -22,8 +22,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "interfaces/iPressureSensor.hpp"
#include "interfaces/iTemperatureSensor.hpp"
#include <interfaces/iPressure.hpp>
#include <interfaces/iTemperature.hpp>
#include "mraa/i2c.hpp"
namespace upm
@ -58,7 +58,7 @@ namespace upm
* @snippet ms5611.cxx Interesting
*/
class MS5611 : public IPressureSensor, public ITemperatureSensor
class MS5611 : virtual public iPressure, virtual public iTemperature
{
public:
enum OsrMode
@ -71,8 +71,22 @@ public:
virtual const char* getModuleName() { return "ms5611"; }
void setOverSampling(OsrMode osrMode);
int getTemperatureCelsius();
/**
* Returns the temperature in degrees Celsius
*
* @return The Temperature in degrees Celsius
*/
virtual float getTemperature();
int getPressurePa();
/**
* Return the current measured pressure in Pascals (Pa).
*
* @return The pressure in Pascals (Pa).
*/
virtual float getPressure();
private:
/* Disable implicit copy and assignment operators */
MS5611(const MS5611&) = delete;

View File

@ -2,10 +2,6 @@
/* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA
%import "../interfaces/javaupm_iTemperatureSensor.i"
%import "../interfaces/javaupm_iPressureSensor.i"
%typemap(javaimports) SWIGTYPE %{import upm_interfaces.*;%}
JAVA_JNI_LOADLIBRARY(javaupm_ms5611)
#endif
/* END Java syntax */