libretro / libretro/RetroArch

RetroArch sysled driver is outdated -- workaround supplied

Open
#16,004 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
14.1k
Forks
2.2k
Avg merge
7h 35m
Merged PRs (30d)
51

Description

MAME 2003-Plus Asteroids flashes the keyboard LED(s) after inserting coin(s), as emulated off the real machine to indicate it is waiting for a Player 1 or Player 2 Start button press.

Upon inspection of RetroArch led_sys_linux.c, it has a hard-wired path to "/sys/class/leds/led%d" to process off the list enumerated by trigger, which allows for invoking the set brightness (0 or 1) later.

The problem is Linux leds are enumerated out from the keyboard (USB or Bluetooth) device entry as "/sys/class/leds/input%d::%s" whereas this sysled driver would need to also supply %s as "capslock", "numlock", or "scrolllock" -- there may be others listed, but I am focused on these three common keyboard LEDs.
See LED handling under Linux.

For giggles, I replaced the led_sys_linux.c hard-coded path to sysfs /sys/class/leds and simply pointed it to devtmpfs /dev, then wrote this udev rule as /etc/udev/rules.d/99-leds.rules:

# 8BitDo retro mechanical keyboard led aliases

SUBSYSTEM=="leds", ACTION=="add", ATTR{trigger}=="*\[kbd-capslock\]*", PROGRAM="/bin/sh -c ' \
        rm -f /dev/led1 ; \
        ln -s /sys%p /dev/led1 ; \
        chmod a+w /dev/led1/brightness /dev/led1/trigger ; \
'"

SUBSYSTEM=="leds", ACTION=="add", ATTR{trigger}=="*\[kbd-scrolllock\]*", PROGRAM="/bin/sh -c ' \
        rm -f /dev/led2 ; \
        ln -s /sys%p /dev/led2 ; \
        chmod a+w /dev/led2/brightness /dev/led2/trigger ; \
'"

SUBSYSTEM=="leds", ACTION=="add", ATTR{trigger}=="*\[kbd-numlock\]*", PROGRAM="/bin/sh -c ' \
        rm -f /dev/led3 ; \
        ln -s /sys%p /dev/led3 ; \
        chmod a+w /dev/led3/brightness /dev/led3/trigger ; \
'"

... and added the led driver configuration lines into retroarch.cfg as:

led_driver = "sysled"
led1_map = "1"
led2_map = "2"
led3_map = "3"

This keyboard makes it easy to switch between Bluetooth and USB modes thus triggering the udev events, which in turn, makes these usable symbolic links to the leds interface.

Upon firing Asteroids up and inserting 1st coin, yay, the CAPSLK led began flashing. Insert 2nd coin, yay, the SCRLK led began flashing. After hitting P2 start, unfortunately I caught it in the state where the LEDs were ON and they remained ON. Even after exiting the game, so perhaps another "cleanup" issue?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with RetroArch's led_sys_linux.c and the led_driver, led1_map, led2_map, and led3_map settings shown in retroarch.cfg. Reproduce the MAME 2003-Plus Asteroids keyboard LED behavior, then compare the driver's /sys/class/leds path with the input%d::capslock, numlock, and scrolllock entries described in the issue. Done means the relevant LEDs can be controlled and are cleaned up after the game exits.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.