Skip to main content
deleted 346 characters in body
Source Link

I'm having an issue trying to use a normal non-member function of my main sketch file as a callback. I can't get the function pointer to invoke from a function other than it was saved. More info below;

MotorEncoder.h

typedef void (*cb)(int16_t,int16_t);
class MotorEncoder
  ...
  private:
    cb _motor_callback;

Program.ino

cb encoder_cb = NULL;
...
encoder_cb = function_that_accepts_2_int16
DC_Encoder_1.move(motor_pos, speed, motor_id, encoder_cb);

I'm ableEDIT: I want to useedit the pointer inside of MotorEncoderdescription as to not confuse anyone.cpp but only inside of The code with the "move" functioncallbacks above is all correct. My main sketch gets the callback when The issue was I use either the the function parameter orwas working with open-source software and another developer was setting the MotorEncoder callback variable that I storeselected serial-port connection back to the function parameterbluetooth channel in. Program-correctly.ino calls a loop() function on the encoder and eventually I'd like to call my Program back via the The callback thatwas executed, I saved during the initial move call. The problem I'm having is the function pointer is still set (initializedwas connected to NULL inside of MotorEncoder, and still set) but it doesn't actually invoke the function on Program.ino.

I assume I'm missing something with scope/context but I'm not exactly sure what because I'm not tryingATMega2560 via serial connection to use a member function asraspberry pi and was looking for the callback it's just a normal function in my main sketch file. Any helps or tips would be appreciatedto show there, thanks!not monitoring bluetooth so I didn't see any data come across. Document your code.

I'm having an issue trying to use a normal non-member function of my main sketch file as a callback. I can't get the function pointer to invoke from a function other than it was saved. More info below;

MotorEncoder.h

typedef void (*cb)(int16_t,int16_t);
class MotorEncoder
  ...
  private:
    cb _motor_callback;

Program.ino

cb encoder_cb = NULL;
...
encoder_cb = function_that_accepts_2_int16
DC_Encoder_1.move(motor_pos, speed, motor_id, encoder_cb);

I'm able to use the pointer inside of MotorEncoder.cpp but only inside of the "move" function. My main sketch gets the callback when I use either the the function parameter or the MotorEncoder callback variable that I store the function parameter in. Program.ino calls a loop() function on the encoder and eventually I'd like to call my Program back via the callback that I saved during the initial move call. The problem I'm having is the function pointer is still set (initialized to NULL inside of MotorEncoder, and still set) but it doesn't actually invoke the function on Program.ino.

I assume I'm missing something with scope/context but I'm not exactly sure what because I'm not trying to use a member function as the callback it's just a normal function in my main sketch file. Any helps or tips would be appreciated, thanks!

I'm having an issue trying to use a normal non-member function of my main sketch file as a callback. I can't get the function pointer to invoke from a function other than it was saved. More info below;

MotorEncoder.h

typedef void (*cb)(int16_t,int16_t);
class MotorEncoder
  ...
  private:
    cb _motor_callback;

Program.ino

cb encoder_cb = NULL;
...
encoder_cb = function_that_accepts_2_int16
DC_Encoder_1.move(motor_pos, speed, motor_id, encoder_cb);

EDIT: I want to edit the description as to not confuse anyone. The code with the callbacks above is all correct. The issue was I was working with open-source software and another developer was setting the selected serial-port connection back to the bluetooth channel in-correctly. The callback was executed, I was connected to the ATMega2560 via serial connection to a raspberry pi and was looking for the callback to show there, not monitoring bluetooth so I didn't see any data come across. Document your code.

added 23 characters in body
Source Link

I'm having an issue trying to use a normal non-member function of my main sketch file as a callback. I can't get the function pointer to invoke from a function other than it was saved. More info below;

MotorEncoder.h

typedef void (*cb)(int16_t,int16_t);
class MotorEncoder
  ...
  private:
    cb _motor_callback;

Program.ino

cb encoder_cb = NULL;
...
encoder_cb = function_that_accepts_2_int16
DC_Encoder_1.move(motor_pos, speed, motor_id, encoder_cb);

