Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Eunomiac

[OC 1.3] Inconsistent autorun.lua

Question

I have a computer with three gpu's, connected to three screens.  One monitor has a keyboard attached to it, and is meant to be the main access terminal; the other two screens are display-only.

 

I've added the following autorun.lua file to the computer's hard drive, to mount the hard drive and set the appropriate primary gpu and screen:

local primaryGPUAddr = "3f5"
local primaryScreenAddr = "1a1"

local component = require("component")
component.setPrimary("gpu",component.get(primaryGPUAddr))
local gpu = component.gpu
gpu.bind(component.get(primaryScreenAddr))

local fs = require("filesystem")
local proxy = ...
fs.mount(proxy, "main")

print("Main Screen Bound") -- to test all went well

However, whenever I boot up my computer, autorun.lua doesn't always run---the primary GPU/screen is randomly chosen from among the three I have connected, the hard drive isn't mounted under "main", and I don't see that "Main Screen Bound" message (on any of the screens).

 

Oddly enough, sometimes it all works perfectly (including the mounting and the printed message), but it usually doesn't---and I'm left with my cursor blinking unhelpfully on one of the giant display screens on the opposite side of the room!

Link to post
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Thanks for your quick reply (I had to wait until I had a chance to test before responding in kind)---unfortunately, I'm afraid that doesn't work :( 

 

Here is the autorun.lua file contained in the root directory of the only hard drive on the computer:

local event = require('event')

event.listen('init', function()
  local primaryGPU = "3f5"
  local primaryScreen = "1a1"

  local component = require("component")
  component.setPrimary("gpu",component.get(primaryGPU))
  local gpu = component.gpu
  gpu.bind(component.get(primaryScreen))

  local fs = require("filesystem")
  local proxy = ...
  fs.mount(proxy, "main")

  print("Main Screen Bound")
end)

The above didn't appear to run, and the /tmp/event.log contains the following error:

/mnt/14b/autorun.lua:13: cannot use '...' outside a vararg function near '...'

That error led me to try mounting the hard drive by referencing its address directly, like so:

local event = require('event')

event.listen('init', function()
  local primaryGPU = "3f5"
  local primaryScreen = "1a1"
  local primaryHD = "14b"

  local component = require("component")
  component.setPrimary("gpu",component.get(primaryGPU))
  local gpu = component.gpu
  gpu.bind(component.get(primaryScreen))

  local fs = require("filesystem")
  primaryHD = component.get(primaryHD)
  fs.mount(primaryHD, "main")

  print("Main Screen Bound")
end)

... which eliminated the error from the event log, but took me back to my original problem:  The hard drive isn't mounted, one of my three connected displays is chosen at random, and the "Main Screen Bound" message doesn't appear on any of the screens.

Link to post
Share on other sites
  • 0

Could you try your first version with the event, but extracting the address before you define the function? So like:

local address = ...
event.listen('init', function()
  ...
  fs.mount(address, "main") 
end

This should get rid of the varargs error. 

Link to post
Share on other sites
  • 0

Ok, I've been at this for a long while, trying all sorts of different strategies.  Please forgive the lengthy post, and thanks in advance for your help!  I've bolded key points as an inline TL;DR.

 

I think the problem is that the 'init' event isn't being heard by the autorun program.  The listener is being registered, but the callback function isn't being run.

 

Here's my current autorun.lua, with a bunch of debugging "print()" messages to help see exactly what code is being run:

local address = ...
local primaryGPU = "3f5"
local primaryScreen = "1a1"

print("Mounting Drive: " .. tostring(address))

local fs = require("filesystem")
fs.mount(address, "/main")

function BindGPU() -- I extracted the function from the event declaration to see if that did anything, but it made no difference.
  component = require("component")
  component.setPrimary("gpu",component.get(primaryGPU))
  gpu = component.gpu
  gpu.bind(component.get(primaryScreen))
  
  print("Init Event Heard.")
  print("Primary GPU = " .. component.get(primaryGPU))
  print("Primary Display = " .. component.get(primaryScreen))
end

local event = require('event')

print("Waiting for Init Event")

print("Registering Event: " .. tostring(event.listen('init', BindGPU)))

print("Testing Event Registration (should be false): " .. tostring(event.listen('init', BindGPU))) -- Just a check to make sure the listener was registered, by trying to register it again.

The above code does reliably mount the hard drive, which is awesome.  However, the primary screen is still chosen randomly, and none of the print messages inside the listener callback function (BindGPU) appear anywhere:

========================================================================
| OpenOS 1.2 (2048k RAM)                                               |
| Keyboards have to be attached to or placed next to a screen to work. |
========================================================================
/# Mounting Drive: table: 0000000015AA6F00
Waiting for Init Event
Registering Listener: true
Testing Listener Registration (should be false): false

I also tried eliminating the event code, and running the GPU/screen binding immediately after (successfully) mounting the hard drive:

local address = ...
local primaryGPU = "3f5"
local primaryScreen = "1a1"

local fs = require("filesystem")
fs.mount(address, "/main")

component = require("component")
component.setPrimary("gpu",component.get(primaryGPU))
gpu = component.gpu
gpu.bind(component.get(primaryScreen))

... but that didn't work either, and the event.log file in /tmp contains the following error:

boot/03_component.lua:51: no primary 'gpu' available 

... which I assume is what happens when I fiddle with the gpu too quickly, before the system is finished initializing and fires the 'init' event, yes?

 

Thanks for your help!  It strikes me as weird that I'm the only one having this problem... is anyone else using multiple screens and successfully binding a primary display via autorun?  The code I'm using seems fairly straight-forward, so I don't know what I could be doing differently from others...

 

Edit:  Other things I've tried:

  • leaving everything except "require('event')" and "address = ..." inside the listener callback function, as you originally suggested (nope)
  • alternating between double and single quotes, to see if inconsistencies there caused the problem (nope)
  • inserting an "os.sleep(5)" after mounting the hard drive, to see if I could give the system time to "catch up" without having to wait for the init event (nope; I gather os.sleep() just puts everything on hold, including the init process)
  • leaving the "BindGPU" function inside the event registration, as SpiritedDusty originally wrote it  (nope)
  • repeatedly registering the event listener inside a "while InitNotHeard do" loop, with the "InitNotHeard" being toggled off inside the listener callback function, breaking the loop if the function is ever called (nope, loop runs endlessly, constantly failing to re-register the listener, as expected)
  • removing "local" from all of the variables, then adding them back, and finally only removing them from within the listener callback function (nope)

Edit-Edit:  I ran an experiment, in which I repeated "event.pull()" inside a while loop at the very beginning of autorun.lua, just to see what events were being sent.  Apparently, no events are being pushed to autorun; the only output from that loop was a long list of "nil".

Link to post
Share on other sites
  • 0

And things keep getting weirder.  Apparently, "setPrimary" isn't working for me.  Here's a test "autorun.lua" I ran after trying to figure out that "no primary gpu" error in the event.log (I used a debug file, since "print" depends on there being a primary GPU, which is the main problem):

local primaryGPU = "3f5"
local primaryScreen = "1a1"

function db(text) -- //snip// just writes "text" to a debug file -- end

local component = require("component")
primaryGPU = component.get(primaryGPU) -- resolve full address

-- First, check whether primary GPU was randomly assigned:
db("Primary GPU Exists at Init? " .. tostring(component.isAvailable("gpu")))
if component.isAvailable("gpu") then
	db("... and Primary GPU at Init is: " .. component.gpu.address)
end

-- Then, set primary GPU to desired address:
db("Now Setting Primary to " .. tostring(primaryGPU))

component.setPrimary("gpu",primaryGPU)

-- And check again whether primary GPU exists:
db("Primary GPU Exists? " .. tostring(component.isAvailable("gpu")))
if component.isAvailable("gpu") then
  db("... and the new Primary GPU is: " .. component.gpu.address)
else
  db("What? No Primary GPU!")
end

And the output to my debug file:

Primary GPU Exists at Init? true
... and Primary GPU at Init is: 98aa9c50-3f18-433f-99af-93fc83b7bbe5
Now Setting Primary to 3f5359d7-b4a9-442b-a17d-26cef3db1e48
Primary GPU Exists? false
What? No Primary GPU!

... so now I have no idea what's going on, and I've been at this for... uh... five hours now.  I need a drink.  Drinks.  Many drinks.  Please help :P

Link to post
Share on other sites
  • 0

Have a drink! ;)

 

You, sir, are a gentleman and a scholar and a sterling example that elevates us all as human beings  :D

 

You're using OC 1.3, right? so that autorun file is probably on your os disk, right? or is it on a separate hard drive?

 

Yes, OC 1.3 on MC 1.7.2.  I installed the OS to the hard drive, and placed the autorun.lua in the same location.

 

Currently, the following "autorun.lua" file almost works.  My current problem is that setPrimary() apparently selects the gpu randomly from the three I have installed, despite the fact that (I think) I've properly passed a valid gpu address to setPrimary().  The weirdness happens somewhere in the section I've commented as "2) Setting Primary GPU", halfway down the code:

local primaryGPUAddr = "3f5"
local primaryScreenAddr = "1a1"
local fs = require("filesystem")
local component = require("component")

-- A quick list of the components, just so you can verify my addresses are correct.
-- 'db(text)' is a function I've snipped out for brevity; it just writes the text parameter to a debug file, which I'll post below

db("COMPONENTS:")
for compAddr, compType in component.list() do
  db(compAddr .. " --- " .. compType)
end
db("\n")

-- 1) Mounting the hard drive & verifying
local address = ...
local hdCheck, hdError = fs.mount(address, "/main")
if hdCheck then
  db("1) Mounted hard drive under '/main'")
