Closed ddemidov closed 9 years ago
Done for C++ and exposed in Python. For now each button should be handled individually:
def say_hello(pressed): if pressed: print('hello')
button.enter.onclick( say_hello )
while True: button.enter.process()
What I don't like about this is the processing part. I think I would prefer a single process()
function that would iterate over all buttons. What is stopping me from implementing this is mainly where to put it (as a static method in a button class, or as a standalone helper class?) and how to name it.
Of course, it may be easily done on the user side of the code as well.
I've added a static button::process_all()
method. It simply calls button::process()
for each of the EV3 buttons.
Done for C++ and exposed in Python. For now each button should be handled individually:
def say_hello(pressed): if pressed: print('hello') button.enter.onclick( say_hello ) while True: button.enter.process()
I don't understand how to use this onclick and process function. Could you create a small example using the onclick function in C++ ?
Something like this should work:
// Set a functor (here created as a lambda function) as the button event handler:
ev3dev::button::enter.onclick = [](bool state) {
std::cout << state ? "pressed" : "not pressed" << std::endl;
};
// Do event processing in a loop. Whenever the enter button changes state,
// the onclick functor is called with the appropriate argument:
while (!ev3dev::button::back.pressed())
ev3dev::button::enter.process();
Similar to how it is implemented in the
remote_control
class.