Hi im trying to make a function that returns a function pointer. ´
It would work like this, when the first function is called from my main loop, the next function it calls will be the second function.
It will remind a little bit about a state pattern, with the states changing inside the functions, and the main loop not knowing what state it is.
It looks like this:
Code:
typedef void * (*fptr)(char *, char *, signed char );
void *InitCalibration(char * upperLcdTxt, char *lowerLcdTxt, signed char Button);
void *Step2Calibration(char * upperLcdTxt, char *lowerLcdTxt, signed char Button);
void *Step2Calibration(char * upperLcdTxt, char *lowerLcdTxt, signed char Button)
{
fptr fp = InitCalibration;
char* temp = "Calibrationsmode";
char* temp2 = "Press CAL 90 KG" ;
strcpy(upperLcdTxt, temp);
strcpy(lowerLcdTxt, temp2);
return &fp;
}
void *InitCalibration(char * upperLcdTxt, char *lowerLcdTxt, signed char Button)
{
fptr fp = Step2Calibration;
char* temp = "Calibrationsmode";
char* temp2 = "Press CAL 0 KG" ;
strcpy(upperLcdTxt, temp);
strcpy(lowerLcdTxt, temp2);
return &fp;
}
Then i would attempt to cast the return value to the right function pointer from my main.
main looks like this:
Code:
fptr fp = &InitCalibration;
while (1)
{
delay_ms(2000);
keyBoardVal = keyboard();
fp = (fptr) fp(convert, convert2, keyBoardVal);
};
so every time fp function pointer calls a function its a different one, but it doesnt work, what could be wrong.
The adress changing in the main loop doesnt work, fp points nowhere, and i might have misunderstood all this function pointer stuff, so please help me correct my errors