Implemented first Hangar-Service

Dependencies:   CalibrateMagneto QuaternionMath

Fork of SML2 by TobyRich GmbH

Committer:
pvaibhav
Date:
Wed Feb 18 15:13:41 2015 +0000
Revision:
8:cba37530d480
Parent:
7:604a8369b801
Child:
12:1632d7391453
Use Vector3 instead of Sensor::Data

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 6:c12cea26842d 7 class Sensor {
pvaibhav 6:c12cea26842d 8 public:
pvaibhav 6:c12cea26842d 9 /// Defines protocol used to send data back to owner. Derive from this class and use Sensor.setDelegate() to receive sensor updates.
pvaibhav 6:c12cea26842d 10 class Delegate {
pvaibhav 6:c12cea26842d 11 public:
pvaibhav 6:c12cea26842d 12 /// A new sensor data frame, might be called several (hundred) times a second.
pvaibhav 8:cba37530d480 13 virtual void sensorUpdate(Sensor* source, Vector3 data) = 0;
pvaibhav 6:c12cea26842d 14 };
pvaibhav 6:c12cea26842d 15
pvaibhav 6:c12cea26842d 16 virtual void setDelegate(Delegate &d) {
pvaibhav 6:c12cea26842d 17 _delegate = &d;
pvaibhav 6:c12cea26842d 18 }
pvaibhav 6:c12cea26842d 19
pvaibhav 6:c12cea26842d 20 /// Power on a sensor and make it ready for use.
pvaibhav 6:c12cea26842d 21 /// @return true if power-up was successful, false otherwise.
pvaibhav 6:c12cea26842d 22 virtual bool powerOn() = 0;
pvaibhav 6:c12cea26842d 23
pvaibhav 6:c12cea26842d 24 /// Power off a sensor. This will generally only put the sensor into deep sleep.
pvaibhav 6:c12cea26842d 25 virtual void powerOff() = 0;
pvaibhav 6:c12cea26842d 26
pvaibhav 6:c12cea26842d 27 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 28 virtual void stop() = 0; ///< Stop capturing data.
pvaibhav 6:c12cea26842d 29
pvaibhav 8:cba37530d480 30 virtual Vector3 read() = 0; ///< Read and return instantaneous (current) sensor data. No need to start the sensor.
pvaibhav 6:c12cea26842d 31
pvaibhav 6:c12cea26842d 32 protected:
pvaibhav 6:c12cea26842d 33 /// Derived classes should use this method to pass sensor data to their owner. Delegate existence check is automatically done before dispatching.
pvaibhav 8:cba37530d480 34 void sendData(Vector3 frame) {
pvaibhav 6:c12cea26842d 35 if (_delegate)
pvaibhav 6:c12cea26842d 36 _delegate->sensorUpdate(this, frame);
pvaibhav 6:c12cea26842d 37 }
pvaibhav 6:c12cea26842d 38 Delegate * _delegate;
pvaibhav 6:c12cea26842d 39 };
pvaibhav 6:c12cea26842d 40
pvaibhav 6:c12cea26842d 41 #endif//_H_SENSOR_H