Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Fixes for 1.12 (#551)
Browse files Browse the repository at this point in the history
* Fixes for 1.12

- Add verbose log info for connecting to network
- Try to fix rotary encoder
- Fix ultrasonic sensor interrupt never attached

* Lint
  • Loading branch information
OttoWinter committed Mar 16, 2019
1 parent e254cce commit 5081b1d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/esphome/sensor/rotary_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ void RotaryEncoderSensor::dump_config() {
LOG_PIN(" Pin A: ", this->pin_a_);
LOG_PIN(" Pin B: ", this->pin_b_);
LOG_PIN(" Pin I: ", this->pin_i_);
switch (this->store_.resolution) {
case ROTARY_ENCODER_1_PULSE_PER_CYCLE:
ESP_LOGCONFIG(TAG, " Resolution: 1 Pulse Per Cycle");
break;
case ROTARY_ENCODER_2_PULSES_PER_CYCLE:
ESP_LOGCONFIG(TAG, " Resolution: 2 Pulses Per Cycle");
break;
case ROTARY_ENCODER_4_PULSES_PER_CYCLE:
ESP_LOGCONFIG(TAG, " Resolution: 4 Pulse Per Cycle");
break;
}
}
void RotaryEncoderSensor::loop() {
if (this->pin_i_ != nullptr && this->pin_i_->digital_read()) {
Expand Down
2 changes: 1 addition & 1 deletion src/esphome/sensor/rotary_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class RotaryEncoderSensor : public Sensor, public Component {
GPIOPin *pin_b_;
GPIOPin *pin_i_{nullptr}; /// Index pin, if this is not nullptr, the counter will reset to 0 once this pin is HIGH.

RotaryEncoderSensorStore store_;
RotaryEncoderSensorStore store_{};
};

} // namespace sensor
Expand Down
5 changes: 3 additions & 2 deletions src/esphome/sensor/ultrasonic_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void UltrasonicSensorComponent::setup() {
this->echo_pin_->setup();
this->trigger_pin_->setup();
this->trigger_pin_->digital_write(false);
this->echo_pin_->attach_interrupt(UltrasonicSensorStore::gpio_intr, &this->store_, RISING);
}
void ICACHE_RAM_ATTR UltrasonicSensorStore::gpio_intr(UltrasonicSensorStore *arg) {
if (arg->has_echo || !arg->has_triggered)
Expand Down Expand Up @@ -60,8 +61,8 @@ void UltrasonicSensorComponent::dump_config() {
LOG_SENSOR("", "Ultrasonic Sensor", this);
LOG_PIN(" Echo Pin: ", this->echo_pin_);
LOG_PIN(" Trigger Pin: ", this->trigger_pin_);
ESP_LOGCONFIG(TAG, " Pulse time: %u µs", this->pulse_time_us_);
ESP_LOGCONFIG(TAG, " Timeout: %u µs", this->timeout_us_);
ESP_LOGCONFIG(TAG, " Pulse time: %u µs", this->pulse_time_us_);
ESP_LOGCONFIG(TAG, " Timeout: %u µs", this->timeout_us_);
LOG_UPDATE_INTERVAL(this);
}
float UltrasonicSensorComponent::us_to_m(uint32_t us) {
Expand Down
40 changes: 35 additions & 5 deletions src/esphome/wifi_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,31 @@ std::string format_mac_addr(const uint8_t mac[6]) {

void WiFiComponent::start_connecting(const WiFiAP &ap, bool two) {
ESP_LOGI(TAG, "WiFi Connecting to '%s'...", ap.get_ssid().c_str());
#ifdef ESPHOME_LOG_HAS_VERBOSE
ESP_LOGV(TAG, "Connection Params:");
ESP_LOGV(TAG, " SSID: '%s'", ap.get_ssid().c_str());
if (ap.get_bssid().has_value()) {
bssid_t b = *ap.get_bssid();
ESP_LOGV(TAG, " BSSID: %02X:%02X:%02X:%02X:%02X:%02X", b[0], b[1], b[2], b[3], b[4], b[5]);
} else {
ESP_LOGV(TAG, " BSSID: Not Set");
}
ESP_LOGV(TAG, " Password: " LOG_SECRET("'%s'"), ap.get_password());
if (ap.get_channel().has_value()) {
ESP_LOGV(TAG, " Channel: %u", *ap.get_channel());
} else {
ESP_LOGV(TAG, " Channel: Not Set");
}
if (ap.get_manual_ip().has_value()) {
ManualIP m = *ap.get_manual_ip();
ESP_LOGV(TAG, " Manual IP: Static IP=%s Gateway=%s Subnet=%s DNS1=%s DNS2=%s", m.static_ip.toString().c_str(),
m.gateway.toString().c_str(), m.subnet.toString().c_str(), m.dns1.toString().c_str(),
m.dns2.toString().c_str());
} else {
ESP_LOGV(TAG, " Using DHCP IP");
}
ESP_LOGV(TAG, " Hidden: %s", YESNO(ap.get_hidden()));
#endif

if (!this->wifi_sta_connect_(ap)) {
ESP_LOGE(TAG, "wifi_sta_connect_ failed!");
Expand Down Expand Up @@ -308,16 +333,21 @@ void WiFiComponent::check_scanning_finished() {

WiFiAP ap;
WiFiScanResult scan_res = this->scan_result_[0];
ap.set_ssid(scan_res.get_ssid());
ap.set_bssid(scan_res.get_bssid());
ap.set_channel(scan_res.get_channel());
for (auto &ap2 : this->sta_) {
if (scan_res.matches(ap2)) {
if (ap.get_ssid().empty()) {
if (ap2.get_hidden()) {
// selected network is hidden
ap.set_hidden(true);
ap.set_ssid(scan_res.get_ssid());
} else {
// selected network is visible
ap.set_hidden(false);
ap.set_ssid(ap2.get_ssid());
ap.set_channel(scan_res.get_channel());
ap.set_bssid(scan_res.get_bssid());
}
ap.set_password(ap2.get_password());
ap.set_manual_ip(ap2.get_manual_ip());
ap.set_password(ap2.get_password());
break;
}
}
Expand Down

0 comments on commit 5081b1d

Please sign in to comment.