2 * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3 * Copyright (c) 2014 Intel Corporation.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 GroveLed::GroveLed(int pin)
37 m_gpio = maa_gpio_init(pin);
38 maa_gpio_dir(m_gpio, MAA_GPIO_OUT);
39 m_name = "LED Socket";
44 maa_gpio_close(m_gpio);
47 maa_result_t GroveLed::write(int value)
50 return maa_gpio_write(m_gpio, 1);
52 return maa_gpio_write(m_gpio, 0);
55 maa_result_t GroveLed::on()
60 maa_result_t GroveLed::off()
67 GroveTemp::GroveTemp(unsigned int pin)
70 m_aio = maa_aio_init(pin);
71 m_name = "Temperature Sensor";
74 GroveTemp::~GroveTemp()
79 int GroveTemp::value ()
81 int a = maa_aio_read(m_aio);
82 float r = (float)(1023-a)*10000/a;
83 float t = 1/(logf(r/10000)/3975 + 1/298.15)-273.15;
87 float GroveTemp::raw_value()
89 return (float) maa_aio_read(m_aio);
94 GroveLight::GroveLight(unsigned int pin)
97 m_aio = maa_aio_init(pin);
98 m_name = "Light Sensor";
101 GroveLight::~GroveLight()
103 maa_aio_close(m_aio);
106 int GroveLight::value ()
108 // rough conversion to Lux
109 int a = maa_aio_read(m_aio);
110 a = 10000/(((1023-a)*10/a)*15)^(4/3);
114 float GroveLight::raw_value()
116 return (float) maa_aio_read(m_aio);