Author Topic: execute a file when layout/emulator is chosen?  (Read 14276 times)

nitrogen_widget

  • Sr. Member
  • ****
  • Posts: 307
    • View Profile
execute a file when layout/emulator is chosen?
« on: June 14, 2015, 09:37:39 AM »
Is there a way to run a file on the computer when I select a different emulator?

I'm setting up two instances of mame on my RPI.
One instance is vertical & the other horizontal.
I plan to use a motor or servo to rotate the lcd panel based on which layout i'm using.

I can easily do it manually with a pair of buttons but having it trigger automatically when I switch emulators in AM would of course be cooler.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: execute a file when layout/emulator is chosen?
« Reply #1 on: June 14, 2015, 10:04:54 AM »
Yep! I'll tell you if you give the details of your moto/rotation setup :)

plugin_command() and plugin_command_bg():
https://github.com/mickelson/attract/blob/master/Layouts.md#plugin_command

plugin_command() will wait until the command has finished running. Ideally you would use plugin_command_bg() which will run and continue on - maybe you don't want it to launch the game until the rotation has finished though? I guess that depends on your executable.

You would run this in an transition function, I guess ToGame:

Code: [Select]
fe.add_transition_callback("onTransition");

function onTransition( ttype, var, ttime )
{
   if ( ttype == Transition.ToGame )
  {
    local argString = "";
    fe.plugin_command_bg( "rotate", argString );
  }
}

I'm not entirely sure how/if that works in a layout - but it should. I think using that it would expect the rotate executable to be in your layout folder, but not positive.

Also, if that doesn't work I believe there is also this:
Code: [Select]
local cmd = system("rotate -r 60");

nitrogen_widget

  • Sr. Member
  • ****
  • Posts: 307
    • View Profile
Re: execute a file when layout/emulator is chosen?
« Reply #2 on: June 14, 2015, 11:16:01 AM »
not quite that far yet. :)
I'm going to use the RPI's gpio's to control the motor.

Basically, it's gonna be in vertical mode with all the vertical games or horizontal mode with all the horizontal games.
So once I pick the emulator it should rotate the monitor to the proper orientation for the game list.

Looks like I need to get my hardware working on the pi then I can revisit this.
Thank you!

takoni

  • Full Member
  • ***
  • Posts: 51
    • View Profile
Re: execute a file when layout/emulator is chosen?
« Reply #3 on: October 02, 2023, 05:06:05 PM »
I used args inside runcommand-onstart file to launch a python script in RPI

https://youtu.be/JNBNhP7byXU?si=WNukWY2lAR4qIaHX