2.4 KiB
2.4 KiB
Lock Control
Purpose
This module commands the KR-S79 lock opening input.
The lock itself remains powered by the battery pack. The firmware only drives the control stage connected to the lock SIG input.
Hardware
- Seeed Studio XIAO nRF52840.
- Control signal: XIAO pin
D9. - D9 mapping in Zephyr:
GPIO1 pin 14. - D9 is declared in the application Devicetree overlay as
GPIO_ACTIVE_HIGH. - External S8050/S8550 driver stage.
- Active-high signal.
The GPIO is configured directly with GPIO_OUTPUT_INACTIVE. The idle state is low to avoid accidental opening at startup or after flashing.
Public API
int lock_control_init(void);
int lock_control_open(void);
Current Behavior
lock_control_init()configures D9 directly as an inactive GPIO output.lock_control_init()never sends an unlock pulse.lock_control_open()drives D9 high for 150 ms, then immediately returns it inactive withgpio_pin_set_dt(..., 0). The additional 50 ms compared with the original pulse gives the mechanical relay more time to pull in while limiting coil-on time and battery use.- All GPIO return codes used by the lock control path are logged.
- No PWM is used.
Access Code Flow
The main loop collects numeric keypad input.
- Codes are six digits long.
- Up to 8 permanent and 20 temporary/one-time codes can be stored.
- Codes are persisted through Zephyr settings with the NVS backend.
- The development default code is
784512. - A valid six-digit entry triggers
lock_control_open(). - The PN532 reader triggers
lock_control_open()after a valid stored tag UID is detected. *,#, andBclear the current entry.- A valid six-digit entry triggers one long success beep before the opening pulse.
- An invalid six-digit entry triggers three short close beeps and keeps the red LED on for 1 second.
- The first keypad press starts one non-renewable 15-second NFC scan window, shown with the blue LED; later presses cannot extend the active window.
- A valid NFC tag UID uses the same success beep and lock opening path as a valid keypad code.
- The green LED stays on while the lock state feedback reports the lock open.
- A short reminder beep is emitted every 2 seconds while the lock state feedback reports open.
- Door state changes are reported over UART as
Door openedandDoor closed. - Each periodic reminder is reported over UART as
Door open reminder beep. - LEDs stay off during startup and while the lock is closed.