For an Arduino LED animation project I have been working on an editor tool using HTML and javascript. After setting up various things, the tool enables generating C++ code to paste into an Arduino sketch.
It's all been working fine, the generated code compiles and runs on the board but there is an annoying 'auto-formatting' quirk in the Arduino IDE.
The code generator outputs a block of code like this:
const Scene scene_library[] PROGMEM = {
{ 7, 1, 40, 5, 320, 0xFF,
{ { 0, ANIM_ROW_CHASE, 1, 3, 0, 0, 0, 0 },
{ 1, ANIM_ROW_CHASE, 2, 3, 0, 0, 0, 0 },
{ 2, ANIM_ROW_CHASE, 3, 3, 0, 0, 0, 0 },
{ 3, ANIM_ROW_CHASE, 4, 3, 0, 0, 0, 0 },
{ 4, ANIM_ROW_CHASE, 5, 3, 0, 0, 0, 0 },
{ 5, ANIM_ROW_CHASE, 6, 3, 0, 0, 0, 0 },
{ 6, ANIM_ROW_CHASE, 7, 3, 0, 0, 0, 0 } }, 7 }
};
But if I use the 'auto-formatting' feature (cmd-T on MacOS) it unwraps the data and puts it on a single line. It still compiles and runs but it means the page scrolls horizontally a ridiculous amount.
What causes this and what I can do this fix it?
const Scene scene_library[] PROGMEM = {
{ 7, 1, 40, 5, 320, 0xFF, { { 0, ANIM_ROW_CHASE, 1, 3, 0, 0, 0, 0 }, { 1, ANIM_ROW_CHASE, 2, 3, 0, 0, 0, 0 }, { 2, ANIM_ROW_CHASE, 3, 3, 0, 0, 0, 0 }, { 3, ANIM_ROW_CHASE, 4, 3, 0, 0, 0, 0 }, { 4, ANIM_ROW_CHASE, 5, 3, 0, 0, 0, 0 }, { 5, ANIM_ROW_CHASE, 6, 3, 0, 0, 0, 0 }, { 6, ANIM_ROW_CHASE, 7, 3, 0, 0, 0, 0 } }, 7 }
};
I generate other data blocks which format fine:
const AnimConfig ambient_configs[] PROGMEM = {
{ 7, ANIM_STATIC_ROW, 0, 40, 0, 0, 255, 0 },
{ 7, ANIM_STATIC_ROW, 0, 25, 0, 0, 255, 0 },
{ 7, ANIM_STATIC_ROW, 0, 15, 0, 0, 255, 0 },
{ 7, ANIM_STATIC_ROW, 0, 8, 0, 0, 255, 0 },
{ 7, ANIM_STATIC_ROW, 0, 5, 8, 0, 255, 0 }
};