Callbacks

Yeah
20 characters
Needs more

Well, after putting some heads together in robotics our solution was this
(Controller1.Axis2.value() + Controller1.Axis4.value() - Controller1.Axis1.value())*x
with x as a variable we change for the different speeds with the change activated by this
Controller1.ButtonY.pressed(function1);
anyone know why this wont work?

1 Like

Anyone have a solution?

have the function run upon release of the Button

I will try that
20 characters

go like
if(pressed)
{
while (pressed) {}
function;
}

our code was like this
controller.button.pressed(function)
we had two different buttons and they changed the value of x

@jpearman, could you please confirm that when we register .pressed() or .released() event on a button for the second time, it does not consume additional thread resource out of the limited pool of 100, but uses already allocated thread for the new callback function?

4 Likes

It does consume additional resource, event handlers should only be registered once, if you register either the same or an additional callback the event will call both handlers.

On V5 each event handler is a thread blocked on a semaphore, when the event fires, vexos released the semaphore allowing the thread to run, the thread calls the user registered callback.

There is currently no way to unregister an individual event handler.

On IQ, which uses the same core functionality in VEXcode, we don’t have enough memory to dedicate a thread to each event so we have to use a thread pool instead, this limits the number of events that can simultaneously fire and be serviced.

5 Likes