I dont like any of the methods ive seen. What I want is my own event (ie a
user event "myEvent") to go off approximatly every second. I have a method
that posts an event in the call to EvtGetEvent if a second has passed since
my last event. However my method requires me to return a value other that
evtWaitForever to work, as there does not seem to be enough system events to
keep it happy.  Much less than one a second, which supprises me.

The following function is called in EvtGetEvent, you can use TimGetTicks
instead of seconds to get different granualarity, but I only want aprox
every second so this works fine after the first events (takes two myEvents
to settle). The main issue here is what value to return, so that the
function gets called often enough to know when the time has changed. It
seems to work well with 10 and 100 so Im not sure how important it is. I
suppose the only real impact is on battery life. 

static Int32 TimeUntilNextRead (void)
{
        static UInt32 time_of_last_read = 0;/* Holds time of last read */

        UInt32 current_time = TimGetSeconds ();
                /* If a second has passed (approx) */                   
        if (current_time > time_of_last_read)           
        {
                EventType user_event;                   /* Post our own
event to the queue */
                user_event.eType = (eventsEnum)userReadPort;
                EvtAddEventToQueue (&user_event);
        }
                
        time_of_last_read = current_time;
        
        return 10;
        }
}

Being a big head, I reckon this method is the best Ive seen (becuase I
thought of it myself). If anyone can see any problems with it or know a
better way please let me know.

Thanks 

Rik Anderson


> -----Original Message-----
> From: Dave Lippincott [SMTP:[EMAIL PROTECTED]]
> Sent: 08 August 2000 14:14
> To:   Palm Developer Forum
> Subject:      Re: Creating a non accurate 1 second timer
> 
> Set EvtGetEvent to generate a nilEvent about every second or 1/2 second.
> Trap the nilEvent in your dialog's event loop (be sure to return false
> when
> you do handle the nilEvent)  If its time to perform your function, then do
> so.  If not, ignore the nilEvent.
> 
> Read the description of timeout parameter in the EvtGetEvent function.
> 
> There are other methods of generating timers in the Palm OS, search the
> list
> archives for examples.
> 
> 
> 
> -- 
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/tech/support/forums/

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

Reply via email to