Skip to content

bug: LED toggle() can have inconsistent state #48

@gdellis

Description

@gdellis

Problem

In led_driver.cpp:23-26, toggle() reads the actual hardware level via gpio_get_level() to update state_. If something else modifies the pin externally, state_ becomes inconsistent with reality. Additionally, if gpio_set_level() fails, ESP_ERROR_CHECK will crash but state_ has already been toggled.

Location

  • firmware/main/led_driver.cpp:23-26

Severity

MEDIUM - LED state can diverge from tracked state

Suggested Fix

Track state internally and only use gpio_set_level() to change state, not read it:

gpio_set_level(pin_, !state_);
state_ = !state_;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions