Input driver
Detroit engine has capability to load external input drivers at runtime. Drivers to load is specified in application config file, by input_driver_enable option. At the time of writing, Detroit is supplied with one input driver which supports USB classic NES gamepad. The device looks like the original NES gamepad but has USB plug at the end of the cord. In order to use input driver, application config file needs to be set as:
input_driver_enable = input_usb_classic_nes_gamepad.so
To compile the driver along the engine, pass following option to configure script:
--with-usb_classic_nes_gamepad
There is also other settings to control the input driver, most notable input_driver_params_1 and its device attribute. Parameter format is pipe (|) separated list of attributes, their optional values separated by equal sign (=). For example, if your NES gamepad is attached to /dev/uhid1, you need to use following setting to get the gamepad working if it was not detected automatically:
input_driver_params_1 = input_usb_classic_nes_gamepad.so:device=/dev/uhid1
If driver autodetects the gamepad, there is no need to use the device attribute.
To control event forwarding from the gamepad to application, use input_driver_events_1 parameter. Parameter format is either pipe (|) separated list of window names where to pass the events, or a pipe (|) separated list of event names with Ano script function names separated by equal sign (=). In later case, each event coming from the driver has its own predefined name:
- bp, button press event
- br, button release event
- kp, key press event
- kr, key release event
- xy, x/y motion event
- xyz, x/y/z motion event
- ad, angle/distance motion event
For example, to call drv_bp() and drv_br() functions in Ano script when corresponding event occurs, following parameters can be used:
input_driver_events_1 = input_usb_classic_nes_gamepad.so:bp=drv_bp|br=drv_br
Each event callback function must take parameters explained below, each parameter should be self explanatory what they contain when event occurs and callback function is called:
callback drv_bp (_button, _state, _pressure) { dump _button dump _state dump _pressure } callback drv_br (_button, _state) { dump _button dump _state } callback drv_kp (_button, _state, _pressure) { dump _button dump _state dump _pressure } callback drv_kr (_button, _state) { dump _button dump _state } callback drv_xy (_x, _y) { dump _x dump _y } callback drv_xyz (_x, _y, _z) { dump _x dump _y dump _z } callback drv_ad (_angle, _distance) { dump _angle dump _distance }
Another example translates events from the input_usb_classic_nes_gamepad.so driver to window system events, and sends them to window named WindowName. That way the gamepad works like any other pointing device, there is no need to use any callback functions.
input_driver_events_1 = input_usb_classic_nes_gamepad.so:WindowName
See examples/input_driver directory for live example.
Copyright © 2023, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.