Skip to main content
Share Your Experience: Take the 2024 Developer Survey
6 votes
Accepted

User callback functions

I don't know the user's function parameters, A common way for dealing with this issue is to pass a generic pointer to arbitrary data. See below. return type It makes little sense to allow for ...
Edgar Bonet's user avatar
  • 43.3k
4 votes

Non-blocking MQTT library

I had the same question and found an mqtt library that is completely non-blocking. https://github.com/marvinroger/async-mqtt-client You need to manually install it and the docs give instructions: ...
Rudy Albachten's user avatar
3 votes
Accepted

Passing a method pointer

The easiest method I know to do this would be to use a "C"-style wrapper for the member function call. This is in fact done to interface C callbacks with C++ objects. You could do it like ...
Mat's user avatar
  • 464
3 votes
Accepted

How to get variable from callback function?

Callback functions are usually void and don't return real data, because they are called by some type of event handling system, like the mentioned library. As this is calling the callback function, not ...
chrisl's user avatar
  • 16.3k
3 votes

User callback functions

You can't call arbitrary functions (with random return types, and any number of arguments) but you can specify a callback function that takes a certain number of specific arguments, and returns a ...
Nick Gammon's user avatar
  • 38.3k
2 votes

ESP8266 ASyncTCP class example

There are examples in the ESP8266 library https://github.com/me-no-dev/ESPAsyncTCP/tree/master/examples
renatobo's user avatar
2 votes
Accepted

Use callbacks in Arduino with pointers to functions (will functions persist in memory?)

Your functions won't cease to exist. All of the code in your compiled and linked code image gets loaded into code-memory (Flash) and it stays there throughout the run, through resets, and through ...
JRobert's user avatar
  • 15.3k
2 votes

How do I write efficient callback functions on a Teensy 4.0?

I have been using callbacks quite intensively on an Arduino Mega 2560, for managing RS-485 messages. This board has roughly 8 times less flash and 128 times less RAM than your Teensy. However, as the ...
Edgar Bonet's user avatar
  • 43.3k
2 votes
Accepted

Array of Functions

The C++ language makes a distinction between an initialization and an assignment. An initialization is the initial value you give to a variable at the point where you are defining it. An assignment is ...
Edgar Bonet's user avatar
  • 43.3k
2 votes
Accepted

How to pass variables to custom callback functions

The function you are trying to call is a template function: template<typename TArg> void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg) { .... } So, you need to tell it ...
001's user avatar
  • 953
1 vote

How to pass variables to custom callback functions

It looks like you are trying to do a lambda function and that's a bit too modern for the Arduino compiler. So you have: change_pin.attach_ms(100, ????, desired_state); Its just the ???? we need to ...
Code Gorilla's user avatar
  • 5,637
1 vote
Accepted

Call functions of one class from another class - Callback

What you are doing here encoder.Setup(menu.UpDown, menu.Tab, []{display.Toggle();rtc.Toggle();}); is not only passing a function pointer. You are passing a member function pointer. This is 2 levels ...
Thomas Weller's user avatar
1 vote
Accepted

Share interrupt service between class

This is not an Arduino specific question but a C++ question, and as such you might get more or better answers on StackOverflow. Anyway, I'll suggest a possible solution. A member method always ...
the busybee's user avatar
  • 2,078
1 vote

Trigger event onRelease of button

The onPressed() event Triggers a callback function when the button has been pressed and released. Here's a test sketch to show what I mean. I've also added a function you could use to detect the ...
VE7JRO's user avatar
  • 2,559
1 vote

Parent class callback from child class

Use virtual functions. On object of type Child, fnc2 defined in Parent will call fnc1 of class Child: class Parent { public: virtual void fnc1() { } void fnc2 { ... fnc1(); ... }...
Juraj's user avatar
  • 18k
1 vote
Accepted

Callback functions when using a class

The ESP8266WebServer uses callback functions to handle HTTP request by your code. This callback functions can't be members of a class. But you can use anonymous functions to implement this callbacks. ...
Juraj's user avatar
  • 18k
1 vote

Passing non-static member function using bind

In your MyClass example, the drawPaged() call is given only a single argument, while according to the library, it needs two: void drawPaged(void (*drawCallback)(const void*), const void* pv) The ...
ByteWelder's user avatar
1 vote

ESP8266 ASyncTCP class example

If there are no examples provided with the library then you will have to make do with the example you have :( If you think about what a web server does it is really just a glorified Telnet server ...
Code Gorilla's user avatar
  • 5,637
1 vote
Accepted

Typedef Function Pointer Invoking Issue

This answer contains a few debugging guidelines, as I don't know what the problem is and don't see how one could tell without a good deal more of information. I suggest creating a Minimal, Complete, ...
James Waldby - jwpat7's user avatar
1 vote

What are the parameters of the browseUrl() callback in the Ethercard library?

Apparently, the callback is executed on every packet which arrives by the browseUrl call. "off" and "len" are pointers to the Ethernet buffer holding the data. "Off" are the initial value (offset) ...
fabrosell's user avatar
  • 216

Only top scored, non community-wiki answers of a minimum length are eligible