Fake mtouch driver
You can find the fake mtouch driver available at https://gitlab.com/qnx/projects/drivers/mtouch-fake.
The fake driver loops in a separate thread generating random touch events. It also updates the fake device state, that is, which touch points are valid, their coordinates, uses patterns to calculate coordinates. The driver only uses the required/optional callbacks to return the current state of the fake device. This is in contrast to the Stub mtouch driver, which has a much simpler logic, generating device state during the callback invocation based on current time.
The following diagram illustrates the fake driver:

To use the fake mtouch driver, verify that libmtouch-fake.so is available on your device, and modify the mtouch.conf file:
begin mtouch
driver = fake
options = start_delay_secs=10,iteration_delay_usecs=5000,burst_count=2
end mtouchThe fake driver:
Defines a fake device-specific structure
fake_device_t.Implements the required callback functions get_contact_id(), is_contact_down(), and get_coords().
- get_contact_id(), is_contact_down(), and get_coords() return appropriate values based on the device state as set by the hardware thread.
Implements the single optional function get_down_count() to support the MTOUCH_CAPABILITIES_CONTACT_COUNT capability.
- get_down_count() returns appropriate value based on the device state as set by the hardware thread.
Implements the following functions to generate touch events in specific patterns:
- reset_fingers() — sets the active touch count to 0, and resets all coordinates to (0, 0).
- next_state() — cycles through different generation patterns.
- diags_state(), sine_state(), zigzag_state() — generate touch event data for a single finger.
- diags2_state(), sine2_state(), zigzag2_state() — generate touch event data for two fingers.
- circle_state()
- event_generator() — runs in a new thread created by mtouch_driver_init(), and after a delay, loops, updating the fake device state, calling mtouch_driver_process_packet() to simulate touch events and sleeping for a period of time, until cancelled by mtouch_driver_fini().
Implements the required mtouch_driver_init() function, which:
Dynamically allocates memory for the fake device and initializes it with defaults.
Calls input_parseopts() to parse the options found in configuration file and to process them using the set_option() function.
Sets driver parameters based on the parsed options.
Calls attach_driver() to set up the
mtouchframework. The attach_driver() function:Declares
mtouch_driver_funcs_tinstance and specifies the implemented functions get_contact_id(), is_contact_down(), get_coords(), and get_down_count(), leaving all other functions unimplemented by specifying NULL.Declares
mtouch_driver_params_tinstance and initializes the driver parameters using defaults, as well as options specified in the configuration file.Calls mtouch_driver_attach() to attach the driver to the Input Events framework.
Creates a new thread to execute event_generator().
Returns pointer to the initialized device or NULL on error.
Implements the required mtouch_driver_fini() function, which:
Calls cancels the event_generator() thread.
Calls mtouch_driver_detach() to detach the driver from the Input Events framework.
Frees the memory allocated for the fake device.
Implements the set_option() function used by input_parseopts() to process the options from the configuration file.
- Based on the passed in option, the function sets specific driver options to value or displays an error.
