You are correct that the resolution is roughly a second. The alarm is quite useful, however, when you either do not want to count ticks or need a periodic alarm while powered off (ticks stop when powered off).
I generally use both - the EvtGetEvent() with timeout method while powered on and the AlmSetProcAlarm() method when power is off. -------------------- Jeff Loucks Work 425-284-1128 [EMAIL PROTECTED] Mobile 253-691-8812 [EMAIL PROTECTED] Home 253-851-8908 [EMAIL PROTECTED] -----Original Message----- From: Nathan Black [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 29, 2004 5:41 PM To: Palm Developer Forum Subject: RE: Timer and Callback? That is only useful if you want a timer with only 1 second resolution, which i think i most cases is not acceptable. The Palm OS was originally totally event driven. The way to do this is do any processing you need to when you're not processing events. First off modify your event loop in AppEventLoop (if you're using the standard palm app stationary) by changing the wait in EvtGetEvent() to 0 or a value close to the interval you want. (second parameter). more on this later Then, you can check the number of "ticks" that have elapsed since your last time through, and compare that with the previous time through and see if you're at your interval, and do the processing you need. here's an example: static void AppEventLoop(void) { UInt16 error; EventType event; UInt32 curTicks, myTickInterval, lastTicks = 0; myTickInterval = kMyTickInteralSeconds * SysTicksPerSecond(); // fyi it's 100 on about all Palm Devices do { EvtGetEvent(&event, 0); if (! SysHandleEvent(&event)) if (! MenuHandleEvent(0, &event, &error)) if (! AppHandleEvent(&event)) FrmDispatchEvent(&event); curTicks = TimGetTicks(); if (curTicks - lastTicks >= myTickInterval) { DoSomething(); lastTicks = curTicks; } } while (event.eType != appStopEvent); } If your interval is high, you might want to change 0 to something that's like 1/4 of your interval. The reason is, the processor goes to sleep when it's waiting for the next event. Otherwise, with 0, it never does, and uses battery power faster. Nathan -----Original Message----- From: [EMAIL PROTECTED] [mailto:bounce-palm- [EMAIL PROTECTED] Behalf Of Jeffry Loucks Sent: Tuesday, June 29, 2004 5:17 PM To: Palm Developer Forum Subject: RE: Timer and Callback? Try this (don't forget to clear the alarm before exiting your app): Err AlarmCallback(UInt16 almProcCmd, SysAlarmTriggeredParamType *paramP) { // at this point, app globals are not available, so pass // what you need as a reference parameter return 0; } void PrvSetCallbackAlarm(UInt32 milliseconds) { if (milliseconds) { milliseconds = milliseconds / 1000 + 1; // Not stable if set for less than 2 seconds if (milliseconds < 2) milliseconds = 2; // set alarm AlmSetProcAlarm(AlarmCallback,0,TimGetSeconds() + milliseconds); } else { // clear alarm AlmSetProcAlarm(0,0,0); } } -------------------- Jeff Loucks Work 425-284-1128 [EMAIL PROTECTED] Mobile 253-691-8812 [EMAIL PROTECTED] Home 253-851-8908 [EMAIL PROTECTED] -----Original Message----- From: Marc A. Lepage [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 29, 2004 4:07 PM To: Palm Developer Forum Subject: Timer and Callback? Is there an API for setting a callback to be called at time intervals (e.g. every second)? I looked but I could not find one. Must I manually count ticks and call the callback myself? -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
