00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _Sensor_H_
00022 #define _Sensor_H_
00023
00024 #include <config.h>
00025
00026 #if defined(CONF_DSENSOR)
00027
00028 #include <dsensor.h>
00029 #include <conio.h>
00030
00054 class Sensor {
00055 public:
00067 enum Port {
00068 S1 = 0,
00069 S2,
00070 S3,
00071 Battery
00072 };
00073
00084 Sensor(const Port port, bool makeActive = false)
00085 : sensor((port == S1) ? SENSOR_1 :
00086 (port == S2) ? SENSOR_2 :
00087 (port == S3) ? SENSOR_3 :
00088 BATTERY)
00089 {
00090 if (makeActive) active();
00091 else passive();
00092 }
00093
00101 ~Sensor() {off();}
00102
00109 unsigned int get() const {return sensor;}
00110
00118 void mode(bool makeActive) const {
00119 if (makeActive) active();
00120 else passive();
00121 }
00122
00127 void passive() const {ds_passive(&sensor);}
00128
00133 void active() const {ds_active(&sensor);}
00134
00139 void on () const {active();}
00140
00145 void off() const {passive();}
00146
00151 void strobe() const {off(); on();}
00152
00158 void strobe(const int ms) const {off(); delay(ms); on();}
00159
00167 unsigned int sample(unsigned int size = 10, int wait = 2) const {
00168 if (size == 0) size = 1;
00169 unsigned int sum(get());
00170 for (unsigned int i = 1; i < size; ++i) {
00171 sum += get();
00172 delay(wait);
00173 }
00174 return sum / size;
00175 }
00176
00177 protected:
00181 volatile unsigned int& sensor;
00182 };
00183
00184 #else // CONF_DSENSOR
00185 #warning Enable CONF_DSENSOR to use Sensor.H
00186 #endif // CONF_DSENSOR
00187 #endif // _Sensor_H_
00188