liveBook · Manning

Device file

As explained in Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi

A filesystem entry that provides a file-like interface to a hardware device or kernel device driver.

A device file is a filesystem entry that gives software a file-like interface to hardware or a kernel device driver. On Unix systems, connected joysticks appear automatically as device files such as /dev/input/js0, /dev/input/js1, and /dev/input/js2. section 7.5.1

Device files make hardware discovery and event inspection straightforward:

  • List joystick device files with ls /dev/input/js*. section 7.5.1
  • Use the device-file path with jstest to inspect live button and axis events. section 7.5.1
  • Map numeric button and axis identifiers to controls in an application. section 7.5.1

Inspecting a controller

After locating /dev/input/js0, run jstest /dev/input/js0. The terminal reports detected axes and buttons, then updates their values as controls are pressed or moved. section 7.5.1

$ ls /dev/input/js*
/dev/input/js0

Use this listing to discover the joystick device path before reading its events. section 7.5.1

How Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi covers it

How deep it goes
Defines automatic creation and naming, then demonstrates event inspection without descending into kernel implementation.
Examples
Uses /dev/input/js0, ls, jstest, controller buttons, axes, and numeric event mappings.
What it assumes
Assumes a connected joystick and basic terminal use while introducing device paths and event values.
What you can do after
Operate joystick inspection with jstest and identify control numbers for application mappings.
How it connects
Connects the Linux input subsystem, joystick support, Unix systems, and device drivers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi. The section links point to the parts of the book it draws on.