Merge branch 'ratgdo32' of https://github.com/ratgdo/esphome-ratgdo into ratgdo32
This commit is contained in:
commit
52bc8cc1d3
|
@ -28,18 +28,18 @@ namespace ratgdo {
|
|||
this->parent_->subscribe_button_state([=](ButtonState state) {
|
||||
this->publish_state(state == ButtonState::PRESSED);
|
||||
});
|
||||
} else if(this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_DETECTED) {
|
||||
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_DETECTED) {
|
||||
this->publish_initial_state(false);
|
||||
this->parent_->subscribe_vehicle_detected_state([=](VehicleDetectedState state) {
|
||||
this->publish_state(state == VehicleDetectedState::YES);
|
||||
this->parent_->presence_change(state == VehicleDetectedState::YES);
|
||||
});
|
||||
} else if(this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_ARRIVING) {
|
||||
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_ARRIVING) {
|
||||
this->publish_initial_state(false);
|
||||
this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) {
|
||||
this->publish_state(state == VehicleArrivingState::YES);
|
||||
});
|
||||
} else if(this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_LEAVING) {
|
||||
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_LEAVING) {
|
||||
this->publish_initial_state(false);
|
||||
this->parent_->subscribe_vehicle_leaving_state([=](VehicleLeavingState state) {
|
||||
this->publish_state(state == VehicleLeavingState::YES);
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace ratgdo {
|
|||
this->parent_->subscribe_closing_delay([=](uint32_t value) {
|
||||
this->update_state(value);
|
||||
});
|
||||
} else if (this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT){
|
||||
} else if (this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT) {
|
||||
// this->parent_->subscribe_target_distance_measurement([=](float value) {
|
||||
// this->update_state(value);
|
||||
// });
|
||||
|
@ -98,7 +98,7 @@ namespace ratgdo {
|
|||
this->traits.set_step(0x1000);
|
||||
this->traits.set_min_value(0x539);
|
||||
this->traits.set_max_value(0x7ff539);
|
||||
} else if(this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT) {
|
||||
} else if (this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT) {
|
||||
this->traits.set_step(1);
|
||||
this->traits.set_min_value(5);
|
||||
this->traits.set_max_value(3500);
|
||||
|
|
|
@ -5,49 +5,54 @@
|
|||
namespace esphome {
|
||||
namespace ratgdo {
|
||||
|
||||
static const char *TAG = "ratgdo.output";
|
||||
static const char* TAG = "ratgdo.output";
|
||||
|
||||
void RATGDOOutput::setup(){
|
||||
ESP_LOGD(TAG,"Output was setup");
|
||||
void RATGDOOutput::setup()
|
||||
{
|
||||
ESP_LOGD(TAG, "Output was setup");
|
||||
|
||||
if(this->output_type_ == OutputType::RATGDO_BEEPER){
|
||||
this->beeper_->add_on_finished_playback_callback([=] { this->finished_playback(); });
|
||||
if (this->output_type_ == OutputType::RATGDO_BEEPER) {
|
||||
this->beeper_->add_on_finished_playback_callback([=] { this->finished_playback(); });
|
||||
|
||||
this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) {
|
||||
if(state == VehicleArrivingState::YES){
|
||||
this->play();
|
||||
}
|
||||
});
|
||||
|
||||
this->parent_->subscribe_door_action_delayed([=](DoorActionDelayed state) {
|
||||
if(state == DoorActionDelayed::YES){
|
||||
this->play();
|
||||
this->repeat_ = true;
|
||||
} else if(state == DoorActionDelayed::NO) {
|
||||
this->repeat_ = false;
|
||||
}
|
||||
});
|
||||
this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) {
|
||||
if (state == VehicleArrivingState::YES) {
|
||||
this->play();
|
||||
}
|
||||
});
|
||||
|
||||
this->parent_->subscribe_door_action_delayed([=](DoorActionDelayed state) {
|
||||
if (state == DoorActionDelayed::YES) {
|
||||
this->play();
|
||||
this->repeat_ = true;
|
||||
} else if (state == DoorActionDelayed::NO) {
|
||||
this->repeat_ = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RATGDOOutput::play(){
|
||||
this->beeper_->play(this->rtttlSong_);
|
||||
}
|
||||
|
||||
void RATGDOOutput::finished_playback(){
|
||||
if(this->repeat_) this->play();
|
||||
}
|
||||
|
||||
void RATGDOOutput::dump_config() {
|
||||
if (this->output_type_ == OutputType::RATGDO_BEEPER) {
|
||||
ESP_LOGCONFIG(TAG, " Type: Beeper");
|
||||
void RATGDOOutput::play()
|
||||
{
|
||||
this->beeper_->play(this->rtttlSong_);
|
||||
}
|
||||
}
|
||||
|
||||
void RATGDOOutput::set_output_type(OutputType output_type_) {
|
||||
this->output_type_ = output_type_;
|
||||
}
|
||||
void RATGDOOutput::finished_playback()
|
||||
{
|
||||
if (this->repeat_)
|
||||
this->play();
|
||||
}
|
||||
|
||||
} //namespace ratgdo
|
||||
} //namespace esphome
|
||||
void RATGDOOutput::dump_config()
|
||||
{
|
||||
if (this->output_type_ == OutputType::RATGDO_BEEPER) {
|
||||
ESP_LOGCONFIG(TAG, " Type: Beeper");
|
||||
}
|
||||
}
|
||||
|
||||
void RATGDOOutput::set_output_type(OutputType output_type_)
|
||||
{
|
||||
this->output_type_ = output_type_;
|
||||
}
|
||||
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include "../ratgdo.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/rtttl/rtttl.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ratgdo {
|
||||
|
||||
enum OutputType {
|
||||
RATGDO_BEEPER
|
||||
};
|
||||
enum OutputType {
|
||||
RATGDO_BEEPER
|
||||
};
|
||||
|
||||
class RATGDOOutput : public RATGDOClient, public Component {
|
||||
public:
|
||||
void setup() override;
|
||||
void play();
|
||||
void finished_playback();
|
||||
void dump_config() override;
|
||||
void set_output_type(OutputType output_type);
|
||||
void set_song(std::string rtttlSong){ this->rtttlSong_ = rtttlSong; }
|
||||
void set_rtttl(rtttl::Rtttl *output){ this->beeper_ = output; }
|
||||
class RATGDOOutput : public RATGDOClient, public Component {
|
||||
public:
|
||||
void setup() override;
|
||||
void play();
|
||||
void finished_playback();
|
||||
void dump_config() override;
|
||||
void set_output_type(OutputType output_type);
|
||||
void set_song(std::string rtttlSong) { this->rtttlSong_ = rtttlSong; }
|
||||
void set_rtttl(rtttl::Rtttl* output) { this->beeper_ = output; }
|
||||
|
||||
protected:
|
||||
OutputType output_type_;
|
||||
rtttl::Rtttl* beeper_;
|
||||
std::string rtttlSong_;
|
||||
bool repeat_;
|
||||
};
|
||||
protected:
|
||||
OutputType output_type_;
|
||||
rtttl::Rtttl* beeper_;
|
||||
std::string rtttlSong_;
|
||||
bool repeat_;
|
||||
};
|
||||
|
||||
} //namespace ratgdo
|
||||
} //namespace esphome
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
|
|
@ -63,14 +63,14 @@ namespace ratgdo {
|
|||
this->subscribe_door_state([=](DoorState state, float position) {
|
||||
static DoorState lastState = DoorState::UNKNOWN;
|
||||
|
||||
if(lastState != DoorState::UNKNOWN && state != DoorState::CLOSED && !this->presence_detect_window_active_){
|
||||
if (lastState != DoorState::UNKNOWN && state != DoorState::CLOSED && !this->presence_detect_window_active_) {
|
||||
this->presence_detect_window_active_ = true;
|
||||
set_timeout("presence_detect_window", PRESENCE_DETECT_WINDOW, [=] {
|
||||
this->presence_detect_window_active_ = false;
|
||||
});
|
||||
}
|
||||
|
||||
if(state == DoorState::CLOSED){
|
||||
if (state == DoorState::CLOSED) {
|
||||
this->presence_detect_window_active_ = false;
|
||||
cancel_timeout("presence_detect_window");
|
||||
}
|
||||
|
@ -361,13 +361,15 @@ namespace ratgdo {
|
|||
this->closing_duration = duration;
|
||||
}
|
||||
|
||||
void RATGDOComponent::set_target_distance_measurement(int16_t distance){
|
||||
void RATGDOComponent::set_target_distance_measurement(int16_t distance)
|
||||
{
|
||||
this->target_distance_measurement = distance;
|
||||
}
|
||||
|
||||
void RATGDOComponent::set_distance_measurement(int16_t distance)
|
||||
{
|
||||
if(distance > 0 && distance < MIN_DISTANCE) return;
|
||||
if (distance > 0 && distance < MIN_DISTANCE)
|
||||
return;
|
||||
|
||||
this->last_distance_measurement = distance;
|
||||
|
||||
|
@ -395,8 +397,10 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
if(all_in_range) this->vehicle_detected_state = VehicleDetectedState::YES;
|
||||
if(all_out_of_range) this->vehicle_detected_state = VehicleDetectedState::NO;
|
||||
if (all_in_range)
|
||||
this->vehicle_detected_state = VehicleDetectedState::YES;
|
||||
if (all_out_of_range)
|
||||
this->vehicle_detected_state = VehicleDetectedState::NO;
|
||||
|
||||
// auto k = this->distance_measurement;
|
||||
// ESP_LOGD(TAG,"measure: %i,%i,%i,%i,%i,%i,%i,%i,%i,%i; target: %i; all_in: %s; all_out: %s;", k[0],k[1],k[2],k[3],k[4],k[5],k[6],k[7],k[8],k[9], *this->target_distance_measurement, all_in_range ? "y" : "n", all_out_of_range ? "y" : "n");
|
||||
|
@ -404,14 +408,14 @@ namespace ratgdo {
|
|||
|
||||
void RATGDOComponent::presence_change(bool sensor_value)
|
||||
{
|
||||
if(this->presence_detect_window_active_){
|
||||
if(sensor_value){
|
||||
if (this->presence_detect_window_active_) {
|
||||
if (sensor_value) {
|
||||
this->vehicle_arriving_state = VehicleArrivingState::YES;
|
||||
this->vehicle_leaving_state = VehicleLeavingState::NO;
|
||||
set_timeout(CLEAR_PRESENCE, [=] {
|
||||
this->vehicle_arriving_state = VehicleArrivingState::NO;
|
||||
});
|
||||
}else{
|
||||
} else {
|
||||
this->vehicle_arriving_state = VehicleArrivingState::NO;
|
||||
this->vehicle_leaving_state = VehicleLeavingState::YES;
|
||||
set_timeout(CLEAR_PRESENCE, [=] {
|
||||
|
@ -584,13 +588,13 @@ namespace ratgdo {
|
|||
|
||||
void RATGDOComponent::door_action(DoorAction action)
|
||||
{
|
||||
if(*this->closing_delay > 0 && action == DoorAction::CLOSE){
|
||||
if (*this->closing_delay > 0 && action == DoorAction::CLOSE) {
|
||||
this->door_action_delayed = DoorActionDelayed::YES;
|
||||
set_timeout("door_action", *this->closing_delay * 1000, [=] {
|
||||
this->door_action_delayed = DoorActionDelayed::NO;
|
||||
this->protocol_->door_action(DoorAction::CLOSE);
|
||||
});
|
||||
}else{
|
||||
} else {
|
||||
this->protocol_->door_action(action);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace ratgdo {
|
|||
observable<uint32_t> closing_delay { 0 };
|
||||
|
||||
observable<int16_t> target_distance_measurement { -1 };
|
||||
std::vector<int16_t> distance_measurement{std::vector<int16_t>(10,-1)}; // the length of this vector determines how many in-range readings are required for presence detection to change states
|
||||
std::vector<int16_t> distance_measurement { std::vector<int16_t>(10, -1) }; // the length of this vector determines how many in-range readings are required for presence detection to change states
|
||||
observable<int16_t> last_distance_measurement { 0 };
|
||||
|
||||
observable<uint16_t> openings { 0 }; // number of times the door has been opened
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace ratgdo {
|
|||
this->distance_sensor_.setI2cDevice(&I2C);
|
||||
this->distance_sensor_.setXShutPin(32);
|
||||
// I2C.begin(17,16);
|
||||
I2C.begin(19,18);
|
||||
I2C.begin(19, 18);
|
||||
this->distance_sensor_.begin();
|
||||
this->distance_sensor_.VL53L4CX_Off();
|
||||
this->distance_sensor_.InitSensor(0x59);
|
||||
|
@ -77,7 +77,7 @@ namespace ratgdo {
|
|||
#ifdef USE_DISTANCE
|
||||
if (this->ratgdo_sensor_type_ == RATGDOSensorType::RATGDO_DISTANCE) {
|
||||
VL53L4CX_MultiRangingData_t distanceData;
|
||||
VL53L4CX_MultiRangingData_t *pDistanceData = &distanceData;
|
||||
VL53L4CX_MultiRangingData_t* pDistanceData = &distanceData;
|
||||
uint8_t dataReady = 0;
|
||||
int objCount = 0;
|
||||
int16_t maxDistance = 0;
|
||||
|
@ -94,7 +94,7 @@ namespace ratgdo {
|
|||
* in most situations, unless its mounted really far away.
|
||||
* If this doesn't work, then the vector size will have to increase substantially
|
||||
*/
|
||||
if(maxDistance > 0){
|
||||
if (maxDistance > 0) {
|
||||
this->parent_->set_distance_measurement(maxDistance);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#include "esphome/core/component.h"
|
||||
|
||||
#ifdef USE_DISTANCE
|
||||
#include "Wire.h"
|
||||
#include "vl53l4cx_class.h"
|
||||
#define I2C Wire
|
||||
#include "Wire.h"
|
||||
#include "vl53l4cx_class.h"
|
||||
#define I2C Wire
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
|
|
|
@ -39,4 +39,3 @@ async def to_code(config):
|
|||
if CONF_PIN in config:
|
||||
pin = await cg.gpio_pin_expression(config[CONF_PIN])
|
||||
cg.add(var.set_pin(pin))
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ratgdo {
|
|||
this->parent_->subscribe_learn_state([=](LearnState state) {
|
||||
this->publish_state(state == LearnState::ACTIVE);
|
||||
});
|
||||
}else if(this->switch_type_ == SwitchType::RATGDO_LED) {
|
||||
} else if (this->switch_type_ == SwitchType::RATGDO_LED) {
|
||||
this->pin_->setup();
|
||||
this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) {
|
||||
this->write_state(state == VehicleArrivingState::YES);
|
||||
|
@ -37,7 +37,7 @@ namespace ratgdo {
|
|||
} else {
|
||||
this->parent_->inactivate_learn();
|
||||
}
|
||||
} else if(this->switch_type_ == SwitchType::RATGDO_LED){
|
||||
} else if (this->switch_type_ == SwitchType::RATGDO_LED) {
|
||||
this->pin_->digital_write(state);
|
||||
this->publish_state(state);
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ namespace ratgdo {
|
|||
void set_switch_type(SwitchType switch_type_) { this->switch_type_ = switch_type_; }
|
||||
|
||||
void write_state(bool state) override;
|
||||
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
||||
void set_pin(GPIOPin* pin) { pin_ = pin; }
|
||||
|
||||
protected:
|
||||
SwitchType switch_type_;
|
||||
GPIOPin *pin_;
|
||||
GPIOPin* pin_;
|
||||
};
|
||||
|
||||
} // namespace ratgdo
|
||||
|
|
Loading…
Reference in New Issue