diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 12943299..7fcb576e 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -158,7 +158,26 @@ static bool lcd_selfcheck_pulleys(int axis); #endif //TMC2130 static bool lcd_selfcheck_check_heater(bool _isbed); -static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay); +enum class testScreen +{ + extruderFan, + printFan, + fansOk, + endStops, + axisX, + axisY, + axisZ, + bed, + hotend, + hotendOk, + fsensor, + fsensorOk, + allCorrect, + failed, + home, +}; + +static int lcd_selftest_screen(testScreen screen, int _progress, int _progress_scale, bool _clear, int _delay); static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator); static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite); static bool lcd_selftest_fan_dialog(int _fan); @@ -6295,7 +6314,7 @@ bool lcd_selftest() delay(2000); KEEPALIVE_STATE(IN_HANDLER); - _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000); + _progress = lcd_selftest_screen(testScreen::extruderFan, _progress, 3, true, 2000); #if (defined(FANCHECK) && defined(TACH_0)) _result = lcd_selftest_fan_dialog(0); #else //defined(TACH_0) @@ -6310,7 +6329,7 @@ bool lcd_selftest() if (_result) { - _progress = lcd_selftest_screen(0, _progress, 3, true, 2000); + _progress = lcd_selftest_screen(testScreen::printFan, _progress, 3, true, 2000); #if (defined(FANCHECK) && defined(TACH_1)) _result = lcd_selftest_fan_dialog(1); #else //defined(TACH_1) @@ -6326,7 +6345,7 @@ bool lcd_selftest() if (_result) { - _progress = lcd_selftest_screen(1, _progress, 3, true, 2000); + _progress = lcd_selftest_screen(testScreen::fansOk, _progress, 3, true, 2000); #ifndef TMC2130 _result = lcd_selfcheck_endstops(); #else @@ -6337,7 +6356,7 @@ bool lcd_selftest() if (_result) { //current_position[Z_AXIS] += 15; //move Z axis higher to avoid false triggering of Z end stop in case that we are very low - just above heatbed - _progress = lcd_selftest_screen(3, _progress, 3, true, 2000); + _progress = lcd_selftest_screen(testScreen::axisX, _progress, 3, true, 2000); #ifdef TMC2130 _result = lcd_selfcheck_axis_sg(X_AXIS); #else @@ -6350,7 +6369,7 @@ bool lcd_selftest() if (_result) { - _progress = lcd_selftest_screen(3, _progress, 3, true, 0); + _progress = lcd_selftest_screen(testScreen::axisX, _progress, 3, true, 0); #ifndef TMC2130 _result = lcd_selfcheck_pulleys(X_AXIS); @@ -6360,7 +6379,7 @@ bool lcd_selftest() if (_result) { - _progress = lcd_selftest_screen(4, _progress, 3, true, 1500); + _progress = lcd_selftest_screen(testScreen::axisY, _progress, 3, true, 1500); #ifdef TMC2130 _result = lcd_selfcheck_axis_sg(Y_AXIS); #else @@ -6370,7 +6389,7 @@ bool lcd_selftest() if (_result) { - _progress = lcd_selftest_screen(4, _progress, 3, true, 0); + _progress = lcd_selftest_screen(testScreen::axisZ, _progress, 3, true, 0); #ifndef TMC2130 _result = lcd_selfcheck_pulleys(Y_AXIS); #endif // TMC2130 @@ -6391,7 +6410,7 @@ bool lcd_selftest() current_position[Z_AXIS] = current_position[Z_AXIS] + 10; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder); st_synchronize(); - _progress = lcd_selftest_screen(5, _progress, 3, true, 1500); + _progress = lcd_selftest_screen(testScreen::axisZ, _progress, 3, true, 1500); _result = lcd_selfcheck_axis(2, Z_MAX_POS); if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) { enquecommand_P(PSTR("G28 W")); @@ -6405,11 +6424,11 @@ bool lcd_selftest() current_position[Z_AXIS] = current_position[Z_AXIS] + 10; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder); st_synchronize(); - _progress = lcd_selftest_screen(13, 0, 2, true, 0); + _progress = lcd_selftest_screen(testScreen::home, 0, 2, true, 0); bool bres = tmc2130_home_calibrate(X_AXIS); - _progress = lcd_selftest_screen(13, 1, 2, true, 0); + _progress = lcd_selftest_screen(testScreen::home, 1, 2, true, 0); bres &= tmc2130_home_calibrate(Y_AXIS); - _progress = lcd_selftest_screen(13, 2, 2, true, 0); + _progress = lcd_selftest_screen(testScreen::home, 2, 2, true, 0); if (bres) eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1); _result = bres; @@ -6418,24 +6437,24 @@ bool lcd_selftest() if (_result) { - _progress = lcd_selftest_screen(6, _progress, 3, true, 2000); //check bed + _progress = lcd_selftest_screen(testScreen::bed, _progress, 3, true, 2000); _result = lcd_selfcheck_check_heater(true); } if (_result) { - _progress = lcd_selftest_screen(7, _progress, 3, true, 1000); //check nozzle + _progress = lcd_selftest_screen(testScreen::hotend, _progress, 3, true, 1000); _result = lcd_selfcheck_check_heater(false); } if (_result) { - _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //nozzle ok + _progress = lcd_selftest_screen(testScreen::hotendOk, _progress, 3, true, 2000); //nozzle ok } #ifdef FILAMENT_SENSOR if (_result) { - _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor + _progress = lcd_selftest_screen(testScreen::fsensor, _progress, 3, true, 2000); //check filaments sensor if (mmu_enabled) { _result = selftest_irsensor(); @@ -6446,17 +6465,17 @@ bool lcd_selftest() } if (_result) { - _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK + _progress = lcd_selftest_screen(testScreen::fsensorOk, _progress, 3, true, 2000); //fil sensor OK } #endif // FILAMENT_SENSOR if (_result) { - _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct + _progress = lcd_selftest_screen(testScreen::allCorrect, _progress, 3, true, 5000); //all correct } else { - _progress = lcd_selftest_screen(12, _progress, 3, true, 5000); + _progress = lcd_selftest_screen(testScreen::failed, _progress, 3, true, 5000); } lcd_reset_alert_level(); enquecommand_P(PSTR("M84")); @@ -6663,7 +6682,7 @@ static bool lcd_selfcheck_axis(int _axis, int _travel) } else { - _progress = lcd_selftest_screen(3 + _axis, _progress, 3, false, 0); + _progress = lcd_selftest_screen(static_cast(static_cast(testScreen::axisX) + _axis), _progress, 3, false, 0); _lcd_refresh = 0; } @@ -6830,7 +6849,7 @@ static bool lcd_selfcheck_check_heater(bool _isbed) manage_heater(); manage_inactivity(true); - _progress = (_isbed) ? lcd_selftest_screen(6, _progress, 2, false, 400) : lcd_selftest_screen(7, _progress, 2, false, 400); + _progress = (_isbed) ? lcd_selftest_screen(testScreen::bed, _progress, 2, false, 400) : lcd_selftest_screen(testScreen::hotend, _progress, 2, false, 400); /*if (_isbed) { MYSERIAL.print("Bed temp:"); MYSERIAL.println(degBed()); @@ -7040,16 +7059,16 @@ static bool selftest_irsensor() TempBackup tempBackup; setTargetHotend(ABS_PREHEAT_HOTEND_TEMP,active_extruder); mmu_wait_for_heater_blocking(); - progress = lcd_selftest_screen(9, 0, 1, true, 0); + progress = lcd_selftest_screen(testScreen::fsensor, 0, 1, true, 0); mmu_filament_ramming(); } - progress = lcd_selftest_screen(9, progress, 1, true, 0); + progress = lcd_selftest_screen(testScreen::fsensor, progress, 1, true, 0); mmu_command(MMU_CMD_U0); manage_response(false, false); for(uint_least8_t i = 0; i < 200; ++i) { - if (0 == (i % 32)) progress = lcd_selftest_screen(9, progress, 1, true, 0); + if (0 == (i % 32)) progress = lcd_selftest_screen(testScreen::fsensor, progress, 1, true, 0); mmu_load_step(false); while (blocks_queued()) @@ -7227,12 +7246,11 @@ static bool lcd_selftest_fan_dialog(int _fan) return _result; } -static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay) +static int lcd_selftest_screen(testScreen screen, int _progress, int _progress_scale, bool _clear, int _delay) { lcd_update_enable(false); - int _step_block = 0; const char *_indicator = (_progress >= _progress_scale) ? "-" : "|"; if (_clear) lcd_clear(); @@ -7240,58 +7258,58 @@ static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bo lcd_set_cursor(0, 0); - if (_step == -1) lcd_puts_P(_T(MSG_SELFTEST_FAN)); - if (_step == 0) lcd_puts_P(_T(MSG_SELFTEST_FAN)); - if (_step == 1) lcd_puts_P(_T(MSG_SELFTEST_FAN)); - if (_step == 2) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20 r=0 - if (_step == 3) lcd_puts_P(_i("Checking X axis "));////MSG_SELFTEST_CHECK_X c=20 r=0 - if (_step == 4) lcd_puts_P(_i("Checking Y axis "));////MSG_SELFTEST_CHECK_Y c=20 r=0 - if (_step == 5) lcd_puts_P(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20 r=0 - if (_step == 6) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED)); - if (_step == 7 - || _step == 8) lcd_puts_P(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20 r=0 - if (_step == 9) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR)); - if (_step == 10) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR)); - if (_step == 11) lcd_puts_P(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20 r=0 - if (_step == 12) lcd_puts_P(_T(MSG_SELFTEST_FAILED)); - if (_step == 13) lcd_puts_P(PSTR("Calibrating home")); + if (screen == testScreen::extruderFan) lcd_puts_P(_T(MSG_SELFTEST_FAN)); + if (screen == testScreen::printFan) lcd_puts_P(_T(MSG_SELFTEST_FAN)); + if (screen == testScreen::fansOk) lcd_puts_P(_T(MSG_SELFTEST_FAN)); + if (screen == testScreen::endStops) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20 r=0 + if (screen == testScreen::axisX) lcd_puts_P(_i("Checking X axis "));////MSG_SELFTEST_CHECK_X c=20 r=0 + if (screen == testScreen::axisY) lcd_puts_P(_i("Checking Y axis "));////MSG_SELFTEST_CHECK_Y c=20 r=0 + if (screen == testScreen::axisZ) lcd_puts_P(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20 r=0 + if (screen == testScreen::bed) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED)); + if (screen == testScreen::hotend + || screen == testScreen::hotendOk) lcd_puts_P(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20 r=0 + if (screen == testScreen::fsensor) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR)); + if (screen == testScreen::fsensorOk) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR)); + if (screen == testScreen::allCorrect) lcd_puts_P(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20 r=0 + if (screen == testScreen::failed) lcd_puts_P(_T(MSG_SELFTEST_FAILED)); + if (screen == testScreen::home) lcd_puts_P(_i("Calibrating home"));////c=20 r=1 lcd_set_cursor(0, 1); lcd_puts_P(separator); - if ((_step >= -1) && (_step <= 1)) + if ((screen >= testScreen::extruderFan) && (screen <= testScreen::fansOk)) { //SERIAL_ECHOLNPGM("Fan test"); lcd_puts_at_P(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18 r=0 lcd_set_cursor(18, 2); - (_step < 0) ? lcd_print(_indicator) : lcd_print("OK"); + (screen < testScreen::printFan) ? lcd_print(_indicator) : lcd_print("OK"); lcd_puts_at_P(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18 r=0 lcd_set_cursor(18, 3); - (_step < 1) ? lcd_print(_indicator) : lcd_print("OK"); + (screen < testScreen::fansOk) ? lcd_print(_indicator) : lcd_print("OK"); } - else if (_step >= 9 && _step <= 10) + else if (screen >= testScreen::fsensor && screen <= testScreen::fsensorOk) { lcd_puts_at_P(0, 2, _i("Filament sensor:"));////MSG_SELFTEST_FILAMENT_SENSOR c=18 r=0 lcd_set_cursor(18, 2); - (_step == 9) ? lcd_print(_indicator) : lcd_print("OK"); + (screen == testScreen::fsensor) ? lcd_print(_indicator) : lcd_print("OK"); } - else if (_step < 9) + else if (screen < testScreen::fsensor) { //SERIAL_ECHOLNPGM("Other tests"); - _step_block = 3; - lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator); + testScreen _step_block = testScreen::axisX; + lcd_selftest_screen_step(2, 2, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), "X", _indicator); - _step_block = 4; - lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator); + _step_block = testScreen::axisY; + lcd_selftest_screen_step(2, 8, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), "Y", _indicator); - _step_block = 5; - lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator); + _step_block = testScreen::axisZ; + lcd_selftest_screen_step(2, 14, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), "Z", _indicator); - _step_block = 6; - lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator); + _step_block = testScreen::bed; + lcd_selftest_screen_step(3, 0, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), "Bed", _indicator); - _step_block = 7; - lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator); + _step_block = testScreen::hotend; + lcd_selftest_screen_step(3, 9, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), "Hotend", _indicator); } if (_delay > 0) delay_keep_alive(_delay);