Virtual base class for sensors that measure motion
Dependents: FXOS8700Q MAG3110 MMA8451Q MAG3110 ... more
Diff: MotionSensor.h
- Revision:
- 4:67e4fd9f47c5
- Parent:
- 3:4d6e28d4a18a
- Child:
- 5:226520fc09bf
--- a/MotionSensor.h Thu Apr 24 16:18:41 2014 +0000 +++ b/MotionSensor.h Thu Jun 18 16:23:26 2015 +0000 @@ -1,36 +1,111 @@ +/* MotionSensor Base Class + * Copyright (c) 2014-2015 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef MOTIONSENSOR_H #define MOTIONSENSOR_H -#include <stdint.h> +#include "stdint.h" + +/** motion_data_counts_t struct + */ +typedef struct { + int16_t x; /*!< x-axis counts */ + int16_t y; /*!< y-axis counts */ + int16_t z; /*!< z-axis counts */ +} motion_data_counts_t; -typedef struct MotionSensorDataCounts -{ - int16_t x, y, z; -} MotionSensorDataCounts; +/** motion_data_units_t struct + */ +typedef struct { + float x; /*!< x-axis counts */ + float y; /*!< y-axis counts */ + float z; /*!< z-axis counts */ +} motion_data_units_t; -typedef struct MotionSensorDataUnits -{ - float x, y, z; -} MotionSensorDataUnits; - +/** Motion Sensor Base Class + Useful for accessing data in a common way + */ class MotionSensor { public: - //virtual MotionSensor(); - virtual void enable(void) = 0; - virtual void disable(void) = 0; - virtual uint32_t sampleRate(uint32_t frequency) = 0; - virtual uint32_t whoAmI(void) = 0; - virtual uint32_t dataReady(void) = 0; - virtual void getX(int16_t * x) = 0; - virtual void getY(int16_t * y) = 0; - virtual void getZ(int16_t * z) = 0; - virtual void getX(float * x) = 0; - virtual void getY(float * y) = 0; - virtual void getZ(float * z) = 0; - virtual void getAxis(MotionSensorDataCounts &data) = 0; - virtual void getAxis(MotionSensorDataUnits &data) = 0; + + /** Enable the sensor for operation + */ + virtual void enable(void) const = 0; + + /** disable the sensors operation + */ + virtual void disable(void) const = 0; + + /** Set the sensor sample rate + @param frequency The desires sample frequency + @return The amount of error in Hz between desired and actual frequency + */ + virtual uint32_t sampleRate(uint32_t frequency) const = 0; + + /** Tells of new data is ready + @return The amount of data samples ready to be read from a device + */ + virtual uint32_t dataReady(void) const = 0; + + /** Get the x data in counts + @param x A referene to the variable to put the data in, 0 denotes not used + @return The x data in counts + */ + virtual int16_t getX(const int16_t &x = 0) const = 0; + + /** Get the y data in counts + @param y A referene to the variable to put the data in, 0 denotes not used + @return The y data in counts + */ + virtual void getY(const int16_t &y = 0) const = 0; + + /** Get the z data in counts + @param z A referene to the variable to put the data in, 0 denotes not used + @return The z data in counts + */ + virtual void getZ(const int16_t &z) const = 0; + + /** Get the x data in units + @param x A referene to the variable to put the data in, 0 denotes not used + @return The x data in units + */ + virtual void getX(const float &x) const = 0; + + /** Get the y data in units + @param y A referene to the variable to put the data in, 0 denotes not used + @return The y data in units + */ + virtual void getY(const float &y) const = 0; + + /** Get the z data in units + @param z A referene to the variable to put the data in, 0 denotes not used + @return The z data in units + */ + virtual void getZ(const float &z) const = 0; + + /** Get the x,y,z data in counts + @param xyz A referene to the variable to put the data in, 0 denotes not used + */ + virtual void getAxis(const motion_data_counts_t &xyz) const = 0; + + /** Get the x,y,z data in units + @param xyz A referene to the variable to put the data in, 0 denotes not used + */ + virtual void getAxis(const motion_data_units_t &xyz) const = 0; }; #endif