![]() |
RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
|
An HC-SR501 PIR motion sensor. More...
#include <HCSR501.h>
Public Member Functions | |
| HCSR501 (unsigned int inputPinNumber) | |
| Builds an HC-SR501 motion sensor on the given input pin, with no motion detected yet. More... | |
| virtual | ~HCSR501 () |
| Destroys the motion sensor. More... | |
| virtual void | TurnOn () override |
| Turns the sensor on: sets its pin as a digital input and enables the pull-down resistor so the line idles LOW and reads HIGH only on motion. More... | |
| virtual void | TurnOff () override |
| Turns the sensor off. More... | |
| virtual void | ProcessRawValues () override |
| Reads the sensor's pin (HIGH = motion) and latches any detection so a brief pulse between snapshots is not lost. More... | |
| virtual std::string | ToString () const override |
| Serializes the sensor's current motion state to a string. More... | |
| bool | GetIsMotionDetected () const |
| Gets whether motion was detected on the most recent read. More... | |
| bool | ConsumeMotionSinceLastRead () |
| Returns whether motion was seen since the last call, then clears the latch so the next window starts fresh. 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... | |
Private Attributes | |
| bool | myIsMotionDetected |
| Whether motion was detected on the most recent read. More... | |
| unsigned int | myInputPinNumber |
| The GPIO input pin the sensor is read from. More... | |
| bool | myMotionLatch |
| Latched "motion since the last read": ProcessRawValues raises it whenever the pin reads HIGH, and the snapshot consumes it via ConsumeMotionSinceLastRead(). 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... | |
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... | |
An HC-SR501 PIR motion sensor.
Fast-sampled each poll; a brief motion pulse is latched so it is not lost between the less-frequent snapshots.
| RumPi::HCSR501::HCSR501 | ( | unsigned int | inputPinNumber | ) |
Builds an HC-SR501 motion sensor on the given input pin, with no motion detected yet.
| [in] | inputPinNumber | The BCM GPIO input pin the sensor is read from. |
|
virtual |
| bool RumPi::HCSR501::ConsumeMotionSinceLastRead | ( | ) |
Returns whether motion was seen since the last call, then clears the latch so the next window starts fresh.
Used by the dashboard snapshot so a brief motion pulse between snapshots is still reported once.
| bool RumPi::HCSR501::GetIsMotionDetected | ( | ) | const |
Gets whether motion was detected on the most recent read.
|
overridevirtual |
Reads the sensor's pin (HIGH = motion) and latches any detection so a brief pulse between snapshots is not lost.
Fast-sampling this sensor (~100ms) is what makes the short HIGH reliably land in one of these reads.
Implements RumPi::BaseComponent.
|
overridevirtual |
Serializes the sensor's current motion state to a string.
Implements RumPi::BaseComponent.
|
overridevirtual |
Turns the sensor off.
The input pin needs no active teardown, so this is effectively a no-op.
Implements RumPi::BaseComponent.
|
overridevirtual |
Turns the sensor on: sets its pin as a digital input and enables the pull-down resistor so the line idles LOW and reads HIGH only on motion.
Implements RumPi::BaseComponent.
|
private |
The GPIO input pin the sensor is read from.
|
private |
Whether motion was detected on the most recent read.
|
private |
Latched "motion since the last read": ProcessRawValues raises it whenever the pin reads HIGH, and the snapshot consumes it via ConsumeMotionSinceLastRead().
Fast-sampling the sensor (~every 100ms) is what makes a brief motion pulse land in one of these reads even though we only build the snapshot every couple of seconds. Only the worker thread touches it, so a plain bool is enough.