mirror of
https://github.com/esphome/esphome.git
synced 2025-04-18 00:30:29 +01:00
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Spencer Yan <spencer@spenyan.com>
51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
#pragma once
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/defines.h"
|
|
#ifdef USE_BINARY_SENSOR
|
|
#include "esphome/components/binary_sensor/binary_sensor.h"
|
|
#endif
|
|
#ifdef USE_SENSOR
|
|
#include "esphome/components/sensor/sensor.h"
|
|
#endif
|
|
#include "esphome/components/uart/uart.h"
|
|
#include "esphome/core/automation.h"
|
|
#include "esphome/core/helpers.h"
|
|
|
|
#include <map>
|
|
|
|
namespace esphome {
|
|
namespace seeed_mr60bha2 {
|
|
static const uint8_t FRAME_HEADER_BUFFER = 0x01;
|
|
static const uint16_t BREATH_RATE_TYPE_BUFFER = 0x0A14;
|
|
static const uint16_t PEOPLE_EXIST_TYPE_BUFFER = 0x0F09;
|
|
static const uint16_t HEART_RATE_TYPE_BUFFER = 0x0A15;
|
|
static const uint16_t DISTANCE_TYPE_BUFFER = 0x0A16;
|
|
static const uint16_t PRINT_CLOUD_BUFFER = 0x0A04;
|
|
|
|
class MR60BHA2Component : public Component,
|
|
public uart::UARTDevice { // The class name must be the name defined by text_sensor.py
|
|
#ifdef USE_BINARY_SENSOR
|
|
SUB_BINARY_SENSOR(has_target);
|
|
#endif
|
|
#ifdef USE_SENSOR
|
|
SUB_SENSOR(breath_rate);
|
|
SUB_SENSOR(heart_rate);
|
|
SUB_SENSOR(distance);
|
|
SUB_SENSOR(num_targets);
|
|
#endif
|
|
|
|
public:
|
|
float get_setup_priority() const override { return esphome::setup_priority::LATE; }
|
|
void dump_config() override;
|
|
void loop() override;
|
|
|
|
protected:
|
|
bool validate_message_();
|
|
void process_frame_(uint16_t frame_id, uint16_t frame_type, const uint8_t *data, size_t length);
|
|
|
|
std::vector<uint8_t> rx_message_;
|
|
};
|
|
|
|
} // namespace seeed_mr60bha2
|
|
} // namespace esphome
|