| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "Gate.h" | ||
| 2 | #include "esp_log.h" | ||
| 3 | |||
| 4 | static const char* TAG = "Gate"; | ||
| 5 | |||
| 6 | ✗ | Gate::Gate(gpio_num_t lightBarrierPin, gpio_num_t motorPin, ledc_channel_t ledcChannel) | |
| 7 | ✗ | : m_button(nullptr) // No button | |
| 8 | ✗ | , m_isOpen(false) { | |
| 9 | // Create light barrier and motor | ||
| 10 | ✗ | m_lightBarrier = std::make_unique<EspGpioInput>(lightBarrierPin, 0); | |
| 11 | ✗ | m_motor = std::make_unique<EspServoOutput>(motorPin, ledcChannel, false); | |
| 12 | |||
| 13 | // Start with barrier closed | ||
| 14 | ✗ | m_motor->setLevel(false); | |
| 15 | ✗ | } | |
| 16 | |||
| 17 | ✗ | Gate::Gate(gpio_num_t buttonPin, uint32_t buttonDebounceMs, | |
| 18 | ✗ | gpio_num_t lightBarrierPin, gpio_num_t motorPin, ledc_channel_t ledcChannel) | |
| 19 | ✗ | : m_isOpen(false) { | |
| 20 | // Create button, light barrier and motor | ||
| 21 | ✗ | m_button = std::make_unique<EspGpioInput>(buttonPin, buttonDebounceMs); | |
| 22 | ✗ | m_lightBarrier = std::make_unique<EspGpioInput>(lightBarrierPin, 0); | |
| 23 | ✗ | m_motor = std::make_unique<EspServoOutput>(motorPin, ledcChannel, false); | |
| 24 | |||
| 25 | // Start with barrier closed | ||
| 26 | ✗ | m_motor->setLevel(false); | |
| 27 | ✗ | } | |
| 28 | |||
| 29 | ✗ | void Gate::open() { | |
| 30 | ✗ | if (!m_isOpen) { | |
| 31 | ✗ | ESP_LOGI(TAG, "Opening barrier"); | |
| 32 | ✗ | m_motor->setLevel(true); // HIGH = Open | |
| 33 | ✗ | m_isOpen = true; | |
| 34 | } | ||
| 35 | ✗ | } | |
| 36 | |||
| 37 | ✗ | void Gate::close() { | |
| 38 | ✗ | if (m_isOpen) { | |
| 39 | ✗ | ESP_LOGI(TAG, "Closing barrier"); | |
| 40 | ✗ | m_motor->setLevel(false); // LOW = Closed | |
| 41 | ✗ | m_isOpen = false; | |
| 42 | } | ||
| 43 | ✗ | } | |
| 44 | |||
| 45 | ✗ | bool Gate::isOpen() const { | |
| 46 | ✗ | return m_isOpen; | |
| 47 | } | ||
| 48 | |||
| 49 | ✗ | bool Gate::isCarDetected() const { | |
| 50 | // Light barrier returns HIGH when blocked (car present) | ||
| 51 | ✗ | return m_lightBarrier->getLevel(); | |
| 52 | } | ||
| 53 |