00001 00007 // 00008 // The contents of this file are subject to the Mozilla Public License 00009 // Version 1.0 (the "License"); you may not use this file except in 00010 // compliance with the License. You may obtain a copy of the License 00011 // at http://www.mozilla.org/MPL/ 00012 // 00013 // Software distributed under the License is distributed on an "AS IS" 00014 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00015 // the License for the specific language governing rights and 00016 // limitations under the License. 00017 // 00018 // This software was developed as part of the legOS project. 00019 // 00020 // Contributor: Pat Welch (legOS@mousebrains.com) 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 // CONF_DSENSOR_VELOCITY 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_
brickOS is released under the
Mozilla Public License.
Original code copyright 1998-2002 by the authors. |