EasyManua.ls Logo

LEGO MINDSTORMS Robots

LEGO MINDSTORMS Robots
226 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
wakeup_t wait_event(wakeup_t (wakeup)(wakeup_t), wakeup_t data)
Use this function to wait for a specific event. The function pointed at by wakeup is called, with data as a parameter, until it returns a non-zero result. At this point, wait_event() will return.
It's not hard to use wait_event(), but it's certainly not obvious. It helps to look at some of the examples that come with legOS. The following is a rewrite of the previous example that uses
wait_event() instead of a while loop:
#include "conio.h"
#include "direct-button.h"
#include "unistd.h"
#include "sys/tm.h"
pid_t pid;
int display_task(int argc, char ∗∗argv) {
while(1) {
cputs("Hello");
lcd_refresh();
sleep(1);
cputs("nurse");
lcd_refresh();
Page 202
sleep(1);
}
return 0;
}
wakeup_t button_press_wakeup(wakeup_t data) {
return PRESSED(button_state(),data);
}
int stop_task(int argc, char ∗∗argv) {
msleep(200);
wait_event(&button_press_wakeup, BUTTON_RUN);
kill(pid);
return 0;
}
int main() {
pid = execi(&display_task, 0, NULL, 0, DEFAULT_STACK_SIZE);
execi(&stop_task, 0, NULL, 0, DEFAULT_STACK_SIZE);
tm_start();
return 0;
}
All that happened in this code was that the while loop from the previous example was replaced with a call to wait_event. The given function, button_press_wakeup(), does the dirty
work of checking the state of the button.
Memory (stdlib.h)

Table of Contents

Related product manuals