Henk Jonas wrote:
> Christian Lindemeier wrote:

>> and as Brandon said you just have to say in your eventloop
>> EvtGetEvent(&event, ticks);
>>
>> where ticks is the time you want the app to update your time.
>> I would suggest 6000 for an update every minute.
>> You just have to fetch the nilEvent in your eventhandler to call the
>> function and display the time in a field.

> I would use a number a bit smaller than necessary, to ensure, you get
> the event early enough in any case. Also I would suggest to use
> something like 59 * SysTicksPerSecond(),

I agree about SysTicksPerSecond().  But, updating every 59 seconds
is going to give odd results too.  Every now and then, there will
be a minute during which you update during the first second.
Then you will update 59 seconds later, and it will still be the
same minute, so you will draw the same thing and then
Which means that from the user's point of view, most minutes will
appear to be 59 seconds long, but occasionally a minute will appear
to be 118 seconds long.

One solution is to just update every 5 seconds.  It's not going to
be too big a load on the CPU if you do that.

You can also get a lot more elaborate.  It's possible to compute
the next time that the minute will change and thus know when you
next will need to be awoken:

        DateTimeType nextminute;
        Int32 waketime;
        
        TimSecondsToDateTime (TimGetSeconds(), & nextminute);
        nextminute.second = 0;          // start of this minute
        TimAdjust (& nextminute, 60);   // start of next minute
        waketime = TimDateTimeToSeconds (& nextminute);

Once you know waketime, you can set a small fixed interval, like 1
second or so, on EvtGetEvent() and poll for it:

        case nilEvent:
            if (TimGetSeconds() >= waketime)
            {
                DrawClock();
                waketime = ComputeClockWakeTime();
            }

            break;

Or, if you don't need nilEvents for any other purpose, you can even
do this:

        EvtGetEvent (
                & event,
                (waketime - TimGetSeconds()) * SysTicksPerSecond());

That way you wake up only when you need to, and you update the clock
very near the time when the minute changes.

  - Logan

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to