maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Timer programming, battery consumption (https://talk.maemo.org/showthread.php?t=59290)

naabi 2010-07-28 19:45

Re: Timer programming, battery consumption
 
Quote:

Originally Posted by phil128 (Post 768200)
The reason i don't really wanna code up an endless loop was due to a lecture slide from the stanford university where it states "don't use big loops, use timers etc" I assume due to its more efficient. At the same time i guess it i want to transmit data in real-time i guess i have no choice but to use and endless loop to cycle through reading from the proc filesystem(accelerometer) and transmit this over bluetooth.

If you want data in real-time, use the events that accelometer API provides. If you end up using timed queries to proc filesystem, find out whether there's an timer API that you can use to schedule execution, i.e. no need for loop.

shadowjk 2010-07-29 10:46

Re: Timer programming, battery consumption
 
here's some quick code:

while (1) {
f = fopen("/sys/devices...blahblah",...)
fread()
write to bluetooth();
...
usleep(500);
}

qwerty12 2010-07-29 12:23

Re: Timer programming, battery consumption
 
Quote:

Originally Posted by shadowjk (Post 768173)
As a sidenote, both intel and the QT folks are working on synchronizing timers in MeeGo. That is, the app can request a wakeup with specified precision (or lack thereof). Say you want your app to wake up every 10 second, but you don't care that much about exactly 10 second. So you can ask "10 seconds, give or take a few", and the kernel or qt can look for another app that has a similar requirements, and slowly move their timers closer together until they fire at the same time, effectively coalescing the wakeups of two apps into becoming a single wakeup.

Actually, unless I'm mistaken, Fremantle also has such a feature: http://maemo.org/api_refs/5.0/5.0-fi...eat-signal-add

The above is for applets, but libiphb can be used directly. Shame most applet writers opt for g_timeout_add_seconds () first...

Quote:

Originally Posted by http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Architecture/UI_Framework#Status_menu_plugin_API
Function for registering callbacks using the system-wide synchronized timers: hd_status_plugin_item_heartbeat_signal_add


shadowjk 2010-07-29 19:31

Re: Timer programming, battery consumption
 
Oh! libiphb! I've been trying to remember that name for half a year now! Thanks!

janeuner 2010-07-29 20:06

Re: Timer programming, battery consumption
 
sleep() is bad. Never use sleep() for anything except for quick debugging. If you need to do something that is periodic, either figure out how to poll for it, or use a system timer. That heartbeat mechanism is sexy.

Never, ever, ever use sleep.


All times are GMT. The time now is 15:46.

vBulletin® Version 3.8.8