Posted 13 March 2012 - 03:18 PM
I'm trying to write a program that will run (and manage a IC nuclear reactor automatically) without input, but which can accept input during the run loop:
W : speeds up the sampling cycle
S : slows down the sampling cycle
Q : quits the automatic manager, dropping you back into the OS.
E : override shutdown
R : override run
The issue I am having is using
causes the whole program to wait for an event to fire, so it doesn't run as it should.
I've read somewhere that os.timer works better than sleep for something like this, but I can't find where I read it.
EDIT3:
I'm guessing this is going to be something like replacing the sleep(sTime); with (psudocode)
while eTime < sTime do – While elapsed time is less than sample time
os.startTimer(0.2);
evType, evValue = os.pullEventRaw();
if evType == "key", do
stuff
else
eTime = eTime + 0.2;
that would generate a timer event every 1/5th of a second, which would trigger the os.pullEvent (which it would then discard as not a keypress) and catch ctrl+T (which will be allowed but I'll be inserting the forced shutdown code prior to termination)
Does that make sense?
W : speeds up the sampling cycle
S : slows down the sampling cycle
Q : quits the automatic manager, dropping you back into the OS.
E : override shutdown
R : override run
The issue I am having is using
while evInterrupt == false do -- while not interrupted
tos.splash(); -- clears and retitles the terminal
if redstone.getInput("left") and timer < maxtime then -- if MFSU is not full & cooldown not required
status = 1; -- turn on
else
status = 0; -- turn off
--snipped code to show status
if status == 1 then
redstone.setOutput("right", true);
timer = timer + sTime; -- increment timer by stepTime
euCyc = euEff * sTime; -- calculate EU/sample(cycle)
euGen = euGen +euCyc; -- Calculate total EU since program started
sleep(sTime); -- let reactor run this cycle
else
redstone.setOutput("right", false);
timer = timer - sTime; --calculate time left to cooldown after this cycle
sleep(sTime); -- let reactor cool this cycle
end
evType, evValue = os.pullEvent()
if (what i'm looking for) then (do stuff)
causes the whole program to wait for an event to fire, so it doesn't run as it should.
I've read somewhere that os.timer works better than sleep for something like this, but I can't find where I read it.
EDIT3:
I'm guessing this is going to be something like replacing the sleep(sTime); with (psudocode)
while eTime < sTime do – While elapsed time is less than sample time
os.startTimer(0.2);
evType, evValue = os.pullEventRaw();
if evType == "key", do
stuff
else
eTime = eTime + 0.2;
that would generate a timer event every 1/5th of a second, which would trigger the os.pullEvent (which it would then discard as not a keypress) and catch ctrl+T (which will be allowed but I'll be inserting the forced shutdown code prior to termination)
Does that make sense?