A little help using Chronometer

JTmartins

Active Member
Licensed User
Longtime User
Hi everyone.

I'm using the clocks library and have a chronometer runing.

This chronometer stops when there is no move for a certain amount of time (GPS controled)..this is all working.

My problem, is that after stopping the chronometer, at let's say 1:29 I want it to restart at that point (not revert to zero).

The code that initializes the chrono is the standard

B4X:
Chrono.Initialize("Chrono")
ChronoBase = Chrono.GetElapsedRealTime
Chrono.BaseTime = ChronoBase    
Chrono.Start

then later in the code I stop it.

Now I want to start again, but continuing the count.

I have ChronoBase, but setting chrono.basetime again to Chronobase, before start again, does not work.

Can some one help with this ?

Thanks

Jose
 
Last edited:

agraham

Expert
Licensed User
Longtime User
You must not be setting Chrono.BaseTime to the correct value. When you start it at zero save GetElapsedRealTime in a Global. When you stop it again save GetElapsedRealTime in a Global. The difference is the chronometer reading. When you start it again read GetElapsedRealTime again and subtract from it the chronometer reading and use that for Chrono.BaseTime.
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
I will retry

That was what I was trying...

one less the other, and the chrono jumps to stupid values as one hour and 42 seconds...things like that (I it will vary according to the time the emulator is running)

I will re-check my code, to see if I understand what I'm doing wrong
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
Need help. Can't see

It must be something stupid...

I've been playing around. This is the little part that is giving me problems.

This is running inside a timer _tick sub that checks for GPS, saves coordinates to a DB, compare distances, etc.

distok is a variable that carries zero when there is no movement.

nomove is a controler. It stops the chrono when it reaches 7

Now..The first time when there is no movement, the chrono stops...When movment starts, the chrono resumes continuing properly. NO PROBLEM IN THE FIRST TIME.

The second time when there is no movement, the chrono stops, but when it resumes...it jumps to the future...(adding the time while there was no movement)

I've tryed several diferent ways of coding...and always get the same result and I'm starting to get lost. So I must be doing someting really stupid.

B4X:
' please note that this part is inside a _thick sub that runs every 10 secs.

If distok=0.0 Then ' no move
   nomove=nomove+1 
End If


   
If nomove=7 Then
   flag_movimento=False
   LastTime=Chrono.GetElapsedRealTime
   Timex=LastTime-ChronoBase
   Chrono.Stop
End If
      

If distok<>0 Then ' movement exists
         
   If flag_movimento=False  Then
       Time2=Chrono.GetElapsedRealTime - Timex
       Chrono.BaseTime=Time2
    End If
            
   Chrono.Start 
   nomove=0       
   flag_movimento=True
      
         
End If

Any help will be welcomed.
:BangHead:
 
Last edited:
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
nope

Nop Erel

By doing That it does not work correctly and it's even worst. Even the first time fails, and jumps to 38 minutes or so, after being stoped for a minute.

This really drives me nuts...works only on the first time.

grrr

José
 
Last edited:
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
Solved.

Solved...

Not updating the variable chronobase (the one that saves the time at the very first time) was the problem.

Thanks to all
 
Upvote 0
Top