Reply
Thread Tools
Posts: 219 | Thanked: 94 times | Joined on Nov 2009 @ Helsinki, Finland
#11
Originally Posted by phil128 View Post
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.
__________________
Ham > Turkey
 
Posts: 1,258 | Thanked: 672 times | Joined on Mar 2009
#12
here's some quick code:

while (1) {
f = fopen("/sys/devices...blahblah",...)
fread()
write to bluetooth();
...
usleep(500);
}
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#13
Originally Posted by shadowjk View Post
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...

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

Last edited by qwerty12; 2010-07-29 at 12:26.
 

The Following 2 Users Say Thank You to qwerty12 For This Useful Post:
Posts: 1,258 | Thanked: 672 times | Joined on Mar 2009
#14
Oh! libiphb! I've been trying to remember that name for half a year now! Thanks!
 
Posts: 8 | Thanked: 18 times | Joined on Apr 2010 @ USA
#15
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.
 
Reply


 
Forum Jump


All times are GMT. The time now is 03:50.