1 /*
2  * Copyright (C) 2015 Intel Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <cutils/log.h>
18 #include "GroveTemperature.hpp"
19 #include "SensorsHAL.hpp"
20 
21 struct sensor_t GroveTemperature::sensorDescription = {
22   .name = "Grove Temperature Sensor",
23   .vendor = "Murata",
24   .version = 1,
25   .handle = -1,
26   .type = SENSOR_TYPE_TEMPERATURE,
27   .maxRange = 125.0f,
28   .resolution = 1.0f,
29   .power = 0.001f,
30   .minDelay = 10,
31   .fifoReservedEventCount = 0,
32   .fifoMaxEventCount = 0,
33   .stringType = SENSOR_STRING_TYPE_TEMPERATURE,
34   .requiredPermission = "",
35   .maxDelay = 1000,
36   .flags = SENSOR_FLAG_ON_CHANGE_MODE,
37   .reserved = {},
38 };
39 
createSensor(int pollFd)40 Sensor * GroveTemperature::createSensor(int pollFd) {
41   return new GroveTemperature(pollFd, 0);
42 }
43 
initModule()44 void GroveTemperature::initModule() {
45   SensorContext::addSensorModule(&sensorDescription, createSensor);
46 }
47 
GroveTemperature(int pollFd,int pin)48 GroveTemperature::GroveTemperature(int pollFd, int pin) : upm::GroveTemp(pin), pollFd(pollFd) {
49   handle = sensorDescription.handle;
50   type = SENSOR_TYPE_TEMPERATURE;
51 }
52 
~GroveTemperature()53 GroveTemperature::~GroveTemperature() {}
54 
pollEvents(sensors_event_t * data,int count)55 int GroveTemperature::pollEvents(sensors_event_t* data, int count) {
56   data->temperature = value();
57   return 1;
58 }
59 
activate(int handle,int enabled)60 int GroveTemperature::activate(int handle, int enabled) {
61   /* start or stop the acquisition thread */
62   return activateAcquisitionThread(pollFd, handle, enabled);
63 }
64