c - How to look for a change in a file without polling? -


I have beagle bone and want to read GPIO pin from my program. The file has 1 or 0 at any moment. I have a time loop in my C program, which always remains due to the CPU hog with the fountain function whenever this pin is low (0) and when it is high (1) this code runs me It seems it is very useless of resources. Is there any way I can see this file is 1 and then run the code? I do not like voting, especially when the beagle bone battery is operated.

Use an information system, by example using.

The basic idea is, if a callback is called, then data is available.

If this does not work, you may need to use another API to get there, for example, INFOIFA.

Docs:

  // requires a single header file # include & lt; Ev.h> # Include & lt; Stdio.h & gt; For // // each viewer has its own typedef'd structure / / name with ev_TYPE ev_io stdin_watcher; Ev_timer timeout_watcher; // All viewers have the same signature of the callback / it is called callback when the data can be read on stdin static void stdin_cb (EV_P_ ev_io * w, int revents) {puts ("stdin ready"); // For one-shot incidents, manually the viewer will have to manually stop / stop with the stop function i Ev_io_stop (EV_A_w); // This causes the nested EV_RON to stop the eve-break (EV_A_ EV BREAK_ALL) iteration; } // another callback, a time-out static zero timeout_cb for this time (EV_P_ ev_timer * w, int revents) {puts ("timeout"); // This is the easiest ev_run to repeat EVA_ EVBREAK_ONE; } Int main (zero) {// Use the default event loop until you have the special needs structure ev_loop * loop = EV_DEFAULT; // Start an IO checker, then start it // it will be readin for reading studio EVOIIT (and stdin_watcher, stdin_cb, / * STDIN_FILENO * / 0, EV_READ); Ev_io_start (loop, & stdin_watcher); // Start a timer viewer, then start it // simple non-repetitive 5.5 seconds timeout ev_timer_init (& timeout_watcher, timeout_cb, 5.5, 0.); Ev_timer_start (loop, and timeout_veter); // Now wait events for ev_run (loop, 0); // Break was called, hence exit return 0; }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -