Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Lua os.execute()rotates display in console.. why not in vertical.ini .lay file  (Read 22237 times)

0 Members and 1 Guest are viewing this topic.

cimedaca

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 3
  • Last login:August 29, 2021, 07:12:11 pm
  • I want to build my own arcade controls!
I can can call os.execute("powershell.exe -file vertical.ps1") from the MAME Lua console and it will rotate my display by sending a serial code to an esp32 with stepper controller.  Does anyone know why my Lua default.lay file below (that will parse other Lua code) will not execute the powershell and rotate my display automatically for games that use Vertical.ini?  For now I'm editing every vertical game to call a batch file that sends the powershell command and then launches MAME.  (See YouTube 30 second link below).  That's just a janky way to do it and I see the DOS batch files flash on the screen. 

Code: [Select]
<?xml version="1.0"?>
<mamelayout version="2">
<!-- the content of the script element will be called as a function by the layout plugin -->
<!-- use CDATA block to avoid the need to escape angle brackets and ampersands -->
<script><![CDATA[
-- file is the layout file object
-- set a function to call after resolving tags
file:set_resolve_tags_callback(
function()
os.execute("powershell.exe -file vertical.ps1")
end)
]]></script>
</mamelayout>


10yard

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 139
  • Last login:Today at 10:33:12 am
  • L BREAK into program
    • DKAFE Frontend
Can you adjust your os.execute command to log what is happening in powershell:
Code: [Select]
os.execute("powershell.exe -file vertical.ps1 > ps_log.txt")
Now run a test, and look for the file ps_log.txt.  The file should be created in the same location as your vertical.ps1 file.  It may be created inside the plugins/layout folder,  i'm not sure.  Anyway,  you should be sure that your vertical.ps1 file is copied to the same location as ps_log.txt.

Post your ps_log.txt here too.
 
I love your setup BTW :applaud:.
Check out my Donkey Kong Arcade Frontend at https://github.com/10yard/dkafe#readme


cimedaca

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 3
  • Last login:August 29, 2021, 07:12:11 pm
  • I want to build my own arcade controls!
Unfortunately, it almost certainly doesn't execute the PowerShell since if I paste that command into the Lua console it runs. It is just the super simple ps script below.  I have also just tried to get it to run notepad.exe with no luck.  I really expect I have some Lua .lay file syntax error or I'm not understanding how to get it to execute my Lua commands/scripts.  Also -- I suppose -- maybe for some reason os.execute() is not supported in a .lay file. 

On the setup.  Yes, well, I purchased a nice 1440P display so I went cheap with two $32 boards, a few cross cuts and a 18 small 3Dprinted connector parts.  After owning the tank stick for more than eight years I finally decided I should go minimalist because I clearly don't have the patience for complex cabinet woodworking.  Then there is just an a extra joystick controller and several 5v lighted buttons added.


