grove: add grove temperature sensor support and example

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2014-05-06 15:58:48 +01:00
parent 050d6553cd
commit 11ac453218
4 changed files with 87 additions and 1 deletions

View File

@ -22,10 +22,15 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include "grove.h"
#include "math.h"
using namespace upm;
//// GroveLed ////
GroveLed::GroveLed(int pin)
{
maa_init();
@ -56,3 +61,30 @@ maa_result_t GroveLed::off()
{
return write(0);
}
//// GroveTemp ////
GroveTemp::GroveTemp(unsigned int pin)
{
maa_init();
m_aio = maa_aio_init(pin);
m_name = "Temperature Sensor";
}
GroveTemp::~GroveTemp()
{
maa_aio_close(m_aio);
}
int GroveTemp::value ()
{
int a = maa_aio_read_u16(m_aio);
float r = (float)(1023-a)*10000/a;
float t = 1/(logf(r/10000)/3975 + 1/298.15)-273.15;
return (int) t;
}
float GroveTemp::raw_value()
{
return (float) maa_aio_read_u16(m_aio);
}

View File

@ -24,6 +24,7 @@
#pragma once
#include <string>
#include <maa/aio.h>
#include <maa/gpio.h>
namespace upm {
@ -47,7 +48,17 @@ class GroveLed: public Grove {
maa_result_t off();
maa_result_t on();
private:
maa_gpio_context * m_gpio;
maa_gpio_context* m_gpio;
};
class GroveTemp: public Grove {
public:
GroveTemp(unsigned int pin);
~GroveTemp();
float raw_value();
int value();
private:
maa_aio_context* m_aio;
};
}