RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
HCSR501.h
Go to the documentation of this file.
1#pragma once
2#include <wiringPi.h>
3#include "BaseComponent.h"
4
5namespace RumPi
6{
14 class HCSR501 : public BaseComponent
15 {
16 private:
19
21 unsigned int myInputPinNumber;
22
28
29 public:
43 HCSR501(unsigned int inputPinNumber);
44
56 virtual ~HCSR501();
57
69 virtual void TurnOn() override;
70
81 virtual void TurnOff() override;
82
94 virtual void ProcessRawValues() override;
95
108 virtual std::string ToString() const override;
109
125 bool GetIsMotionDetected() const;
126
141 };
142} // namespace RumPi
Abstract base class for every component (sensor, actuator, etc.) the library manages.
Definition: BaseComponent.h:60
An HC-SR501 PIR motion sensor.
Definition: HCSR501.h:15
bool ConsumeMotionSinceLastRead()
Returns whether motion was seen since the last call, then clears the latch so the next window starts ...
Definition: HCSR501.cpp:166
unsigned int myInputPinNumber
The GPIO input pin the sensor is read from.
Definition: HCSR501.h:21
virtual void ProcessRawValues() override
Reads the sensor's pin (HIGH = motion) and latches any detection so a brief pulse between snapshots i...
Definition: HCSR501.cpp:89
HCSR501(unsigned int inputPinNumber)
Builds an HC-SR501 motion sensor on the given input pin, with no motion detected yet.
Definition: HCSR501.cpp:18
bool GetIsMotionDetected() const
Gets whether motion was detected on the most recent read.
Definition: HCSR501.cpp:148
virtual ~HCSR501()
Destroys the motion sensor.
Definition: HCSR501.cpp:38
virtual void TurnOn() override
Turns the sensor on: sets its pin as a digital input and enables the pull-down resistor so the line i...
Definition: HCSR501.cpp:54
virtual std::string ToString() const override
Serializes the sensor's current motion state to a string.
Definition: HCSR501.cpp:117
virtual void TurnOff() override
Turns the sensor off.
Definition: HCSR501.cpp:73
bool myMotionLatch
Latched "motion since the last read": ProcessRawValues raises it whenever the pin reads HIGH,...
Definition: HCSR501.h:27
bool myIsMotionDetected
Whether motion was detected on the most recent read.
Definition: HCSR501.h:18
RumPi is the library's top-level facade.
Definition: AlertManager.h:6