Parking Garage Control System
ESP32 Parking Garage – ESP-IDF/FreeRTOS
Loading...
Searching...
No Matches
EntryGateController.h
Go to the documentation of this file.
1#pragma once
2
3#include "IEventBus.h"
4#include "IGpioInput.h"
5#include "IGate.h"
6#include "ITicketService.h"
7#include "freertos/FreeRTOS.h"
8#include "freertos/timers.h"
9#include <memory>
10
24
38 public:
48 IEventBus& eventBus,
49 IGpioInput& button,
50 IGate& gate,
51 ITicketService& ticketService,
52 uint32_t barrierTimeoutMs = 2000);
53
55
56 // Prevent copying
59
63 [[nodiscard]] EntryGateState getState() const { return m_state; }
64
68 [[nodiscard]] const char* getStateString() const;
69
73 [[nodiscard]] IGate& getGate() { return *m_gate; }
74
78 [[nodiscard]] IGpioInput& getButton() { return *m_button; }
79
85
90 void reset();
91
92#ifdef UNIT_TEST
93 // Test helpers to simulate timer expirations without FreeRTOS timers
94 void TEST_forceBarrierTimeout() {
95 onBarrierTimeout();
96 }
97#endif
98
99 private:
100 void onButtonPressed(const Event& event);
101 void onLightBarrierBlocked(const Event& event);
102 void onLightBarrierCleared(const Event& event);
103 void onBarrierTimeout();
104
105 void setState(EntryGateState newState);
106 void startBarrierTimer();
107 void stopBarrierTimer();
108
109 static void barrierTimerCallback(TimerHandle_t xTimer);
110
111 IEventBus& m_eventBus;
112 IGpioInput* m_button;
113 IGate* m_gate;
114 ITicketService& m_ticketService;
115
116 EntryGateState m_state;
117 uint32_t m_barrierTimeoutMs;
118 uint32_t m_currentTicketId;
119 TimerHandle_t m_barrierTimer;
120};
EntryGateState
Entry gate state machine states.
Definition EntryGateController.h:14
Entry gate controller with state machine.
Definition EntryGateController.h:37
IGpioInput & getButton()
Get button reference (for debugging/console commands)
Definition EntryGateController.h:78
EntryGateController(const EntryGateController &)=delete
void setupGpioInterrupts()
Setup GPIO interrupts Call this after construction to enable hardware interrupts.
Definition EntryGateController.cpp:46
~EntryGateController()
Definition EntryGateController.cpp:40
IGate & getGate()
Get gate reference (for debugging/console commands)
Definition EntryGateController.h:73
void reset()
Reset controller to initial state Stops timers, resets state to Idle, clears current ticket,...
Definition EntryGateController.cpp:82
EntryGateController & operator=(const EntryGateController &)=delete
EntryGateState getState() const
Get current state.
Definition EntryGateController.h:63
const char * getStateString() const
Get state as string.
Definition EntryGateController.cpp:59
Interface for event bus.
Definition IEventBus.h:12
Gate interface for barrier control abstraction.
Definition IGate.h:9
Interface for GPIO input abstraction.
Definition IGpioInput.h:11
Interface for ticket service.
Definition ITicketService.h:13
Event structure.
Definition Event.h:45
Coverage