We have moved to a new Sailfish OS Forum. Please start new discussions there.
1

Timer running inconsistent

asked 2014-08-30 14:45:25 +0300

FloR707 gravatar image

Hi,

I realized that the Timer function is not really running constantly.

Timer {
        id: ticker
        interval: 1000
        repeat: true

        onTriggered: {
            clock.time--
            console.log(clock.time)
        }
}

As long as the display is on it runes okay. Also if I turn off the display manually (there is a keep alive function running). The only issue is when the display dimmes down, then the last five seconds speed up and are done in 2.5. Any idea why?

edit retag flag offensive close delete

Comments

You should never rely on interval functions to be precise (no matter which language); even if they generally are pretty close, there can always be external circumstances that make them unprecise and it sums up quickly. Better remember the start timestamp in a variable and calculate the difference to the current time on each tick to update the displayed time (or whatever you need to do with it).

tokaru ( 2014-08-30 19:45:52 +0300 )edit

Looking for a solution I found similar comments regarding timers several times. Too bad, the Timer function just look so simpel and it was so easy to get my code working.
I guess I have to change my code and work with timestamps. If I do that I would still have the timer to update the view. What interval would you use to update the time stamps? 1000 ms or less?

FloR707 ( 2014-08-31 12:38:18 +0300 )edit

Actually, it is nearly as simple, so instead of clock.time-- you could just do something like (pseudo-code) remainingTime = countdownDuration - (nowTimestamp - startTimestamp), assuming it is supposed to be a countdown timer. The interval depends on your needs: if you actually create a countdown displaying seconds, there is no need to go below 1000ms. From the performance point of view it could be much shorter, after all it is just a simple calculation and updating the user interface.

tokaru ( 2014-08-31 16:24:37 +0300 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2014-08-30 18:56:34 +0300

Tanghus gravatar image

You'll have to use e.g. libiphb to have timers that triggers during sleep mode. I've made a QML module that uses it: https://github.com/tanghus/kitchen-timer-qml/tree/master/src/insomniac

edit flag offensive delete publish link more

Comments

I am aware of that problem and found a simpel solution for me to prevent sleep. Probably it would have been the right way to use such a plugin but it looked too difficult to me. Is there any documentation on how to use it, yet?

FloR707 ( 2014-08-31 12:35:28 +0300 )edit

It's very similar to the standard Timerelement. See https://github.com/tanghus/kitchen-timer-qml/blob/master/qml/harbour-kitchentimer.qml#L118

Tanghus ( 2014-08-31 20:34:32 +0300 )edit
Login/Signup to Answer

Question tools

Follow
1 follower

Stats

Asked: 2014-08-30 14:45:25 +0300

Seen: 551 times

Last updated: Aug 30 '14