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