Implemented first Hangar-Service
Dependencies: CalibrateMagneto QuaternionMath
Fork of SML2 by
Sensor.h@46:fd5a62296b12, 2015-05-27 (annotated)
- Committer:
- pvaibhav
- Date:
- Wed May 27 13:01:43 2015 +0000
- Revision:
- 46:fd5a62296b12
- Parent:
- 21:5a0c9406e119
Code reformatted
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pvaibhav | 6:c12cea26842d | 1 | #ifndef _H_SENSOR_H |
pvaibhav | 6:c12cea26842d | 2 | #define _H_SENSOR_H |
pvaibhav | 6:c12cea26842d | 3 | |
pvaibhav | 8:cba37530d480 | 4 | #include "Vector3.h" |
pvaibhav | 8:cba37530d480 | 5 | |
pvaibhav | 6:c12cea26842d | 6 | /// Base class for I2C-connected sensors. Defines functionality supported by all sensors. |
pvaibhav | 12:1632d7391453 | 7 | class Sensor |
pvaibhav | 12:1632d7391453 | 8 | { |
pvaibhav | 6:c12cea26842d | 9 | public: |
pvaibhav | 6:c12cea26842d | 10 | /// Defines protocol used to send data back to owner. Derive from this class and use Sensor.setDelegate() to receive sensor updates. |
pvaibhav | 12:1632d7391453 | 11 | class Delegate |
pvaibhav | 12:1632d7391453 | 12 | { |
pvaibhav | 6:c12cea26842d | 13 | public: |
pvaibhav | 6:c12cea26842d | 14 | /// A new sensor data frame, might be called several (hundred) times a second. |
pvaibhav | 21:5a0c9406e119 | 15 | virtual void sensorUpdate(Vector3 data) {} |
pvaibhav | 6:c12cea26842d | 16 | }; |
pvaibhav | 12:1632d7391453 | 17 | |
pvaibhav | 6:c12cea26842d | 18 | virtual void setDelegate(Delegate &d) { |
pvaibhav | 21:5a0c9406e119 | 19 | delegate = &d; |
pvaibhav | 6:c12cea26842d | 20 | } |
pvaibhav | 12:1632d7391453 | 21 | |
pvaibhav | 6:c12cea26842d | 22 | /// Power on a sensor and make it ready for use. |
pvaibhav | 6:c12cea26842d | 23 | /// @return true if power-up was successful, false otherwise. |
pvaibhav | 6:c12cea26842d | 24 | virtual bool powerOn() = 0; |
pvaibhav | 12:1632d7391453 | 25 | |
pvaibhav | 6:c12cea26842d | 26 | /// Power off a sensor. This will generally only put the sensor into deep sleep. |
pvaibhav | 6:c12cea26842d | 27 | virtual void powerOff() = 0; |
pvaibhav | 12:1632d7391453 | 28 | |
pvaibhav | 6:c12cea26842d | 29 | virtual void start() = 0; ///< Start continuous data capture. If a delegate is set, its sensorUpdate() method will be called for each data frame. |
pvaibhav | 6:c12cea26842d | 30 | virtual void stop() = 0; ///< Stop capturing data. |
pvaibhav | 12:1632d7391453 | 31 | |
pvaibhav | 8:cba37530d480 | 32 | virtual Vector3 read() = 0; ///< Read and return instantaneous (current) sensor data. No need to start the sensor. |
pvaibhav | 46:fd5a62296b12 | 33 | |
pvaibhav | 21:5a0c9406e119 | 34 | Sensor() : delegate(&defaultDelegate) {} |
pvaibhav | 12:1632d7391453 | 35 | |
pvaibhav | 6:c12cea26842d | 36 | protected: |
pvaibhav | 21:5a0c9406e119 | 37 | Delegate defaultDelegate; |
pvaibhav | 21:5a0c9406e119 | 38 | Delegate *delegate; |
pvaibhav | 6:c12cea26842d | 39 | }; |
pvaibhav | 6:c12cea26842d | 40 | |
pvaibhav | 6:c12cea26842d | 41 | #endif//_H_SENSOR_H |