| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "EspGpioOutput.h" | ||
| 2 | #include "esp_log.h" | ||
| 3 | |||
| 4 | static const char* TAG = "EspGpioOutput"; | ||
| 5 | |||
| 6 | ✗ | EspGpioOutput::EspGpioOutput(gpio_num_t pin, bool initialLevel) | |
| 7 | ✗ | : m_pin(pin) | |
| 8 | ✗ | , m_currentLevel(initialLevel) { | |
| 9 | // Configure GPIO as output | ||
| 10 | ✗ | gpio_config_t io_conf = {}; | |
| 11 | ✗ | io_conf.pin_bit_mask = (1ULL << pin); | |
| 12 | ✗ | io_conf.mode = GPIO_MODE_OUTPUT; | |
| 13 | ✗ | io_conf.pull_up_en = GPIO_PULLUP_DISABLE; | |
| 14 | ✗ | io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; | |
| 15 | ✗ | io_conf.intr_type = GPIO_INTR_DISABLE; | |
| 16 | |||
| 17 | ✗ | esp_err_t ret = gpio_config(&io_conf); | |
| 18 | ✗ | if (ret != ESP_OK) { | |
| 19 | ✗ | ESP_LOGE(TAG, "Failed to configure GPIO %d: %s", pin, esp_err_to_name(ret)); | |
| 20 | } else { | ||
| 21 | // Set initial level | ||
| 22 | ✗ | gpio_set_level(m_pin, initialLevel ? 1 : 0); | |
| 23 | ✗ | ESP_LOGI(TAG, "GPIO %d configured as output (initial: %s)", pin, initialLevel ? "HIGH" : "LOW"); | |
| 24 | } | ||
| 25 | ✗ | } | |
| 26 | |||
| 27 | ✗ | void EspGpioOutput::setLevel(bool high) { | |
| 28 | ✗ | m_currentLevel = high; | |
| 29 | ✗ | gpio_set_level(m_pin, high ? 1 : 0); | |
| 30 | ✗ | } | |
| 31 | |||
| 32 | ✗ | bool EspGpioOutput::getLevel() const { | |
| 33 | ✗ | return m_currentLevel; | |
| 34 | } | ||
| 35 |