Sleep command issue

Linux specific questions.
fxm
Moderator
Posts: 12083
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Sleep command issue

Post by fxm »

What about 'Sleep' during a specified time on Linux text console

On a Linux text console, can you check if the following program is rightly working?
Waiting for one keypress to print 'one', then automatic delay of two seconds between each next printing (without pressing any key):

Code: Select all

sleep
?"one"
sleep 2000
?"two"
sleep 2000
?"three"
sleep 2000
?"four"
sleep
tom_dehn
Posts: 4
Joined: Apr 05, 2017 13:50

Re: Sleep command issue

Post by tom_dehn »

Hallo,

it`s almost all fine with the macros, but they sleep "forever".
Any idea to do a macro "timeout" like the DOC says:

"Waits until a specified time has elapsed, or a key is pressed.
Syntax
Declare Sub Sleep ( ByVal amount As Long = -1 )
Declare Function Sleep ( ByVal amount As Long , ByVal keyflag As Long ) As Long"

(copied from CHM, "mk:@MSITStore:C:\PRG\FBC\HelpFiles\FB-manual-1.05.0.chm::/KeyPgSleep.html")

Just have a look at my pause(); don´t bother about performance: It is a _sleep_ :)

TD
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: Sleep command issue

Post by lizard »

fxm wrote:On a Linux text console, can you check if the following program is rightly working?
No. It waits for a keypress, then displays the rest without any delay.

Code: Select all

one
two
three
four
fxm
Moderator
Posts: 12083
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Sleep command issue

Post by fxm »

More general workaround macro using a variadic syntax:

Code: Select all

#macro _sleep( args... )
    While InKey() <> "" : Wend
    Sleep args
#endmacro

_sleep( )
?"one"
_sleep( 2000 )
?"two"
_sleep( 2000 , 0 )
?"three"
_sleep( 2000 )
?"four"
_sleep( 10000, 1 )
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: Sleep command issue

Post by lizard »

Funny, that works, but without delay, Only after four there is 10 seconds delay before end.
fxm
Moderator
Posts: 12083
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Sleep command issue

Post by fxm »

Having no Linux PC, I can not go further in the investigation.
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: Sleep command issue

Post by lizard »

You could use a live dvd.
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: Sleep command issue

Post by lizard »

I have booted in win 10 recently and what i never expected all the years, win appears slow and akward now. I will stay with Mint.
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: Sleep command issue

Post by sancho3 »

@FXM:
Your variadic macro works perfectly on Ubuntu.
All the timings worked.
I tested keypresses to bypass the sleep and they all worked as they should have. It ignored the keypress on the last sleep 10000, 1.
I will post a bug report tonight, if someone hasn't already done so.
Bug reported
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Sleep command issue

Post by coderJeff »

Proposed fix @ https://github.com/freebasic/fbc/pull/84

Current problem is that fb linux rtlib was using "is there a key to be read?" as the test for "has a key been hit?"

I changed unix keyboard handler so should behave same as windows console. In this example code, if you press a key during the 5 sec delay at the start the, first SLEEP is passed, but not the second SLEEP. Like in windows.

Code: Select all

dim t as double = timer
print "wait 5 secs"
while( timer - t ) < 5
wend
print "1"
sleep
print "2"
sleep
print "3"
sleep
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: Sleep command issue

Post by sancho3 »

Very nice. Thank you for working on this and fixing it.
Post Reply