Apply loop shorthand macros (#17159)

This commit is contained in:
Scott Lahteine
2020-03-13 23:18:16 -05:00
committed by GitHub
parent a96be32fae
commit 118bd2f8b2
93 changed files with 465 additions and 505 deletions

View File

@ -140,13 +140,13 @@ void BrickoutGame::game_screen() {
// Draw bricks
if (PAGE_CONTAINS(BRICK_TOP, BRICK_BOT)) {
for (uint8_t y = 0; y < BRICK_ROWS; ++y) {
LOOP_L_N(y, BRICK_ROWS) {
const uint8_t yy = y * BRICK_H + BRICK_TOP;
if (PAGE_CONTAINS(yy, yy + BRICK_H - 1)) {
for (uint8_t x = 0; x < BRICK_COLS; ++x) {
LOOP_L_N(x, BRICK_COLS) {
if (TEST(bdat.bricks[y], x)) {
const uint8_t xx = x * BRICK_W;
for (uint8_t v = 0; v < BRICK_H - 1; ++v)
LOOP_L_N(v, BRICK_H - 1)
if (PAGE_CONTAINS(yy + v, yy + v))
u8g.drawHLine(xx, yy + v, BRICK_W - 1);
}

View File

@ -170,7 +170,7 @@ inline void update_invader_data() {
uint8_t m = idat.bugs[y];
if (m) idat.botmost = y + 1;
inv_mask |= m;
for (uint8_t x = 0; x < INVADER_COLS; ++x)
LOOP_L_N(x, INVADER_COLS)
if (TEST(m, x)) idat.shooters[sc++] = (y << 4) | x;
}
idat.leftmost = 0;
@ -371,11 +371,11 @@ void InvadersGame::game_screen() {
// Draw invaders
if (PAGE_CONTAINS(idat.pos.y, idat.pos.y + idat.botmost * (INVADER_ROW_H) - 2 - 1)) {
int8_t yy = idat.pos.y;
for (uint8_t y = 0; y < INVADER_ROWS; ++y) {
LOOP_L_N(y, INVADER_ROWS) {
const uint8_t type = inv_type[y];
if (PAGE_CONTAINS(yy, yy + INVADER_H - 1)) {
int8_t xx = idat.pos.x;
for (uint8_t x = 0; x < INVADER_COLS; ++x) {
LOOP_L_N(x, INVADER_COLS) {
if (TEST(idat.bugs[y], x))
u8g.drawBitmapP(xx, yy, 2, INVADER_H, invader[type][idat.game_blink]);
xx += INVADER_COL_W;

View File

@ -83,7 +83,7 @@ void MazeGame::game_screen() {
if (PAGE_UNDER(HEADER_H)) lcd_put_int(0, HEADER_H - 1, score);
// Draw the maze
// for (uint8_t n = 0; n < head_ind; ++n) {
// LOOP_L_N(n, head_ind) {
// const pos_t &p = maze_walls[n], &q = maze_walls[n + 1];
// if (p.x == q.x) {
// const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));

View File

@ -84,14 +84,14 @@ void shorten_tail() {
}
if (shift) {
sdat.head_ind--;
for (uint8_t i = 0; i <= sdat.head_ind; ++i)
LOOP_LE_N(i, sdat.head_ind)
sdat.snake_tail[i] = sdat.snake_tail[i + 1];
}
}
// The food is on a line
inline bool food_on_line() {
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
if ((sdat.foodx == p.x - 1 || sdat.foodx == p.x) && WITHIN(sdat.foody, _MIN(p.y, q.y), _MAX(p.y, q.y)))
@ -151,7 +151,7 @@ bool snake_overlap() {
// VERTICAL head segment?
if (h1.x == h2.x) {
// Loop from oldest to segment two away from head
for (uint8_t n = 0; n < sdat.head_ind - 2; ++n) {
LOOP_L_N(n, sdat.head_ind - 2) {
// Segment p to q
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x != q.x) {
@ -163,7 +163,7 @@ bool snake_overlap() {
}
else {
// Loop from oldest to segment two away from head
for (uint8_t n = 0; n < sdat.head_ind - 2; ++n) {
LOOP_L_N(n, sdat.head_ind - 2) {
// Segment p to q
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.y != q.y) {
@ -240,7 +240,7 @@ void SnakeGame::game_screen() {
#if SNAKE_WH < 2
// At this scale just draw a line
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));
@ -256,7 +256,7 @@ void SnakeGame::game_screen() {
#elif SNAKE_WH == 2
// At this scale draw two lines
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));
@ -275,7 +275,7 @@ void SnakeGame::game_screen() {
#else
// Draw a series of boxes
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
const int8_t y1 = _MIN(p.y, q.y), y2 = _MAX(p.y, q.y);

View File

@ -114,7 +114,7 @@ void menu_cancelobject();
#if EXTRUDERS == 1
EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
#elif EXTRUDERS > 1
for (uint8_t n = 0; n < EXTRUDERS; n++)
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
#endif
#endif
@ -125,7 +125,7 @@ void menu_cancelobject();
if (parser.volumetric_enabled) {
EDIT_ITEM_FAST(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#if EXTRUDERS > 1
for (uint8_t n = 0; n < EXTRUDERS; n++)
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_FAST_N(float43, n, MSG_FILAMENT_DIAM_E, &planner.filament_size[n], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#endif
}
@ -142,13 +142,13 @@ void menu_cancelobject();
EDIT_ITEM_FAST(float3, MSG_FILAMENT_UNLOAD, &fc_settings[active_extruder].unload_length, 0, extrude_maxlength);
#if EXTRUDERS > 1
for (uint8_t n = 0; n < EXTRUDERS; n++)
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_FAST_N(float3, n, MSG_FILAMENTUNLOAD_E, &fc_settings[n].unload_length, 0, extrude_maxlength);
#endif
EDIT_ITEM_FAST(float3, MSG_FILAMENT_LOAD, &fc_settings[active_extruder].load_length, 0, extrude_maxlength);
#if EXTRUDERS > 1
for (uint8_t n = 0; n < EXTRUDERS; n++)
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_FAST_N(float3, n, MSG_FILAMENTLOAD_E, &fc_settings[n].load_length, 0, extrude_maxlength);
#endif
#endif
@ -358,7 +358,7 @@ void menu_cancelobject();
EDIT_ITEM_FAST(float3, MSG_VMAX_E, &planner.settings.max_feedrate_mm_s[E_AXIS_N(active_extruder)], 1, max_fr_edit_scaled.e);
#endif
#if ENABLED(DISTINCT_E_FACTORS)
for (uint8_t n = 0; n < E_STEPPERS; n++)
LOOP_L_N(n, E_STEPPERS)
EDIT_ITEM_FAST_N(float3, n, MSG_VMAX_EN, &planner.settings.max_feedrate_mm_s[E_AXIS_N(n)], 1, max_fr_edit_scaled.e);
#endif
@ -409,7 +409,7 @@ void menu_cancelobject();
#if ENABLED(DISTINCT_E_FACTORS)
EDIT_ITEM_FAST(long5_25, MSG_AMAX_E, &planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(active_extruder)], 100, max_accel_edit_scaled.e, []{ planner.reset_acceleration_rates(); });
for (uint8_t n = 0; n < E_STEPPERS; n++)
LOOP_L_N(n, E_STEPPERS)
EDIT_ITEM_FAST_N(long5_25, n, MSG_AMAX_EN, &planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(n)], 100, max_accel_edit_scaled.e, []{ _reset_e_acceleration_rate(MenuItemBase::itemIndex); });
#elif E_STEPPERS
EDIT_ITEM_FAST(long5_25, MSG_AMAX_E, &planner.settings.max_acceleration_mm_per_s2[E_AXIS], 100, max_accel_edit_scaled.e, []{ planner.reset_acceleration_rates(); });
@ -484,7 +484,7 @@ void menu_advanced_steps_per_mm() {
#if ENABLED(DISTINCT_E_FACTORS)
EDIT_ITEM_FAST(float51, MSG_E_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(active_extruder)], 5, 9999, []{ planner.refresh_positioning(); });
for (uint8_t n = 0; n < E_STEPPERS; n++)
LOOP_L_N(n, E_STEPPERS)
EDIT_ITEM_FAST_N(float51, n, MSG_EN_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(n)], 5, 9999, []{ _planner_refresh_e_positioning(MenuItemBase::itemIndex); });
#elif E_STEPPERS
EDIT_ITEM_FAST(float51, MSG_E_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS], 5, 9999, []{ planner.refresh_positioning(); });
@ -558,7 +558,7 @@ void menu_advanced_settings() {
#if EXTRUDERS == 1
EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
#elif EXTRUDERS > 1
for (uint8_t n = 0; n < E_STEPPERS; n++)
LOOP_L_N(n, E_STEPPERS)
EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
#endif
#endif

View File

@ -114,7 +114,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
GCODES_ITEM_P(msg, PSTR("M600 B0"));
#else
PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE_E);
for (uint8_t s = 0; s < E_STEPPERS; s++) {
LOOP_L_N(s, E_STEPPERS) {
if (thermalManager.targetTooColdToExtrude(s))
SUBMENU_N_P(s, msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, MenuItemBase::itemIndex); });
else {
@ -138,7 +138,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
GCODES_ITEM_P(msg_load, PSTR("M701"));
#else
PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD_E);
for (uint8_t s = 0; s < E_STEPPERS; s++) {
LOOP_L_N(s, E_STEPPERS) {
if (thermalManager.targetTooColdToExtrude(s))
SUBMENU_N_P(s, msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, MenuItemBase::itemIndex); });
else {
@ -162,7 +162,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
#if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
{
bool too_cold = false;
for (uint8_t s = 0; s < E_STEPPERS; s++) {
LOOP_L_N(s, E_STEPPERS) {
if (thermalManager.targetTooColdToExtrude(s)) {
too_cold = true; break;
}
@ -174,7 +174,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
}
#endif
PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD_E);
for (uint8_t s = 0; s < E_STEPPERS; s++) {
LOOP_L_N(s, E_STEPPERS) {
if (thermalManager.targetTooColdToExtrude(s))
SUBMENU_N_P(s, msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, MenuItemBase::itemIndex); });
else {

View File

@ -181,7 +181,7 @@ void lcd_mixer_mix_edit() {
#if CHANNEL_MIX_EDITING
for (uint8_t n = 1; n <= MIXING_STEPPERS; n++)
LOOP_S_LE_N(n, 1, MIXING_STEPPERS)
EDIT_ITEM_FAST_N(float52, n, MSG_MIX_COMPONENT_N, &mixer.collector[n-1], 0, 10);
ACTION_ITEM(MSG_CYCLE_MIX, _lcd_mixer_cycle_mix);

View File

@ -54,7 +54,7 @@ void _mmu2_load_filament(uint8_t index) {
ui.reset_status();
}
void action_mmu2_load_all() {
for (uint8_t i = 0; i < EXTRUDERS; i++)
LOOP_L_N(i, EXTRUDERS)
_mmu2_load_filament(i);
ui.return_to_status();
}

View File

@ -357,7 +357,7 @@ void menu_move() {
#elif E_MANUAL > 1
// Independent extruders with one E-stepper per hotend
for (uint8_t n = 0; n < E_MANUAL; n++) SUBMENU_MOVE_E(n);
LOOP_L_N(n, E_MANUAL) SUBMENU_MOVE_E(n);
#endif

View File

@ -111,7 +111,7 @@ void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb
#if HAS_HEATED_BED
_PREHEAT_ITEMS(1,0);
#endif
for (uint8_t n = 1; n < HOTENDS; n++) PREHEAT_ITEMS(1,n);
LOOP_S_L_N(n, 1, HOTENDS) PREHEAT_ITEMS(1,n);
ACTION_ITEM(MSG_PREHEAT_1_ALL, []() {
#if HAS_HEATED_BED
_preheat_bed(0);
@ -139,7 +139,7 @@ void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb
#if HAS_HEATED_BED
_PREHEAT_ITEMS(2,0);
#endif
for (uint8_t n = 1; n < HOTENDS; n++) PREHEAT_ITEMS(2,n);
LOOP_S_L_N(n, 1, HOTENDS) PREHEAT_ITEMS(2,n);
ACTION_ITEM(MSG_PREHEAT_2_ALL, []() {
#if HAS_HEATED_BED
_preheat_bed(1);

View File

@ -222,7 +222,7 @@ void menu_tune() {
EDIT_ITEM(int3, MSG_FLOW, &planner.flow_percentage[active_extruder], 10, 999, []{ planner.refresh_e_factor(active_extruder); });
// Flow En:
#if EXTRUDERS > 1
for (uint8_t n = 0; n < EXTRUDERS; n++)
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_N(int3, n, MSG_FLOW_N, &planner.flow_percentage[n], 10, 999, []{ planner.refresh_e_factor(MenuItemBase::itemIndex); });
#endif
#endif
@ -234,7 +234,7 @@ void menu_tune() {
#if EXTRUDERS == 1
EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
#elif EXTRUDERS > 1
for (uint8_t n = 0; n < EXTRUDERS; n++)
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
#endif
#endif