![]() |
RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
|
Abstract base class for every component (sensor, actuator, etc.) the library manages. More...
#include <BaseComponent.h>
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... | |
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.
| 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.
|
virtual |
Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass.
|
static |
Maps an EComponentType to its string name.
Keep this in sync with the EComponentType enum (and with StringToComponentType, its inverse).
| [in] | theComponentTypeToConvert | The component type to convert. |
|
virtual |
Gets the component's type.
| const std::string & RumPi::BaseComponent::GetName | ( | ) | const |
Gets the component's unique per-instance name.
|
pure virtual |
Reads and processes the component's latest raw values (called once per poll).
Implemented by each concrete component.
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.
| 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.
| [in] | name | The new name for the component. |
|
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.
| [in] | theComponentTypeName | The type name to convert. |
|
pure virtual |
Serializes the component's current readings to a string (usually JSON).
Implemented by each concrete component.
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.
|
pure virtual |
Turns the component off.
Implemented by each concrete component.
Implemented in RumPi::GasSensor, RumPi::ComponentManager, RumPi::BMP180, RumPi::BMP280, RumPi::DHT11, RumPi::DualLED, 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.
|
pure virtual |
Turns the component on (e.g.
powers a sensor, lights an LED). Implemented by each concrete component.
Implemented in RumPi::GasSensor, RumPi::ComponentManager, RumPi::BMP180, RumPi::BMP280, RumPi::DHT11, RumPi::DualLED, 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.
|
protected |
The kind of component this is (set by each concrete subclass).
|
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.