Day44 - Input Userspace Application¶
Objective¶
- Read input events from
/dev/input/eventX - Decode key events (short / long / double click)
- Implement a userspace application
- Control LED based on input events
System Flow¶
GPIO Button
↓
Kernel Input Driver
↓
input_report_key()
↓
/dev/input/eventX
↓
Python Application
↓
LED Control (sysfs)
Input Event Mapping¶
| Action | Key Code |
|---|---|
| Short Click | KEY_ENTER |
| Long Click | KEY_ESC |
| Double Click | KEY_SPACE |
Userspace Reader¶
File¶
Implementation Overview¶
1. Open input device¶
2. Parse input_event¶
3. Filter key press events¶
4. Map key to action¶
LED Control¶
Check LED device¶
Example:
Switch to manual mode¶
Control LED¶
Application Logic¶
Build & Run¶
Expected Output¶
Validation Steps¶
1. Verify input events¶
2. Run application¶
3. Perform actions¶
- Press button shortly → LED toggles
- Hold button (>2s) → LED ON
- Double click → LED OFF
Observations¶
- Input driver does not define behavior
- Userspace decides how to interpret events
- Same key event can map to different actions
Key Learning¶
Extension Ideas¶
- Support multiple input devices
- Use select/poll for event loop
- Add debounce in userspace (compare behavior)
- Build CLI or GUI application
- Integrate with other subsystems (e.g. IIO trigger)