Button to play sample alert tone
This commit is contained in:
@@ -22,7 +22,6 @@ class RATGDOData:
|
|||||||
"""Track observable subscriber counts for compile-time sizing."""
|
"""Track observable subscriber counts for compile-time sizing."""
|
||||||
|
|
||||||
door_state: int = 0
|
door_state: int = 0
|
||||||
door_action_delayed: int = 0
|
|
||||||
distance: int = 0
|
distance: int = 0
|
||||||
|
|
||||||
|
|
||||||
@@ -36,10 +35,6 @@ def subscribe_door_state() -> None:
|
|||||||
_get_data().door_state += 1
|
_get_data().door_state += 1
|
||||||
|
|
||||||
|
|
||||||
def subscribe_door_action_delayed() -> None:
|
|
||||||
_get_data().door_action_delayed += 1
|
|
||||||
|
|
||||||
|
|
||||||
def subscribe_distance() -> None:
|
def subscribe_distance() -> None:
|
||||||
_get_data().distance += 1
|
_get_data().distance += 1
|
||||||
|
|
||||||
@@ -49,9 +44,6 @@ async def _emit_subscriber_defines():
|
|||||||
"""Emit observable subscriber count defines after all children have registered."""
|
"""Emit observable subscriber count defines after all children have registered."""
|
||||||
data = _get_data()
|
data = _get_data()
|
||||||
cg.add_define("RATGDO_MAX_DOOR_STATE_SUBSCRIBERS", data.door_state)
|
cg.add_define("RATGDO_MAX_DOOR_STATE_SUBSCRIBERS", data.door_state)
|
||||||
cg.add_define(
|
|
||||||
"RATGDO_MAX_DOOR_ACTION_DELAYED_SUBSCRIBERS", data.door_action_delayed
|
|
||||||
)
|
|
||||||
cg.add_define("RATGDO_MAX_DISTANCE_SUBSCRIBERS", data.distance)
|
cg.add_define("RATGDO_MAX_DISTANCE_SUBSCRIBERS", data.distance)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ TYPES = {
|
|||||||
"rolling_code_counter": NumberType.RATGDO_ROLLING_CODE_COUNTER,
|
"rolling_code_counter": NumberType.RATGDO_ROLLING_CODE_COUNTER,
|
||||||
"opening_duration": NumberType.RATGDO_OPENING_DURATION,
|
"opening_duration": NumberType.RATGDO_OPENING_DURATION,
|
||||||
"closing_duration": NumberType.RATGDO_CLOSING_DURATION,
|
"closing_duration": NumberType.RATGDO_CLOSING_DURATION,
|
||||||
"target_distance_measurement": NumberType.RATGDO_TARGET_DISTANCE_MEASUREMENT,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ 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;
|
||||||
case RATGDO_TARGET_DISTANCE_MEASUREMENT:
|
|
||||||
ESP_LOGCONFIG(TAG, " Type: Target Distance Measurement");
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -79,11 +76,6 @@ void RATGDONumber::setup()
|
|||||||
this->update_state(value);
|
this->update_state(value);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case RATGDO_TARGET_DISTANCE_MEASUREMENT:
|
|
||||||
// this->parent_->subscribe_target_distance_measurement([=](float value) {
|
|
||||||
// this->update_state(value);
|
|
||||||
// });
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -107,11 +99,6 @@ 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;
|
||||||
case RATGDO_TARGET_DISTANCE_MEASUREMENT:
|
|
||||||
this->traits.set_step(1);
|
|
||||||
this->traits.set_min_value(5);
|
|
||||||
this->traits.set_max_value(3500);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -142,9 +129,6 @@ 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;
|
||||||
case RATGDO_TARGET_DISTANCE_MEASUREMENT:
|
|
||||||
this->parent_->set_target_distance_measurement(value);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ enum NumberType {
|
|||||||
RATGDO_ROLLING_CODE_COUNTER,
|
RATGDO_ROLLING_CODE_COUNTER,
|
||||||
RATGDO_OPENING_DURATION,
|
RATGDO_OPENING_DURATION,
|
||||||
RATGDO_CLOSING_DURATION,
|
RATGDO_CLOSING_DURATION,
|
||||||
RATGDO_TARGET_DISTANCE_MEASUREMENT,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RATGDONumber : public number::Number, public RATGDOClient, public Component {
|
class RATGDONumber : public number::Number, public RATGDOClient, public Component {
|
||||||
|
|||||||
@@ -266,11 +266,6 @@ void RATGDOComponent::set_closing_duration(float duration)
|
|||||||
this->closing_duration = duration;
|
this->closing_duration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::set_target_distance_measurement(int16_t distance)
|
|
||||||
{
|
|
||||||
this->target_distance_measurement = distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RATGDOComponent::set_distance_measurement(int16_t distance)
|
void RATGDOComponent::set_distance_measurement(int16_t distance)
|
||||||
{
|
{
|
||||||
this->last_distance_measurement = distance;
|
this->last_distance_measurement = distance;
|
||||||
|
|||||||
@@ -28,22 +28,6 @@
|
|||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "ratgdo_state.h"
|
#include "ratgdo_state.h"
|
||||||
|
|
||||||
// Observable subscriber counts — set by Python codegen via cg.add_define().
|
|
||||||
// Missing defines are a build error to catch codegen issues early.
|
|
||||||
#ifndef RATGDO_MAX_DOOR_STATE_SUBSCRIBERS
|
|
||||||
#error "RATGDO_MAX_DOOR_STATE_SUBSCRIBERS must be defined by codegen"
|
|
||||||
#endif
|
|
||||||
#ifndef RATGDO_MAX_DOOR_ACTION_DELAYED_SUBSCRIBERS
|
|
||||||
#error "RATGDO_MAX_DOOR_ACTION_DELAYED_SUBSCRIBERS must be defined by codegen"
|
|
||||||
#endif
|
|
||||||
#ifndef RATGDO_MAX_DISTANCE_SUBSCRIBERS
|
|
||||||
#error "RATGDO_MAX_DISTANCE_SUBSCRIBERS must be defined by codegen"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace esphome {
|
|
||||||
class InternalGPIOPin;
|
|
||||||
} // namespace esphome
|
|
||||||
|
|
||||||
namespace esphome::ratgdo {
|
namespace esphome::ratgdo {
|
||||||
|
|
||||||
class RATGDOComponent;
|
class RATGDOComponent;
|
||||||
@@ -73,7 +57,6 @@ public:
|
|||||||
float start_closing { -1 };
|
float start_closing { -1 };
|
||||||
single_observable<float> closing_duration { 0 };
|
single_observable<float> closing_duration { 0 };
|
||||||
|
|
||||||
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 };
|
||||||
|
|
||||||
@@ -81,7 +64,6 @@ public:
|
|||||||
|
|
||||||
observable<DoorState, RATGDO_MAX_DOOR_STATE_SUBSCRIBERS> door_state { DoorState::UNKNOWN };
|
observable<DoorState, RATGDO_MAX_DOOR_STATE_SUBSCRIBERS> door_state { DoorState::UNKNOWN };
|
||||||
observable<float, RATGDO_MAX_DOOR_STATE_SUBSCRIBERS> door_position { DOOR_POSITION_UNKNOWN };
|
observable<float, RATGDO_MAX_DOOR_STATE_SUBSCRIBERS> door_position { DOOR_POSITION_UNKNOWN };
|
||||||
observable<DoorActionDelayed, RATGDO_MAX_DOOR_ACTION_DELAYED_SUBSCRIBERS> door_action_delayed { DoorActionDelayed::NO };
|
|
||||||
|
|
||||||
unsigned long door_start_moving { 0 };
|
unsigned long door_start_moving { 0 };
|
||||||
float door_start_position { DOOR_POSITION_UNKNOWN };
|
float door_start_position { DOOR_POSITION_UNKNOWN };
|
||||||
@@ -120,7 +102,6 @@ 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();
|
||||||
void set_target_distance_measurement(int16_t distance);
|
|
||||||
void set_distance_measurement(int16_t distance);
|
void set_distance_measurement(int16_t distance);
|
||||||
|
|
||||||
// light
|
// light
|
||||||
@@ -199,8 +180,6 @@ public:
|
|||||||
template <typename F>
|
template <typename F>
|
||||||
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);
|
|
||||||
template <typename F>
|
|
||||||
void subscribe_distance_measurement(F&& f);
|
void subscribe_distance_measurement(F&& f);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -216,7 +195,6 @@ 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 distance_sub_num_ { 0 };
|
uint8_t distance_sub_num_ { 0 };
|
||||||
}; // RATGDOComponent
|
}; // RATGDOComponent
|
||||||
|
|
||||||
@@ -244,11 +222,8 @@ namespace scheduler_ids {
|
|||||||
inline constexpr uint32_t DEFER_DOOR_STATE_COUNT = RATGDO_MAX_DOOR_STATE_SUBSCRIBERS;
|
inline constexpr uint32_t DEFER_DOOR_STATE_COUNT = RATGDO_MAX_DOOR_STATE_SUBSCRIBERS;
|
||||||
inline constexpr uint32_t DEFER_DOOR_STATE_BASE = INTERVAL_POSITION_SYNC + 1;
|
inline constexpr uint32_t DEFER_DOOR_STATE_BASE = INTERVAL_POSITION_SYNC + 1;
|
||||||
|
|
||||||
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_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_STATE_BASE + DEFER_DOOR_STATE_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;
|
||||||
|
|
||||||
// Single-subscriber IDs
|
// Single-subscriber IDs
|
||||||
@@ -346,16 +321,6 @@ void RATGDOComponent::subscribe_sync_failed(F&& f)
|
|||||||
this->sync_failed.subscribe(std::forward<F>(f));
|
this->sync_failed.subscribe(std::forward<F>(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
|
||||||
void RATGDOComponent::subscribe_door_action_delayed(F&& f)
|
|
||||||
{
|
|
||||||
uint32_t id = get_scheduler_id(scheduler_ids::DEFER_DOOR_ACTION_DELAYED_BASE, scheduler_ids::DEFER_DOOR_ACTION_DELAYED_COUNT,
|
|
||||||
this->door_action_delayed_sub_num_, LOG_STR("door_action_delayed"));
|
|
||||||
this->door_action_delayed.subscribe([this, f, id](DoorActionDelayed state) {
|
|
||||||
defer(id, [f, state] { f(state); });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
void RATGDOComponent::subscribe_distance_measurement(F&& f)
|
void RATGDOComponent::subscribe_distance_measurement(F&& f)
|
||||||
{
|
{
|
||||||
|
|||||||
+6
-5
@@ -175,16 +175,17 @@ button:
|
|||||||
then:
|
then:
|
||||||
lambda: !lambda |-
|
lambda: !lambda |-
|
||||||
id(garage_gate).door_toggle();
|
id(garage_gate).door_toggle();
|
||||||
|
- platform: template
|
||||||
|
id: garage_gate_play_alert
|
||||||
|
name: "Play Alert"
|
||||||
|
on_press:
|
||||||
|
then:
|
||||||
|
- rtttl.play: "alert:d=8,o=5,b=120:a,p,a,p,a,p,4b,p"
|
||||||
|
|
||||||
output:
|
output:
|
||||||
- platform: ledc
|
- platform: ledc
|
||||||
pin: GPIO33
|
pin: GPIO33
|
||||||
id: garage_gate_ledc
|
id: garage_gate_ledc
|
||||||
- platform: ratgdo
|
|
||||||
id: garage_gate_beeper
|
|
||||||
type: beeper
|
|
||||||
rtttl: garage_gate_rtttl
|
|
||||||
song: "alert:d=8,o=5,b=120:a,p,a,p,a,p,4b,p"
|
|
||||||
|
|
||||||
rtttl:
|
rtttl:
|
||||||
- id: garage_gate_rtttl
|
- id: garage_gate_rtttl
|
||||||
|
|||||||
Reference in New Issue
Block a user