brickOS C++ v0.9.0
TemperatureSensor Class Reference

Temperature-sensor interface. More...

#include <c++/TemperatureSensor.H>

Inheritance diagram for TemperatureSensor:
Collaboration diagram for TemperatureSensor:

Public Types

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

Public Member Functions

 TemperatureSensor (const Sensor::Port port)
 Construct a temperature sensor.
 
 ~TemperatureSensor ()
 Destroy this instance of TemperatureSensor.
 
float C () const
 Get the current temperature in Celsius.
 
float F () const
 Get the current temperature in F.
 
int tenths () const
 Get the current temperature in C * 10, as an int.
 
int degrees () const
 Get the current temperature in C, as an int.
 
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

Temperature-sensor interface.

This is class deals with temperature sensors

The methods include: TemperatureSensor(sensor port) C() returns a float which is the temperature in C. The sensor appears to have a resolution of ~1/8 degree. F() returns a float which is the temperature in F. tenths() returns an int which is the temperature in C * 10 degrees() returns an int which is the temperature in C

It also includes all methods in Sensor

N.B. the transform from sensor reading to temperature is done using a simple linear regression compared to my outdoor thermometer over the range of -20 to +30 C. I can not vouch for the accuracy or precision of these numbers! So if you have a well calibrated temperature monitor, and you can check my conversions, please let me know the results, and I can clean up the regression parameters.

Definition at line 53 of file TemperatureSensor.H.

Member Enumeration Documentation

◆ Port

enum Sensor::Port
inherited

List of sensor identifiers (IDs).

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

Possible Sensor Port Values

See also
Battery
Enumerator
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

◆ TemperatureSensor()

TemperatureSensor::TemperatureSensor ( const Sensor::Port  port)
inline

Construct a temperature sensor.

At time of construction identify where it is connected.

Parameters
portThe port to be associated with this instance
See also
Sensor::Port

Definition at line 62 of file TemperatureSensor.H.

◆ ~TemperatureSensor()

TemperatureSensor::~TemperatureSensor ( )
inline

Destroy this instance of TemperatureSensor.

Definition at line 67 of file TemperatureSensor.H.

Member Function Documentation

◆ active()

void Sensor::active ( ) const
inlineinherited

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::sensor.

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

◆ C()

float TemperatureSensor::C ( ) const
inline

Get the current temperature in Celsius.

Returns
float - the current temperature in C

Definition at line 74 of file TemperatureSensor.H.

References Sensor::get().

Referenced by degrees(), F(), and tenths().

◆ degrees()

int TemperatureSensor::degrees ( ) const
inline

Get the current temperature in C, as an int.

Returns
int - the current temperature in C

Definition at line 97 of file TemperatureSensor.H.

References C().

◆ F()

float TemperatureSensor::F ( ) const
inline

Get the current temperature in F.

Returns
float - the current temperature in F

Definition at line 83 of file TemperatureSensor.H.

References C().

◆ get()

unsigned int Sensor::get ( ) const
inlineinherited

Get the current sensor reading.

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

Definition at line 109 of file Sensor.H.

References Sensor::sensor.

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

◆ mode()

void Sensor::mode ( bool  makeActive) const
inlineinherited

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 Sensor::active(), and Sensor::passive().

◆ off()

void Sensor::off ( ) const
inlineinherited

Turn the sensor off (turn off voltage to connector)

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

Definition at line 145 of file Sensor.H.

References Sensor::passive().

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

◆ on()

void Sensor::on ( ) const
inlineinherited

Turn the sensor on (provide voltage to connector)

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

Definition at line 139 of file Sensor.H.

References Sensor::active().

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

◆ passive()

void Sensor::passive ( ) const
inlineinherited

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::sensor.

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

◆ sample()

unsigned int Sensor::sample ( unsigned int  size = 10,
int  wait = 2 
) const
inlineinherited

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

Definition at line 167 of file Sensor.H.

References delay(), and Sensor::get().

◆ strobe() [1/2]

void Sensor::strobe ( ) const
inlineinherited

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 Sensor::off(), and Sensor::on().

◆ strobe() [2/2]

void Sensor::strobe ( const int  ms) const
inlineinherited

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(), Sensor::off(), and Sensor::on().

◆ tenths()

int TemperatureSensor::tenths ( ) const
inline

Get the current temperature in C * 10, as an int.

Returns
int - the current temperature in C * 10

Definition at line 90 of file TemperatureSensor.H.

References C().

Member Data Documentation

◆ sensor

volatile unsigned int& Sensor::sensor
protectedinherited

The documentation for this class was generated from the following file: