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

Abstract base class for every component (sensor, actuator, etc.) the library manages. More...

#include <BaseComponent.h>

Inheritance diagram for RumPi::BaseComponent:
[legend]

Public Member Functions

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

Static Public Member Functions

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

Protected Attributes

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

Detailed Description

Abstract base class for every component (sensor, actuator, etc.) the library manages.

Defines the common actions - turn on/off, poll (ProcessRawValues), and serialize (ToString) - plus the type and unique name each component carries.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ BaseComponent()

RumPi::BaseComponent::BaseComponent ( )

Builds a base component with an unknown type and an empty name.

Concrete subclasses set their own type in their constructors, and the ComponentManager assigns the name when the component is added.

Author
Eddie O'Hagan
Date
8/13/2026
//Called by every concrete component's constructor via BaseComponent().
class LED : public BaseComponent { ... };
BaseComponent()
Builds a base component with an unknown type and an empty name.
Definition: BaseComponent.cpp:17

◆ ~BaseComponent()

RumPi::BaseComponent::~BaseComponent ( )
virtual

Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass.

Author
Eddie O'Hagan
Date
8/13/2026
BaseComponent* component = new LED(PIN_GPIO_12);
delete component; //runs LED's destructor via this virtual base destructor.
constexpr unsigned int PIN_GPIO_12
BCM GPIO pin 12.
Definition: Common.h:38

Member Function Documentation

◆ ComponentTypeToString()

std::string RumPi::BaseComponent::ComponentTypeToString ( const EComponentType  theComponentTypeToConvert)
static

Maps an EComponentType to its string name.

Keep this in sync with the EComponentType enum (and with StringToComponentType, its inverse).

Author
Eddie O'Hagan
Date
8/13/2026
static std::string ComponentTypeToString(const EComponentType theComponentTypeToConvert)
Maps an EComponentType to its string name.
Definition: BaseComponent.cpp:54
Parameters
[in]theComponentTypeToConvertThe component type to convert.
Returns
The type's string name, or "Unknown" if it is not recognized.

◆ GetComponentType()

EComponentType RumPi::BaseComponent::GetComponentType ( ) const
virtual

Gets the component's type.

Author
Eddie O'Hagan
Date
8/13/2026
if (component->GetComponentType() == EComponentType::E_LED)
{
//it's an LED...
}
Returns
The component's type.

◆ GetName()

const std::string & RumPi::BaseComponent::GetName ( ) const

Gets the component's unique per-instance name.

Author
Eddie O'Hagan
Date
8/13/2026
printf("Component: %s\n", component->GetName().c_str());
Returns
The component's unique name.

◆ ProcessRawValues()

virtual void RumPi::BaseComponent::ProcessRawValues ( )
pure virtual

Reads and processes the component's latest raw values (called once per poll).

Implemented by each concrete component.

Author
Eddie O'Hagan
Date
8/13/2026
component->ProcessRawValues(); //refresh this component's readings.

Implemented in RumPi::ComponentManager, RumPi::BMP180, RumPi::BMP280, RumPi::DHT11, RumPi::DualLED, RumPi::GasSensor, RumPi::HCSR501, RumPi::LCD1602, RumPi::LED, RumPi::MCP3008, RumPi::Motor, RumPi::PCF8591, RumPi::Photoresistor, RumPi::PiCamera, RumPi::PMS5003, RumPi::PTQS1005, RumPi::QSFS01, RumPi::RainSensor, RumPi::Receiver, RumPi::Relay, RumPi::RGBLED, RumPi::RotaryEncoder, RumPi::SoundSensor, RumPi::SystemHealthComponent, RumPi::TSL2591, and RumPi::Vehicle.

◆ SetName()

void RumPi::BaseComponent::SetName ( const std::string &  name)

Sets the component's unique per-instance name.

Normally called by the ComponentManager when the component is added, so every managed component ends up with a distinct name.

Author
Eddie O'Hagan
Date
8/13/2026
component->SetName("Status LED");
Parameters
[in]nameThe new name for the component.

◆ StringToComponentType()

EComponentType RumPi::BaseComponent::StringToComponentType ( const std::string &  theComponentTypeName)
static

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.

Author
Eddie O'Hagan
Date
8/13/2026
EComponentType type = BaseComponent::StringToComponentType("DHT11"); //EComponentType::E_DHT11
static EComponentType StringToComponentType(const std::string &theComponentTypeName)
Maps a type name back to its EComponentType (the inverse of ComponentTypeToString),...
Definition: BaseComponent.cpp:209
EComponentType
Identifies each kind of component the library supports.
Definition: BaseComponent.h:14
Parameters
[in]theComponentTypeNameThe type name to convert.
Returns
The matching EComponentType, or E_Unknown if the name is not recognized.

◆ ToString()

virtual std::string RumPi::BaseComponent::ToString ( ) const
pure virtual

Serializes the component's current readings to a string (usually JSON).

Implemented by each concrete component.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = component->ToString();
Returns
The component's serialized readings.

Implemented in RumPi::ComponentManager, RumPi::BMP180, RumPi::BMP280, RumPi::DHT11, RumPi::DualLED, RumPi::GasSensor, RumPi::HCSR501, RumPi::LCD1602, RumPi::LED, RumPi::MCP3008, RumPi::Motor, RumPi::MQ135, RumPi::MQ3, RumPi::MQ4, RumPi::MQ5, RumPi::MQ6, RumPi::MQ7, RumPi::MQ8, RumPi::MQ9, RumPi::PCF8591, RumPi::Photoresistor, RumPi::PiCamera, RumPi::PMS5003, RumPi::PTQS1005, RumPi::QSFS01, RumPi::RainSensor, RumPi::Receiver, RumPi::Relay, RumPi::RGBLED, RumPi::RotaryEncoder, RumPi::SoundSensor, RumPi::SystemHealthComponent, RumPi::TSL2591, and RumPi::Vehicle.

◆ TurnOff()

virtual void RumPi::BaseComponent::TurnOff ( )
pure virtual

◆ TurnOn()

virtual void RumPi::BaseComponent::TurnOn ( )
pure virtual

Member Data Documentation

◆ myComponentType

EComponentType RumPi::BaseComponent::myComponentType
protected

The kind of component this is (set by each concrete subclass).

◆ myName

std::string RumPi::BaseComponent::myName
protected

A unique per-instance name, assigned when the component is added to the manager.

Two components of the same type share a type but never a name, so the wire format and client UI key on this to tell them apart.


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