Save 20b in smart_fill_mesh with PROGMEM

This commit is contained in:
Scott Lahteine 2017-06-06 07:18:46 -05:00
parent b7dc4d9973
commit 6bb05c4543

View file

@ -1593,24 +1593,33 @@
typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info; typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info;
void unified_bed_leveling::smart_fill_mesh() { void unified_bed_leveling::smart_fill_mesh() {
const smart_fill_info info[] = { static const smart_fill_info
{ 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false }, // Bottom of the mesh looking up info0 PROGMEM = { 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false }, // Bottom of the mesh looking up
{ 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false }, // Top of the mesh looking down info1 PROGMEM = { 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false }, // Top of the mesh looking down
{ 0, GRID_MAX_POINTS_X - 2, 0, GRID_MAX_POINTS_Y, true }, // Left side of the mesh looking right info2 PROGMEM = { 0, GRID_MAX_POINTS_X - 2, 0, GRID_MAX_POINTS_Y, true }, // Left side of the mesh looking right
{ GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true } // Right side of the mesh looking left info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true }; // Right side of the mesh looking left
}; static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
// static const smart_fill_info info[] PROGMEM = {
// { 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false } PROGMEM, // Bottom of the mesh looking up
// { 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false } PROGMEM, // Top of the mesh looking down
// { 0, GRID_MAX_POINTS_X - 2, 0, GRID_MAX_POINTS_Y, true } PROGMEM, // Left side of the mesh looking right
// { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true } PROGMEM // Right side of the mesh looking left
// };
for (uint8_t i = 0; i < COUNT(info); ++i) { for (uint8_t i = 0; i < COUNT(info); ++i) {
const smart_fill_info &f = info[i]; const smart_fill_info *f = (smart_fill_info*)pgm_read_word(&info[i]);
if (f.yfirst) { const int8_t sx = pgm_read_word(&f->sx), sy = pgm_read_word(&f->sy),
const int8_t dir = f.ex > f.sx ? 1 : -1; ex = pgm_read_word(&f->ex), ey = pgm_read_word(&f->ey);
for (uint8_t y = f.sy; y != f.ey; ++y) if (pgm_read_byte(&f->yfirst)) {
for (uint8_t x = f.sx; x != f.ex; x += dir) const int8_t dir = ex > sx ? 1 : -1;
for (uint8_t y = sy; y != ey; ++y)
for (uint8_t x = sx; x != ex; x += dir)
if (smart_fill_one(x, y, dir, 0)) break; if (smart_fill_one(x, y, dir, 0)) break;
} }
else { else {
const int8_t dir = f.ey > f.sy ? 1 : -1; const int8_t dir = ey > sy ? 1 : -1;
for (uint8_t x = f.sx; x != f.ex; ++x) for (uint8_t x = sx; x != ex; ++x)
for (uint8_t y = f.sy; y != f.ey; y += dir) for (uint8_t y = sy; y != ey; y += dir)
if (smart_fill_one(x, y, 0, dir)) break; if (smart_fill_one(x, y, 0, dir)) break;
} }
} }