evento#
Inicializando la clase de evento#
Un evento se crea utilizando el siguiente constructor:
The event(callback)
constructor uses two parameters:
Parámetro |
Descripción |
---|---|
|
Una función previamente definida que se llamará como un hilo cuando se transmita el evento. |
// Define the function print()
void print(){
brain.screen.print("Event was broadcast");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Construct an Event "Event" with the event class.
event Event = event(print);
}
This Event
object will be used in all subsequent examples throughout this API documentation when referring to event class methods.
Métodos de clase#
set()#
The set(callback)
command sets a new callback and arguments for the Event.
Parámetros |
Descripción |
---|---|
llamar de vuelta |
La nueva función de devolución de llamada que se llamará cuando se active el evento. |
Devoluciones: Ninguna.
broadcast()#
The broadcast()
command broadcasts the event and causes all registered callback functions to run.
Devoluciones: Ninguna.
void runOnBroadcast1() {
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Broadcast1 Running");
}
void runOnBroadcast2() {
Brain.Screen.setCursor(2, 1);
Brain.Screen.print("Broadcast2 Running");
}
int main() {
// Register callback functions to event.
Event(runOnBroadcast1);
Event(runOnBroadcast2);
// Brief wait to ensure event is registered
wait(15, msec);
// Broadcast the event.
Event.broadcast();
}
broadcastAndWait()#
The broadcastAndWait()
command broadcasts the event, causes all registered callback functions to run, and waits until all callback functions have been completed.
Devoluciones: Ninguna.
void runOnBroadcast1() {
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Broadcast1 Running");
}
void runOnBroadcast2() {
Brain.Screen.setCursor(2, 1);
Brain.Screen.print("Broadcast2 Running");
}
int main() {
// Register callback functions to event.
Event(runOnBroadcast1);
Event(runOnBroadcast2);
// Brief wait to ensure event is registered
wait(15, msec);
// Broadcast the event and wait for completion.
Event.broadcastAndWait();
Brain.Screen.setCursor(3, 1);
Brain.Screen.print("Listeners finished running");
}