I'm able to use the pointer inside of MotorEncoder.cpp but only inside of the "move" function. My main sketch gets the callback when I use either the the function parameter or the MotorEncoder callback variable that I store the function parameter in. Program.ino calls a loop() function on the encoder and eventually I'd like to call my Program back via the callback that I saved during the initial move call. The problem I'm having is the function pointer is still set (initialized to NULL inside of MotorEncoder, and still set) but it doesn't actually invoke the function on Program.ino.

I assume I'm missing something with scope/context but I'm not exactly sure what because I'm not trying to use a member function as the callback it's just a normal function in my main sketch file. Any helps or tips would be appreciated, thanks!

I'm having an issue trying to use a normal non-member function of my main sketch file as a callback. I can't get the function pointer to invoke from a function other than it was saved. More info below;

MotorEncoder.h

typedef void (*cb)(int16_t,int16_t);
class MotorEncoder
  ...
  private:
    cb _motor_callback;

Program.ino

cb encoder_cb = NULL;
...
encoder_cb = function_that_accepts_2_int16
DC_Encoder_1.move(motor_pos, speed, motor_id, encoder_cb);

I'm able to use the pointer inside of MotorEncoder.cpp but only inside of the "move" function. My main sketch gets the callback when I use either the the function parameter or the MotorEncoder callback variable that I store the function parameter in. Program.ino calls a loop() function on the encoder and eventually I'd like to call my Program back via the callback that I saved during the initial move call. The problem I'm having is the function pointer is still set (initialized to NULL, and still set) but it doesn't actually invoke the function on Program.ino.

I assume I'm missing something with scope/context but I'm not exactly sure what because I'm not trying to use a member function as the callback it's just a normal function in my main sketch file. Any helps or tips would be appreciated, thanks!

I'm having an issue trying to use a normal non-member function of my main sketch file as a callback. I can't get the function pointer to invoke from a function other than it was saved. More info below;

MotorEncoder.h

typedef void (*cb)(int16_t,int16_t);
class MotorEncoder
  ...
  private:
    cb _motor_callback;

Program.ino

cb encoder_cb = NULL;
...
encoder_cb = function_that_accepts_2_int16
DC_Encoder_1.move(motor_pos, speed, motor_id, encoder_cb);

I'm able to use the pointer inside of MotorEncoder.cpp but only inside of the "move" function. My main sketch gets the callback when I use either the the function parameter or the MotorEncoder callback variable that I store the function parameter in. Program.ino calls a loop() function on the encoder and eventually I'd like to call my Program back via the callback that I saved during the initial move call. The problem I'm having is the function pointer is still set (initialized to NULL inside of MotorEncoder, and still set) but it doesn't actually invoke the function on Program.ino.

I assume I'm missing something with scope/context but I'm not exactly sure what because I'm not trying to use a member function as the callback it's just a normal function in my main sketch file. Any helps or tips would be appreciated, thanks!

Source Link

Typedef Function Pointer Invoking Issue

I'm having an issue trying to use a normal non-member function of my main sketch file as a callback. I can't get the function pointer to invoke from a function other than it was saved. More info below;

MotorEncoder.h

typedef void (*cb)(int16_t,int16_t);
class MotorEncoder
  ...
  private:
    cb _motor_callback;

Program.ino

cb encoder_cb = NULL;
...
encoder_cb = function_that_accepts_2_int16
DC_Encoder_1.move(motor_pos, speed, motor_id, encoder_cb);

I'm able to use the pointer inside of MotorEncoder.cpp but only inside of the "move" function. My main sketch gets the callback when I use either the the function parameter or the MotorEncoder callback variable that I store the function parameter in. Program.ino calls a loop() function on the encoder and eventually I'd like to call my Program back via the callback that I saved during the initial move call. The problem I'm having is the function pointer is still set (initialized to NULL, and still set) but it doesn't actually invoke the function on Program.ino.

I assume I'm missing something with scope/context but I'm not exactly sure what because I'm not trying to use a member function as the callback it's just a normal function in my main sketch file. Any helps or tips would be appreciated, thanks!