Compare commits

..

3 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
ddf1e27ac3 Move gpio_intr_enable after gpio_isr_handler_add per review feedback
Co-authored-by: jesserockz <3060199+jesserockz@users.noreply.github.com>
2025-11-20 22:55:08 +00:00
copilot-swe-agent[bot]
55d7344086 Remove gpio_intr_enable() call to fix level-triggered interrupt panic
Co-authored-by: jesserockz <3060199+jesserockz@users.noreply.github.com>
2025-11-20 19:54:05 +00:00
copilot-swe-agent[bot]
fae833b73b Initial plan 2025-11-20 19:49:10 +00:00
6 changed files with 36 additions and 33 deletions

View File

@@ -19,7 +19,7 @@ void CST816Touchscreen::continue_setup_() {
case CST816T_CHIP_ID:
break;
default:
this->status_set_error(str_sprintf("Unknown chip ID 0x%02X", this->chip_id_));
this->status_set_error(str_sprintf("Unknown chip ID 0x%02X", this->chip_id_).c_str());
this->mark_failed();
return;
}

View File

@@ -85,7 +85,6 @@ void ESP32InternalGPIOPin::attach_interrupt(void (*func)(void *), void *arg, gpi
break;
}
gpio_set_intr_type(this->get_pin_num(), idf_type);
gpio_intr_enable(this->get_pin_num());
if (!isr_service_installed) {
auto res = gpio_install_isr_service(ESP_INTR_FLAG_LEVEL3);
if (res != ESP_OK) {
@@ -95,6 +94,7 @@ void ESP32InternalGPIOPin::attach_interrupt(void (*func)(void *), void *arg, gpi
isr_service_installed = true;
}
gpio_isr_handler_add(this->get_pin_num(), func, arg);
gpio_intr_enable(this->get_pin_num());
}
std::string ESP32InternalGPIOPin::dump_summary() const {

View File

@@ -51,7 +51,7 @@ void HttpRequestUpdate::update_task(void *params) {
if (container == nullptr || container->status_code != HTTP_STATUS_OK) {
std::string msg = str_sprintf("Failed to fetch manifest from %s", this_update->source_url_.c_str());
// Defer to main loop to avoid race condition on component_state_ read-modify-write
this_update->defer([this_update, msg]() { this_update->status_set_error(msg); });
this_update->defer([this_update, msg]() { this_update->status_set_error(msg.c_str()); });
UPDATE_RETURN;
}
@@ -60,7 +60,7 @@ void HttpRequestUpdate::update_task(void *params) {
if (data == nullptr) {
std::string msg = str_sprintf("Failed to allocate %zu bytes for manifest", container->content_length);
// Defer to main loop to avoid race condition on component_state_ read-modify-write
this_update->defer([this_update, msg]() { this_update->status_set_error(msg); });
this_update->defer([this_update, msg]() { this_update->status_set_error(msg.c_str()); });
container->end();
UPDATE_RETURN;
}
@@ -123,7 +123,7 @@ void HttpRequestUpdate::update_task(void *params) {
if (!valid) {
std::string msg = str_sprintf("Failed to parse JSON from %s", this_update->source_url_.c_str());
// Defer to main loop to avoid race condition on component_state_ read-modify-write
this_update->defer([this_update, msg]() { this_update->status_set_error(msg); });
this_update->defer([this_update, msg]() { this_update->status_set_error(msg.c_str()); });
UPDATE_RETURN;
}

View File

@@ -10,7 +10,7 @@ namespace jsn_sr04t {
static const char *const TAG = "jsn_sr04t.sensor";
void Jsnsr04tComponent::update() {
this->write_byte((this->model_ == AJ_SR04M) ? 0x01 : 0x55);
this->write_byte(0x55);
ESP_LOGV(TAG, "Request read out from sensor");
}
@@ -31,10 +31,19 @@ void Jsnsr04tComponent::loop() {
}
void Jsnsr04tComponent::check_buffer_() {
uint8_t checksum = this->buffer_[0] + this->buffer_[1] + this->buffer_[2];
uint8_t checksum = 0;
switch (this->model_) {
case JSN_SR04T:
checksum = this->buffer_[0] + this->buffer_[1] + this->buffer_[2];
break;
case AJ_SR04M:
checksum = this->buffer_[1] + this->buffer_[2];
break;
}
if (this->buffer_[3] == checksum) {
uint16_t distance = encode_uint16(this->buffer_[1], this->buffer_[2]);
if (distance > ((this->model_ == AJ_SR04M) ? 200 : 250)) {
if (distance > 250) {
float meters = distance / 1000.0f;
ESP_LOGV(TAG, "Distance from sensor: %umm, %.3fm", distance, meters);
this->publish_state(meters);

View File

@@ -35,7 +35,7 @@ static const char *const TAG = "component";
namespace {
struct ComponentErrorMessage {
const Component *component;
std::string message;
const char *message;
};
struct ComponentPriorityOverride {
@@ -146,7 +146,7 @@ void Component::call_dump_config() {
if (component_error_messages) {
for (const auto &entry : *component_error_messages) {
if (entry.component == this) {
error_msg = entry.message.c_str();
error_msg = entry.message;
break;
}
}
@@ -307,33 +307,28 @@ void Component::status_set_warning(const LogString *message) {
ESP_LOGW(TAG, "%s set Warning flag: %s", LOG_STR_ARG(this->get_component_log_str()),
message ? LOG_STR_ARG(message) : LOG_STR_LITERAL("unspecified"));
}
void Component::status_set_error(const std::string &message) {
void Component::status_set_error(const char *message) {
if ((this->component_state_ & STATUS_LED_ERROR) != 0)
return;
this->component_state_ |= STATUS_LED_ERROR;
App.app_state_ |= STATUS_LED_ERROR;
ESP_LOGE(TAG, "%s set Error flag: %s", LOG_STR_ARG(this->get_component_log_str()), message.c_str());
// Lazy allocate the error messages vector if needed
if (!component_error_messages) {
component_error_messages = std::make_unique<std::vector<ComponentErrorMessage>>();
}
// Check if this component already has an error message
for (auto &entry : *component_error_messages) {
if (entry.component == this) {
entry.message = message;
return;
ESP_LOGE(TAG, "%s set Error flag: %s", LOG_STR_ARG(this->get_component_log_str()),
message ? message : LOG_STR_LITERAL("unspecified"));
if (message != nullptr) {
// Lazy allocate the error messages vector if needed
if (!component_error_messages) {
component_error_messages = std::make_unique<std::vector<ComponentErrorMessage>>();
}
// Check if this component already has an error message
for (auto &entry : *component_error_messages) {
if (entry.component == this) {
entry.message = message;
return;
}
}
// Add new error message
component_error_messages->emplace_back(ComponentErrorMessage{this, message});
}
// Add new error message
component_error_messages->emplace_back(ComponentErrorMessage{this, message});
}
void Component::status_set_error() {
// No message version - just set the error flag
if ((this->component_state_ & STATUS_LED_ERROR) != 0)
return;
this->component_state_ |= STATUS_LED_ERROR;
App.app_state_ |= STATUS_LED_ERROR;
ESP_LOGE(TAG, "%s set Error flag: %s", LOG_STR_ARG(this->get_component_log_str()), LOG_STR_LITERAL("unspecified"));
}
void Component::status_clear_warning() {
if ((this->component_state_ & STATUS_LED_WARNING) == 0)

View File

@@ -216,8 +216,7 @@ class Component {
void status_set_warning(const char *message = nullptr);
void status_set_warning(const LogString *message);
void status_set_error(const std::string &message);
void status_set_error();
void status_set_error(const char *message = nullptr);
void status_clear_warning();