RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::RainSensor Class Reference

Rain sensor - reads surface wetness as an analog value through an ADC channel. More...

#include <RainSensor.h>

Inheritance diagram for RumPi::RainSensor:
[legend]
Collaboration diagram for RumPi::RainSensor:
[legend]

Public Member Functions

 RainSensor ()
 Builds a default rain sensor with no ADC wired yet. More...
 
 RainSensor (IAnalogDigitalConverterComponent *analogToDigitalConverter, const unsigned int &analogToDigitalConverterIndex)
 Builds a rain sensor bound to the given ADC and channel index. More...
 
virtual ~RainSensor ()
 Destroys the sensor, turning it off first. More...
 
virtual void TurnOn () override
 No-op: the rain sensor is passive and reads on demand, so there is nothing to turn on. More...
 
virtual void TurnOff () override
 No-op: the rain sensor holds no resources that need releasing when turned off. More...
 
int ReadRawAnalogValue () const
 Reads the raw analog wetness value from the ADC, or -1 if no ADC is wired. More...
 
virtual void ProcessRawValues () override
 No-op: the rain sensor reads its value on demand in ReadRawAnalogValue, so there are no raw values to process. More...
 
virtual std::string ToString () const override
 Serializes the rain sensor's raw analog value to a string. More...
 
unsigned int GetAnalogToDigitalConverterPinIndex () const
 Gets the ADC channel index this sensor reads from. More...
 
IAnalogDigitalConverterComponentGetAnalogDigitalConverter () const
 Gets the ADC this sensor reads through. More...
 
void SetAnalogToDigitalConverterPinIndex (unsigned int pinIndex)
 Sets the ADC channel index this sensor reads from. More...
 
void SetAnalogDigitalConverter (IAnalogDigitalConverterComponent *analogDigitalConverter)
 Sets the ADC this sensor reads through. More...
 
- Public Member Functions inherited from RumPi::BaseComponent
 BaseComponent ()
 Builds a base component with an unknown type and an empty name. More...
 
virtual ~BaseComponent ()
 Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More...
 
