Files
esphome-dev/esphome/components/ultrasonic/ultrasonic_sensor.h
T
Otto Winter 8e75980ebd Cleanup dashboard JS (#491)
* Cleanup dashboard JS

* Add vscode

* Save start_mark/end_mark

* Updates

* Updates

* Remove need for cv.nameable

It's a bit hacky but removes so much bloat from integrations

* Add enum helper

* Document APIs, and Improvements

* Fixes

* Fixes

* Update PULL_REQUEST_TEMPLATE.md

* Updates

* Updates

* Updates
2019-04-22 21:56:30 +02:00

44 lines
1.3 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/core/esphal.h"
#include "esphome/components/sensor/sensor.h"
namespace esphome {
namespace ultrasonic {
class UltrasonicSensorComponent : public sensor::Sensor, public PollingComponent {
public:
void set_trigger_pin(GPIOPin *trigger_pin) { trigger_pin_ = trigger_pin; }
void set_echo_pin(GPIOPin *echo_pin) { echo_pin_ = echo_pin; }
/// Set the timeout for waiting for the echo in µs.
void set_timeout_us(uint32_t timeout_us);
// ========== INTERNAL METHODS ==========
// (In most use cases you won't need these)
/// Set up pins and register interval.
void setup() override;
void dump_config() override;
void update() override;
float get_setup_priority() const override;
/// Set the time in µs the trigger pin should be enabled for in µs, defaults to 10µs (for HC-SR04)
void set_pulse_time_us(uint32_t pulse_time_us);
protected:
/// Helper function to convert the specified echo duration in µs to meters.
static float us_to_m(uint32_t us);
/// Helper function to convert the specified distance in meters to the echo duration in µs.
GPIOPin *trigger_pin_;
GPIOPin *echo_pin_;
uint32_t timeout_us_{}; /// 2 meters.
uint32_t pulse_time_us_{};
};
} // namespace ultrasonic
} // namespace esphome