Questions tagged [callbacks]

This refer to the call back procedure in computer programming.

In computer programming, a callback is a piece of executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at some convenient time. The invocation may be immediate as in a synchronous callback, or it might happen at a later time as in an asynchronous callback.

21 questions
6
votes
2 answers

User callback functions

I want to write a class that allows the user to attach his own function to a member function that listens for messages coming from a wireless module, so that the user's function can be called depending on the message. I am thinking about using…
Vasil Kalchev
  • 293
  • 1
  • 2
  • 12
5
votes
1 answer

Non-blocking MQTT library

Are there any MQTT libraries that do not block while connecting? I'm currently using PubSubClient, and the connection part contains this code: https://github.com/knolleary/pubsubclient/blob/master/src/PubSubClient.cpp while…
Stephen Denne
  • 151
  • 1
  • 6
4
votes
1 answer

How to get variable from callback function?

There is a library davetcc / IoAbstraction. The only library working as expected with my rotary encoder. The problem that on rotation I can only see serial output with position data, but I cannot get these data as some variable value. There is the…
4
votes
2 answers

How to pass variables to custom callback functions

I want to use the Ticker library of the ESP8266 Arduino core to (asynchronously) delay the switch of a pin to a desired state like below. I am not sure about the "here is" function definitions and I am having a hard time to find some documentation.…
milkpirate
  • 143
  • 1
  • 4
3
votes
1 answer

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

I'm reading a code that uses Arduino as a webclient and when he tries to catch the info from the site, he uses a callback with the following parameters: static void response_callback (byte status, word off, word len) Can anyone explain me how does…
2
votes
0 answers

Program crashes when calling external library code via function pointer

I've written a user library for the Pi Pico that uses the TaskScheduler library to abstract timing away from the user. The user provides a function in their sketch which the library calls periodically via function pointer passed in the…
Joe of Loath
  • 157
  • 3
2
votes
1 answer

Passing non-static member function using bind

I'm using the GxEPD2 library to communicate with an E-Paper display. I now wanted to use the drawPaged method of this library with an object display. I also have written my own class from which I want to print stuff on the display. Here's the…
Lithimlin
  • 145
  • 1
  • 8
1
vote
2 answers

Array of Functions

I'm new to C++. How to make a menu without if() {} else {} & switch() case? I made a menu on an array, but for some reason it doesn't compile. How to correct it? typedef void (*cbd)(uint8_t, uint8_t); typedef void (*cbt)(uint8_t, uint8_t); typedef…
Andre
  • 27
  • 6
1
vote
2 answers

Call functions of one class from another class - Callback

I am new to C++ & I need to call functions of one class from another class. And so that the classes do not know anything about each other. How to do it in Arduino environment? class Encoder { using CallBack2 = void( * )(const int, const int); …
Andre
  • 27
  • 6
1
vote
2 answers

Callback functions when using a class

This question is somewhat similar to How to pass non-static class member to callback?, but there are a few differences, especially since a lot of my uses have "interesting" additional complexities. I'd like to understand better my options in using…
user47164
1
vote
2 answers

ESP8266 ASyncTCP class example

I am new to ESP programming on Arduino, as before I was developing on eLua. There were some memory problems in Lua, so I decided to move to Arduino. After looking at some examples, I found a library called AsyncTCP and I was very glad because it…
mansoor
  • 11
  • 1
  • 3
1
vote
1 answer

Pass class's public function as an argument to external command

I am trying to write a library for encoders. main.ino: #include <./Encoders.h> Encoders encoders(); void setup(){ Serial.begin(9600); } void loop(){ Serial.print(""); } Encoders.h: #ifndef Encoders_h #define…
Marcel
  • 181
  • 4
  • 11
0
votes
1 answer

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

I am looking at refactoring my code by implementing callback functions in order to be able to reuse the abstract logic of other functions/classes. However, I feel I need to learn more about the limits of callback functions on embedded systems like…
Erik
  • 271
  • 1
  • 15
0
votes
3 answers

Trigger event onRelease of button

I am using the EasyButton library to detect button presses on an arduino. I want do execute a function when the user Presses a button Presses and holds a button Releases a button Detecting when a user presses or holds a button is straight…
spuder
  • 111
  • 1
  • 8
0
votes
1 answer

Passing a method pointer

I created a small library, which takes a callback function: MyClass::add_callback(bool (*callback_function)(), byte behaviour) { // ... bool result = callback_function(); // ... } So far, I'm using it for periodic polling (for which I don't…
MacFreek
  • 103
  • 5
1
2