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_
Sensor
Definition: Sensor.H:54
RotationSensor::off
void off() const
turn off rotation tracking
Definition: RotationSensor.H:84
RotationSensor::~RotationSensor
~RotationSensor()
Destroy this instance.
Definition: RotationSensor.H:71
Sensor::sensor
volatile unsigned int & sensor
The address of our sensor value.
Definition: Sensor.H:181
ROTATION_3
#define ROTATION_3
rotation sensor on input 3
Definition: dsensor.h:93
dsensor.h
Interface: direct reading of sensors.
ds_rotation_set
void ds_rotation_set(volatile unsigned *sensor, int pos)
set rotation to an absolute value
ds_rotation_off
void ds_rotation_off(volatile unsigned *sensor)
stop tracking rotation sensor
Definition: dsensor.h:220
ROTATION_2
#define ROTATION_2
rotation sensor on input 2
Definition: dsensor.h:92
Sensor.H
C++ Sensor Class Interface.
RotationSensor::RotationSensor
RotationSensor(const Port port, int position=0)
Create an instance of an active rotation sensor which is attached at {port}.
Definition: RotationSensor.H:53
ds_rotation_on
void ds_rotation_on(volatile unsigned *sensor)
start tracking rotation sensor
Definition: dsensor.h:207
Sensor::S2
RCX sensor port 2.
Definition: Sensor.H:69
RotationSensor::on
void on() const
turn on rotation tracking
Definition: RotationSensor.H:79
RotationSensor::pos
void pos(int position) const
set the current absolute postion
Definition: RotationSensor.H:90
Sensor::Port
Port
List of sensor identifiers (IDs).
Definition: Sensor.H:67
ROTATION_1
#define ROTATION_1
rotation sensor on input 1
Definition: dsensor.h:91
RotationSensor
Definition: RotationSensor.H:46
Sensor::S1
RCX sensor port 1.
Definition: Sensor.H:68
RotationSensor::pos
int pos() const
get the current absolute postion
Definition: RotationSensor.H:96

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

Generated for brickOS C++ by doxygen 1.8.16