virtual void TurnOn ()=0
 Turns the component on (e.g. More...
 
virtual void TurnOff ()=0
 Turns the component off. More...
 
virtual std::string ToString () const =0
 Serializes the component's current readings to a string (usually JSON). More...
 
virtual void ProcessRawValues ()=0
 Reads and processes the component's latest raw values (called once per poll). More...
 
virtual EComponentType GetComponentType () const
 Gets the component's type. More...
 
const std::string & GetName () const
 Gets the component's unique per-instance name. More...
 
void SetName (const std::string &name)
 Sets the component's unique per-instance name. More...
 

Protected Attributes

unsigned int myAnalogToDigitalConverterPinIndex
 The ADC channel index this sensor reads from. More...
 
IAnalogDigitalConverterComponentmyAnalogToDigitalConverter
 The ADC this sensor reads through. More...
 
- Protected Attributes inherited from RumPi::BaseComponent
EComponentType myComponentType
 The kind of component this is (set by each concrete subclass). More...
 
std::string myName
 A unique per-instance name, assigned when the component is added to the manager. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from RumPi::BaseComponent
static std::string ComponentTypeToString (const EComponentType theComponentTypeToConvert)
 Maps an EComponentType to its string name. More...
 
static EComponentType StringToComponentType (const std::string &theComponentTypeName)
 Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More...
 

Detailed Description

Rain sensor - reads surface wetness as an analog value through an ADC channel.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ RainSensor() [1/2]

RumPi::RainSensor::RainSensor ( )

Builds a default rain sensor with no ADC wired yet.

Author
Eddie O'Hagan
Date
8/13/2026
RainSensor rainSensor;
RainSensor()
Builds a default rain sensor with no ADC wired yet.
Definition: RainSensor.cpp:15

◆ RainSensor() [2/2]

RumPi::RainSensor::RainSensor ( IAnalogDigitalConverterComponent analogToDigitalConverter,
const unsigned int &  analogToDigitalConverterIndex 
)

Builds a rain sensor bound to the given ADC and channel index.

Author
Eddie O'Hagan
Date
8/13/2026
RainSensor rainSensor(adc, 1);
Parameters
[in]analogToDigitalConverterThe ADC this sensor reads through.
[in]analogToDigitalConverterIndexThe ADC channel index this sensor reads from.

◆ ~RainSensor()

RumPi::RainSensor::~RainSensor ( )
virtual

Destroys the sensor, turning it off first.

Author
Eddie O'Hagan
Date
8/13/2026
RainSensor* rainSensor = new RainSensor();
delete rainSensor;

Member Function Documentation

◆ GetAnalogDigitalConverter()

IAnalogDigitalConverterComponent * RumPi::RainSensor::GetAnalogDigitalConverter ( ) const

Gets the ADC this sensor reads through.

Author
Eddie O'Hagan
Date
8/13/2026
IAnalogDigitalConverterComponent* adc = rainSensor.GetAnalogDigitalConverter();
Returns
The ADC, or nullptr if none is set.

◆ GetAnalogToDigitalConverterPinIndex()

unsigned int RumPi::RainSensor::GetAnalogToDigitalConverterPinIndex ( ) const

Gets the ADC channel index this sensor reads from.

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int index = rainSensor.GetAnalogToDigitalConverterPinIndex();
Returns
The ADC channel index.

◆ ProcessRawValues()

void RumPi::RainSensor::ProcessRawValues ( )
overridevirtual

No-op: the rain sensor reads its value on demand in ReadRawAnalogValue, so there are no raw values to process.

Author
Eddie O'Hagan
Date
8/13/2026
rainSensor.ProcessRawValues();

Implements RumPi::BaseComponent.

◆ ReadRawAnalogValue()

int RumPi::RainSensor::ReadRawAnalogValue ( ) const

Reads the raw analog wetness value from the ADC, or -1 if no ADC is wired.

Author
Eddie O'Hagan
Date
8/13/2026
int value = rainSensor.ReadRawAnalogValue();
Returns
The raw analog value, or -1 if no ADC is set.

◆ SetAnalogDigitalConverter()

void RumPi::RainSensor::SetAnalogDigitalConverter ( IAnalogDigitalConverterComponent analogDigitalConverter)

Sets the ADC this sensor reads through.

Author
Eddie O'Hagan
Date
8/13/2026
rainSensor.SetAnalogDigitalConverter(adc);
Parameters
[in]analogDigitalConverterThe ADC to set.

◆ SetAnalogToDigitalConverterPinIndex()

void RumPi::RainSensor::SetAnalogToDigitalConverterPinIndex ( unsigned int  pinIndex)

Sets the ADC channel index this sensor reads from.

Author
Eddie O'Hagan
Date
8/13/2026
rainSensor.SetAnalogToDigitalConverterPinIndex(1);
Parameters
[in]pinIndexThe ADC channel index to set.

◆ ToString()

std::string RumPi::RainSensor::ToString ( ) const
overridevirtual

Serializes the rain sensor's raw analog value to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = rainSensor.ToString();
Returns
A string describing the sensor's reading.

Implements RumPi::BaseComponent.

◆ TurnOff()

void RumPi::RainSensor::TurnOff ( )
overridevirtual

No-op: the rain sensor holds no resources that need releasing when turned off.

Author
Eddie O'Hagan
Date
8/13/2026
rainSensor.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::RainSensor::TurnOn ( )
overridevirtual

No-op: the rain sensor is passive and reads on demand, so there is nothing to turn on.

Author
Eddie O'Hagan
Date
8/13/2026
rainSensor.TurnOn();

Implements RumPi::BaseComponent.

Member Data Documentation

◆ myAnalogToDigitalConverter

IAnalogDigitalConverterComponent* RumPi::RainSensor::myAnalogToDigitalConverter
protected

The ADC this sensor reads through.

◆ myAnalogToDigitalConverterPinIndex

unsigned int RumPi::RainSensor::myAnalogToDigitalConverterPinIndex
protected

The ADC channel index this sensor reads from.


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