feat: reimplemented door sensor with EventBus and GPIO interrupts#243
feat: reimplemented door sensor with EventBus and GPIO interrupts#243foylaou wants to merge 3 commits intorednblkx:mainfrom
Conversation
- Use EventBus for component communication (no direct dependencies) - Implement interrupt-based GPIO with FreeRTOS task - Add 50ms debounce mechanism - Support invert logic for NO/NC sensors - Add Web UI configuration section - Sync door state to HomeKit CurrentDoorState characteristic
WalkthroughAdds door-sensor support: new misc config fields and UI, firmware ISR/task and EventBus publishing of door state, HomeKit CurrentDoorState characteristic and subscription, plus a client-only logs page and a subproject pointer update. Changes
Sequence Diagram(s)sequenceDiagram
participant GPIO as GPIO Pin
participant ISR as ISR Handler
participant Task as Door Sensor Task
participant EB as EventBus
participant HK as HomeKit Service
GPIO->>ISR: edge interrupt
ISR->>Task: enqueue/notify
Task->>Task: debounce & read pin
Task->>EB: publish EventDoorState(payload)
EB->>HK: deliver EventDoorState
HK->>HK: update CurrentDoorState characteristic
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@main/HardwareManager.cpp`:
- Around line 236-259: Check the results of xQueueCreate and
xTaskCreateUniversal when initializing the door sensor (m_doorSensorQueue and
m_doorSensorTaskHandle) and bail out before calling gpio_isr_handler_add or
gpio_install_isr_service if either allocation failed; if an allocation fails,
free any partial resources (delete queue or delete task handle if applicable),
log an error via ESP_LOGE, and avoid registering the ISR
(door_sensor_isr_handler) or publishing the initial state so the ISR cannot
dereference a null queue. Ensure you reference m_miscConfig.doorSensorPin,
m_miscConfig.doorSensorInvert, m_doorSensorQueue, m_doorSensorTaskHandle,
xQueueCreate, xTaskCreateUniversal, gpio_install_isr_service and
gpio_isr_handler_add in your checks and early-return cleanup.
🧹 Nitpick comments (1)
data/src/routes/logs/+page.ts (1)
5-7: Theasynckeyword is unnecessary here.The
loadfunction returns a plain object synchronously, so theasynckeyword adds no value and slightly increases bundle size.♻️ Suggested fix
-export const load: PageLoad = async () => { - return {}; -} +export const load: PageLoad = () => { + return {}; +};
|
@rednblkx Thank you for the feedback! I've completely reimplemented the door sensor feature from scratch based on your requirements. Here's what has been changed: Architecture Improvements ✅ EventBus-based communication - Removed direct HardwareManager dependency from LockMechanismService. The door sensor now communicates exclusively through EventBus, maintaining proper decoupling. ✅ Interrupt-based GPIO - Replaced polling with GPIO interrupts + FreeRTOS task. The implementation includes:
✅ Minimal dependencies - Only ConfigManager is passed to constructors. All inter-component communication uses EventBus. Implementation Details Backend (C++):
Frontend (Web UI):
Files Modified:
UI Placement I've placed the door sensor configuration in its own section in "System Settings" (between Ethernet and WebUI). I wasn't sure if you'd prefer it elsewhere - happy to move it if you have a better location in mind. Let me know if there are any other changes needed. Thanks for taking the time to review this! |
…p (ours) and loggable (theirs)
|
there's still some changes needed but i don't really have time for review atm, one thing is that you have to drop the unrelated changes, you are free to use AI however you want but at least keep it on a tighter leash. |
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.