I have a need to return a pointer for a unknown data type.
This example code shows a global data structure with values, a helper routine to retrieve the values and a menu display routine
that calls the helper routine to fill in the fields of the menu. the data type is know by the field.
this is the field definition:
[%03D1] : the square brackets identify the field.
the % marks a variable
the 0 means zero left fill.
the 3 is field width
the D marks it as a decimal field
the 1 is field number 1 for helper routines.
typedef struct {
int a;
char st[80];
uint8_t d,e;
} CFGS;
CFGS cfg;
Pointer data_handler( int field_id){ // the compiler dies complaining about unknown named type (Pointer) I substitute void *
// but the results are not what I expect
switch(field_id) {
case 1: return &cfg.a;
break;
case 2: return &cfg.st;
break;
case 3: return &cfg.d;
break;
case 4: return &cfg.e;
break;
default : ;
}
void setup(){
int i;
do{
i = disp_menu("menu text [%03D1] name [%8A2]",data_handler);
}while(I!=0);
}
// example data structures, that support the menu fields
union FLDbits {
struct {
unsigned char SPACEFill : 1;
unsigned char ZEROFill : 1;
unsigned char : 6;};
unsigned char value;
};
typedef struct {
int fieldid;
int fieldtype;
int location;
FLDbits f_opts;
} FLDS;
FLDS flds[10];
// the actual routine that needs the untyped pointer function.
int disp_menu(const char st[],Pointer (*dh)(int)){
// create menu structure ... missing code
for(int i=0;i<fldcount;i++){
switch(flds[i].fieldtype){
case 1: int * i = dh(flds[i].fieldid);
// fill in field with integer value
break;
case 2: char * ch[] = dh(flds[i].fieldid);
// fill in field with character value
break;
// the rest of the code
Does anyone understand what I am asking? I am new to the Arduino, I mainly use Delphi. C++ throws me. and the Restrictions of Arduino confuse me even more.
Chuck Todd