Writing a device detection controller