Added temperature and relay nodes
This commit is contained in:
71
lib/HomieNodes/PingNode.hpp
Normal file
71
lib/HomieNodes/PingNode.hpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* BME280Node.h
|
||||
* Homie Node for BME280 sensors using Adafruit BME280 library.
|
||||
*
|
||||
* Version: 1.1
|
||||
* Author: Lübbe Onken (http://github.com/luebbe)
|
||||
* Author: Markus Haack (http://github.com/mhaack)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "NewPing.h"
|
||||
|
||||
#include "SensorNode.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
#define DEFAULTPIN -1
|
||||
|
||||
class PingNode : public SensorNode
|
||||
{
|
||||
public:
|
||||
typedef std::function<void()> ChangeHandler;
|
||||
private:
|
||||
const float cMinDistance = 0.0;
|
||||
const float cMaxDistance = 3.0;
|
||||
const float cMinimumChange = 0.2;
|
||||
|
||||
static const int MIN_INTERVAL = 1; // in seconds
|
||||
const char *cCaption = "• RCW-0001 sensor";
|
||||
const char *cIndent = " ◦ ";
|
||||
|
||||
int _triggerPin;
|
||||
int _echoPin;
|
||||
float _microseconds2meter;
|
||||
|
||||
unsigned long _measurementInterval;
|
||||
unsigned long _lastMeasurement;
|
||||
unsigned long _publishInterval;
|
||||
unsigned long _lastPublish;
|
||||
|
||||
NewPing* sonar;
|
||||
float _distance = NAN;
|
||||
int _ping_us = NAN;
|
||||
float _lastDistance = 0;
|
||||
ChangeHandler _changeHandler = [](){};
|
||||
|
||||
float getRawEchoTime();
|
||||
void setMicrosecondsToMetersFactor(float temperatureCelcius);
|
||||
bool signalChange(float distance, float lastDistance);
|
||||
void printCaption();
|
||||
void send();
|
||||
|
||||
protected:
|
||||
virtual void setup() override;
|
||||
virtual void loop() override;
|
||||
virtual void onReadyToOperate() override;
|
||||
static const int DEFAULT_MEASUREMENT_INTERVAL = 1;
|
||||
static const int DEFAULT_PUBLISH_INTERVAL = 5;
|
||||
|
||||
|
||||
public:
|
||||
explicit PingNode(const char *name,
|
||||
const int triggerPin = DEFAULTPIN,
|
||||
const int echoPin = DEFAULTPIN,
|
||||
const int measurementInterval = DEFAULT_MEASUREMENT_INTERVAL,
|
||||
const int publishInterval = DEFAULT_PUBLISH_INTERVAL);
|
||||
|
||||
float getDistance() const { return _distance; }
|
||||
void setTemperature(float temperatureCelcius) { setMicrosecondsToMetersFactor(temperatureCelcius); }
|
||||
PingNode& setChangeHandler(const ChangeHandler& changeHandler);
|
||||
};
|
||||
Reference in New Issue
Block a user