00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _RotationSensor_H_
00023 #define _RotationSensor_H_
00024
00025 #include <config.h>
00026 #include <c++/Sensor.H>
00027 #include <dsensor.h>
00028
00029 #if defined(CONF_DSENSOR) && defined(CONF_DSENSOR_ROTATION)
00030
00046 class RotationSensor : public Sensor {
00047 public:
00053 RotationSensor(const Port port, int position = 0)
00054 : Sensor((Sensor::Port) port, true),
00055 rsensor((port == S1) ? ROTATION_1 :
00056 (port == S2) ? ROTATION_2 :
00057 ROTATION_3)
00058 #ifdef CONF_DSENSOR_VELOCITY
00059 ,
00060 rvelocity((port == S1) ? VELOCITY_1 :
00061 (port == S2) ? VELOCITY_2 :
00062 VELOCITY_3)
00063 #endif
00064 {
00065 on();
00066 pos(position);
00067 }
00071 ~RotationSensor()
00072 {
00073 off();
00074 }
00075
00079 void on() const {ds_rotation_on(&sensor);}
00080
00084 void off() const {ds_rotation_off(&sensor);}
00085
00090 void pos(int position) const {ds_rotation_set(&sensor, position);}
00091
00096 int pos() const {return rsensor;}
00097 #ifdef CONF_DSENSOR_VELOCITY
00098
00102 int velocity() const {return rvelocity;}
00103 #endif // CONF_DSENSOR_VELOCITY
00104
00105 private:
00109 volatile int& rsensor;
00110 #ifdef CONF_DSENSOR_VELOCITY
00111
00114 volatile int& rvelocity;
00115 #endif // CONF_DSENSOR_VELOCITY
00116 };
00117
00118 #else
00119 #warning Enable CONF_DSENSOR && CONF_DSENSOR_ROTATION to use RotationSensor.H
00120 #endif // CONF_DSENSOR, CONF_DSENSOR_ROTATION
00121 #endif // _RotationSensor_H_