Actually I didn't physically connect the arduino yet since I'm working on other parts of my project, so I will maybe have to adjust the delay afterwards, but I also use the same technique to play audios which say the rom names while I'm navigating over the library, and the best timing for that inside the callback function is 20 (I don't know if it's millisecond), I'm expecting to use the same timing with the arduino, but maybe I will have to adjust it.
Here is what I use as code to create a delay:
local romname_delay = 0;
local romname_set = 0;
// CALLBACK FUNCTIONS
fe.add_transition_callback( "update_lb" );
function update_lb( ttype, var, ttime )
{
switch ( ttype )
{
case Transition.StartLayout:
romname_delay = 0; romname_set = 0;
break;
case Transition.ToNewSelection:
romname_delay = 0; romname_set = 0;
break;
case Transition.ToNewList:
romname_delay = 0; romname_set = 0;
break;
}
}
fe.add_ticks_callback( "tick_fn" );
function tick_fn( ttime )
{
romname_delay++;
if ( romname_delay > 20 && romname_set == 0 ) // - (DELAY: 20 LOOPS), then it sends rom name info to am_arduino.sh and "<system>+<rom name>" to am_tts_titles.sh
{
local romname = fe.game_info( Info.Name );
local system = fe.game_info( Info.Emulator );
local sys_rom = ( system + "+" + romname );
fe.plugin_command_bg( "/home/odroid/.attract/emulators/RGB_leds/am_arduino.sh", romname );
fe.plugin_command_bg( "/home/odroid/.attract/emulators/scripts/tools/text_to_speech/am_tts_titles.sh", sys_rom );
romname_set = 1;
}
}
You need to edit the code to make it work with your project, but everything is there.
"romname_delay" variable is my delay, every-time a new game is selected, this variable is reseted, so the external script will be only launched if I stay on the same selection longer than 20 loops in the callback.
Now that the base of this system works, I'm planning to do a lot of things with it, but I'm not focusing on this right now, so it's still a work in progress feature on my project.