Code: [Select]
#vertial.ps1 - Sends an ascii v to a Arduion/Esp32 script on serial port 3
$port= new-Object System.IO.Ports.SerialPort COM3,115200,None,8,one
$port.open()
$port.Write(“v")
$port.Close()


10yard

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 139
  • Last login:Today at 10:33:12 am
  • L BREAK into program
    • DKAFE Frontend
I'm not familiar with layout files.  Maybe you can achieve the same with a simple LUA script.   os.execute definitely works in LUA script files.  It's just an idea and worth a try for you.

Code: [Select]
if not driver then
driver = emu.driver_find(emu.romname())
if driver.orientation == "rot90" or driver.orientation == "rot270" then
os.execute("powershell.exe -file vertical.ps1")
end
end

This would check the drivers expected orientation when the rom starts up.
The script file should be extracted from the zip and saved into the same location as your vertical.ps1.
You can then update your mame command line arguments to include "-script rotate.lua".  You may need to provide the full path to the rotate.lua.

Jon
Check out my Donkey Kong Arcade Frontend at https://github.com/10yard/dkafe#readme


cimedaca

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 3
  • Last login:August 29, 2021, 07:12:11 pm
  • I want to build my own arcade controls!
Thankyou 10yard.  What you advise is close to what finally worked for me to both initiate rotation on launch and turn it back when exiting MAME.  Getting Lua to execute a program in a layout .lay file cannot be done. Note this from a super helpful "cuavas" on the mamedev chat. "No it doesn't (support OS.Execute). The environment supplied to layout scripts is very restricted."

I was then directed to by cuavas that I could use a plugin and check the state of manager.machine.system.orientation.  I think I may change it to checking ROM orientation.  After looking at how they work from examples in the .\plugins directory I tried it and it works! This seems like a good way to control LEDs and lots of other external devices based on different MAME states in some cases if you don't want to use MAME Hooker.   

Step 1: Make a folder under plugins with your new plugin name like autodisplayrotator.

Step 2: Create a plugin.json and init.lua file like the ones below using the ones in the \plugin\dummy folder as a template. Add the PowerShell or other external executables you want to run to the same plugin folder you created. (My attempts to get Lua to directly write to the serial port were unsuccessful.)

Step 3. Launch MAME and set your plugin to run on launch or add -plugin <your plugin name> to the command line. In my case I add -plugin autodisplayrotator to the MAME command line.

While I'm checking orientation and doing a different thing for start and stop based on manager.machine.system.orientation being set tp "rot270" (due to my vertical.ini file below.)You can do MANY other things with your plugin's init.lua in the \plugins\dummy folder. It allows you to run any code on start, stop, menu populate, and menu callback events. You can use the class references and what I will call pre-populated variables like manager.machine.system.orientation one I used. See: https://docs.mamedev.org/techspecs/luareference.html?highlight=manager%20machine%20system%20orientation

My plugin.jason folder in .\plugins\autodisplayrotator
Code: [Select]
{
"plugin": {
"name": "autodisplayrotator",
"description": "screen rotating plugin",
"version": "0.0.1",
"author": "David von Arb",
"type": "plugin",
"start": "false"
}
}

My init.lua file

Code: [Select]
-- license:BSD-3-Clause
-- copyright-holders:David
local exports = {}
exports.name = "autodisplayrotator"
exports.version = "0.0.1"
exports.description = "Rotate Display"
exports.license = "The BSD 3-Clause License"
exports.author = { name = "David" }
local autodisplayrotator = exports
function autodisplayrotator.startplugin()

emu.register\_start(function()
local screenrotation = manager.machine.system.orientation
print (screenrotation)
if (screenrotation == "rot270") or (screenrotation == "rot90")
then
print("Vertical game. Rotating...")
os.execute("powershell.exe -file vertical.ps1")
else
print("Horizontal game. Not Rotating...")
end
end)

emu.register\_stop(function()
local screenrotation = manager.machine.system.orientation
print (screenrotation)
if (screenrotation == "rot270") or (screenrotation == "rot90")
then
print ("Vertical game. Rotating back...")
os.execute("powershell.exe -file horizontal.ps1")
else
print("Horizontal game. No need to rotate back.")
end
end)

end
end exports

10yard

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 139
  • Last login:Today at 10:33:12 am
  • L BREAK into program
    • DKAFE Frontend
Great stuff cimedaca! 
Happy to see you have a working solution.

I've messed around with plugins before.  They're a neat way to wrap up a script...and I will make more use of them in the future.  Thanks for providing the detail :cheers:
Check out my Donkey Kong Arcade Frontend at https://github.com/10yard/dkafe#readme


pageygeeza@yahoo.co.uk

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 2
  • Last login:March 16, 2024, 03:42:23 pm
  • I want to build my own arcade controls!
I'm not familiar with layout files.  Maybe you can achieve the same with a simple LUA script.   os.execute definitely works in LUA script files.  It's just an idea and worth a try for you.

Code: [Select]
if not driver then
driver = emu.driver_find(emu.romname())
if driver.orientation == "rot90" or driver.orientation == "rot270" then
os.execute("powershell.exe -file vertical.ps1")
end
end

This would check the drivers expected orientation when the rom starts up.
The script file should be extracted from the zip and saved into the same location as your vertical.ps1.
You can then update your mame command line arguments to include "-script rotate.lua".  You may need to provide the full path to the rotate.lua.

Jon

This code actually works for me!

The other code is checking the PC system for screen rotation changes, MAME doesn't physically rotate the screen, looks like it just rotates its output. Yours is actually polling rom data.

This leads me to my first question, this is the first time I've dabbled with Lua, so please be gentle:

How do I add a ROM close routine to reset the screen once a portrait game has been ended, I'm not 100% sure how the first two lines work in regards to activating the vertical file.