RotationSensor.H
Go to the documentation of this file.
1 
7 //
8 // The contents of this file are subject to the Mozilla Public License
9 // Version 1.0 (the "License"); you may not use this file except in
10 // compliance with the License. You may obtain a copy of the License
11 // at http://www.mozilla.org/MPL/
12 //
13 // Software distributed under the License is distributed on an "AS IS"
14 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15 // the License for the specific language governing rights and
16 // limitations under the License.
17 //
18 // This software was developed as part of the legOS project.
19 //
20 // Contributor: Pat Welch (legOS@mousebrains.com)
21 
22 #ifndef _RotationSensor_H_
23 #define _RotationSensor_H_
24 
25 #include <config.h>
26 #include <c++/Sensor.H>
27 #include <dsensor.h>
28 
29 #if defined(CONF_DSENSOR) && defined(CONF_DSENSOR_ROTATION)
30 
46 class RotationSensor : public Sensor {
47 public:
53  RotationSensor(const Port port, int position = 0)
54  : Sensor((Sensor::Port) port, true),
55  rsensor((port == S1) ? ROTATION_1 :
56  (port == S2) ? ROTATION_2 :
57  ROTATION_3)
58 #ifdef CONF_DSENSOR_VELOCITY
59  ,
60  rvelocity((port == S1) ? VELOCITY_1 :
61  (port == S2) ? VELOCITY_2 :
62  VELOCITY_3)
63 #endif // CONF_DSENSOR_VELOCITY
64  {
65  on();
66  pos(position);
67  }
72  {
73  off();
74  }
75 
79  void on() const {ds_rotation_on(&sensor);}
80 
84  void off() const {ds_rotation_off(&sensor);}
85 
90  void pos(int position) const {ds_rotation_set(&sensor, position);}
91 
96  int pos() const {return rsensor;}
97 #ifdef CONF_DSENSOR_VELOCITY
98 
102  int velocity() const {return rvelocity;}
103 #endif // CONF_DSENSOR_VELOCITY
104 
105 private:
109  volatile int& rsensor;
110 #ifdef CONF_DSENSOR_VELOCITY
111 
114  volatile int& rvelocity;
115 #endif // CONF_DSENSOR_VELOCITY
116 };
117 
118 #else
119 #warning Enable CONF_DSENSOR && CONF_DSENSOR_ROTATION to use RotationSensor.H
120 #endif // CONF_DSENSOR, CONF_DSENSOR_ROTATION
121 #endif // _RotationSensor_H_

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated on Sat Mar 15 2014 11:28:19 for brickOS C++ by doxygen 1.8.1.2