else
  db("1) Hard Drive did NOT mount: " .. tostring(hdError))
end

-- 2) Setting Primary GPU
-- (a) Checks address of randomly-chosen primary GPU:
if component.isAvailable("gpu") then
  db("2(a) Primary GPU randomly assigned at Boot: " .. tostring(component.gpu.address))
end

-- ( Change primary GPU:
primaryGPUAddr = component.get(primaryGPUAddr) -- resolve full GPU address from the 3-letter abbreviation I set at the very top
db("2( Setting Primary GPU to: " .. tostring(primaryGPUAddr))
component.setPrimary("gpu",primaryGPUAddr)
os.sleep(0.2) -- This "sleep" was advised by Sangar to give setPrimary a chance to catch up; however, as you'll see, it still doesn't seem to work properly.

-- (c) Check again whether primary GPU exists:
if component.isAvailable("gpu") then
  db("2(c) Primary GPU successfully changed: " .. tostring(component.gpu.address))
else
  db("2(c) No Primary GPU!")
  db("... GPU Address = (" .. tostring(component.gpu.address) .. ")")
end

-- 3) Binding Primary GPU to Screen
primaryScreenAddr = component.get(primaryScreenAddr) -- resolve full screen address
local gpu = component.gpu
db("3) Attempting Screen Bind: " .. tostring(gpu.bind(primaryScreenAddr)))

