Honestly @tehn, you must have the patience of a saint to have written all the USB saving and loading code. It has driven me completely round the bend. Anyway...
I think I've gotten it very stable, but I'm not going to make any of the UI enhancements that have been suggested for the sake of my sanity and in case I chuck something out the window (it's a long drop from the top of my house).
Instead I present some thoughts and ideas for the poor soul that comes after me.
At the moment the entire functionality is contained in one function that is about 370 lines long. The main task will be to break this down, in particular you'll want to separate the serialisation parts of the code from the disk handling parts of the code.
I would suggest moving the serialisation code over to the
src directory so that you can test it without having to use the module (being tied to the module constantly is what I find hardest...).
Perhaps 2 public functions like this (naturally, each would use many more private functions):
void tele_serialise(scene_state_t *src, char (*dest)[FIXED_SIZE]);
void tele_deserialise(char (*src)[FIXED_SIZE], scene_state_t *dest);
(Given that we know the maximum size of the resulting text file, it would be better to use statically allocated arrays instead of
malloc IMO, but hey if you're writing the code then you choose how you want to do it...)
Then we can leave the nasty file system code in
module but hopefully without all the serialisation code in the way it will be easier to grok.