Remove distance sensor and esp32 always-true

This commit is contained in:
2026-05-21 20:36:01 +00:00
parent 5ba4ce86f4
commit fd14ff3434
9 changed files with 7 additions and 55 deletions
@@ -34,11 +34,9 @@ void RATGDONumber::dump_config()
case RATGDO_CLOSING_DURATION: case RATGDO_CLOSING_DURATION:
ESP_LOGCONFIG(TAG, " Type: Closing Duration"); ESP_LOGCONFIG(TAG, " Type: Closing Duration");
break; break;
#ifdef RATGDO_USE_DISTANCE_SENSOR
case RATGDO_TARGET_DISTANCE_MEASUREMENT: case RATGDO_TARGET_DISTANCE_MEASUREMENT:
ESP_LOGCONFIG(TAG, " Type: Target Distance Measurement"); ESP_LOGCONFIG(TAG, " Type: Target Distance Measurement");
break; break;
#endif
default: default:
break; break;
} }
@@ -81,13 +79,11 @@ void RATGDONumber::setup()
this->update_state(value); this->update_state(value);
}); });
break; break;
#ifdef RATGDO_USE_DISTANCE_SENSOR
case RATGDO_TARGET_DISTANCE_MEASUREMENT: case RATGDO_TARGET_DISTANCE_MEASUREMENT:
// this->parent_->subscribe_target_distance_measurement([=](float value) { // this->parent_->subscribe_target_distance_measurement([=](float value) {
// this->update_state(value); // this->update_state(value);
// }); // });
break; break;
#endif
default: default:
break; break;
} }
@@ -111,13 +107,11 @@ void RATGDONumber::set_number_type(NumberType number_type_)
this->traits.set_min_value(0x539); this->traits.set_min_value(0x539);
this->traits.set_max_value(0x7ff539); this->traits.set_max_value(0x7ff539);
break; break;
#ifdef RATGDO_USE_DISTANCE_SENSOR
case RATGDO_TARGET_DISTANCE_MEASUREMENT: case RATGDO_TARGET_DISTANCE_MEASUREMENT:
this->traits.set_step(1); this->traits.set_step(1);
this->traits.set_min_value(5); this->traits.set_min_value(5);
this->traits.set_max_value(3500); this->traits.set_max_value(3500);
break; break;
#endif
default: default:
break; break;
} }
@@ -148,11 +142,9 @@ void RATGDONumber::control(float value)
value = normalize_client_id(value); value = normalize_client_id(value);
this->parent_->call_protocol(SetClientID { static_cast<uint32_t>(value) }); this->parent_->call_protocol(SetClientID { static_cast<uint32_t>(value) });
break; break;
#ifdef RATGDO_USE_DISTANCE_SENSOR
case RATGDO_TARGET_DISTANCE_MEASUREMENT: case RATGDO_TARGET_DISTANCE_MEASUREMENT:
this->parent_->set_target_distance_measurement(value); this->parent_->set_target_distance_measurement(value);
break; break;
#endif
default: default:
break; break;
} }
-2
View File
@@ -13,9 +13,7 @@ enum NumberType {
RATGDO_ROLLING_CODE_COUNTER, RATGDO_ROLLING_CODE_COUNTER,
RATGDO_OPENING_DURATION, RATGDO_OPENING_DURATION,
RATGDO_CLOSING_DURATION, RATGDO_CLOSING_DURATION,
#ifdef RATGDO_USE_DISTANCE_SENSOR
RATGDO_TARGET_DISTANCE_MEASUREMENT, RATGDO_TARGET_DISTANCE_MEASUREMENT,
#endif
}; };
class RATGDONumber : public number::Number, public RATGDOClient, public Component { class RATGDONumber : public number::Number, public RATGDOClient, public Component {
-2
View File
@@ -266,7 +266,6 @@ void RATGDOComponent::set_closing_duration(float duration)
this->closing_duration = duration; this->closing_duration = duration;
} }
#ifdef RATGDO_USE_DISTANCE_SENSOR
void RATGDOComponent::set_target_distance_measurement(int16_t distance) void RATGDOComponent::set_target_distance_measurement(int16_t distance)
{ {
this->target_distance_measurement = distance; this->target_distance_measurement = distance;
@@ -276,7 +275,6 @@ void RATGDOComponent::set_distance_measurement(int16_t distance)
{ {
this->last_distance_measurement = distance; this->last_distance_measurement = distance;
} }
#endif
Result RATGDOComponent::call_protocol(Args args) Result RATGDOComponent::call_protocol(Args args)
{ {
-14
View File
@@ -73,11 +73,9 @@ public:
float start_closing { -1 }; float start_closing { -1 };
single_observable<float> closing_duration { 0 }; single_observable<float> closing_duration { 0 };
#ifdef RATGDO_USE_DISTANCE_SENSOR
single_observable<int16_t> target_distance_measurement { -1 }; single_observable<int16_t> target_distance_measurement { -1 };
std::bitset<256> in_range; // the length of this bitset determines how many out of range readings are required for presence detection to change states std::bitset<256> in_range; // the length of this bitset determines how many out of range readings are required for presence detection to change states
observable<int16_t, RATGDO_MAX_DISTANCE_SUBSCRIBERS> last_distance_measurement { 0 }; observable<int16_t, RATGDO_MAX_DISTANCE_SUBSCRIBERS> last_distance_measurement { 0 };
#endif
single_observable<uint16_t> openings { 0 }; // number of times the door has been opened single_observable<uint16_t> openings { 0 }; // number of times the door has been opened
@@ -122,10 +120,8 @@ public:
void schedule_door_position_sync(float update_period = 500); void schedule_door_position_sync(float update_period = 500);
void door_position_update(); void door_position_update();
void cancel_position_sync_callbacks(); void cancel_position_sync_callbacks();
#ifdef RATGDO_USE_DISTANCE_SENSOR
void set_target_distance_measurement(int16_t distance); void set_target_distance_measurement(int16_t distance);
void set_distance_measurement(int16_t distance); void set_distance_measurement(int16_t distance);
#endif
// light // light
void light_on(); void light_on();
@@ -204,10 +200,8 @@ public:
void subscribe_sync_failed(F&& f); void subscribe_sync_failed(F&& f);
template <typename F> template <typename F>
void subscribe_door_action_delayed(F&& f); void subscribe_door_action_delayed(F&& f);
#ifdef RATGDO_USE_DISTANCE_SENSOR
template <typename F> template <typename F>
void subscribe_distance_measurement(F&& f); void subscribe_distance_measurement(F&& f);
#endif
protected: protected:
// Pointers first (4-byte aligned) // Pointers first (4-byte aligned)
@@ -223,9 +217,7 @@ protected:
// Subscriber counters for defer name allocation // Subscriber counters for defer name allocation
uint8_t door_state_sub_num_ { 0 }; uint8_t door_state_sub_num_ { 0 };
uint8_t door_action_delayed_sub_num_ { 0 }; uint8_t door_action_delayed_sub_num_ { 0 };
#ifdef RATGDO_USE_DISTANCE_SENSOR
uint8_t distance_sub_num_ { 0 }; uint8_t distance_sub_num_ { 0 };
#endif
}; // RATGDOComponent }; // RATGDOComponent
void log_subscriber_overflow(const LogString* observable_name, uint32_t max); void log_subscriber_overflow(const LogString* observable_name, uint32_t max);
@@ -255,13 +247,9 @@ namespace scheduler_ids {
inline constexpr uint32_t DEFER_DOOR_ACTION_DELAYED_COUNT = RATGDO_MAX_DOOR_ACTION_DELAYED_SUBSCRIBERS; inline constexpr uint32_t DEFER_DOOR_ACTION_DELAYED_COUNT = RATGDO_MAX_DOOR_ACTION_DELAYED_SUBSCRIBERS;
inline constexpr uint32_t DEFER_DOOR_ACTION_DELAYED_BASE = DEFER_DOOR_STATE_BASE + DEFER_DOOR_STATE_COUNT; inline constexpr uint32_t DEFER_DOOR_ACTION_DELAYED_BASE = DEFER_DOOR_STATE_BASE + DEFER_DOOR_STATE_COUNT;
#ifdef RATGDO_USE_DISTANCE_SENSOR
inline constexpr uint32_t DEFER_DISTANCE_COUNT = RATGDO_MAX_DISTANCE_SUBSCRIBERS; inline constexpr uint32_t DEFER_DISTANCE_COUNT = RATGDO_MAX_DISTANCE_SUBSCRIBERS;
inline constexpr uint32_t DEFER_DISTANCE_BASE = DEFER_DOOR_ACTION_DELAYED_BASE + DEFER_DOOR_ACTION_DELAYED_COUNT; inline constexpr uint32_t DEFER_DISTANCE_BASE = DEFER_DOOR_ACTION_DELAYED_BASE + DEFER_DOOR_ACTION_DELAYED_COUNT;
inline constexpr uint32_t DEFER_DISTANCE_END = DEFER_DISTANCE_BASE + DEFER_DISTANCE_COUNT; inline constexpr uint32_t DEFER_DISTANCE_END = DEFER_DISTANCE_BASE + DEFER_DISTANCE_COUNT;
#else
inline constexpr uint32_t DEFER_DISTANCE_END = DEFER_DOOR_ACTION_DELAYED_BASE + DEFER_DOOR_ACTION_DELAYED_COUNT;
#endif
// Single-subscriber IDs // Single-subscriber IDs
enum : uint32_t { enum : uint32_t {
@@ -368,7 +356,6 @@ void RATGDOComponent::subscribe_door_action_delayed(F&& f)
}); });
} }
#ifdef RATGDO_USE_DISTANCE_SENSOR
template <typename F> template <typename F>
void RATGDOComponent::subscribe_distance_measurement(F&& f) void RATGDOComponent::subscribe_distance_measurement(F&& f)
{ {
@@ -378,6 +365,5 @@ void RATGDOComponent::subscribe_distance_measurement(F&& f)
defer(id, [f, state] { f(state); }); defer(id, [f, state] { f(state); });
}); });
} }
#endif
} // namespace esphome::ratgdo } // namespace esphome::ratgdo
-4
View File
@@ -1,7 +1,5 @@
#include "ratgdo_uart.h" #include "ratgdo_uart.h"
#ifdef USE_ESP32
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include <driver/uart.h> #include <driver/uart.h>
@@ -183,5 +181,3 @@ void RatgdoUART::on_shutdown()
} }
} // namespace esphome::ratgdo } // namespace esphome::ratgdo
#endif
-4
View File
@@ -2,8 +2,6 @@
#include "esphome/core/defines.h" #include "esphome/core/defines.h"
#ifdef USE_ESP32
#include <driver/rmt_tx.h> #include <driver/rmt_tx.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@@ -53,5 +51,3 @@ private:
}; };
} // namespace esphome::ratgdo } // namespace esphome::ratgdo
#endif
+7 -9
View File
@@ -55,12 +55,10 @@ async def to_code(config):
cg.add(var.set_ratgdo_sensor_type(config[CONF_TYPE])) cg.add(var.set_ratgdo_sensor_type(config[CONF_TYPE]))
await register_ratgdo_child(var, config) await register_ratgdo_child(var, config)
if config["type"] == "distance": cg.add_library(name="Wire", version=None)
cg.add_library(name="Wire", version=None) cg.add_library(
cg.add_library( name="vl53l4cx",
name="vl53l4cx", repository="https://github.com/stm32duino/VL53L4CX",
repository="https://github.com/stm32duino/VL53L4CX", version=None,
version=None, )
) subscribe_distance()
cg.add_define("RATGDO_USE_DISTANCE_SENSOR")
subscribe_distance()
@@ -17,7 +17,6 @@ void RATGDOSensor::setup()
}); });
break; break;
case RATGDOSensorType::RATGDO_DISTANCE: case RATGDOSensorType::RATGDO_DISTANCE:
#ifdef RATGDO_USE_DISTANCE_SENSOR
this->distance_sensor_.setI2cDevice(&I2C); this->distance_sensor_.setI2cDevice(&I2C);
this->distance_sensor_.setXShutPin(32); this->distance_sensor_.setXShutPin(32);
// I2C.begin(17,16); // I2C.begin(17,16);
@@ -27,12 +26,9 @@ void RATGDOSensor::setup()
this->distance_sensor_.InitSensor(0x59); this->distance_sensor_.InitSensor(0x59);
this->distance_sensor_.VL53L4CX_SetDistanceMode(VL53L4CX_DISTANCEMODE_LONG); this->distance_sensor_.VL53L4CX_SetDistanceMode(VL53L4CX_DISTANCEMODE_LONG);
this->distance_sensor_.VL53L4CX_StartMeasurement(); this->distance_sensor_.VL53L4CX_StartMeasurement();
#ifdef RATGDO_USE_DISTANCE_SENSOR
this->parent_->subscribe_distance_measurement([this](int16_t value) { this->parent_->subscribe_distance_measurement([this](int16_t value) {
this->publish_state(value); this->publish_state(value);
}); });
#endif
#endif
break; break;
default: default:
break; break;
@@ -54,7 +50,6 @@ void RATGDOSensor::dump_config()
} }
} }
#ifdef RATGDO_USE_DISTANCE_SENSOR
void RATGDOSensor::loop() void RATGDOSensor::loop()
{ {
if (this->ratgdo_sensor_type_ == RATGDOSensorType::RATGDO_DISTANCE) { if (this->ratgdo_sensor_type_ == RATGDOSensorType::RATGDO_DISTANCE) {
@@ -97,6 +92,5 @@ void RATGDOSensor::loop()
} }
} }
} }
#endif
} // namespace esphome::ratgdo } // namespace esphome::ratgdo
-6
View File
@@ -6,11 +6,9 @@
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/defines.h" #include "esphome/core/defines.h"
#ifdef RATGDO_USE_DISTANCE_SENSOR
#include "Wire.h" #include "Wire.h"
#include "vl53l4cx_class.h" #include "vl53l4cx_class.h"
#define I2C Wire #define I2C Wire
#endif
namespace esphome::ratgdo { namespace esphome::ratgdo {
@@ -23,17 +21,13 @@ class RATGDOSensor : public sensor::Sensor, public RATGDOClient, public Componen
public: public:
void dump_config() override; void dump_config() override;
void setup() override; void setup() override;
#ifdef RATGDO_USE_DISTANCE_SENSOR
void loop() override; void loop() override;
#endif
void set_ratgdo_sensor_type(RATGDOSensorType ratgdo_sensor_type_) { this->ratgdo_sensor_type_ = ratgdo_sensor_type_; } void set_ratgdo_sensor_type(RATGDOSensorType ratgdo_sensor_type_) { this->ratgdo_sensor_type_ = ratgdo_sensor_type_; }
protected: protected:
RATGDOSensorType ratgdo_sensor_type_; RATGDOSensorType ratgdo_sensor_type_;
#ifdef RATGDO_USE_DISTANCE_SENSOR
VL53L4CX distance_sensor_; VL53L4CX distance_sensor_;
#endif
}; };
} // namespace esphome::ratgdo } // namespace esphome::ratgdo