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

Photoresistor (LDR) - reads ambient light as an analog value through an ADC channel. More...

#include <Photoresistor.h>

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

Public Member Functions

 Photoresistor ()
 Builds a default photoresistor with no ADC wired yet. More...
 
 Photoresistor (IAnalogDigitalConverterComponent *analogToDigitalConverter, const unsigned int analogToDigitalConverterIndex)
 Builds a photoresistor bound to the given ADC and channel index. More...
 
virtual ~Photoresistor ()
 Destroys the sensor, turning it off first. More...
 
virtual void TurnOn () override
 No-op: the photoresistor is passive and reads on demand, so there is nothing to turn on. More...
 
virtual void TurnOff () override
 No-op: the photoresistor holds no resources that need releasing when turned off. More...
 
virtual void ProcessRawValues () override
 No-op: the photoresistor reads its value on demand in ReadRawAnalogValue, so there are no raw values to process. More...
 
int ReadRawAnalogValue () const
 Reads the raw analog light value from the ADC, or -1 if no ADC is wired. More...
 
virtual std::string ToString () const override
 Serializes the photoresistor'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

Photoresistor (LDR) - reads ambient light as an analog value through an ADC channel.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ Photoresistor() [1/2]

RumPi::Photoresistor::Photoresistor ( )

Builds a default photoresistor with no ADC wired yet.

Author
Eddie O'Hagan
Date
8/13/2026
Photoresistor lightSensor;
Photoresistor()
Builds a default photoresistor with no ADC wired yet.
Definition: Photoresistor.cpp:15

◆ Photoresistor() [2/2]

RumPi::Photoresistor::Photoresistor ( IAnalogDigitalConverterComponent analogToDigitalConverter,
const unsigned int  analogToDigitalConverterIndex 
)

Builds a photoresistor bound to the given ADC and channel index.

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

◆ ~Photoresistor()

RumPi::Photoresistor::~Photoresistor ( )
virtual

Destroys the sensor, turning it off first.

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

Member Function Documentation

◆ GetAnalogDigitalConverter()

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

Gets the ADC this sensor reads through.

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

◆ GetAnalogToDigitalConverterPinIndex()

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

Gets the ADC channel index this sensor reads from.

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

◆ ProcessRawValues()

void RumPi::Photoresistor::ProcessRawValues ( )
overridevirtual

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

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

Implements RumPi::BaseComponent.

◆ ReadRawAnalogValue()

int RumPi::Photoresistor::ReadRawAnalogValue ( ) const

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

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

◆ SetAnalogDigitalConverter()

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

Sets the ADC this sensor reads through.

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

◆ SetAnalogToDigitalConverterPinIndex()

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

Sets the ADC channel index this sensor reads from.

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

◆ ToString()

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

Serializes the photoresistor's raw analog value to a string.

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

Implements RumPi::BaseComponent.

◆ TurnOff()

void RumPi::Photoresistor::TurnOff ( )
overridevirtual

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

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

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::Photoresistor::TurnOn ( )
overridevirtual

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

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

Implements RumPi::BaseComponent.

Member Data Documentation

◆ myAnalogToDigitalConverter

IAnalogDigitalConverterComponent* RumPi::Photoresistor::myAnalogToDigitalConverter
protected

The ADC this sensor reads through.

◆ myAnalogToDigitalConverterPinIndex

unsigned int RumPi::Photoresistor::myAnalogToDigitalConverterPinIndex
protected

The ADC channel index this sensor reads from.


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