Software Support > Automated Projects
Lua os.execute()rotates display in console.. why not in vertical.ini .lay file
cimedaca:
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: ---<?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>
--- End code ---
10yard:
Can you adjust your os.execute command to log what is happening in powershell:
--- Code: ---os.execute("powershell.exe -file vertical.ps1 > ps_log.txt")
--- End code ---
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:.
cimedaca:
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: ---#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()
--- End code ---
10yard:
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: ---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
--- End code ---
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
cimedaca:
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: ---{
"plugin": {
"name": "autodisplayrotator",
"description": "screen rotating plugin",
"version": "0.0.1",
"author": "David von Arb",
"type": "plugin",
"start": "false"
}
}
--- End code ---
My init.lua file
--- Code: ----- 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
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version