This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
boudragon's profile picture

Redpulse Without Computer Sleeping

Started by boudragon, 05 March 2013 - 03:39 AM
boudragon #1
Posted 05 March 2013 - 04:39 AM
Ok so I did a bit of looking around and can't seem to find anything on this. I'm looking for a way to ask the computer to send a redpulse signal without it sleeping. Meaning when you do a command like :

shell.run (redpulse, "right", 1, 20)

It will send the pulse for 20 seconds but not freeze up the computer. I looked into the redpulse file but it really looks like it the way it works is off of redset which works solely on true and false. In which case removing any sleep timers would just break the entire pulse to begin with. Any thoughts would be much appreciated!
Moody #2
Posted 05 March 2013 - 04:48 AM
why do you want to avoid letting the computer sleep? Is there a specific reason or do you just need the pulse to be very short?
remiX #3
Posted 05 March 2013 - 04:48 AM
So basically you want it to be able to send redstone signals for X amount of seconds while you are still able to do certain things on the computer? Looks like you need to use parallel api.
This api basically allows you to run multiple functions simultaneously, allowing users to have a great advantage for functions.

PS, using the shell.run you need quotes around everything
shell.run("redpulse right 1 20")
boudragon #4
Posted 05 March 2013 - 04:50 AM
Yeah sorry was typing fast… forgot "" anyways… I need to be able to "buzz" myself into a room in which the doors close behind me and I would like to have computer functionality after buzzing the doors. and yes remiX thats exactly what I need a parallel process basically… how would I go about doing that?
Moody #5
Posted 05 March 2013 - 04:56 AM
maybe a bit like

function pulse()
-- code for pulse here
end
function otherStuff()
--other stuff here
end
parallel.waitForAll(otherStuff,pulse)

it will wait until both function have finished and returned a value
just make sure there wont be long codefragments that dont yield (if you are unsure about that, just use os.sleep(0.1) every now and then)
Also you can use parallel.waitForAny(), which breaks the program when one function finishes
boudragon #6
Posted 05 March 2013 - 09:11 AM
Moody what I am looking for is the pulse to be long without the wait time on the computer to be long. If Im reading what you posted above correctly then that is making the system wait for all functions to finish before allowing the user to continue… If Im wrong I will slap myself :)/> lol
immibis #7
Posted 05 March 2013 - 11:26 AM
What would happen if you opened the door while it was already open?
boudragon #8
Posted 06 March 2013 - 01:17 AM
Shouldn't do anything… either reset the timer (say the initial timer was 10 seconds. 5 seconds go by when you open the doors again then it goes back to 10 or it adds 10 more seconds to the timer)
superaxander #9
Posted 06 March 2013 - 08:57 AM
Moody what I am looking for is the pulse to be long without the wait time on the computer to be long. If Im reading what you posted above correctly then that is making the system wait for all functions to finish before allowing the user to continue… If Im wrong I will slap myself :)/> lol
His code works you can put the code you want to be executed in the other stuff function and they will do it in parallel
Pharap #10
Posted 06 March 2013 - 09:46 AM
It depends on what you're trying to use while the pulse is active.
All sleep actually does is set a timer and block all else until the timer expires.
If the program you're trying to use handles events, make the computer set a timer when the pulse starts and make the program you're using shut off the pulse when it detects that timer's event.
boudragon #11
Posted 06 March 2013 - 11:10 AM
Ok… so we have two methods… a parallel process or event calling… which would you suggest to a beginner? Basically the program I am writing is a "system manager" which can only be accessed after you put in a password. The reason I need one of these two methods is because in order to buzz open a door you must do so through the system manager. Now… lets say I open the door for myself… but the computer is frozen because of opening the doors. Now I either have to wait (in which case I cant go through the door myself) or leave my computer unsecured. For now I have it re-run the password checker but Id rather have complete control.
1lann #12
Posted 06 March 2013 - 11:22 AM
Ok… so we have two methods… a parallel process or event calling… which would you suggest to a beginner? Basically the program I am writing is a "system manager" which can only be accessed after you put in a password. The reason I need one of these two methods is because in order to buzz open a door you must do so through the system manager. Now… lets say I open the door for myself… but the computer is frozen because of opening the doors. Now I either have to wait (in which case I cant go through the door myself) or leave my computer unsecured. For now I have it re-run the password checker but Id rather have complete control.
Uhh, just make the door open for 3 seconds? If you realllyyyy have to do it like that, play around with events and parallel. I'm on my iPod right now, but basically have one loop waiting for events, which trigger the door opening and the other loop which calls the events.
boudragon #13
Posted 06 March 2013 - 01:27 PM
The door is much further than a 3 second run away ;-) takes roughly 8-10 seconds to exit the computer and run to the door. Point is I want to be able to trigger the door… "logout" and THEN go through the door. And in the case of buzzing someone else through… be able to open the doors without FORCING a password input. See right now… it opens the doors… (computer freezes) and when the computer unfreezes it requires a password again. I sort of want the option of whether or not it requires a password again.
Pharap #14
Posted 06 March 2013 - 03:20 PM
In that case, do it like this:
Make a table in global to store 'system events' (events queued to happen at a certain time).
Make the login screen wait for events
(it probably already waits for keypresses, ,unless you're using the built in read() system, in which case, change it asap)
When a timer/alarm fires, make it check the 'system events' to check how to react to that event
(ie use the timer/alarm table returned by the start timer/ set alarm as the key for the value in the table)
In your door open/close program, make it set an alarm/timer as a system event (ie systemevents[os.startTimer(10)]="closedoor")
then make it logout
when the alarm goes off, the login screen will know to check system events to see if one matches the returned timer ref,
if it works correctly, the login screen should know to close the door.

I recommend making system events either store a function to call or a string to run dostring on, since it gives you more adaptability than just set commands.
Not exactly a simple way to do things, but then again interrupting the natural flow of events isn't really a novice thing.

Of course since sleeping stops the computer getting input, you could just make the system logout before calling sleep, then close the door when sleep is up. It would be a lot simpler, just not as realistic. Then again, nobody uses computers to open doors in the real world, so hey-ho.
boudragon #15
Posted 07 March 2013 - 03:10 AM
LOL yeah sounds like something I may not be ready for yet then… you say not for a novice… Im a beginner! Yeah yeah… noob this noob that heard it all :-p I'm thinking I may just bite the bullet and just set it up to ask for a password after the doors open/close and just deal with the down-time. Right now my level of programming is just now getting into rebuilding files that are missing, system restore disks, file checks etc. So anything involving meta tables or altering the core system may be way out of my league for now. But thank you all for the help and ideas I will keep them in mind should I be tempted to be bold and daring! :)/>
Pharap #16
Posted 07 March 2013 - 10:41 AM
LOL yeah sounds like something I may not be ready for yet then… you say not for a novice… Im a beginner! Yeah yeah… noob this noob that heard it all :-p I'm thinking I may just bite the bullet and just set it up to ask for a password after the doors open/close and just deal with the down-time. Right now my level of programming is just now getting into rebuilding files that are missing, system restore disks, file checks etc. So anything involving meta tables or altering the core system may be way out of my league for now. But thank you all for the help and ideas I will keep them in mind should I be tempted to be bold and daring! :)/>

Just stick with my last point. Assuming you have a logoff function:

OpenDoor()--Do redstone stuff to open door
LogOff()--Log Out of the computer
Wait(10)--Wait some time
CloseDoor()--Do redstone stuff to close door
GoToLogin()--Return to login screen