Virtual base class for sensors that measure motion

Dependents:   FXOS8700Q MAG3110 MMA8451Q MAG3110 ... more

Committer:
sam_grove
Date:
Thu Jun 18 16:23:26 2015 +0000
Revision:
4:67e4fd9f47c5
Parent:
3:4d6e28d4a18a
Child:
5:226520fc09bf
Update base class interface and add comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 4:67e4fd9f47c5 1 /* MotionSensor Base Class
sam_grove 4:67e4fd9f47c5 2 * Copyright (c) 2014-2015 ARM Limited
sam_grove 4:67e4fd9f47c5 3 *
sam_grove 4:67e4fd9f47c5 4 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 4:67e4fd9f47c5 5 * you may not use this file except in compliance with the License.
sam_grove 4:67e4fd9f47c5 6 * You may obtain a copy of the License at
sam_grove 4:67e4fd9f47c5 7 *
sam_grove 4:67e4fd9f47c5 8 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 4:67e4fd9f47c5 9 *
sam_grove 4:67e4fd9f47c5 10 * Unless required by applicable law or agreed to in writing, software
sam_grove 4:67e4fd9f47c5 11 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 4:67e4fd9f47c5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 4:67e4fd9f47c5 13 * See the License for the specific language governing permissions and
sam_grove 4:67e4fd9f47c5 14 * limitations under the License.
sam_grove 4:67e4fd9f47c5 15 */
sam_grove 0:dbc8909af0eb 16
sam_grove 0:dbc8909af0eb 17 #ifndef MOTIONSENSOR_H
sam_grove 0:dbc8909af0eb 18 #define MOTIONSENSOR_H
sam_grove 0:dbc8909af0eb 19
sam_grove 4:67e4fd9f47c5 20 #include "stdint.h"
sam_grove 4:67e4fd9f47c5 21
sam_grove 4:67e4fd9f47c5 22 /** motion_data_counts_t struct
sam_grove 4:67e4fd9f47c5 23 */
sam_grove 4:67e4fd9f47c5 24 typedef struct {
sam_grove 4:67e4fd9f47c5 25 int16_t x; /*!< x-axis counts */
sam_grove 4:67e4fd9f47c5 26 int16_t y; /*!< y-axis counts */
sam_grove 4:67e4fd9f47c5 27 int16_t z; /*!< z-axis counts */
sam_grove 4:67e4fd9f47c5 28 } motion_data_counts_t;
sam_grove 0:dbc8909af0eb 29
sam_grove 4:67e4fd9f47c5 30 /** motion_data_units_t struct
sam_grove 4:67e4fd9f47c5 31 */
sam_grove 4:67e4fd9f47c5 32 typedef struct {
sam_grove 4:67e4fd9f47c5 33 float x; /*!< x-axis counts */
sam_grove 4:67e4fd9f47c5 34 float y; /*!< y-axis counts */
sam_grove 4:67e4fd9f47c5 35 float z; /*!< z-axis counts */
sam_grove 4:67e4fd9f47c5 36 } motion_data_units_t;
sam_grove 0:dbc8909af0eb 37
sam_grove 4:67e4fd9f47c5 38 /** Motion Sensor Base Class
sam_grove 4:67e4fd9f47c5 39 Useful for accessing data in a common way
sam_grove 4:67e4fd9f47c5 40 */
sam_grove 0:dbc8909af0eb 41 class MotionSensor
sam_grove 0:dbc8909af0eb 42 {
sam_grove 0:dbc8909af0eb 43 public:
sam_grove 4:67e4fd9f47c5 44
sam_grove 4:67e4fd9f47c5 45 /** Enable the sensor for operation
sam_grove 4:67e4fd9f47c5 46 */
sam_grove 4:67e4fd9f47c5 47 virtual void enable(void) const = 0;
sam_grove 4:67e4fd9f47c5 48
sam_grove 4:67e4fd9f47c5 49 /** disable the sensors operation
sam_grove 4:67e4fd9f47c5 50 */
sam_grove 4:67e4fd9f47c5 51 virtual void disable(void) const = 0;
sam_grove 4:67e4fd9f47c5 52
sam_grove 4:67e4fd9f47c5 53 /** Set the sensor sample rate
sam_grove 4:67e4fd9f47c5 54 @param frequency The desires sample frequency
sam_grove 4:67e4fd9f47c5 55 @return The amount of error in Hz between desired and actual frequency
sam_grove 4:67e4fd9f47c5 56 */
sam_grove 4:67e4fd9f47c5 57 virtual uint32_t sampleRate(uint32_t frequency) const = 0;
sam_grove 4:67e4fd9f47c5 58
sam_grove 4:67e4fd9f47c5 59 /** Tells of new data is ready
sam_grove 4:67e4fd9f47c5 60 @return The amount of data samples ready to be read from a device
sam_grove 4:67e4fd9f47c5 61 */
sam_grove 4:67e4fd9f47c5 62 virtual uint32_t dataReady(void) const = 0;
sam_grove 4:67e4fd9f47c5 63
sam_grove 4:67e4fd9f47c5 64 /** Get the x data in counts
sam_grove 4:67e4fd9f47c5 65 @param x A referene to the variable to put the data in, 0 denotes not used
sam_grove 4:67e4fd9f47c5 66 @return The x data in counts
sam_grove 4:67e4fd9f47c5 67 */
sam_grove 4:67e4fd9f47c5 68 virtual int16_t getX(const int16_t &x = 0) const = 0;
sam_grove 4:67e4fd9f47c5 69
sam_grove 4:67e4fd9f47c5 70 /** Get the y data in counts
sam_grove 4:67e4fd9f47c5 71 @param y A referene to the variable to put the data in, 0 denotes not used
sam_grove 4:67e4fd9f47c5 72 @return The y data in counts
sam_grove 4:67e4fd9f47c5 73 */
sam_grove 4:67e4fd9f47c5 74 virtual void getY(const int16_t &y = 0) const = 0;
sam_grove 4:67e4fd9f47c5 75
sam_grove 4:67e4fd9f47c5 76 /** Get the z data in counts
sam_grove 4:67e4fd9f47c5 77 @param z A referene to the variable to put the data in, 0 denotes not used
sam_grove 4:67e4fd9f47c5 78 @return The z data in counts
sam_grove 4:67e4fd9f47c5 79 */
sam_grove 4:67e4fd9f47c5 80 virtual void getZ(const int16_t &z) const = 0;
sam_grove 4:67e4fd9f47c5 81
sam_grove 4:67e4fd9f47c5 82 /** Get the x data in units
sam_grove 4:67e4fd9f47c5 83 @param x A referene to the variable to put the data in, 0 denotes not used
sam_grove 4:67e4fd9f47c5 84 @return The x data in units
sam_grove 4:67e4fd9f47c5 85 */
sam_grove 4:67e4fd9f47c5 86 virtual void getX(const float &x) const = 0;
sam_grove 4:67e4fd9f47c5 87
sam_grove 4:67e4fd9f47c5 88 /** Get the y data in units
sam_grove 4:67e4fd9f47c5 89 @param y A referene to the variable to put the data in, 0 denotes not used
sam_grove 4:67e4fd9f47c5 90 @return The y data in units
sam_grove 4:67e4fd9f47c5 91 */
sam_grove 4:67e4fd9f47c5 92 virtual void getY(const float &y) const = 0;
sam_grove 4:67e4fd9f47c5 93
sam_grove 4:67e4fd9f47c5 94 /** Get the z data in units
sam_grove 4:67e4fd9f47c5 95 @param z A referene to the variable to put the data in, 0 denotes not used
sam_grove 4:67e4fd9f47c5 96 @return The z data in units
sam_grove 4:67e4fd9f47c5 97 */
sam_grove 4:67e4fd9f47c5 98 virtual void getZ(const float &z) const = 0;
sam_grove 4:67e4fd9f47c5 99
sam_grove 4:67e4fd9f47c5 100 /** Get the x,y,z data in counts
sam_grove 4:67e4fd9f47c5 101 @param xyz A referene to the variable to put the data in, 0 denotes not used
sam_grove 4:67e4fd9f47c5 102 */
sam_grove 4:67e4fd9f47c5 103 virtual void getAxis(const motion_data_counts_t &xyz) const = 0;
sam_grove 4:67e4fd9f47c5 104
sam_grove 4:67e4fd9f47c5 105 /** Get the x,y,z data in units
sam_grove 4:67e4fd9f47c5 106 @param xyz A referene to the variable to put the data in, 0 denotes not used
sam_grove 4:67e4fd9f47c5 107 */
sam_grove 4:67e4fd9f47c5 108 virtual void getAxis(const motion_data_units_t &xyz) const = 0;
sam_grove 0:dbc8909af0eb 109 };
sam_grove 0:dbc8909af0eb 110
sam_grove 0:dbc8909af0eb 111 #endif