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