Code Monkey home page Code Monkey logo

Comments (4)

ddemidov avatar ddemidov commented on July 30, 2024

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.

from ev3dev-lang.

ddemidov avatar ddemidov commented on July 30, 2024

I've added a static button::process_all() method. It simply calls button::process() for each of the EV3 buttons.

from ev3dev-lang.

cho934 avatar cho934 commented on July 30, 2024

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++ ?

from ev3dev-lang.

ddemidov avatar ddemidov commented on July 30, 2024

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();

from ev3dev-lang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.