Mapping Controllers in Moonlight
-
Hi all,
Has anyone had any luck editing the gamecontrollerdb.txt file to get a generic gamepad working with Moonlight NVIDIA GE? I've mapped out my controller previously using this here:
https://retropie.org.uk/forum/topic/15577/ppsspp-controller-setup-guide-for-when-nothing-else-worksLike so, I get the following output:
030000004f1b00000692000001010000,SparkFun SparkFun Pro Micro,platform:Linux,a:b5,b:b1,x:b4,y:b2,back:b8,start:b3,leftstick:b12,rightstick:b0,leftshoulder:b11,rightshoulder:b7,dpup:+a4,dpdown:-a4,dpleft:-a5,dpright:+a5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b9,righttrigger:b6,
I've added this configuration to the /home/pi/.config/moonlight/gamecontrollerdb.txt file.
The only current problem is, my DPAD doesn't work at the moment and I am not entirely sure what I'm doing wrong - the inputs just aren't being recognized by the host PC. Would appreciate some help from anyone who may have tackled this issue before with Moonlight and is familiar with xinput/dinput type controllers.
Let me add that the DPAD works just fine in Steam Link standalone, and audio also works just fine in Steam Link standalone application. However, the only two things that are not working with NVIDIA Gamestreaming are the DPAD inputs and audio.
Here is the contents of my moonlight.conf file:
## Hostname or IP-address of host to connect to ## By default host is autodiscovered using mDNS #address = 1.2.3.4 ## Video streaming configuration #width = 1280 #height = 720 #fps = 60 ## Output rotation (independent of xrandr or framebuffer settings!) ## Allowed values: 0, 90, 180, 270 #rotation = 0 ## Bitrate depends by default on resolution and fps ## Set to -1 to enable default ## 20Mbps (20000) for 1080p (60 fps) ## 10Mbps (10000) for 1080p or 60 fps ## 5Mbps (5000) for lower resolution or fps #bitrate = -1 ## Size of network packets should be lower than MTU ## If streaming with WAN optimizations, this will be capped at 1024. #packetsize = 1392 ## Select video codec (auto/h264/h265) #codec = auto ## Default started application on host #app = Steam ## Default used mapping for streaming ## Searched for in $XDG_DATA_DIRS/moonlight or /usr/share/moonlight and /usr/local/share/moonlight ## Mapping can also be user overrided in $XDG_CONFIG_DIR/moonlight or ~/.config/moonlight or current directory #mapping = gamecontrollerdb.txt ## Enable selected input devices ## By default all available input devices should be used ## Only evdev devices /dev/input/event* are allowed ## To use a different mapping then default another mapping should be declared above the input #input = event1 ## Enable GFE for changing graphical game settings for optimal performance and quality #sops = true ## Play audio on host instead of streaming to client #localaudio = false ## Send quit app request to remote after quitting session #quitappafter = false ## Disable all input processing (view-only mode) #viewonly = false ## Select audio device to play sound on #audio = local ## Select the audio and video decoder to use # default - autodetect ## aml - hardware video decoder for ODROID-C1/C2 ## rk - hardware video decoder for ODROID-N1 Rockchip ## omx - hardware video decoder for Raspberry Pi ## imx - hardware video decoder for i.MX6 devices ## x11 - software decoder ## sdl - software decoder with SDL input and audio ## fake - no audio and video ##platform = default ## Directory to store encryption keys ## By default keys are stored in $XDG_CACHE_DIR/moonlight or ~/.cache/moonlight #keydir = /dir/to/keys ## Enable QOS settings to optimize for internet or local network ## yes - optimize for WAN streaming ## no - optimize for LAN streaming ## auto (default) - decide automatically based on target IP address #remote = auto ## Enable 5.1/7.1 surround sound #surround = 5.1 ## Load additional configuration files #config = /path/to/config
Thanks all
-
Run
moonlight
with the-verbose
parameter and see if the mapping file is read. In yourmoonlight.conf
file, the option for the file is commented out, did you try un-commenting it ? -
Sorry, which part is commented exactly? I don’t see anything related to the controller or audio that is commented.
OK. How do I run moonlight with verbose logging? I’ve just been executing it from the main RetroPie menu front end. I don't know if this matters, but my DPAD is mapped as RX/RY values in the controller we have, since that was the easiest way to do it. Other controllers seem to use a different mapping, for example with "h" instead of the "a" prefix.
-
@stonededge said in Mapping Controllers in Moonlight:
Sorry, which part is commented exactly? I don’t see anything related to the controller or audio that is commented.
The
mapping
option seems commented out with the#
.OK. How do I run moonlight with verbose logging? I’ve just been executing it from the main RetroPie menu front end.
Edit the
emulators.cfg
file from/opt/retropie/configs/steam
and add the-verbose
parameter to themoonlight
start command.
Looking at themoonlight
's startup command, I see it relocates$XDG_CONFIG_DIR
to/opt/retropie/configs/all/moonlight
so try also copying your mapping file in that folder. -
@mitu said in Mapping Controllers in Moonlight:
@stonededge said in Mapping Controllers in Moonlight:
Sorry, which part is commented exactly? I don’t see anything related to the controller or audio that is commented.
The
mapping
option seems commented out with the#
.OK. How do I run moonlight with verbose logging? I’ve just been executing it from the main RetroPie menu front end.
Edit the
emulators.cfg
file from/opt/retropie/configs/steam
and add the-verbose
parameter to themoonlight
start command.
Looking at themoonlight
's startup command, I see it relocates$XDG_CONFIG_DIR
to/opt/retropie/configs/all/moonlight
so try also copying your mapping file in that folder.OK, I've added the verbose comment - could I ask you where I can find the log output?
Regarding the last point, the configuration for my Sparkfun Sparkfun Pro Micro controller was already added under the #Linux category within that repository.
Within the /dev/shm folder directory, I can show you that the runcommand log returns the following output:
Parameters: Executing: /opt/retropie/supplementary/moonlight/moonlight.sh stream -config "/home/pi/RetroPie/roms/steam/Steam.ml"
-
@stonededge said in Mapping Controllers in Moonlight:
OK, I've added the verbose comment - could I ask you where I can find the log output?
Should be in
/dev/shm/runcommand.log
? Looking at the log you posted, there is no-verbose
parameter added.
Try executing the start command manually, after exiting EmulationStation/opt/retropie/supplementary/moonlight/moonlight.sh stream -verbose -config "/home/pi/RetroPie/roms/steam/Steam.ml"
-
@mitu said in Mapping Controllers in Moonlight:
/opt/retropie/supplementary/moonlight/moonlight.sh stream -verbose -config "/home/pi/RetroPie/roms/steam/Steam.ml"
Ok, thanks Mitu. That returns the following verbose log, which to me looks like its pairing and detecting the controller. Do you see any issues here? It does seem to loop over the controller twice, saying "Not mapping SparkFun SparkFun Pro Micro as a gamepad" but then proceeds to connect again. As mentioned before, all buttons work, apart from the DPAD itself.
Moonlight Embedded 2.5.2 (PI;MMAL;ALSA;PULSE;EMBEDDED) Searching for server... Connect to 100.64.1.21... GPU: NVIDIA GeForce RTX 2060, GFE: 3.24.0.126 (gs_04_37_30719632, 7.1.437.0) Platform Raspberry Pi (Broadcom) Loading mappingfile /opt/retropie/configs/all/moonlight/gamecontrollerdb.txt Detected SparkFun SparkFun Pro Micro (030000004f1b00000692000001010000) on /dev/input/event0 as SparkFun SparkFun Pro Micro Not mapping SparkFun SparkFun Pro Micro as a gamepad Detected SparkFun SparkFun Pro Micro (030000004f1b00000692000001010000) on /dev/input/event1 as SparkFun SparkFun Pro Micro Stream 1280 x 720, 60 fps, 10000 kbps RTSP port: 48010 Initializing platform...done Resolving host name...done Packet size capped at 1KB for remote streaming Initializing audio stream...done Starting RTSP handshake...Audio port: 48000 Video port: 47998 Control port: 47999 done Initializing control stream...done Initializing video stream...done Initializing input stream...done Starting control stream...done Starting video stream...done Starting audio stream...done Starting input stream...Received first audio packet after 0 ms Initial audio resync period: 500 milliseconds done Received first video packet after 0 ms Leaving fast audio recovery mode after OOS audio data (214 < 216)
Regarding the audio issue, here is what the verbose log provides when I click a button (which should technically output sound in Steamlink on the client side):
Unable to recover audio data block 41904 to 41907 (2+0=2 received < 4 needed) Unable to recover audio data block 41916 to 41919 (0+1=1 received < 4 needed) Network dropped audio data (expected 41906, but received 41920)
-
@stonededge said in Mapping Controllers in Moonlight:
It does seem to loop over the controller twice, saying "Not mapping SparkFun SparkFun Pro Micro as a gamepad" but then proceeds to connect again
It's not looping twice, you have 2 event devices with the same name (
/dev/input/event0
and/dev/input/event1
).
The message Not mapping SparkFun SparkFun Pro Micro as a gamepad may be the hint of why your mapping is not loaded. The classification is done here. Check withevtest
if your gamepad emits the necessary events, my guess is thatABS_X
andABS_Y
may be missing andmoonlight
doesn't consider your controller as a gamepad device. -
Hmm, I am not sure why that is happening. Is there a way to only direct steamlink to read on event 1?
This is the output of evtest on event 1. Event 0 doesn't return any response to any buttons.
D-Up: Code 4: 37267
D-Down: Code 4: -37267
D-Left: Code 5: -32767
D-Right: Code 5: +32767Since they share the same code, I assume it might not be possible to map it, if the DPAD is set up to act like an analog stick maximum X/Y values?
Event: time 1643695032.112436, type 3 (EV_ABS), code 4 (ABS_RY), value 32767 Event: time 1643695032.112436, -------------- SYN_REPORT ------------ Event: time 1643695032.196429, type 3 (EV_ABS), code 4 (ABS_RY), value 0 Event: time 1643695032.196429, -------------- SYN_REPORT ------------ Event: time 1643695033.356351, type 3 (EV_ABS), code 4 (ABS_RY), value 32767 Event: time 1643695033.356351, -------------- SYN_REPORT ------------ Event: time 1643695033.450352, type 3 (EV_ABS), code 4 (ABS_RY), value 0 Event: time 1643695033.450352, -------------- SYN_REPORT ------------ Event: time 1643695034.512282, type 3 (EV_ABS), code 4 (ABS_RY), value 32767 Event: time 1643695034.512282, -------------- SYN_REPORT ------------ Event: time 1643695034.612271, type 3 (EV_ABS), code 4 (ABS_RY), value 0 Event: time 1643695034.612271, -------------- SYN_REPORT ------------ Event: time 1643695034.922248, type 3 (EV_ABS), code 4 (ABS_RY), value -32767 Event: time 1643695034.922248, -------------- SYN_REPORT ------------ Event: time 1643695035.004241, type 3 (EV_ABS), code 4 (ABS_RY), value 0 Event: time 1643695035.004241, -------------- SYN_REPORT ------------ Event: time 1643695035.998177, type 3 (EV_ABS), code 5 (ABS_RZ), value 32767 Event: time 1643695035.998177, -------------- SYN_REPORT ------------ Event: time 1643695036.104171, type 3 (EV_ABS), code 5 (ABS_RZ), value 0 Event: time 1643695036.104171, -------------- SYN_REPORT ------------ Event: time 1643695036.516148, type 3 (EV_ABS), code 5 (ABS_RZ), value -32767 Event: time 1643695036.516148, -------------- SYN_REPORT ------------ Event: time 1643695036.564144, type 3 (EV_ABS), code 5 (ABS_RZ), value 0 Event: time 1643695036.564144, -------------- SYN_REPORT ------------
-
@stonededge said in Mapping Controllers in Moonlight:
Since they share the same code, I assume it might not be possible to map it, if the DPAD is set up to act like an analog stick maximum X/Y values?
No, it should work, but your gamepad sends
ABS_RX/ABS_RY
and notABS_X/ABS_Y
and this makesmoonlight
ignore the device. This looks like amoonlight
issue and you could ask them to augment the gamepad detection to include cases like this. Or you could modify the controller code to sendABS_X/ABS_Y
, this will probably change the D-Pad mappings you have already configured. -
Okay, thanks Mitu for helping find our problem, very much appreciated as always.
I will set up my DPAD as hat switches for the time being hopefully, or request the devs to make a change to the code (hopefully its quick and painless).
Regarding audio, do you have any idea on how I could solve the no audio issues? I'll try to provide as much information as I can, including my asound.rc contents. I'm using "dmix" as I want to be able to play background music, as well as RetroPie sounds from one device to two sources, without getting a "Device or Resource Busy Error" thrown at me.
I've also tried adding "-audio default/sysdefault/dmix" to the command that is run from the moonlight.sh file. I believe it is in the /opt/retropie/supplementary/moonlight/ folder, however this didn't fix anything for me.
asound.rc file:
pcm.!default { type asym playback.pcm { type plug slave.pcm "dmix" } capture.pcm { type plug slave.pcm "dmix" } } pcm.output { type hw card 0 } ctl.!default { type hw card 0 }
-
@stonededge said in Mapping Controllers in Moonlight:
Regarding audio, do you have any idea on how I could solve the no audio issues?
I don't see any messages regarding the audio output in the log you posted, but if ALSA is working correctly, then maybe you can instruct
moonlight
to use it instead of MMAL/PulseAudio/other.I'm using "dmix" as I want to be able to play background music, as well as RetroPie sounds from one device to two sources, without getting a "Device or Resource Busy Error" thrown at me.
I thought the default ALSA configuration for Pi4 already had built-in mixing (via
dmix
), as you using the new KMS audio driver ? -
@mitu I believe I am still using the fake kms drivers within my config.txt files, but I thought that only referenced the video drivers, not audio.
Do you know how to adjust the conf file to use ALSA as the primary audio source? Steam link seems to stream across the audio just fine and playback is perfect. I do notice that NVIDIA HDMI Audio setting is at maximum volume on my host PC, so I don’t think it’s a problem with the host device. I couldn’t find any documentation on the settings and what is available.
In order to get two audio outputs with one device, I had to set the astound.rc file to dmix. The default was sysdefault which resulted in the emulationstation navigation sounds and emulator audio being muted, but that is a different issue entirely.
-
@stonededge said in Mapping Controllers in Moonlight:
Do you know how to adjust the conf file to use ALSA as the primary audio source?
I don't know - I don't see a list of options for
audio
in the configuration file. -
@mitu I've managed to get audio working now, I just needed to add the "-audio default" command to the below. Hope this helps someone else. Now just to solve the DPAD issue :) Thank you!
/opt/retropie/supplementary/moonlight/moonlight.sh stream -verbose -config - audio default "/home/pi/RetroPie/roms/steam/Steam.ml"
-
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.