Selecting a device showed nothing: whether it paired went only to the
log. A pairing now says on screen when it starts and whether it worked,
and a Wii controller that could not be paired gets a reminder to press
its sync button and select it again while its lights blink.
Windows asked the user for a Wii controller's PIN, which is the radio's
own address in binary and cannot be typed. The driver now registers for
the device's authentication and answers its PIN request itself, falling
back to the older call without Vista's functions. A device whose name
the search had not heard yet is looked up again before pairing, so a
Wii controller is not taken for another device.
Quitting while a pairing waited on Windows hung, as the driver joined
its thread. A thread still running is now let go, and the last of it
and the driver to finish frees the driver.
Windows can run a Bluetooth adapter on its own generic driver, which
often finds no classic device at all - no phone, no Wii controller -
and says nothing of it: its own pairing screen is as empty. When a
scan finds nothing, the Windows driver looks whether the adapter's
driver is bth.inf, Windows' own, and the list's "No Bluetooth Devices
Found" then says so and what to install; the log says it too. A
driver can tell this through a new, optional call.
The Bluetooth list had no way to look again short of leaving it and
coming back. It now ends with Scan for Devices, below the devices so
their places stay the driver's numbers for them.
A scan waited out its whole ten-second window whatever the driver was
doing. A driver can now say it has found all it will, and the scan
task, parked meanwhile and looking every 100 ms, ends then. The
Windows driver says so when its search returns, and searches for
about five seconds instead of eight: a controller in pairing mode
answers within the first. It also lists a device that has not said
its name yet, by its address, and logs a search that found nothing.
A scan that found nothing cleared the list and put nothing back, and
a list with nothing in it cannot be left with Back. It now says no
devices were found, as the list does before a scan; the Windows
driver also logs how many a scan found.
Windows' settings often cannot pair a Wii remote or a Wii U Pro
Controller. A Bluetooth driver on Windows' own stack, through
bthprops.cpl loaded when it starts, gives the menu's Bluetooth list:
a scan finds the devices in pairing mode, and picking one pairs it.
A Wii controller is paired as Dolphin pairs one whose sync button was
pressed - the radio's address its PIN, after a pairing Windows
remembers but cannot reach is forgotten - and its HID service is
turned on, so Windows makes it a HID device the hid joypad driver
finds. Searching and pairing block for seconds, so each runs on a
thread of the driver's.
Windows builds have Bluetooth by default. The list now scans again
each time it is opened, showing the last scan's devices meanwhile, so
a pad put in pairing mode since is found; and the scan task is
declared without networking.
A nearby Bluetooth name can contain a newline that forges a line in
bluetoothctl devices output. The next status check or a connect action
used the forged line's second token in a popen() command, allowing
shell commands to run as the RetroArch user.
Accept only lines with a valid Bluetooth address, use that address
for status, connect, and remove commands, and cap the list to the
fixed status arrays.
A Bluetooth scan ran inside one task handler call, and both drivers
waited out the ten-second discovery window in it: bluez in a
retro_sleep(10000) between StartDiscovery and StopDiscovery,
bluetoothctl in a pclose() of "bluetoothctl --timeout 10 scan on".
That is the task queue's one worker thread, so for the whole window
every other task - downloads, thumbnails, cloud sync - sat queued
behind the scan.
The driver interface's scan() becomes scan_begin() and scan_end(),
BLUETOOTH_SCAN_WINDOW_US apart. The scan task calls begin, sets its own
'when' to the end of the window and returns unfinished; the task queue
keeps scheduled tasks behind ready ones, so everything else runs in the
meantime, and the task comes back at the end of the window to call end
and finish. A cancel ends the window early.
- bluez: begin powers the adapter and starts discovery on a connection
it keeps open - BlueZ ends a client's discovery when its connection
goes - and end stops discovery, reads the devices and disconnects.
A begin that failed part way leaves end only disconnecting. The
driver's free() now releases a connection a scan still holds, and
the device list, which it leaked.
- bluetoothctl: begin starts "scan on" with popen() and returns; end
pcloses it, which by the end of the window has already exited, then
lists the devices as before. free() closes a scan still running.
samples/tasks/bluetooth_scan runs the scan task on the real threaded
task queue against stand-in driver calls, with the window shortened to
300 ms. It pins that begin and end run once each a window apart, that
another task pushed during the window runs within 100 ms, and that the
scan's callback fires. Clean under ASan, UBSan and TSan; added to the
samples/tasks job.
the previous method does not remove the pairing of the selected device,
user must remove the pairing manually by modifying filesystem.
change tested on real system (Lakka-RPi4.aarch64).
* Less string copies
* Some general cleanups
* Add extra param to runloop_message_queue_push so we can pass size_t
of the message
* Consistent conventions for local variable usage for certain things
due to some changes in bluez / bluetoothctl, `pairable on` is required
in order to create a `[LinkKey]` section in the configuration file for
the connected device. if this section is missing, the device / gamepad
will not pair after being disconnect and has to be repaired again.