mirror of
https://github.com/esphome/esphome.git
synced 2026-10-15 02:32:49 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b1e76523b |
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
@@ -11,6 +12,19 @@ ESPHOME_LOG_TAG(TAG, "seeed_mr24hpc1");
|
||||
|
||||
static constexpr uint32_t STARTUP_DELAY_MS = 1000;
|
||||
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
PROGMEM_STRING_TABLE(MotionStatusStrings, "None", "Motionless", "Active");
|
||||
PROGMEM_STRING_TABLE(KeepAwayStrings, "None", "Close", "Away");
|
||||
|
||||
/// Copies a table entry out of flash and publishes it; the caller checks idx against Table::COUNT.
|
||||
template<typename Table> static void publish_table_str(text_sensor::TextSensor *sensor, uint8_t idx) {
|
||||
char text[Table::MAX_LENGTH + 1];
|
||||
ESPHOME_strncpy_P(text, reinterpret_cast<ESPHOME_PGM_P>(Table::get_progmem_str(idx, Table::LAST_INDEX)),
|
||||
sizeof(text));
|
||||
sensor->publish_state(text);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Prints the component's configuration data. dump_config() prints all of the component's configuration
|
||||
// items in an easy-to-read format, including the configuration key-value pairs.
|
||||
void MR24HPC1Component::dump_config() {
|
||||
@@ -447,10 +461,9 @@ void MR24HPC1Component::r24_frame_parse_open_underlying_information_(uint8_t *da
|
||||
}
|
||||
break;
|
||||
case 0x83:
|
||||
if (this->custom_presence_of_detection_sensor_ != nullptr &&
|
||||
data[FRAME_DATA_INDEX] < std::size(S_PRESENCE_OF_DETECTION_RANGE_STR)) {
|
||||
this->custom_presence_of_detection_sensor_->publish_state(
|
||||
S_PRESENCE_OF_DETECTION_RANGE_STR[data[FRAME_DATA_INDEX]]);
|
||||
// 0 to 3 m in steps of 0.5 m
|
||||
if (this->custom_presence_of_detection_sensor_ != nullptr && data[FRAME_DATA_INDEX] <= 6) {
|
||||
this->custom_presence_of_detection_sensor_->publish_state(data[FRAME_DATA_INDEX] * 0.5f);
|
||||
}
|
||||
break;
|
||||
case 0x84:
|
||||
@@ -468,8 +481,8 @@ void MR24HPC1Component::r24_frame_parse_open_underlying_information_(uint8_t *da
|
||||
case 0x06:
|
||||
case 0x86:
|
||||
// none:0x00 close_to:0x01 far_away:0x02
|
||||
if ((this->keep_away_text_sensor_ != nullptr) && (data[FRAME_DATA_INDEX] < 3)) {
|
||||
this->keep_away_text_sensor_->publish_state(S_KEEP_AWAY_STR[data[FRAME_DATA_INDEX]]);
|
||||
if ((this->keep_away_text_sensor_ != nullptr) && (data[FRAME_DATA_INDEX] < KeepAwayStrings::COUNT)) {
|
||||
publish_table_str<KeepAwayStrings>(this->keep_away_text_sensor_, data[FRAME_DATA_INDEX]);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
@@ -642,8 +655,8 @@ void MR24HPC1Component::r24_frame_parse_human_information_(uint8_t *data) {
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
case 0x01:
|
||||
case 0x81:
|
||||
if (this->has_target_binary_sensor_ != nullptr && data[FRAME_DATA_INDEX] < std::size(S_SOMEONE_EXISTS_STR)) {
|
||||
this->has_target_binary_sensor_->publish_state(S_SOMEONE_EXISTS_STR[data[FRAME_DATA_INDEX]]);
|
||||
if (this->has_target_binary_sensor_ != nullptr && data[FRAME_DATA_INDEX] <= 1) {
|
||||
this->has_target_binary_sensor_->publish_state(data[FRAME_DATA_INDEX] == 1);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
@@ -658,15 +671,15 @@ void MR24HPC1Component::r24_frame_parse_human_information_(uint8_t *data) {
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
case 0x02:
|
||||
case 0x82:
|
||||
if ((this->motion_status_text_sensor_ != nullptr) && (data[FRAME_DATA_INDEX] < 3)) {
|
||||
this->motion_status_text_sensor_->publish_state(S_MOTION_STATUS_STR[data[FRAME_DATA_INDEX]]);
|
||||
if ((this->motion_status_text_sensor_ != nullptr) && (data[FRAME_DATA_INDEX] < MotionStatusStrings::COUNT)) {
|
||||
publish_table_str<MotionStatusStrings>(this->motion_status_text_sensor_, data[FRAME_DATA_INDEX]);
|
||||
}
|
||||
break;
|
||||
case 0x0B:
|
||||
case 0x8B:
|
||||
// none:0x00 close_to:0x01 far_away:0x02
|
||||
if ((this->keep_away_text_sensor_ != nullptr) && (data[FRAME_DATA_INDEX] < 3)) {
|
||||
this->keep_away_text_sensor_->publish_state(S_KEEP_AWAY_STR[data[FRAME_DATA_INDEX]]);
|
||||
if ((this->keep_away_text_sensor_ != nullptr) && (data[FRAME_DATA_INDEX] < KeepAwayStrings::COUNT)) {
|
||||
publish_table_str<KeepAwayStrings>(this->keep_away_text_sensor_, data[FRAME_DATA_INDEX]);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -82,16 +82,6 @@ enum OutputSwitch {
|
||||
OUTPUT_SWTICH_OFF,
|
||||
};
|
||||
|
||||
static const char *const S_SCENE_STR[5] = {"None", "Living Room", "Bedroom", "Washroom", "Area Detection"};
|
||||
static const bool S_SOMEONE_EXISTS_STR[2] = {false, true};
|
||||
static const char *const S_MOTION_STATUS_STR[3] = {"None", "Motionless", "Active"};
|
||||
static const char *const S_KEEP_AWAY_STR[3] = {"None", "Close", "Away"};
|
||||
static const char *const S_UNMANNED_TIME_STR[9] = {"None", "10s", "30s", "1min", "2min",
|
||||
"5min", "10min", "30min", "60min"};
|
||||
static const char *const S_BOUNDARY_STR[10] = {"0.5m", "1.0m", "1.5m", "2.0m", "2.5m",
|
||||
"3.0m", "3.5m", "4.0m", "4.5m", "5.0m"}; // uint: m
|
||||
static const float S_PRESENCE_OF_DETECTION_RANGE_STR[7] = {0.0f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f}; // uint: m
|
||||
|
||||
class MR24HPC1Component final : public Component,
|
||||
public uart::UARTDevice { // The class name must be the name defined by text_sensor.py
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
|
||||
Reference in New Issue
Block a user