Imported from mruwzum/flipperzero-RogueMaster (
applications/external/usb_hid_autofire/AGENTS.md). Install upstream withnpx skills add mruwzum/flipperzero-RogueMaster --skill usb_hid_autofire. Copyright stays with the author.
AGENTS.md
Purpose
This file captures current repository architecture, runtime contracts, and active maintenance priorities. Completed feature history belongs in CHANGELOG.md.
Project Snapshot
- Name:
usb_hid_autofire - Platform: Flipper Zero external app (
.fap) - Primary behavior: emulate USB HID and generate repeated selected events (
Mouse Left/Right,Key Enter,Key Space) - Entry point:
usb_hid_autofire_appinusb_hid_autofire.c - App manifest:
application.fam - App category:
USB - Current version:
0.7(version.h)
Current Module Layout
usb_hid_autofire.c: app lifecycle/orchestration, event loop, centralized cleanupusb_hid_autofire_i.h: shared state, enums, constants, internal module contractsusb_hid_autofire_controller.c: input/controller transitions, delay/mode/preset logic, confirmation flowusb_hid_autofire_hid.c: timer callbacks, HID press/release engine, click scheduler, CPS trackingusb_hid_autofire_ui.c: canvas rendering for main/help screensusb_hid_autofire_settings.c: settings load/save/flush with debounced write scheduling
Critical Invariants
- Always restore previous USB configuration before app exit.
- Never leave any fired control pressed on exit or failure.
- Keep
Backexit reliable from main screen regardless of autofire state. - Keep UI/input responsive while autofire is active.
Runtime Flow
- Allocate queue, viewport, click timer, UI refresh timer, settings debounce timer.
- Switch USB config to HID mouse mode (unless screenshot macro is enabled).
- Load settings from
APP_DATA_PATH(".settings")via Flipper Format. - Feed input and timer callbacks into one event queue.
- Main loop blocks on queue and handles:
- click phase ticks (
press/release+ timer rearm), - periodic UI refresh ticks for real-time CPS (
250 ms), - settings save debounce ticks,
- key events for mode/delay/preset/help/toggle/exit.
- click phase ticks (
- On stop/exit, stop timers, release active control, flush settings, restore USB config, free resources.
Control Model
OKshort (main): toggle active/inactiveOKlong (main): cycle presets (Slow->Medium->Fast)OKconfirm: apply pending high-CPS preset when dialog is shownUpshort/hold-repeat: cycle mode backwardDownshort/hold-repeat: cycle mode forwardLeftshort/hold-repeat: decrease delay with accelerationRightshort/hold-repeat: increase delay with accelerationBacklong (main): open help screenBackshort (help): close help screenBackshort (main): exit app
Timing And Limits
- Delay is clamped to
5..10000 ms. - Click cycle uses half-delay scheduling (
delay / 2each phase), with defensive>=1 mstimer floor. - UI shows real-time CPS from observed release timing, so displayed CPS reflects runtime lag.
- Presets:
Slow:250 msMedium:120 msFast:70 ms(confirmation required)
Persistence
Settings are stored in APP_DATA_PATH(".settings") with debounced writes (500 ms):
delay_msmodepresetstartup_policylast_active
Current UX always forces startup policy to paused on launch. The persisted startup_policy value is saved for future flexibility but is not currently applied at startup.
Active Priorities
P2 (Maintainability)
- Add internal comments only where timing/state transitions are non-obvious.
P3 (Quality + Release)
- Add tests for controller state transitions and timing math.
- Validate behavior across multiple Flipper firmware versions in CI.
- Expand docs with troubleshooting and host OS behavior notes.
Build And Verification
- Build:
./fbt fap_usb_hid_autofire - Build and launch:
./fbt launch_app APPSRC=usb_hid_autofire
Manual smoke checklist:
- App opens and renders status/version.
OKtoggles active/inactive.Up/Downcycle fired mode.Left/Rightadjust delay and clamp at5..10000 ms.OKlong cycles presets;Fastrequires confirmation.Backlong opens help;Backshort closes help.Backshort from main exits and USB behavior is restored.- While active, host receives repeated selected events.
- After exit, no stuck mouse/keyboard pressed state remains.
- After restart, persisted settings are restored.
Notes For Future Agents
- Preserve control contract unless UX changes are intentional and documented.
- If timing behavior changes, keep labels and help text unit-accurate.
- USB config restoration and release-on-stop are non-negotiable safety rules.
- Keep
AGENTS.mdfocused on current state and operating guidance; useCHANGELOG.mdfor completed feature history. - To bump the version of the application you need to adapt
VERSIONinversion.handfap_versioninapplication.fam. Semver is used.
