ECRobot C++ API for LEGO MINDSTORMS NXT  1.0.10
device/Sensor.h
00001 //
00002 // Sensor.h
00003 //
00004 // Copyright 2009 by Takashi Chikamasa, Jon C. Martin and Robert W. Kramer
00005 //
00006 
00007 #ifndef SENSOR_H_
00008 #define SENSOR_H_
00009 
00010 #include "Port.h"
00011 
00012 extern "C"
00013 {
00014         #include "ecrobot_interface.h"
00015         #include "rtoscalls.h"
00016 };
00017 
00018 namespace ecrobot
00019 {
00023 class Sensor
00024 {
00025 public: 
00031         inline S16 get(void) const { return static_cast<S16>(sensor_adc(Sensor::getPort())); }
00032 
00033 protected:
00039         inline ePortS getPort(void) const { return mPort; }
00040 
00047         explicit Sensor(ePortS port, ePower power=POWER_OFF): mPort(port)
00048         {
00049                 AssertDeviceConstructor("Sensor Assert");
00050                 nxt_avr_set_input_power(port, power);
00051         }
00052 
00058         virtual ~Sensor(void) { nxt_avr_set_input_power(mPort, POWER_OFF); }
00059 
00060 private:
00061         ePortS mPort;
00062 };
00063 }
00064 
00065 #endif
 All Classes Files Functions Variables Enumerations Enumerator Friends Defines