Hello Community,
i am Experimenting with Structures and Callback functions. (build a 'Input Event System')
Now iam at the point where i try to make the calling 'object' (a typdefed struct) available in the called function
in my headerfile i have the following definitions:
// Encoder 'Object'
struct sEncoder
{
const byte bNr;
byte pin_A;
byte pin_B;
boolean bA;
boolean bB;
boolean bA_last;
boolean bB_last;
boolean bLastFullStep;
byte bState;
unsigned long ulTimeStamp;
//tCBF_OnStep cbfOnStep;
};
typedef struct sEncoder tEncoder;
// typdef for input state change callback
//typedef void (* tCBF_OnStep) (tEncoder *encObj);
in my ino file iam using it this way:
...
/**************************************************************************************************/
/** Include yourselfs header file (used to define structs and co) **/
/**************************************************************************************************/
#include "SwitchPCB_Test_RotaryEncoder_v02.h"
// use "" for files in same directory as .ino
/**************************************************************************************************/
/** definitions **/
/**************************************************************************************************/
tEncoder enc_left = {
111, //const byte bNr;
22, // byte pin_A;
26, // byte pin_B;
0, // boolean bA;
0, // boolean bB;
0, // boolean bA_last;
0, // boolean bB_last;
0, // boolean bLastFullStep;
state_UNDEFINED, // byte bState;
0, // unsigned long ulTimeStamp;
};
tEncoder enc_right = {
....
};
/**************************************************************************************************/
/** functions **/
/**************************************************************************************************/
void callback_Encoder_OnStep (tEncoder *encObj) {
/** Debug Out **/
Serial.print((*encObj).bNr);
Serial.print(":");
Serial.println((*encObj).bState);
/** **/
}
void readEncoder(tEncoder *encObj) {
boolean bTemp_A = digitalRead((*encObj).pin_A);
boolean bTemp_B = digitalRead((*encObj).pin_B);
.....
/** RUN CALLBACK Function: **/
(*encObj).cbfOnStateChange(encObj);
.....
}
/****************************************************************************************************/
/** Main Loop **/
/****************************************************************************************************/
void loop()
{
readEncoder(&enc_left);
readEncoder(&enc_right);
}
so with this setup the compiler stops and says:
In file included from SwitchPCB_Test_RotaryEncoder_v02.ino:42:
SwitchPCB_Test_RotaryEncoder_v02.h:42: error: 'tCBF_OnStep' does not name a type
- ok thats clear - on this point he does not know the definition that comes later -
but i also cant reorder this - because in the function i use the type tEncoder - and if i write this for the tEncoder definition he also cant find it..
i hope it is clear what iam trying to do -
is there a solution or iam just on the absolute wrong way with this concept?!
i just know a little about this 'callback function' and pointer and reference and co system.
if you know a good tutorial or example how to do such things i am ready to learn new things..
(iam coming from the computer and javascript world - and sometimes its hard to think in limited memory and co..)
sunny greetings stefan