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 #ifndef GROVE_TEMPERATURE_HPP 18 #define GROVE_TEMPERATURE_HPP 19 20 #include <hardware/sensors.h> 21 #include "Sensor.hpp" 22 #include "grove.h" 23 24 struct sensors_event_t; 25 26 /** 27 * GroveTemperature exposes the Grove Temperature sensor 28 * 29 * Overrides the pollEvents & activate Sensor methods. 30 */ 31 class GroveTemperature : public Sensor, public upm::GroveTemp { 32 public: 33 /** 34 * GroveTemperature constructor 35 * @param pollFd poll file descriptor 36 * @param pin number of the analog input 37 */ 38 GroveTemperature(int pollFd, int pin); 39 40 /** 41 * GroveTemperature destructor 42 */ 43 ~GroveTemperature() override; 44 45 /** 46 * Poll for events 47 * @param data where to store the events 48 * @param count the number of events returned must be <= to the count 49 * @return number of events returned in data on success and a negative error number otherwise 50 */ 51 int pollEvents(sensors_event_t* data, int count) override; 52 53 /** 54 * Activate the sensor 55 * @param handle sensor identifier 56 * @param enabled 1 for enabling and 0 for disabling 57 * @return 0 on success and a negative error number otherwise 58 */ 59 int activate(int handle, int enabled); 60 61 private: 62 static Sensor * createSensor(int pollFd); 63 static void initModule() __attribute__((constructor 64 (DEFAULT_SENSOR_CONSTRUCTOR_PRIORITY))); 65 66 int pollFd; 67 static struct sensor_t sensorDescription; 68 }; 69 70 #endif // GROVE_TEMPERATURE_HPP 71