From 6c28ed6349692f4b35ea358ff7253ef13a621da4 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 21 Mar 2019 22:48:57 +0100 Subject: [PATCH 1/9] Convert lcd_selftest_error() first parameter to enum class. --- Firmware/ultralcd.cpp | 68 ++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index bee46ca2..79f56b70 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -165,7 +165,7 @@ static bool lcd_selfcheck_pulleys(int axis); #endif //TMC2130 static bool lcd_selfcheck_check_heater(bool _isbed); -enum class testScreen +enum class testScreen : uint_least8_t { extruderFan, printFan, @@ -184,6 +184,22 @@ enum class testScreen home, }; +enum class TestError : uint_least8_t +{ + unused, + heater, + bed, + endstops, + motor, + endstop, + printFan, + extruderFan, + pulley, + axis, + swappedFan, + wiringFsensor, +}; + 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); @@ -194,7 +210,7 @@ static bool lcd_selftest_fan_dialog(int _fan); static bool lcd_selftest_fsensor(); #endif //PAT9125 static bool selftest_irsensor(); -static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2); +static void lcd_selftest_error(TestError error, const char *_error_1, const char *_error_2); static void lcd_colorprint_change(); #ifdef SNMM static int get_ext_nr(); @@ -7184,7 +7200,7 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) { if (axis == Y_AXIS) _error_1 = "Y"; if (axis == Z_AXIS) _error_1 = "Z"; - lcd_selftest_error(9, _error_1, NULL); + lcd_selftest_error(TestError::axis, _error_1, NULL); current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); reset_crash_det(axis); @@ -7202,7 +7218,7 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) { if (axis == Y_AXIS) _error_1 = "Y"; if (axis == Z_AXIS) _error_1 = "Z"; - lcd_selftest_error(8, _error_1, NULL); + lcd_selftest_error(TestError::pulley, _error_1, NULL); current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); reset_crash_det(axis); @@ -7309,11 +7325,11 @@ static bool lcd_selfcheck_axis(int _axis, int _travel) if (_travel_done >= _travel) { - lcd_selftest_error(5, _error_1, _error_2); + lcd_selftest_error(TestError::endstop, _error_1, _error_2); } else { - lcd_selftest_error(4, _error_1, _error_2); + lcd_selftest_error(TestError::motor, _error_1, _error_2); } } @@ -7479,12 +7495,12 @@ static bool lcd_selfcheck_check_heater(bool _isbed) } else { - lcd_selftest_error(1, "", ""); + lcd_selftest_error(TestError::heater, "", ""); } } else { - lcd_selftest_error(2, "", ""); + lcd_selftest_error(TestError::bed, "", ""); } manage_heater(); @@ -7493,7 +7509,7 @@ static bool lcd_selfcheck_check_heater(bool _isbed) return _stepresult; } -static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2) +static void lcd_selftest_error(TestError testError, const char *_error_1, const char *_error_2) { lcd_beeper_quick_feedback(); @@ -7509,21 +7525,21 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char * lcd_set_cursor(0, 1); lcd_puts_P(_i("Please check :"));////MSG_SELFTEST_PLEASECHECK c=0 r=0 - switch (_error_no) + switch (testError) { - case 1: + case TestError::heater: lcd_set_cursor(0, 2); lcd_puts_P(_i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=0 r=0 lcd_set_cursor(0, 3); lcd_puts_P(_i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=0 r=0 break; - case 2: + case TestError::bed: lcd_set_cursor(0, 2); lcd_puts_P(_i("Bed / Heater"));////MSG_SELFTEST_BEDHEATER c=0 r=0 lcd_set_cursor(0, 3); lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR)); break; - case 3: + case TestError::endstops: lcd_set_cursor(0, 2); lcd_puts_P(_i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=0 r=0 lcd_set_cursor(0, 3); @@ -7531,7 +7547,7 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char * lcd_set_cursor(17, 3); lcd_print(_error_1); break; - case 4: + case TestError::motor: lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_SELFTEST_MOTOR)); lcd_set_cursor(18, 2); @@ -7541,7 +7557,7 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char * lcd_set_cursor(18, 3); lcd_print(_error_2); break; - case 5: + case TestError::endstop: lcd_set_cursor(0, 2); lcd_puts_P(_i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20 r=1 lcd_set_cursor(0, 3); @@ -7549,7 +7565,7 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char * lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case 6: + case TestError::printFan: lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN)); lcd_set_cursor(0, 3); @@ -7557,7 +7573,7 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char * lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case 7: + case TestError::extruderFan: lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN)); lcd_set_cursor(0, 3); @@ -7565,7 +7581,7 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char * lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case 8: + case TestError::pulley: lcd_set_cursor(0, 2); lcd_puts_P(_i("Loose pulley"));////MSG_LOOSE_PULLEY c=20 r=1 lcd_set_cursor(0, 3); @@ -7573,7 +7589,7 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char * lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case 9: + case TestError::axis: lcd_set_cursor(0, 2); lcd_puts_P(_i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=0 r=0 lcd_set_cursor(0, 3); @@ -7581,7 +7597,7 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char * lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case 10: + case TestError::swappedFan: lcd_set_cursor(0, 2); lcd_puts_P(_i("Front/left fans"));////MSG_SELFTEST_FANS c=0 r=0 lcd_set_cursor(0, 3); @@ -7589,7 +7605,7 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char * lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case 11: + case TestError::wiringFsensor: lcd_set_cursor(0, 2); lcd_puts_P(_i("Filament sensor"));////MSG_FILAMENT_SENSOR c=20 r=0 lcd_set_cursor(0, 3); @@ -7796,7 +7812,7 @@ static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite) static bool lcd_selftest_fan_dialog(int _fan) { bool _result = true; - int _errno = 7; + TestError testError = TestError::extruderFan; switch (_fan) { case 0: fanSpeed = 0; @@ -7851,7 +7867,7 @@ static bool lcd_selftest_fan_dialog(int _fan) printf_P(PSTR("Print fan speed: %d \n"), fan_speed[1]); printf_P(PSTR("Extr fan speed: %d \n"), fan_speed[0]); if (!fan_speed[1]) { - _result = false; _errno = 6; //print fan not spinning + _result = false; testError = TestError::printFan; } #ifdef FAN_SOFT_PWM else { @@ -7862,10 +7878,10 @@ static bool lcd_selftest_fan_dialog(int _fan) _result = lcd_selftest_manual_fan_check(1, true); //turn on print fan and check that left extruder fan is not spinning if (_result) { _result = lcd_selftest_manual_fan_check(1, false); //print fan is stil turned on; check that it is spinning - if (!_result) _errno = 6; //print fan not spinning + if (!_result) testError = TestError::printFan; } else { - _errno = 10; //swapped fans + testError = TestError::swappedFan; } } @@ -7877,7 +7893,7 @@ static bool lcd_selftest_fan_dialog(int _fan) } if (!_result) { - lcd_selftest_error(_errno, NULL, NULL); + lcd_selftest_error(testError, NULL, NULL); } return _result; } From ba23b1b2c580d6f86e4f138daeb10820c76021a6 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 21 Mar 2019 22:50:46 +0100 Subject: [PATCH 2/9] Remove unused. --- Firmware/ultralcd.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 79f56b70..1729ec58 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -186,7 +186,6 @@ enum class testScreen : uint_least8_t enum class TestError : uint_least8_t { - unused, heater, bed, endstops, From 91779a5d04d6ae1cc6cba582187a116ca30627b6 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 21 Mar 2019 23:36:59 +0100 Subject: [PATCH 3/9] Add filament sensor false triggering message. --- Firmware/messages.c | 1 + Firmware/messages.h | 1 + Firmware/ultralcd.cpp | 18 +++++++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Firmware/messages.c b/Firmware/messages.c index 029cf0c6..faa5283d 100644 --- a/Firmware/messages.c +++ b/Firmware/messages.c @@ -78,6 +78,7 @@ const char MSG_SELFTEST_FAN_YES[] PROGMEM_I1 = ISTR("Spinning"); ////c=19 r=0 const char MSG_SELFTEST_CHECK_BED[] PROGMEM_I1 = ISTR("Checking bed "); ////c=20 r=0 const char MSG_SELFTEST_CHECK_FSENSOR[] PROGMEM_I1 = ISTR("Checking sensors "); ////c=20 r=0 const char MSG_SELFTEST_MOTOR[] PROGMEM_I1 = ISTR("Motor"); ////c=0 r=0 +const char MSG_SELFTEST_FILAMENT_SENSOR[] PROGMEM_I1 = ISTR("Filament sensor"); ////c=17 r=0 const char MSG_SELFTEST_WIRINGERROR[] PROGMEM_I1 = ISTR("Wiring error"); ////c=0 r=0 const char MSG_SETTINGS[] PROGMEM_I1 = ISTR("Settings"); ////c=0 r=0 const char MSG_SILENT_MODE_OFF[] PROGMEM_I1 = ISTR("Mode [high power]"); ////c=0 r=0 diff --git a/Firmware/messages.h b/Firmware/messages.h index 5083b26d..752195e9 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -80,6 +80,7 @@ extern const char MSG_SELFTEST_FAN_YES[]; extern const char MSG_SELFTEST_CHECK_BED[]; extern const char MSG_SELFTEST_CHECK_FSENSOR[]; extern const char MSG_SELFTEST_MOTOR[]; +extern const char MSG_SELFTEST_FILAMENT_SENSOR[]; extern const char MSG_SELFTEST_WIRINGERROR[]; extern const char MSG_SETTINGS[]; extern const char MSG_SILENT_MODE_OFF[]; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 1729ec58..f5c44db6 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -197,6 +197,7 @@ enum class TestError : uint_least8_t axis, swappedFan, wiringFsensor, + triggeringFsensor, }; static int lcd_selftest_screen(testScreen screen, int _progress, int _progress_scale, bool _clear, int _delay); @@ -7606,10 +7607,16 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const break; case TestError::wiringFsensor: lcd_set_cursor(0, 2); - lcd_puts_P(_i("Filament sensor"));////MSG_FILAMENT_SENSOR c=20 r=0 + lcd_puts_P(_T(MSG_SELFTEST_FILAMENT_SENSOR)); lcd_set_cursor(0, 3); lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR)); break; + case TestError::triggeringFsensor: + lcd_set_cursor(0, 2); + lcd_puts_P(_T(MSG_SELFTEST_FILAMENT_SENSOR)); + lcd_set_cursor(0, 3); + lcd_puts_P(_i("False triggering"));////c=20 r=0 + break; } _delay(1000); @@ -7685,7 +7692,11 @@ static bool selftest_irsensor() mmu_load_step(false); while (blocks_queued()) { - if (PIN_GET(IR_SENSOR_PIN) == 0) return false; + if (PIN_GET(IR_SENSOR_PIN) == 0) + { + lcd_selftest_error(TestError::triggeringFsensor, "", ""); + return false; + } #ifdef TMC2130 manage_heater(); // Vojtech: Don't disable motors inside the planner! @@ -7941,7 +7952,8 @@ static int lcd_selftest_screen(testScreen screen, int _progress, int _progress_s } 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_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR)); + lcd_putc(':'); lcd_set_cursor(18, 2); (screen == testScreen::fsensor) ? lcd_print(_indicator) : lcd_print("OK"); } From c45a7f86410b62da7f37976da643a190ea9c3e2c Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 21 Mar 2019 23:50:01 +0100 Subject: [PATCH 4/9] Fix 1_75mm_MK3-EINSy10a-E3Dv6full variant build error. --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f5c44db6..8bdb00c2 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7640,7 +7640,7 @@ static bool lcd_selftest_fsensor(void) fsensor_init(); if (fsensor_not_responding) { - lcd_selftest_error(11, NULL, NULL); + lcd_selftest_error(TestError::wiringFsensor, NULL, NULL); } return (!fsensor_not_responding); } From d1c5c0390718f4cfd1a9f95a2ae12f870698c379 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 22 Mar 2019 00:03:14 +0100 Subject: [PATCH 5/9] Fix compile error for manual fan check. --- Firmware/ultralcd.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 8bdb00c2..0513356f 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6921,14 +6921,13 @@ bool lcd_selftest() KEEPALIVE_STATE(IN_HANDLER); _progress = lcd_selftest_screen(testScreen::extruderFan, _progress, 3, true, 2000); -#if (defined(FANCHECK) && defined(TACH_0)) +#if (defined(FANCHECK) && defined(TACH_0)) _result = lcd_selftest_fan_dialog(0); #else //defined(TACH_0) _result = lcd_selftest_manual_fan_check(0, false); if (!_result) { - const char *_err; - lcd_selftest_error(7, _err, _err); //extruder fan not spinning + lcd_selftest_error(TestError::extruderFan, "", ""); } #endif //defined(TACH_0) From 8582babddb2b3d16485b484070d28d2d79628882 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 22 Mar 2019 00:08:44 +0100 Subject: [PATCH 6/9] Fix compile error for manual fan check. --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 0513356f..b42eacf2 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6941,7 +6941,7 @@ bool lcd_selftest() _result = lcd_selftest_manual_fan_check(1, false); if (!_result) { - lcd_selftest_error(6, 0, 0); //print fan not spinning + lcd_selftest_error(TestError::printFan, "", ""); //print fan not spinning } #endif //defined(TACH_1) From 89f1a3bacfb7e70f35775ba43e5fa8a47e2809b6 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 22 Mar 2019 00:11:02 +0100 Subject: [PATCH 7/9] Fix compile error for non TMC2130 pulley check. --- Firmware/ultralcd.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index b42eacf2..192cc8f1 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7368,7 +7368,7 @@ static bool lcd_selfcheck_pulleys(int axis) st_synchronize(); if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) || ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) { - lcd_selftest_error(8, (axis == 0) ? "X" : "Y", ""); + lcd_selftest_error(TestError::pulley, (axis == 0) ? "X" : "Y", ""); return(false); } } @@ -7386,7 +7386,7 @@ static bool lcd_selfcheck_pulleys(int axis) return(true); } else { - lcd_selftest_error(8, (axis == 0) ? "X" : "Y", ""); + lcd_selftest_error(TestError::pulley, (axis == 0) ? "X" : "Y", ""); return(false); } } @@ -7395,7 +7395,7 @@ static bool lcd_selfcheck_pulleys(int axis) 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(); if (_millis() > timeout_counter) { - lcd_selftest_error(8, (axis == 0) ? "X" : "Y", ""); + lcd_selftest_error(TestError::pulley, (axis == 0) ? "X" : "Y", ""); return(false); } } From 966e772702c5ad634d1cc76660eb0022043ef7aa Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 22 Mar 2019 00:14:29 +0100 Subject: [PATCH 8/9] Fix compile error for non TMC2130 endstops check. --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 192cc8f1..e07dd4b7 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7428,7 +7428,7 @@ static bool lcd_selfcheck_endstops() if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X"); if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y"); if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z"); - lcd_selftest_error(3, _error, ""); + lcd_selftest_error(TestError::endstops, _error, ""); } manage_heater(); manage_inactivity(true); From baeee5817e50ed9f0e4e96ac164ce75694e37213 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 22 Mar 2019 00:24:22 +0100 Subject: [PATCH 9/9] Make lcd_selftest_error() calls safer, as nullptr parameter is not handled. It is hard to believe, but it actually saves 4B flash. --- Firmware/ultralcd.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index e07dd4b7..13058569 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7199,7 +7199,7 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) { if (axis == Y_AXIS) _error_1 = "Y"; if (axis == Z_AXIS) _error_1 = "Z"; - lcd_selftest_error(TestError::axis, _error_1, NULL); + lcd_selftest_error(TestError::axis, _error_1, ""); current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); reset_crash_det(axis); @@ -7217,7 +7217,7 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) { if (axis == Y_AXIS) _error_1 = "Y"; if (axis == Z_AXIS) _error_1 = "Z"; - lcd_selftest_error(TestError::pulley, _error_1, NULL); + lcd_selftest_error(TestError::pulley, _error_1, ""); current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); reset_crash_det(axis); @@ -7639,7 +7639,7 @@ static bool lcd_selftest_fsensor(void) fsensor_init(); if (fsensor_not_responding) { - lcd_selftest_error(TestError::wiringFsensor, NULL, NULL); + lcd_selftest_error(TestError::wiringFsensor, "", ""); } return (!fsensor_not_responding); } @@ -7902,7 +7902,7 @@ static bool lcd_selftest_fan_dialog(int _fan) } if (!_result) { - lcd_selftest_error(testError, NULL, NULL); + lcd_selftest_error(testError, "", ""); } return _result; }