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

Commit 5081b1d

Browse files
committed
Fixes for 1.12 (#551)
* Fixes for 1.12 - Add verbose log info for connecting to network - Try to fix rotary encoder - Fix ultrasonic sensor interrupt never attached * Lint
1 parent e254cce commit 5081b1d

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

src/esphome/sensor/rotary_encoder.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ void RotaryEncoderSensor::dump_config() {
122122
LOG_PIN(" Pin A: ", this->pin_a_);
123123
LOG_PIN(" Pin B: ", this->pin_b_);
124124
LOG_PIN(" Pin I: ", this->pin_i_);
125+
switch (this->store_.resolution) {
126+
case ROTARY_ENCODER_1_PULSE_PER_CYCLE:
127+
ESP_LOGCONFIG(TAG, " Resolution: 1 Pulse Per Cycle");
128+
break;
129+
case ROTARY_ENCODER_2_PULSES_PER_CYCLE:
130+
ESP_LOGCONFIG(TAG, " Resolution: 2 Pulses Per Cycle");
131+
break;
132+
case ROTARY_ENCODER_4_PULSES_PER_CYCLE:
133+
ESP_LOGCONFIG(TAG, " Resolution: 4 Pulse Per Cycle");
134+
break;
135+
}
125136
}
126137
void RotaryEncoderSensor::loop() {
127138
if (this->pin_i_ != nullptr && this->pin_i_->digital_read()) {

src/esphome/sensor/rotary_encoder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class RotaryEncoderSensor : public Sensor, public Component {
6969
GPIOPin *pin_b_;
7070
GPIOPin *pin_i_{nullptr}; /// Index pin, if this is not nullptr, the counter will reset to 0 once this pin is HIGH.
7171

72-
RotaryEncoderSensorStore store_;
72+
RotaryEncoderSensorStore store_{};
7373
};
7474

7575
} // namespace sensor

src/esphome/sensor/ultrasonic_sensor.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void UltrasonicSensorComponent::setup() {
2121
this->echo_pin_->setup();
2222
this->trigger_pin_->setup();
2323
this->trigger_pin_->digital_write(false);
24+
this->echo_pin_->attach_interrupt(UltrasonicSensorStore::gpio_intr, &this->store_, RISING);
2425
}
2526
void ICACHE_RAM_ATTR UltrasonicSensorStore::gpio_intr(UltrasonicSensorStore *arg) {
2627
if (arg->has_echo || !arg->has_triggered)
@@ -60,8 +61,8 @@ void UltrasonicSensorComponent::dump_config() {
6061
LOG_SENSOR("", "Ultrasonic Sensor", this);
6162
LOG_PIN(" Echo Pin: ", this->echo_pin_);
6263
LOG_PIN(" Trigger Pin: ", this->trigger_pin_);
63-
ESP_LOGCONFIG(TAG, " Pulse time: %u µs", this->pulse_time_us_);
64-
ESP_LOGCONFIG(TAG, " Timeout: %u µs", this->timeout_us_);
64+
ESP_LOGCONFIG(TAG, " Pulse time: %u µs", this->pulse_time_us_);
65+
ESP_LOGCONFIG(TAG, " Timeout: %u µs", this->timeout_us_);
6566
LOG_UPDATE_INTERVAL(this);
6667
}
6768
float UltrasonicSensorComponent::us_to_m(uint32_t us) {

src/esphome/wifi_component.cpp

+35-5
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,31 @@ std::string format_mac_addr(const uint8_t mac[6]) {
165165

166166
void WiFiComponent::start_connecting(const WiFiAP &ap, bool two) {
167167
ESP_LOGI(TAG, "WiFi Connecting to '%s'...", ap.get_ssid().c_str());
168+
#ifdef ESPHOME_LOG_HAS_VERBOSE
169+
ESP_LOGV(TAG, "Connection Params:");
170+
ESP_LOGV(TAG, " SSID: '%s'", ap.get_ssid().c_str());
171+
if (ap.get_bssid().has_value()) {
172+
bssid_t b = *ap.get_bssid();
173+
ESP_LOGV(TAG, " BSSID: %02X:%02X:%02X:%02X:%02X:%02X", b[0], b[1], b[2], b[3], b[4], b[5]);
174+
} else {
175+
ESP_LOGV(TAG, " BSSID: Not Set");
176+
}
177+
ESP_LOGV(TAG, " Password: " LOG_SECRET("'%s'"), ap.get_password());
178+
if (ap.get_channel().has_value()) {
179+
ESP_LOGV(TAG, " Channel: %u", *ap.get_channel());
180+
} else {
181+
ESP_LOGV(TAG, " Channel: Not Set");
182+
}
183+
if (ap.get_manual_ip().has_value()) {
184+
ManualIP m = *ap.get_manual_ip();
185+
ESP_LOGV(TAG, " Manual IP: Static IP=%s Gateway=%s Subnet=%s DNS1=%s DNS2=%s", m.static_ip.toString().c_str(),
186+
m.gateway.toString().c_str(), m.subnet.toString().c_str(), m.dns1.toString().c_str(),
187+
m.dns2.toString().c_str());
188+
} else {
189+
ESP_LOGV(TAG, " Using DHCP IP");
190+
}
191+
ESP_LOGV(TAG, " Hidden: %s", YESNO(ap.get_hidden()));
192+
#endif
168193

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

309334
WiFiAP ap;
310335
WiFiScanResult scan_res = this->scan_result_[0];
311-
ap.set_ssid(scan_res.get_ssid());
312-
ap.set_bssid(scan_res.get_bssid());
313-
ap.set_channel(scan_res.get_channel());
314336
for (auto &ap2 : this->sta_) {
315337
if (scan_res.matches(ap2)) {
316-
if (ap.get_ssid().empty()) {
338+
if (ap2.get_hidden()) {
339+
// selected network is hidden
340+
ap.set_hidden(true);
341+
ap.set_ssid(scan_res.get_ssid());
342+
} else {
343+
// selected network is visible
344+
ap.set_hidden(false);
317345
ap.set_ssid(ap2.get_ssid());
346+
ap.set_channel(scan_res.get_channel());
347+
ap.set_bssid(scan_res.get_bssid());
318348
}
319-
ap.set_password(ap2.get_password());
320349
ap.set_manual_ip(ap2.get_manual_ip());
350+
ap.set_password(ap2.get_password());
321351
break;
322352
}
323353
}

0 commit comments

Comments
 (0)