mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 09:51:14 +03:00
This is a combination of 2 commits.
aio: mraa_aio_read (v1.0.0) can now return -1, treat that in sensors using it Adds alot of exceptions if the aio read goes wrong Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com> Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:

committed by
Noel Eck

parent
f6816797bb
commit
e51c5f3018
@ -127,7 +127,10 @@ GroveTemp::~GroveTemp()
|
||||
|
||||
int GroveTemp::value ()
|
||||
{
|
||||
int a = mraa_aio_read(m_aio) * m_scale;
|
||||
float a = (float) mraa_aio_read(m_aio);
|
||||
if (a == -1.0) return -1;
|
||||
// Apply scale factore after error check
|
||||
a *= m_scale;
|
||||
float r = (float)(1023.0-a)*10000.0/a;
|
||||
float t = 1.0/(log(r/10000.0)/3975.0 + 1.0/298.15)-273.15;
|
||||
return (int) round(t);
|
||||
@ -159,6 +162,7 @@ int GroveLight::value()
|
||||
{
|
||||
// rough conversion to lux, using formula from Grove Starter Kit booklet
|
||||
float a = (float) mraa_aio_read(m_aio);
|
||||
if (a == -1.0) return -1;
|
||||
a = 10000.0/pow(((1023.0-a)*10.0/a)*15.0,4.0/3.0);
|
||||
return (int) round(a);
|
||||
}
|
||||
|
Reference in New Issue
Block a user