Sys.getTimer() vs Timer() vs (moment)now

im having a ton of trouble in my custom stopwatch app
I am currently using getTimer and due to its nature(?) of incrementing a bit erratically (at least to me) I had to (and still debugging) do a lot of hacks/workaround.

Hence my question would be - for a stopwatch app that wants to track the lap times / rest times and total time, which sort of timer should I be using?

On the on update function, it seems to me that if I don't use the getTimer, the elapsed time for the stopwatch doesn't increment(?)

I think I tried to do/use something like follow the Unix epoch time and then just add the seconds but I think it failed.

Every time I think I'm done, I find another bug (!!)
  • Be careful not to confuse what is displayed vs what the value really is. If onUpdate() is only called every second, what you see will be off if anything smaller than a second is displayed. Have you seen the Garmin written Stopwatch in the app store, BTW? If nothing else, it can show you what things can be done.
  • Unless the source code is provided for that garmin stopwatch.

    But, in a way I've been using that as a "look/feel" guide only. (The built in one on the F3 - but seems like it's the same as the one on the App Store)
  • But the question remains, what are your trying to do that the Garmin stopwatch doesn't do?
  • https://apps.garmin.com/en-US/apps/542affcf-e440-43d4-a118-5aa3bba2f14e

    that's the app i've made till now.

    basically 3 things
    1) keep track of Sets
    2) Keep track of restTime
    3) overall workout time
  • Now, how often is your timer to update the display, as I said before, that could be a factor.
  • you're right. (in some ways)
    I was using 1000 ms, then I tried 300 and now settled on 200.
    This reduces the "round up" or "round down" errors quite a bit.
    but I'm not suer how this effects the battery life or performance, tho now, with 200 (atleast on the simulator) button presses and its effect on the stopwatch counter seems more instant.

    I'm done for 920xt and the F3 on the simulator. Time to load it into the watch.
    I've tried for the VA - but as you've pointed out prev - the lack of the UP and DN keys are a hamper to what I can do with the existing code. It seems like I may need the swipedirection "getDirection" function instead.

    anyways - beta test first. Min must work for my F3
  • Former Member
    Former Member over 10 years ago
    .....button presses and its effect on the stopwatch counter seems more instant.....
    This line makes me think your not calling requestUpdate with each button press. For a stopwatch with an accuracy of seconds you should be fine with a 1000ms timer.
  • Ur right. I am not. (Cos I didn't know how)

    But based on ur statement, and what I've seen on github, calling UI.requestupdate for each EVT onkey would be thr right way to go.

    Will give it a spin. Thanks.
  • Former Member
    Former Member over 10 years ago
    So if you're basing your timer off the system timer, and not already doing so, you will probably want to create an offset when you start, so that the timer is relative to the start time eg
    // on start button
    var offset = System.getTimer();

    // on update
    var duration = (System.getTimer() - offset) / 1000;
    var seconds = duration % 60;
    var minutes = (duration / 60) % 60;
    var hours = duration / 3600;
  • So if you're basing your timer off the system timer, and not already doing so, you will probably want to create an offset when you start, so that the timer is relative to the start time eg
    // on start button
    var offset = System.getTimer();

    // on update
    var duration = (System.getTimer() - offset) / 1000;
    var seconds = duration % 60;
    var minutes = (duration / 60) % 60;
    var hours = duration / 3600;


    // on start
    SwStart = Sys.getTimer();
    Ui.requestUpdate();

    //onupdate
    ElapsedTime = Sys.getTimer() - SwStart;


    that should be similar to what you're saying?
    I take a snapshot of the time at the start.
    then I continuous (or everytime a key is pressed - be it start / pause / restart) snapshot of the time at the various key events.