From: Brendan Le Foll Date: Wed, 7 May 2014 14:40:39 +0000 (+0100) Subject: grove: initial groveLight support X-Git-Tag: v0.1.0~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e14ddb540d1d7b5bded26a54df58b4b9543cc64;p=contrib%2Fupm.git grove: initial groveLight support Signed-off-by: Brendan Le Foll --- diff --git a/src/grove/grove.cxx b/src/grove/grove.cxx index 72be707..4cb211f 100644 --- a/src/grove/grove.cxx +++ b/src/grove/grove.cxx @@ -88,3 +88,30 @@ float GroveTemp::raw_value() { return (float) maa_aio_read_u16(m_aio); } + +//// GroveLight //// + +GroveLight::GroveLight(unsigned int pin) +{ + maa_init(); + m_aio = maa_aio_init(pin); + m_name = "Light Sensor"; +} + +GroveLight::~GroveLight() +{ + maa_aio_close(m_aio); +} + +int GroveLight::value () +{ + // rough conversion to Lux + int a = maa_aio_read_u16(m_aio); + a = 10000/(((1023-a)*10/a)*15)^(4/3); + return a; +} + +float GroveLight::raw_value() +{ + return (float) maa_aio_read_u16(m_aio); +} diff --git a/src/grove/grove.h b/src/grove/grove.h index d573787..2a2a103 100644 --- a/src/grove/grove.h +++ b/src/grove/grove.h @@ -61,4 +61,14 @@ class GroveTemp: public Grove { maa_aio_context* m_aio; }; +class GroveLight: public Grove { + public: + GroveLight(unsigned int pin); + ~GroveLight(); + float raw_value(); + int value(); + private: + maa_aio_context* m_aio; +}; + }