Virtual base class for sensors that measure motion
Dependents: FXOS8700Q MAG3110 MMA8451Q MAG3110 ... more
MotionSensor.h@5:226520fc09bf, 2015-06-18 (annotated)
- Committer:
- sam_grove
- Date:
- Thu Jun 18 22:52:47 2015 +0000
- Revision:
- 5:226520fc09bf
- Parent:
- 4:67e4fd9f47c5
update comments and documentation
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:226520fc09bf | 38 | |
sam_grove | 4:67e4fd9f47c5 | 39 | /** Motion Sensor Base Class |
sam_grove | 4:67e4fd9f47c5 | 40 | Useful for accessing data in a common way |
sam_grove | 4:67e4fd9f47c5 | 41 | */ |
sam_grove | 0:dbc8909af0eb | 42 | class MotionSensor |
sam_grove | 0:dbc8909af0eb | 43 | { |
sam_grove | 0:dbc8909af0eb | 44 | public: |
sam_grove | 4:67e4fd9f47c5 | 45 | |
sam_grove | 4:67e4fd9f47c5 | 46 | /** Enable the sensor for operation |
sam_grove | 4:67e4fd9f47c5 | 47 | */ |
sam_grove | 4:67e4fd9f47c5 | 48 | virtual void enable(void) const = 0; |
sam_grove | 5:226520fc09bf | 49 | |
sam_grove | 4:67e4fd9f47c5 | 50 | /** disable the sensors operation |
sam_grove | 4:67e4fd9f47c5 | 51 | */ |
sam_grove | 4:67e4fd9f47c5 | 52 | virtual void disable(void) const = 0; |
sam_grove | 5:226520fc09bf | 53 | |
sam_grove | 4:67e4fd9f47c5 | 54 | /** Set the sensor sample rate |
sam_grove | 4:67e4fd9f47c5 | 55 | @param frequency The desires sample frequency |
sam_grove | 4:67e4fd9f47c5 | 56 | @return The amount of error in Hz between desired and actual frequency |
sam_grove | 4:67e4fd9f47c5 | 57 | */ |
sam_grove | 4:67e4fd9f47c5 | 58 | virtual uint32_t sampleRate(uint32_t frequency) const = 0; |
sam_grove | 5:226520fc09bf | 59 | |
sam_grove | 4:67e4fd9f47c5 | 60 | /** Tells of new data is ready |
sam_grove | 4:67e4fd9f47c5 | 61 | @return The amount of data samples ready to be read from a device |
sam_grove | 4:67e4fd9f47c5 | 62 | */ |
sam_grove | 4:67e4fd9f47c5 | 63 | virtual uint32_t dataReady(void) const = 0; |
sam_grove | 5:226520fc09bf | 64 | |
sam_grove | 4:67e4fd9f47c5 | 65 | /** Get the x data in counts |
sam_grove | 4:67e4fd9f47c5 | 66 | @param x A referene to the variable to put the data in, 0 denotes not used |
sam_grove | 4:67e4fd9f47c5 | 67 | @return The x data in counts |
sam_grove | 4:67e4fd9f47c5 | 68 | */ |
sam_grove | 5:226520fc09bf | 69 | virtual int16_t getX(int16_t &x) const = 0; |
sam_grove | 5:226520fc09bf | 70 | |
sam_grove | 4:67e4fd9f47c5 | 71 | /** Get the y data in counts |
sam_grove | 4:67e4fd9f47c5 | 72 | @param y A referene to the variable to put the data in, 0 denotes not used |
sam_grove | 4:67e4fd9f47c5 | 73 | @return The y data in counts |
sam_grove | 4:67e4fd9f47c5 | 74 | */ |
sam_grove | 5:226520fc09bf | 75 | virtual int16_t getY(int16_t &y) const = 0; |
sam_grove | 5:226520fc09bf | 76 | |
sam_grove | 4:67e4fd9f47c5 | 77 | /** Get the z data in counts |
sam_grove | 4:67e4fd9f47c5 | 78 | @param z A referene to the variable to put the data in, 0 denotes not used |
sam_grove | 4:67e4fd9f47c5 | 79 | @return The z data in counts |
sam_grove | 4:67e4fd9f47c5 | 80 | */ |
sam_grove | 5:226520fc09bf | 81 | virtual int16_t getZ(int16_t &z) const = 0; |
sam_grove | 5:226520fc09bf | 82 | |
sam_grove | 4:67e4fd9f47c5 | 83 | /** Get the x data in units |
sam_grove | 4:67e4fd9f47c5 | 84 | @param x A referene to the variable to put the data in, 0 denotes not used |
sam_grove | 4:67e4fd9f47c5 | 85 | @return The x data in units |
sam_grove | 4:67e4fd9f47c5 | 86 | */ |
sam_grove | 5:226520fc09bf | 87 | virtual float getX(float &x) const = 0; |
sam_grove | 5:226520fc09bf | 88 | |
sam_grove | 4:67e4fd9f47c5 | 89 | /** Get the y data in units |
sam_grove | 4:67e4fd9f47c5 | 90 | @param y A referene to the variable to put the data in, 0 denotes not used |
sam_grove | 4:67e4fd9f47c5 | 91 | @return The y data in units |
sam_grove | 4:67e4fd9f47c5 | 92 | */ |
sam_grove | 5:226520fc09bf | 93 | virtual float getY(float &y) const = 0; |
sam_grove | 5:226520fc09bf | 94 | |
sam_grove | 4:67e4fd9f47c5 | 95 | /** Get the z data in units |
sam_grove | 4:67e4fd9f47c5 | 96 | @param z A referene to the variable to put the data in, 0 denotes not used |
sam_grove | 4:67e4fd9f47c5 | 97 | @return The z data in units |
sam_grove | 4:67e4fd9f47c5 | 98 | */ |
sam_grove | 5:226520fc09bf | 99 | virtual float getZ(float &z) const = 0; |
sam_grove | 5:226520fc09bf | 100 | |
sam_grove | 4:67e4fd9f47c5 | 101 | /** Get the x,y,z data in counts |
sam_grove | 4:67e4fd9f47c5 | 102 | @param xyz A referene to the variable to put the data in, 0 denotes not used |
sam_grove | 4:67e4fd9f47c5 | 103 | */ |
sam_grove | 5:226520fc09bf | 104 | virtual void getAxis(motion_data_counts_t &xyz) const = 0; |
sam_grove | 5:226520fc09bf | 105 | |
sam_grove | 4:67e4fd9f47c5 | 106 | /** Get the x,y,z data in units |
sam_grove | 4:67e4fd9f47c5 | 107 | @param xyz A referene to the variable to put the data in, 0 denotes not used |
sam_grove | 4:67e4fd9f47c5 | 108 | */ |
sam_grove | 5:226520fc09bf | 109 | virtual void getAxis(motion_data_units_t &xyz) const = 0; |
sam_grove | 0:dbc8909af0eb | 110 | }; |
sam_grove | 0:dbc8909af0eb | 111 | |
sam_grove | 5:226520fc09bf | 112 | #endif |