hdxxvxta: Initial implementation

This driver was developed using the Veris HD2NVSTA1 humidity
transmitter.  The 'T' variant supports a temperature transmitter as
well.  Both signals are provided by the device as analog 0-5Vdc or
0-10Vdc outputs.

The A1 variant supports a temperature range of -40C-50C, while the A2
variant supports a range of 0C-50C.  Humidity ranges for all devices
in this device family range from 0% to 100% (non-condensing).

Temperature measurement can be disabled by passing -1 as the
temperature analog pin to the constructor.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson
2016-01-13 13:49:15 -07:00
committed by Mihai Tudor Panu
parent bf82beaf9c
commit fc7bfc113a
11 changed files with 546 additions and 0 deletions

122
src/hdxxvxta/hdxxvxta.cxx Normal file
View File

@@ -0,0 +1,122 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include "hdxxvxta.h"
using namespace upm;
using namespace std;
// conversion from celcius to fahrenheit
static float c2f(float c)
{
return (c * (9.0 / 5.0) + 32.0);
}
HDXXVXTA::HDXXVXTA(int hPin, int tPin, float aref) :
m_aioHum(hPin), m_aioTemp(0)
{
if (tPin >= 0)
m_hasTemp = true;
else
m_hasTemp = false;
m_temperature = 0.0;
m_humidity = 0.0;
if (m_hasTemp)
{
m_aioTemp = new mraa::Aio(tPin);
m_aResTemp = (1 << m_aioTemp->getBit());
}
else
m_aResTemp = 0;
m_aResHum = (1 << m_aioHum.getBit());
m_aref = aref;
// set the default temperature range to the A1 series (-40C-50C),
// regardless of whether temperature measuring is enabled
setRange(RANGE_MINUS40_50);
}
HDXXVXTA::~HDXXVXTA()
{
if (m_aioTemp)
delete m_aioTemp;
}
void HDXXVXTA::update()
{
// temperature
int val;
float volts;
if (m_hasTemp)
{
val = m_aioTemp->read();
volts = (float(val) * (m_aref / m_aResTemp));
switch (m_range)
{
case RANGE_MINUS40_50:
// valid range is 50 + abs(-40) = 90
m_temperature = ((volts / m_aref) * 90.0) - 40.0;
break;
case RANGE_0_50:
// valid range is 50
m_temperature = ((volts / m_aref) * 50.0);
break;
default:
// shouldn't happen, but...
throw std::out_of_range(std::string(__FUNCTION__) +
": internal error, invalid range value");
break;
}
}
// humidity
val = m_aioHum.read();
volts = (float(val) * (m_aref / m_aResHum));
m_humidity = ((volts / m_aref) * 100.0);
}
float HDXXVXTA::getTemperature(bool fahrenheit)
{
if (fahrenheit)
return c2f(m_temperature);
else
return m_temperature;
}
float HDXXVXTA::getHumidity()
{
return m_humidity;
}