mirror of
https://github.com/esphome/esphome.git
synced 2025-02-24 13:58:14 +00:00
* 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
38 lines
874 B
C++
38 lines
874 B
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/esphal.h"
|
|
#include "esphome/components/sensor/sensor.h"
|
|
|
|
namespace esphome {
|
|
namespace duty_cycle {
|
|
|
|
/// Store data in a class that doesn't use multiple-inheritance (vtables in flash)
|
|
struct DutyCycleSensorStore {
|
|
volatile uint32_t last_interrupt{0};
|
|
volatile uint32_t on_time{0};
|
|
volatile bool last_level{false};
|
|
ISRInternalGPIOPin *pin;
|
|
|
|
static void gpio_intr(DutyCycleSensorStore *arg);
|
|
};
|
|
|
|
class DutyCycleSensor : public sensor::Sensor, public PollingComponent {
|
|
public:
|
|
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
|
|
|
void setup() override;
|
|
float get_setup_priority() const override;
|
|
void dump_config() override;
|
|
void update() override;
|
|
|
|
protected:
|
|
GPIOPin *pin_;
|
|
|
|
DutyCycleSensorStore store_;
|
|
uint32_t last_update_;
|
|
};
|
|
|
|
} // namespace duty_cycle
|
|
} // namespace esphome
|