Hacker News new | ask | show | jobs
by SushiHippie 785 days ago
From his twitter:

(I'll copy and paste the text here, as I don't know how much you see of this text logged out)

> Why couldn’t I just emulate a standard mouse and scroll smoothly? Sounds easy. Unfortunately there is a holdover from two decades ago in the way mouse drivers are written into USB. Because mice used to use low resolution encoders, a single “detent” event would be about 22.5 degrees. Hard coded into the kernel level of Android and Windows is the instruction to interrupt this single detent as a 40 pixel scroll for generic devices. This is what results in the chunky style scrolling on a PC.

> Only recently have specialty devices like the Logitech mice used custom drivers to bypass this and offer high resolution single pixel scrolling instructions. Unfortunately these drivers were not rolled into the Android kernel, so even when I sniffed the BLE traffic with Wireshark and impersonated a Logitech device, I wouldn’t get that silky smooth scrolling on mobile. No go.

> The slightly hacky workaround was to go one level deeper than the standard Arduino libraries.

> A quick description of how USB devices work. HID stands for Human Interface Device and is a protocol implemented over USB protocol. HID devices do advertise their capabilities through the HID report descriptor, a fixed set of bytes describing exactly what HID reports may be sent between the device and the host and the meaning of each individual bit in those reports. For example, a HID Report Descriptor may specify that “in a report with ID 3 the bits from 8 to 15 is the delta x coordinate of a mouse”. The HID report itself then merely carries the actual data values without any extra meta information.

> My goal was to use a customized descriptor to send the byte package of a one finger touchpad with absolutely coordinate system and 1 button to the host. This way I could perform the digital emulation of a finger making contact with the screen, performing a Y axis movement while remaining in contact, and then lifting off the screen before reaching the top. This movement would have to be repeated hundreds of times seamlessly to provide the illusion of smooth scrolling.

> Additional complications arose from the fact that Bluetooth low energy has a minimum latency of 8milliseconds, with most hosts negotiating an even slower rate such as 20 milliseconds. Simply blasting commands at a few hundred hertz doesn’t work.

> The internet is filled with unanswered forum questions about how to do all of this. I think I’m probably the first one to achieve a working implementation of this particular smooth scrolling solution. This single problem occupied much time than the rest of the project combined. No doubt that Logitech or Apply could achieve a more elegant solution. My hope is that a big company takes interest in Doomscroller takes it off my hands.

https://x.com/andrewmccalip/status/1781674889679982991

1 comments

Jump from completely out of context here... Wait, bluetooth devices are USB ones tunneled over bluetooth?

If that's the case, why does audio work so badly? (I'm guessing there's a list of exceptions that BT supports natively, none of which work.)

(I'm not a SME, but I looked a bit into this while buying a bluetooth headphone)

Audio works with some bluetooth specific codecs like SBC, Qualcomm aptX (adaptive/HD), LDAC, ... or Opus and AAC

These codecs need to be supported by both sender and receiver.

And for example many bluetooth speakers only support SBC as they don't want to pay the fees for aptX and LDAC (which are both codecs that sound and work very well, LDAC even supports up to 96 kHz sample rates with 32 bit depth).

So I suppose (i don't know for sure) problems could be a) audio is more of a special case with all its codecs b) SBC is widespread, but does not sound good c) codec support on operating systems and bluetooth chips varies widely.

Yeah, surprised me too. There are different categories inside of Bluetooth, classic and low energy. LE has a low rate, no more than 100hz.