Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Sensor Class Reference

Basic sensor interface. More...

#include <c++/Sensor.H>

Inheritance diagram for Sensor:

Inheritance graph
[legend]
Collaboration diagram for Sensor:

Collaboration graph
[legend]
List of all members.

Public Types

enum  Port { S1 = 0, S2, S3, Battery }
 List of sensor identifiers (IDs). Possible Sensor Port Values. More...


Public Member Functions

 Sensor (const Port port, bool makeActive=false)
 Construct a new sensor instance.

 ~Sensor ()
 Destroy this sensor instance.

unsigned int get () const
 Get the current sensor reading.

void mode (bool makeActive) const
 Set the sensor (mode) to active or passive.

void passive () const
 Set the sensor to passive (turn off voltage to connector).

void active () const
 Set the sensor to active (provide voltage to connector).

void on () const
 Turn the sensor on (provide voltage to connector).

void off () const
 Turn the sensor off (turn off voltage to connector).

void strobe () const
 Quickly turn sensor off then back on.

void strobe (const int ms) const
 Turn sensor off, wait for {ms} milliSeconds, then then turn it back on.

unsigned int sample (unsigned int size=10, int wait=2) const
 Get the average of {size} samples, waiting {wait} mSec between each sample.


Protected Attributes

volatile unsigned int & sensor
 The address of our sensor value.


Detailed Description

Basic sensor interface.

This is the base class for all sensors.

At construction time you specify the RCX connector pad [Port] to which the sensor is attached and whether it should be powered (active/on) or not (passive/off).

The Sensor class provides methods to:

Note:
Generally touch sensors [identical to Sensor but may be spelled TouchSensor] are not powered. Light sensors [LightSensor] may be powered or not (the values are smaller when they are powered and the sensor is more tolerant of ambient light) and Rotation sensors [RotationSensor] must be powered when sensing rotation.
Todo:
how does TemperatureSensor figure in here...?

Definition at line 54 of file Sensor.H.


Member Enumeration Documentation

enum Sensor::Port
 

List of sensor identifiers (IDs). Possible Sensor Port Values.

S1, S2, S3 are connector pads 1, 2 and 3 on the RCX.

Battery is the internal sensor allowing a program to read the current battery voltage in milliVolts

See also:
Battery
Enumeration values:
S1  RCX sensor port 1.
S2  RCX sensor port 2.
S3  RCX sensor port 3.
Battery  RCX battery sensor.

Definition at line 67 of file Sensor.H.


Constructor & Destructor Documentation

Sensor::Sensor const Port  port,
bool  makeActive = false
[inline]
 

Construct a new sensor instance.

At time of construction identify where the sensor is connected and whether it should be active or passive (default is passive).

Parameters:
port The port to be associated with this instance of a sensor
makeActive T/F - Where true means make active (default is false, passive)
See also:
Sensor::Port

Definition at line 84 of file Sensor.H.

References active(), BATTERY, passive(), S1, S2, S3, sensor, SENSOR_1, SENSOR_2, and SENSOR_3.

Sensor::~Sensor  )  [inline]
 

Destroy this sensor instance.

Note:
Just before the sensor instance is destroyed the power to the input pad is turned off (in case is was active) thereby conserving battery power.

Definition at line 101 of file Sensor.H.

References off().


Member Function Documentation

void Sensor::active  )  const [inline]
 

Set the sensor to active (provide voltage to connector).

See also:
Sensor::passive, Sensor::on, Sensor::off, Sensor::mode

Definition at line 133 of file Sensor.H.

References ds_active(), and sensor.

Referenced by mode(), on(), and Sensor().

unsigned int Sensor::get  )  const [inline]
 

Get the current sensor reading.

Returns:
unsigned int - The current raw sensor value
See also:
Sensor::sample

Reimplemented in LightSensor.

Definition at line 109 of file Sensor.H.

References sensor.

Referenced by TemperatureSensor::C(), and sample().

void Sensor::mode bool  makeActive  )  const [inline]
 

Set the sensor (mode) to active or passive.

Parameters:
makeActive - T/F - Where true means to go active (voltage is supplied to the connector pad)
See also:
Sensor::off, Sensor::on, Sensor::active, Sensor::passive

Definition at line 118 of file Sensor.H.

References active(), and passive().

void Sensor::off  )  const [inline]
 

Turn the sensor off (turn off voltage to connector).

See also:
Sensor::on, Sensor::active, Sensor::passive, Sensor::mode

Reimplemented in RotationSensor.

Definition at line 145 of file Sensor.H.

References passive().

Referenced by strobe(), and ~Sensor().

void Sensor::on  )  const [inline]
 

Turn the sensor on (provide voltage to connector).

See also:
Sensor::off, Sensor::active, Sensor::passive, Sensor::mode

Reimplemented in RotationSensor.

Definition at line 139 of file Sensor.H.

References active().

Referenced by strobe().

void Sensor::passive  )  const [inline]
 

Set the sensor to passive (turn off voltage to connector).

See also:
Sensor::active, Sensor::on, Sensor::off, Sensor::mode

Definition at line 127 of file Sensor.H.

References ds_passive(), and sensor.

Referenced by mode(), off(), and Sensor().

unsigned int Sensor::sample unsigned int  size = 10,
int  wait = 2
const [inline]
 

Get the average of {size} samples, waiting {wait} mSec between each sample.

Parameters:
size - Number of samples to average (default = 10 samples)
wait - time (in mS) to wait between samples (default = 2mS)
Returns:
unsigned int - The average of the sampled values
See also:
Sensor::get

Reimplemented in LightSensor.

Definition at line 167 of file Sensor.H.

References delay(), and get().

void Sensor::strobe const int  ms  )  const [inline]
 

Turn sensor off, wait for {ms} milliSeconds, then then turn it back on.

Parameters:
ms - Number of milliSeconds to wait between off and back on
See also:
Sensor::on, Sensor::off, Sensor::active, Sensor::passive, Sensor::mode

Definition at line 158 of file Sensor.H.

References delay(), off(), and on().

void Sensor::strobe  )  const [inline]
 

Quickly turn sensor off then back on.

See also:
Sensor::on, Sensor::off, Sensor::active, Sensor::passive, Sensor::mode

Definition at line 151 of file Sensor.H.

References off(), and on().


Member Data Documentation

volatile unsigned int& Sensor::sensor [protected]
 

The address of our sensor value.

Definition at line 181 of file Sensor.H.

Referenced by active(), get(), passive(), and Sensor().


The documentation for this class was generated from the following file:
brickOS is released under the Mozilla Public License.
Original code copyright 1998-2002 by the authors.

Generated on Mon Feb 16 21:02:35 2004 for brickOS Kernel Developer by doxygen 1.3.5