[qwiic_pir] Clean-up, shorten some log messages (#8951)

This commit is contained in:
Keith Burzinski 2025-06-07 22:44:35 -05:00 committed by GitHub
parent 9e862b8b53
commit 8894f5030a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,31 +11,24 @@ void QwiicPIRComponent::setup() {
// Verify I2C communcation by reading and verifying the chip ID // Verify I2C communcation by reading and verifying the chip ID
uint8_t chip_id; uint8_t chip_id;
if (!this->read_byte(QWIIC_PIR_CHIP_ID, &chip_id)) { if (!this->read_byte(QWIIC_PIR_CHIP_ID, &chip_id)) {
ESP_LOGE(TAG, "Failed to read the chip's ID"); ESP_LOGE(TAG, "Failed to read chip ID");
this->error_code_ = ERROR_COMMUNICATION_FAILED; this->error_code_ = ERROR_COMMUNICATION_FAILED;
this->mark_failed(); this->mark_failed();
return; return;
} }
if (chip_id != QWIIC_PIR_DEVICE_ID) { if (chip_id != QWIIC_PIR_DEVICE_ID) {
ESP_LOGE(TAG, "Unknown chip ID, is this a Qwiic PIR?"); ESP_LOGE(TAG, "Unknown chip ID");
this->error_code_ = ERROR_WRONG_CHIP_ID; this->error_code_ = ERROR_WRONG_CHIP_ID;
this->mark_failed(); this->mark_failed();
return; return;
} }
if (!this->write_byte_16(QWIIC_PIR_DEBOUNCE_TIME, this->debounce_time_)) { if (!this->write_byte_16(QWIIC_PIR_DEBOUNCE_TIME, this->debounce_time_)) {
ESP_LOGE(TAG, "Failed to configure debounce time."); ESP_LOGE(TAG, "Failed to configure debounce time");
this->error_code_ = ERROR_COMMUNICATION_FAILED; this->error_code_ = ERROR_COMMUNICATION_FAILED;
this->mark_failed(); this->mark_failed();
return; return;
} }
@ -43,11 +36,9 @@ void QwiicPIRComponent::setup() {
// Publish the starting raw state of the PIR sensor // Publish the starting raw state of the PIR sensor
// If NATIVE mode, the binary_sensor state would be unknown until a motion event // If NATIVE mode, the binary_sensor state would be unknown until a motion event
if (!this->read_byte(QWIIC_PIR_EVENT_STATUS, &this->event_register_.reg)) { if (!this->read_byte(QWIIC_PIR_EVENT_STATUS, &this->event_register_.reg)) {
ESP_LOGE(TAG, "Failed to read initial sensor state."); ESP_LOGE(TAG, "Failed to read initial state");
this->error_code_ = ERROR_COMMUNICATION_FAILED; this->error_code_ = ERROR_COMMUNICATION_FAILED;
this->mark_failed(); this->mark_failed();
return; return;
} }
@ -59,7 +50,6 @@ void QwiicPIRComponent::loop() {
// Read Event Register // Read Event Register
if (!this->read_byte(QWIIC_PIR_EVENT_STATUS, &this->event_register_.reg)) { if (!this->read_byte(QWIIC_PIR_EVENT_STATUS, &this->event_register_.reg)) {
ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL);
return; return;
} }
@ -98,39 +88,45 @@ void QwiicPIRComponent::loop() {
} }
void QwiicPIRComponent::dump_config() { void QwiicPIRComponent::dump_config() {
ESP_LOGCONFIG(TAG, "Qwiic PIR:"); static const char *const RAW = "RAW";
static const char *const NATIVE = "NATIVE";
static const char *const HYBRID = "HYBRID";
if (this->debounce_mode_ == RAW_DEBOUNCE_MODE) { const char *debounce_mode_str = RAW;
ESP_LOGCONFIG(TAG, " Debounce Mode: RAW"); if (this->debounce_mode_ == NATIVE_DEBOUNCE_MODE) {
} else if (this->debounce_mode_ == NATIVE_DEBOUNCE_MODE) { debounce_mode_str = NATIVE;
ESP_LOGCONFIG(TAG, " Debounce Mode: NATIVE");
ESP_LOGCONFIG(TAG, " Debounce Time: %ums", this->debounce_time_);
} else if (this->debounce_mode_ == HYBRID_DEBOUNCE_MODE) { } else if (this->debounce_mode_ == HYBRID_DEBOUNCE_MODE) {
ESP_LOGCONFIG(TAG, " Debounce Mode: HYBRID"); debounce_mode_str = HYBRID;
}
ESP_LOGCONFIG(TAG, "Qwiic PIR:");
ESP_LOGCONFIG(TAG, " Debounce Mode: %s", debounce_mode_str);
if (this->debounce_mode_ == NATIVE_DEBOUNCE_MODE) {
ESP_LOGCONFIG(TAG, " Debounce Time: %ums", this->debounce_time_);
} }
switch (this->error_code_) { switch (this->error_code_) {
case NONE: case NONE:
break; break;
case ERROR_COMMUNICATION_FAILED: case ERROR_COMMUNICATION_FAILED:
ESP_LOGE(TAG, " Communication with Qwiic PIR failed!"); ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
break; break;
case ERROR_WRONG_CHIP_ID: case ERROR_WRONG_CHIP_ID:
ESP_LOGE(TAG, " Qwiic PIR has wrong chip ID - please verify you are using a Qwiic PIR"); ESP_LOGE(TAG, "Unknown chip ID");
break; break;
default: default:
ESP_LOGE(TAG, " Qwiic PIR error code %d", (int) this->error_code_); ESP_LOGE(TAG, "Error %d", (int) this->error_code_);
break; break;
} }
LOG_I2C_DEVICE(this); LOG_I2C_DEVICE(this);
LOG_BINARY_SENSOR(" ", "Qwiic PIR Binary Sensor", this); LOG_BINARY_SENSOR(" ", "Binary Sensor", this);
} }
void QwiicPIRComponent::clear_events_() { void QwiicPIRComponent::clear_events_() {
// Clear event status register // Clear event status register
if (!this->write_byte(QWIIC_PIR_EVENT_STATUS, 0x00)) if (!this->write_byte(QWIIC_PIR_EVENT_STATUS, 0x00))
ESP_LOGW(TAG, "Failed to clear events on sensor"); ESP_LOGW(TAG, "Failed to clear events");
} }
} // namespace qwiic_pir } // namespace qwiic_pir