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
46class RotationSensor : public Sensor {
47public:
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 :
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
102 int velocity() const {return rvelocity;}
103#endif // CONF_DSENSOR_VELOCITY
104
105private:
109 volatile int& rsensor;
110#ifdef CONF_DSENSOR_VELOCITY
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_
C++ Sensor Class Interface.
Rotation-sensor interface (active mode).
~RotationSensor()
Destroy this instance.
void on() const
turn on rotation tracking
void pos(int position) const
set the current absolute postion
int pos() const
get the current absolute postion
void off() const
turn off rotation tracking
RotationSensor(const Port port, int position=0)
Create an instance of an active rotation sensor which is attached at {port}.
Basic sensor interface.
Definition Sensor.H:54
volatile unsigned int & sensor
The address of our sensor value.
Definition Sensor.H:181
Port
List of sensor identifiers (IDs).
Definition Sensor.H:67
@ S1
RCX sensor port 1.
Definition Sensor.H:68
@ S2
RCX sensor port 2.
Definition Sensor.H:69
Interface: direct reading of sensors.
#define ROTATION_3
rotation sensor on input 3
Definition dsensor.h:93
void ds_rotation_set(volatile unsigned *sensor, int pos)
set rotation to an absolute value
void ds_rotation_off(volatile unsigned *sensor)
stop tracking rotation sensor
Definition dsensor.h:220
#define ROTATION_1
rotation sensor on input 1
Definition dsensor.h:91
void ds_rotation_on(volatile unsigned *sensor)
start tracking rotation sensor
Definition dsensor.h:207
#define ROTATION_2
rotation sensor on input 2
Definition dsensor.h:92

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

Generated for brickOS C++ by doxygen 1.9.8