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