Before I added that "os.sleep(0.2)", the debug output would simply stop at that point---I wasn't giving setPrimary() enough time to configure the gpu, and so the program would stop with a "no primary gpu" error in the event.log.

 

However, now the above code gives me the following debug file.  Note the randomly-selected gpu, different from the gpu address I used with setPrimary():

COMPONENTS:
7ba654c7-9a62-4221-978e-01b9e3e13ede --- computer
98aa9c50-3f18-433f-99af-93fc83b7bbe5 --- gpu
3bdd83ae-1559-42b4-98dd-09cb46a8fb16 --- gpu
dc40b4b8-4663-4378-b4e5-2a4da339b42f --- screen
b3f856ca-8e6c-484f-9f52-bf30448736f2 --- keyboard
1a1c197d-bf4d-4b59-90e6-f6ecc3f74035 --- screen
3f5359d7-b4a9-442b-a17d-26cef3db1e48 --- gpu
e33dafce-6893-422a-b1b1-61ce080735e3 --- screen
83c65b98-76c1-44e6-8e71-0df8fbb2d681 --- filesystem
14bf0dce-d956-4c5e-baa8-f0db51cf11f8 --- filesystem

1) Mounted hard drive under '/main'
2(a) Primary GPU randomly assigned at Boot: 98aa9c50-3f18-433f-99af-93fc83b7bbe5
2( Setting Primary GPU to: 3f5359d7-b4a9-442b-a17d-26cef3db1e48
2(c) Primary GPU successfully changed: 3bdd83ae-1559-42b4-98dd-09cb46a8fb16
3) Attempting Screen Bind: true

Again, this is random behavior---sometimes the primary GPU is properly set, other times it doesn't change it at all from whichever was randomly chosen at boot... it's very odd, and I'd appreciate any help you can provide (drinks too!)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.