Structures of Strutcures and Arrays

Hi All.
I am writing for an ESP32 so I have a bit of memory I can work with. My project is a servo controller/playback system.

typedef struct {
  int board;
  int servo[16];
} ServoLine;

typedef struct {
   char Name[16];
   int sMin;
   int sMax;
   int sDef;
   int sCurr;

} ServoEnt;

typedef struct {
  int Board;
  ServoEnt xElem[16];

} xBoard;


The first structure is for the Servo Controller board.. 4 with 16 servo's on each
The second structure is the details about each servo.. readable name, and capabilities

The third structure xBoard is the issue - as the display will handle paging between each - I need an easy way to have a structure that defines a board - and the full details of all of the servo's on that board.

And the pre-compiler does not like xBoard... It comes up with

Invalid preprocessing directive clang(pp_invalid_directive)

There are no dynamically adjustable arrays etc. Can anyone suggest how to code this.

Many thanks
Dave

Can you post the code that fails? If I paste those defines into a minimal Uno sketch and declare an array of xBoard it compiles without issue.

Your structs are not declared as types but as variables:

struct TYPE_NAME {
  STRUCT_MEMBERS
} VARIABLE_NAME;

You need a/the type name to declare arrays of the struct.

That is what 'typedef' does

typedef struct {
  STRUCT_MEMBERS
} TYPE_NAME;

The code is correct. There are no preprocessor directives in the three structures so it is impossible to say where the error comes from.

What are the 16 'int's in the ServoLine struct? Can you move each of those into the corresponding ServoEnt struct? Then the xBoard struct could take over the duty off the ServoLine struct.

Many thanks for your help

Hi.
The Servo Controller board uses 16 channels, as so for storage and manipulation on an SD card it is easier to have a line of servo positions, and the board that the servo's are attached to.
Technically I can address 62 of these boards and thus 992 individual servo's. Not planning to go that high but it does offer expansion.

I'll be storing the data in a file in the format of the structure ServoLine and so reading it in and writing it out will be easier working in this format.

Many thanks
Dave

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.