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

Interface for analog-to-digital converter components (e.g. More...

#include <AnalogDigitalConverterComponent.h>

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

Public Member Functions

virtual ~IAnalogDigitalConverterComponent ()=0
 Pure virtual destructor, making this an abstract interface. More...
 
virtual int ReadAnalogValue (int adcIndex=0)=0
 Reads an analog value from the given channel. More...
 
float GetADCVoltage () const
 Gets the ADC's reference voltage. More...
 
int GetMaxRawValue () const
 Gets the ADC's full-scale raw count (e.g. 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 Member Functions

 IAnalogDigitalConverterComponent ()
 Initializes the reference voltage and full-scale count to safe 10-bit defaults; concrete ADCs overwrite both in their own constructor, so a subclass that forgets to set them still yields sane (non-garbage) conversions rather than silently wrong volts. More...
 

Protected Attributes

float myADCVoltage
 The ADC's reference voltage, used to convert raw readings to volts. More...
 
int myMaxRawValue
 The ADC's full-scale raw count (255 for an 8-bit chip, 1023 for a 10-bit chip). 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

Interface for analog-to-digital converter components (e.g.

PCF8591, MCP3008), used to read analog sensors.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ IAnalogDigitalConverterComponent()

RumPi::IAnalogDigitalConverterComponent::IAnalogDigitalConverterComponent ( )
inlineprotected

Initializes the reference voltage and full-scale count to safe 10-bit defaults; concrete ADCs overwrite both in their own constructor, so a subclass that forgets to set them still yields sane (non-garbage) conversions rather than silently wrong volts.

Author
Eddie O'Hagan
Date
8/13/2026

◆ ~IAnalogDigitalConverterComponent()

RumPi::IAnalogDigitalConverterComponent::~IAnalogDigitalConverterComponent ( )
inlinepure virtual

Pure virtual destructor, making this an abstract interface.

Author
Eddie O'Hagan
Date
8/13/2026
IAnalogDigitalConverterComponent* adc = new PCF8591(120, 0x48);
delete adc;
IAnalogDigitalConverterComponent()
Initializes the reference voltage and full-scale count to safe 10-bit defaults; concrete ADCs overwri...
Definition: AnalogDigitalConverterComponent.h:27

Member Function Documentation

◆ GetADCVoltage()

float RumPi::IAnalogDigitalConverterComponent::GetADCVoltage ( ) const
inline

Gets the ADC's reference voltage.

Author
Eddie O'Hagan
Date
8/13/2026
float voltage = adc->GetADCVoltage();
Returns
The ADC's reference voltage.

◆ GetMaxRawValue()

int RumPi::IAnalogDigitalConverterComponent::GetMaxRawValue ( ) const
inline

Gets the ADC's full-scale raw count (e.g.

255 for an 8-bit chip, 1023 for a 10-bit chip), so callers can scale a raw reading to volts without assuming a fixed resolution.

Author
Eddie O'Hagan
Date
8/13/2026
int fullScale = adc->GetMaxRawValue();
Returns
The ADC's maximum raw reading.

◆ ReadAnalogValue()

virtual int RumPi::IAnalogDigitalConverterComponent::ReadAnalogValue ( int  adcIndex = 0)
pure virtual

Reads an analog value from the given channel.

Author
Eddie O'Hagan
Date
8/13/2026
int value = adc->ReadAnalogValue(0);
Parameters
[in]adcIndexThe ADC channel index to read.
Returns
The raw analog value, or -1 if the channel index is out of range.

Implemented in RumPi::MCP3008, and RumPi::PCF8591.

Member Data Documentation

◆ myADCVoltage

float RumPi::IAnalogDigitalConverterComponent::myADCVoltage
protected

The ADC's reference voltage, used to convert raw readings to volts.

◆ myMaxRawValue

int RumPi::IAnalogDigitalConverterComponent::myMaxRawValue
protected

The ADC's full-scale raw count (255 for an 8-bit chip, 1023 for a 10-bit chip).


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