FreeSpacenav / spacenavd

Free user-space driver for 6-dof space-mice.
http://spacenav.sourceforge.net
GNU General Public License v3.0
279 stars 55 forks source link

Turn off LED on startup if LED_OFF is set. #39

Closed gebner closed 3 years ago

gebner commented 3 years ago

When plugging in a SpaceMouse Compact, the LED turns on even if it is disabled in the configuration file. It only turns off after toggling the LED setting in spnavcfg.

This PR sends a command to disable the LED after connection (if the LED is disabled in the configuration file). Weirdly enough, a single set_led_evdev(dev, 0) call is not enough to turn off the LED (at least on my device). It is necessary to call set_led_evdev(dev, 1) first.

jtsiomb commented 3 years ago

Interesting. All earlier devices used to start up with the LED disabled, which is why spacenavd only explicitly enables, but doesn't try to disable it on startup. I think it's perfectly reasonable to explicitly force the LED state by regardless of the assumed initial state, but I'm slightly concerned by aving to enable it first before disabling it. I'm afraid this might cause a visible blinking on all other devices which do have the LED disabled by default.

Can you chase this issue down a bit further and figure out why it doesn't turn off by a single set_led_edev(dev, 0) first? Meanwhile I will merge this, but will remove the blink call until it's established that it's definitely necessary.

gebner commented 3 years ago

Can you chase this issue down a bit further and figure out why it doesn't turn off by a single set_led_edev(dev, 0) first?

Do you have any suggestions as to proceed? I've already tried calling set_led_evdev(dev, 0) after every input event (in case it needs to be sent after a delay or multiple times), but that didn't help either.

If it's just the spacemouse compact that starts with the led on, then maybe it would be best to check for the usb id first before the blink call?

jtsiomb commented 3 years ago

Actually I tested it and it seems to be fast enough to not cause any visible blinking, so I merged it as is. Thank you for your fix. I would still like to know why it fails to turn off with a single off command though, so if you can find some time and can think of any experiment that can shed light into it please post your findings here.

The main thing I would try is to see what set_led_evdev does, don't start spacenavd at all, but write a simple program that can send LED off commands, plug the device and see if that helps. It might be the case that the bug is some state caching in the HID driver in the kernel itself, or it might be a device firmwaere bug in the SpaceMouse. In both cases we'll just leave the toggling as is in spacenavd, but it would be interesting to find out what's going on.

Edit: of course don't feel obligated to do any of that. I'm just curious, and it would be nice to shed the redundant call just for aesthetics. But I admit there are much bigger "aesthetic" issues in spacenavd at the moment that I'm not taking the time to fix, than just a call to enable the LED before disabling it.