EasyManuals Logo

LEGO MINDSTORMS Robots User Manual

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
Page #182 background imageLoading...
Page #182 background image
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

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the LEGO MINDSTORMS Robots and is the answer not in the manual?

LEGO MINDSTORMS Robots Specifications

General IconGeneral
Product LineLEGO MINDSTORMS
CategoryToy
Age Range10+
Batteries RequiredYes
Memory64 MB RAM, 16 MB Flash
ConnectivityBluetooth, USB
SensorsTouch, Color, Gyro
Battery TypeAA
Interactive FeaturesProgrammable, Remote Control
App CompatibilityiOS, Android
ProcessorARM9
Pieces Count601
Battery Count6
App NameLEGO MINDSTORMS EV3 Programmer App

Related product manuals