Syncing button leds with gameplay
-
@Folly I am using LEDSpicer and I want to get it working as discussed. LEDSpicer does have a PulseAudio plugin to make cool VUE Meter type animations etc but I am not using PulseAudio :)
So I need to make it work via maybe a program to watch a log file and when it see's "0" it runs a profile/animation to light the credit button.
Not the most elegant solution but I am not going to use a ton of this type of animation/interaction so just for one or two situations I think is fine -
I configured with --enable-raspberrypi and compiled.
But the files are looked up in /usr/local.
So I copied the rules files and the config file to that prefix and added the user to the groups.
This command didn't seem to work :sudo udevadm control --reload-rules && udevadm trigger
After that I am lost.
If you get it working let me know how you did it.
I was only able to extract the led info if I used
-output console
.
When using-output network
and using wget, curl, netcat, telnet or socat I can't extract the data because it's refreshed on the same line.
Very tricky to find a simple solution ;-( -
@Folly
sudo udevadm control --reload-rules && sudo udevadm trigger - missing sudo. I installed it as a Service, its just more convenient.
I will try tonight when I get home but does the command spit out error codes as we can use them... -
It took me more than 4 hours to find a solution in bash readout the socket info correctly.
The problem is that every line send by mame ends with /r (carriage return) only.
Therefor no new line is written to the sdio and so the info cannot be grabbed to do something.
Have looked a numerous options like sed, awk etc but nothing worked.
With this I came a bit further, showing more lines and the \r :netcat 0 8000|od -c
But piping it again did not work good enough.
Instead ofnetcat
I foundsocat
which will work somewhat the same and still had the same issue using it like this :socat - TCP4:localhost:8000
Now I found this site :
https://superuser.com/questions/942217/how-do-i-interactively-type-r-n-terminated-query-in-netcat
Which explaines to use,crnl
at the end.
I figured I only try,cr
and that worked like this :socat - TCP4:localhost:8000,cr
Now we can read the led info and do something with it :
socat - TCP4:localhost:8000,cr|while read line;do echo $line;done
echo $line
can be replace by anif
function to enable/disable leds on the gpio pins.The
socat
command can be reduced using 0 for localhost like this :socat - TCP4:0:8000,cr
Edit :
I have it running for 1 led :socat - TCP4:localhost:8000,cr|while read line;do [[ $line == "led0 = 1" ]] && raspi-gpio set 4 op pn dh;[[ $line == "led0 = 0" ]] && raspi-gpio set 4 op pn dl ;done
-
@hopwon said in Syncing button leds with gameplay:
does the command spit out error codes as we can use them...
With the -d option it gives an error something about a device missing.
Have to look again when I get home. -
@Folly Just looking at my (default) runcommand output:
/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-mame/mamearcade_libretro.so --config /opt/retropie/configs/arcade/retroarch.cfg "/home/pi/RetroPie/roms/arcade/1944.zip"
To integrate into this would probably mean recompiling with support for mame output features.
I see you are just launching mame with a different cli, default mame, if there is such a thing.
I think I am in above my head here!!
I might see what I can do with LEDSpicer. I have it working to the point that, when a game starts both start and credit flash until credit is pressed at which point it stays steady. Maybe a simple counter output to a file when the button is pressed and watched by a background process so that when it gets to 0 again, I can issue an Emitter command to make it flash again... just some draft thoughts!Just looking into this:
-
Indeed I use mame standalone for this.
Could be that lr-mame supports it too but it needs adding the options.
Will look at it later.Edit :
I used my script to produce lr-mame runcommands for arcade :
https://retropie.org.uk/forum/topic/29682/development-of-module-script-generator-for-lr-mess-lr-mame-and-mame-standalone
(used mamedev.sh, the other is not updated anymore, installed arcade from the category menu item)
This will produce configs and runcommands where we can add the-output network
option :lr-mame-basename = "/opt/retropie/emulators/retroarch/bin/retroarch --config /opt/retropie/configs/arcade/retroarch.cfg --appendconfig /opt/retropie/configs/arcade/retroarch.cfg.basename -S /home/pi/RetroPie/roms/arcade -s /home/pi/RetroPie/roms/arcade -v -L /opt/retropie/libretrocores/lr-mame/mamearcade_libretro.so 'mame -cfg_directory /opt/retropie/configs/arcade/lr-mame -c -ui_active -rompath /home/pi/RetroPie/BIOS/mame;/home/pi/RetroPie/roms/arcade/ '%BASENAME%''" lr-mame-basename-network = "/opt/retropie/emulators/retroarch/bin/retroarch --config /opt/retropie/configs/arcade/retroarch.cfg --appendconfig /opt/retropie/configs/arcade/retroarch.cfg.basename -S /home/pi/RetroPie/roms/arcade -s /home/pi/RetroPie/roms/arcade -v -L /opt/retropie/libretrocores/lr-mame/mamearcade_libretro.so 'mame -cfg_directory /opt/retropie/configs/arcade/lr-mame -output network -c -ui_active -rompath /home/pi/RetroPie/BIOS/mame;/home/pi/RetroPie/roms/arcade/ '%BASENAME%''"
Manually added in the second !
Testing it reveals THAT THIS WORKS !!!! ;-) -
@hopwon said in Syncing button leds with gameplay:
does the command spit out error codes as we can use them...
pi@raspberrypi:~ $ ledspicerd -d Program terminated by error: Empty devices section
-
@hopwon If no ones suggested it yet, advanceMame has a scripting system that can take actions on emulated external outputs such as Led's, and other hardware...
https://www.advancemame.it/doc-script here is the documentation for the scripting and outputs.
-
@Folly The computer is telling the truth, you need to populate the /etc/ledspicerd.conf file :)
But this is fantastic, I will have a go at compiling and then give LR-mame a go. I looked at various scripting options last night and while I can create a counter which will increment every time the credit button is pressed, I could not find a way to decrement it, so I went to bed!
-
On which hardware do you run retropie ?
lr-mame can be installed from binary when using rpi.Tell me, what script did you make to count the inserted coins and do you use a joystick or keyboard ?
-
@Folly said in Syncing button leds with gameplay:
On which hardware do you run retropie ?
First post:
... I am using LEDSpicer on RPI4.
-
@Folly said in Syncing button leds with gameplay:
Tell me, what script did you make to count the inserted coins and do you use a joystick or keyboard ?
A bit nasty but:
I used inputseeker running in background to grep for a credit button being pressed on(6=P1, 7=P2 in my case) and when it successfully finds a 6 or 7 it increments a counter +1.
You can do it with awk also but I got tired and when to bed :) -
@Folly said in Syncing button leds with gameplay:
lr-mame can be installed from binary when using rpi.
Installing it now
-
I will look at ledspicer with inputseeker again.
Seem a really nice package but I have to take some time to dig into it.
Hopefully I will grasp it. -
I uninstalled my previous install of LEDspice.
This I what I did :
cd ~/Downloads/LEDSpicer-development/ ./autogen.sh ./configure --prefix=/usr --sysconfdir=/etc --enable-raspberrypi make sudo make install sudo usermod -a -G users pi #replace user with your username sudo usermod -a -G input pi #replace user with your username sudo cp /usr/share/doc/ledspicer/examples/21-ledspicer.rules /etc/udev/rules.d/ sudo chmod 744 /etc/udev/rules.d/21-ledspicer.rules sudo udevadm control --reload-rules && sudo udevadm trigger sudo cp /usr/share/doc/ledspicer/examples/ledspicer.conf /etc ledspicerd -v ledspicerd -d sudo ledspicerd -d #seems to be the way to go with RaspberryPi
Running with -d gives :
Program terminated by error: Empty devices sectionAdded the controller name in /etc/ledspicer.conf :
<devices name="RaspberryPi" boardId="1" > </devices>
or
<devices> name="RaspberryPi" boardId="1" </devices>
Still no dice.
Any help would be appreciated.
-
@Folly You need to manually create your ledspicer.conf, I've attached mine to give you some idea (sorry admins no pastebin!), But basically the file maps pins #'s on your LED controller to an "Element", you can then create groups of Elements and address either the group or Element...
FYI On this controller I have 2 x Joystick + Trackball, each player has 8 buttons, plus start, credit, hotkey and exit.
pi@pacman:~ $ cat /etc/ledspicer.conf <?xml version="1.0" encoding="UTF-8"?> <LEDSpicer version="1.0" type="Configuration" fps="30" port="16161" colors="webColors" loglevel="Info" userId="1000" groupId="1000" craftProfile="true" > <devices> <device name="UltimarcUltimate" boardId="1" > <element name="P1_BUTTON1" red="54" green="53" blue="52" defaultColor="Red" /> <element name="P1_BUTTON2" red="57" green="56" blue="55" defaultColor="VeryDarkMagenta" /> <element name="P1_BUTTON3" red="60" green="59" blue="58" defaultColor="Blue" /> <element name="P1_BUTTON4" red="63" green="62" blue="61" defaultColor="Yellow" /> <element name="P1_BUTTON5" red="66" green="65" blue="64" defaultColor="Salmon" /> <element name="P1_BUTTON6" red="69" green="68" blue="67" defaultColor="Lime" /> <element name="P1_BUTTON7" red="72" green="71" blue="70" defaultColor="Violet" /> <element name="P1_BUTTON8" red="75" green="74" blue="73" defaultColor="VeryDarkYellow" /> <element name="P1_START" red="79" green="80" blue="81" defaultColor="DarkOrange" /> <element name="P1_CREDIT" red="93" green="92" blue="91" defaultColor="DarkOrange" /> <element name="P1_TRACKBALL" red="28" green="29" blue="30" defaultColor="Cyan" /> <element name="P1_JOYSTICK1" red="49" green="50" blue="51" defaultColor="Lime" /> <element name="HOTKEY" led="85" /> <element name="EXIT_KEY" led="88" /> <element name="P2_CREDIT" red="84" green="83" blue="82" defaultColor="DarkOrange" /> <element name="P2_START" red="78" green="77" blue="76" defaultColor="DarkOrange" /> <element name="P2_BUTTON1" red="4" green="5" blue="6" defaultColor="Red" /> <element name="P2_BUTTON2" red="7" green="8" blue="9" defaultColor="Green" /> <element name="P2_BUTTON3" red="10" green="11" blue="12" defaultColor="Blue" /> <element name="P2_BUTTON4" red="13" green="14" blue="15" defaultColor="Yellow" /> <element name="P2_BUTTON5" red="16" green="17" blue="18" defaultColor="Salmon" /> <element name="P2_BUTTON6" red="19" green="20" blue="21" defaultColor="Lime" /> <element name="P2_BUTTON7" red="22" green="23" blue="24" defaultColor="Violet" /> <element name="P2_BUTTON8" red="25" green="26" blue="27" defaultColor="VeryDarkYellow" /> <element name="P2_JOYSTICK1" red="1" green="2" blue="3" defaultColor="HotPink" /> </device> </devices> <restrictors> <restrictor name="ServoStik" boardId="1" player="1" joystick="1" /> <!-- Player 2 with ServoStik --> <restrictor name="ServoStik" boardId="1" player="2" joystick="1" /> </restrictors> <layout defaultProfile="default"> <group name="whole board"> <element name="P1_JOYSTICK1"/> <element name="P1_TRACKBALL"/> <element name="P1_START"/> <element name="P1_CREDIT"/> <element name="P1_BUTTON1"/> <element name="P1_BUTTON2"/> <element name="P1_BUTTON3"/> <element name="P1_BUTTON4"/> <element name="P1_BUTTON5"/> <element name="P1_BUTTON6"/> <element name="P1_BUTTON7"/> <element name="P1_BUTTON8"/> <element name="P2_JOYSTICK1"/> <element name="P2_BUTTON1"/> <element name="P2_BUTTON2"/> <element name="P2_BUTTON3"/> <element name="P2_BUTTON4"/> <element name="P2_BUTTON5"/> <element name="P2_BUTTON6"/> <element name="P2_BUTTON7"/> <element name="P2_BUTTON8"/> <element name="P2_CREDIT"/> <element name="P2_START"/> </group> <group name="Player1"> <element name="P1_JOYSTICK1"/> <element name="P1_TRACKBALL"/> <element name="P1_START"/> <element name="P1_CREDIT"/> <element name="P1_BUTTON1"/> <element name="P1_BUTTON2"/> <element name="P1_BUTTON3"/> <element name="P1_BUTTON4"/> <element name="P1_BUTTON5"/> <element name="P1_BUTTON6"/> <element name="P1_BUTTON7"/> <element name="P1_BUTTON8"/> </group> <group name="Player2"> <element name="P2_JOYSTICK1"/> <element name="P2_BUTTON1"/> <element name="P2_BUTTON2"/> <element name="P2_BUTTON3"/> <element name="P2_BUTTON4"/> <element name="P2_BUTTON5"/> <element name="P2_BUTTON6"/> <element name="P2_BUTTON7"/> <element name="P2_BUTTON8"/> <element name="P2_CREDIT"/> <element name="P2_START"/> </group> <group name="Players"> <element name="P1_JOYSTICK1"/> <element name="P1_TRACKBALL"/> <element name="P1_START"/> <element name="P1_CREDIT"/> <element name="P1_BUTTON1"/> <element name="P1_BUTTON2"/> <element name="P1_BUTTON3"/> <element name="P1_BUTTON4"/> <element name="P1_BUTTON5"/> <element name="P1_BUTTON6"/> <element name="P1_BUTTON7"/> <element name="P1_BUTTON8"/> <element name="P2_JOYSTICK1"/> <element name="P2_BUTTON1"/> <element name="P2_BUTTON2"/> <element name="P2_BUTTON3"/> <element name="P2_BUTTON4"/> <element name="P2_BUTTON5"/> <element name="P2_BUTTON6"/> <element name="P2_BUTTON7"/> <element name="P2_BUTTON8"/> <element name="P2_CREDIT"/> <element name="P2_START"/> </group> <group name="Whole board as a circle"> <element name="HOTKEY"/> <element name="P1_CREDIT"/> <element name="P1_START"/> <element name="P1_JOYSTICK1"/> <element name="P1_BUTTON5"/> <element name="P1_BUTTON1"/> <element name="P1_BUTTON6"/> <element name="P1_BUTTON2"/> <element name="P1_BUTTON7"/> <element name="P1_BUTTON3"/> <element name="P1_BUTTON8"/> <element name="P1_BUTTON4"/> <element name="P1_TRACKBALL"/> <element name="P2_JOYSTICK1"/> <element name="P2_BUTTON5"/> <element name="P2_BUTTON1"/> <element name="P2_BUTTON6"/> <element name="P2_BUTTON2"/> <element name="P2_BUTTON7"/> <element name="P2_BUTTON3"/> <element name="P2_BUTTON8"/> <element name="P2_BUTTON4"/> <element name="P2_CREDIT"/> <element name="P2_START"/> </group> <group name="Ctrl keys"> <element name="HOTKEY"/> <element name="P1_CREDIT"/> <element name="P1_START"/> <element name="P2_CREDIT"/> <element name="P2_START"/> <element name="EXIT_KEY"/> </group> <group name="TopRow"> <element name="P1_CREDIT"/> <element name="P1_START"/> <element name="HOTKEY"/> <element name="EXIT_KEY"/> <element name="P2_CREDIT"/> <element name="P2_START"/> </group> </layout> </LEDSpicer>
-
@Folly said in Syncing button leds with gameplay:
I uninstalled my previous install of LEDspice.
This I what I did :
cd ~/Downloads/LEDSpicer-development/ ./autogen.sh ./configure --prefix=/usr --sysconfdir=/etc --enable-raspberrypi make sudo make install sudo usermod -a -G users pi #replace user with your username sudo usermod -a -G input pi #replace user with your username sudo cp /usr/share/doc/ledspicer/examples/21-ledspicer.rules /etc/udev/rules.d/ sudo chmod 744 /etc/udev/rules.d/21-ledspicer.rules sudo udevadm control --reload-rules && sudo udevadm trigger sudo cp /usr/share/doc/ledspicer/examples/ledspicer.conf /etc ledspicerd -v ledspicerd -d sudo ledspicerd -d #seems to be the way to go with RaspberryPi
Running with -d gives :
Program terminated by error: Empty devices sectionAdded the controller name in /etc/ledspicer.conf :
<devices name="RaspberryPi" boardId="1" > </devices>
or
<devices> name="RaspberryPi" boardId="1" </devices>
Still no dice.
Any help would be appreciated.
Make sure when you are starting for the first time, run the daemon in foreground (-f) as it is the best way to troubleshoot. Its quite verbose in its output so if there is a problem you should get a good indication of exactly what it is.
-
Thanks, will have a look when I am using my pi.
-
@Folly So I managed to get the command line options passed to lr-mame based on the info you provided. I can now see that (I am using Missile Command as a test), led0=0, led1=0, led0=1 led1=1, repeating in the console for any button press.
This tells me (I think) that mame is making two led's flash and thats it. No specific output regarding credit or I could be wrong.From runcommand.log using -output console
led0 = 1 led0 = 0 led0 = 1 led0 = 0 led0 = 1 led0 = 0 led0 = 1 led0 = 0 led0 = 1 led1 = 1 led1 = 0 led0 = 0
These represent a button press, I think one press = 4 log entries
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.