Implemented first Hangar-Service

Dependencies:   CalibrateMagneto QuaternionMath

Fork of SML2 by TobyRich GmbH

Committer:
pvaibhav
Date:
Fri Mar 13 09:12:56 2015 +0000
Revision:
12:1632d7391453
Parent:
8:cba37530d480
Child:
15:4488660e1a3b
Code reformatting

Who changed what in which revision?

UserRevisionLine numberNew 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 8:cba37530d480 15 virtual void sensorUpdate(Sensor* source, Vector3 data) = 0;
pvaibhav 6:c12cea26842d 16 };
pvaibhav 12:1632d7391453 17
pvaibhav 6:c12cea26842d 18 virtual void setDelegate(Delegate &d) {
pvaibhav 6:c12cea26842d 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 12:1632d7391453 33
pvaibhav 6:c12cea26842d 34 protected:
pvaibhav 6:c12cea26842d 35 /// Derived classes should use this method to pass sensor data to their owner. Delegate existence check is automatically done before dispatching.
pvaibhav 8:cba37530d480 36 void sendData(Vector3 frame) {
pvaibhav 6:c12cea26842d 37 if (_delegate)
pvaibhav 6:c12cea26842d 38 _delegate->sensorUpdate(this, frame);
pvaibhav 6:c12cea26842d 39 }
pvaibhav 6:c12cea26842d 40 Delegate * _delegate;
pvaibhav 6:c12cea26842d 41 };
pvaibhav 6:c12cea26842d 42
pvaibhav 6:c12cea26842d 43 #endif//_H_SENSOR_H