Hi. I have an ESP32 project that contains a complex data structure.
The root of the data is a vector array of structures, each of which contain two other vector array of stuctures, each of which….the same.
The length of each part is undefined, as the array length can change, as well as there being String vars which can be different lengths.
At the moment the data is just created by initialisation, but I want the data to be user editable, so I now want to save this data using SPIFFS, read, display, edit and write back.
With the data length being unknown, what is the best method to load and save all this in a byte-wise system? Do I need my own method to store the sizes on write to know the same on read?
Many thanks.
Jim
Here is part of the data structure:
enum modes{alloff, solid, grad, fx};
enum actions{prSolid, prGrad, prFX, BPM, cuRGB, cuHSV, cuGrad, play, stop};
typedef struct
{
uint8_t hue;
uint8_t sat;
uint8_t val;
} CHSV;
typedef struct
{
uint8_t red;
uint8_t green;
uint8_t blue;
} CRGB;
typedef struct
{
uint hueCount;
CHSV hsv1, hsv2, hsv3, hsv4;
uint percentSize; // 0 for graduated fill, or number of LEDs per step.
byte direction;
} hsvGrad;
struct action {
String name; // Action Name (not used)
uint8_t type; // all off, solid, grad, fx or BPM
uint8_t presetIdx; // index into slid/grad/fx array
uint8_t group; // group to apply action to
uint8_t BPM; // BPM for the action (0 leaves tempo unchanged)
bool isPlaying; // is the action playing or static
unsigned long delay; // delay (mS) until the next action is triggered
bool loop; // if true, on the last action will loop back to the first action
CHSV cHSV;
CRGB cRGB;
hsvGrad cGrad; // custom Grad
};
struct songPart {
String name;
vector<action> actions;
};
struct song {
String name;
vector<songPart> parts;
vector<songPart> breaks;
};
songPart actionPartOrBreak;
/* All actions for songs go here */
vector<song> songs
{
{"Song 1",
{
songPart{"Intro",
{
/* Type mS cHSV cRGB cGrad */
action{"Start a", cuRGB,0,all,0,false,2000,false, {0,0,0}, {127,0,255}, 2,{0,255,255},{0,255,255},{0,255,255},{0,255,255},0,FWD},
action{"Start b", cuHSV,0,all,0,false,2000,false, {110,255,255}, {0,0,0}, 2,{0,255,255},{0,255,255},{0,255,255},{0,255,255},0,FWD},
action{"Start c",cuGrad,0,all,0,true, 2000,false, {0,0,0}, {0,0,0}, 2,{192,255,255},{224,255,255},{0,255,255},{0,255,255},0,FWD},
action{"Start d",cuGrad,0,all,0,true, 2000,false, {0,0,0}, {0,0,0}, 2,{192,255,255},{224,255,255},{0,255,255},{0,255,255},50,BNC}
}
},
songPart{"Part 1",
{
action{"Action 1",prSolid,1,all,0,false,1000,false, {0,0,0}, {0,0,0}, 2,{0,255,255},{0,255,255},{0,255,255},{0,255,255},0,FWD}
}
},
songPart{"Part 2",
{
action{"Action 1",prSolid,2,all,0,false,1000,false, {0,0,0}, {0,0,0}, 2,{0,255,255},{0,255,255},{0,255,255},{0,255,255},0,FWD}
}
}
},
{
songPart{"High Low",
{
action{"Action 1",prGrad,0,all,0,true,2000,false, {0,0,0}, {0,0,0}, 2,{0,255,255},{0,255,255},{0,255,255},{0,255,255},0,FWD}
}
},
songPart{"Volume Break",
{
action{"Action 1",prGrad,1,all,0,false,1000,false, {0,0,0}, {0,0,0}, 2,{0,255,255},{0,255,255},{0,255,255},{0,255,255},0,FWD}
}
},
songPart{"Stop 1 Bar",
{
action{"Action 1",prSolid,4,all,0,false,1000,false, {0,0,0}, {0,0,0}, 2,{0,255,255},{0,255,255},{0,255,255},{0,255,255},0,FWD}
}
},
songPart{"Stop -Tams",
{
action{"Action 1",prSolid,0,all,0,false,50,true, {0,0,0}, {0,0,0}, 2,{0,255,255},{0,255,255},{0,255,255},{0,255,255},0,FWD}, //All blue
action{"Action 1",prGrad,4,tams,0,true,1000,false, {0,0,0}, {0,0,0}, 2,{0,255,255},{0,255,255},{0,255,255},{0,255,255},0,FWD} //Tams CMY
}
},
songPart{"Shoulder",
{
action{"Action 1",prGrad,4,all,0,false,250,false, {0,0,0}, {0,0,0}, 2,{0,255,255},{0,255,255},{0,255,255},{0,255,255},0,FWD},
}
}
}
},