Skip to content

Commit 9217e4b

Browse files
committed
Various UBL cleanups and bug fixes
1 parent f49aec0 commit 9217e4b

11 files changed

+459
-549
lines changed

Marlin/G26_Mesh_Validation_Tool.cpp

Lines changed: 107 additions & 142 deletions
Large diffs are not rendered by default.

Marlin/M100_Free_Mem_Chk.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,25 @@ void gcode_M100() {
7676
// We want to start and end the dump on a nice 16 byte boundry even though
7777
// the values we are using are not 16 byte aligned.
7878
//
79-
SERIAL_ECHOPGM("\nbss_end : ");
80-
prt_hex_word((unsigned int) ptr);
81-
ptr = (char*)((unsigned long) ptr & 0xfff0);
79+
SERIAL_ECHOPAIR("\nbss_end : ", hex_word((uint16_t)ptr));
80+
ptr = (char*)((uint32_t)ptr & 0xfff0);
8281
sp = top_of_stack();
83-
SERIAL_ECHOPGM("\nStack Pointer : ");
84-
prt_hex_word((unsigned int) sp);
85-
SERIAL_EOL;
86-
sp = (char*)((unsigned long) sp | 0x000f);
82+
SERIAL_ECHOLNPAIR("\nStack Pointer : ", hex_word((uint16_t)sp));
83+
sp = (char*)((uint32_t)sp | 0x000f);
8784
n = sp - ptr;
8885
//
8986
// This is the main loop of the Dump command.
9087
//
9188
while (ptr < sp) {
92-
prt_hex_word((unsigned int) ptr); // Print the address
89+
print_hex_word((uint16_t)ptr); // Print the address
9390
SERIAL_CHAR(':');
9491
for (i = 0; i < 16; i++) { // and 16 data bytes
95-
prt_hex_byte(*(ptr + i));
92+
print_hex_byte(*(ptr + i));
9693
SERIAL_CHAR(' ');
9794
}
9895
SERIAL_CHAR('|'); // now show where non 0xE5's are
99-
for (i = 0; i < 16; i++) {
100-
if (*(ptr + i) == (char)0xe5)
101-
SERIAL_CHAR(' ');
102-
else
103-
SERIAL_CHAR('?');
104-
}
96+
for (i = 0; i < 16; i++)
97+
SERIAL_CHAR((*(ptr + i) == (char)0xe5) ? ' ' : '?');
10598
SERIAL_EOL;
10699
ptr += 16;
107100
}
@@ -127,9 +120,7 @@ void gcode_M100() {
127120
j = how_many_E5s_are_here(ptr + i);
128121
if (j > 8) {
129122
SERIAL_ECHOPAIR("Found ", j);
130-
SERIAL_ECHOPGM(" bytes free at 0x");
131-
prt_hex_word((int) ptr + i);
132-
SERIAL_EOL;
123+
SERIAL_ECHOLNPAIR(" bytes free at 0x", hex_word((uint16_t)(ptr + i)));
133124
i += j;
134125
block_cnt++;
135126
}
@@ -164,8 +155,7 @@ void gcode_M100() {
164155
j = n / (x + 1);
165156
for (i = 1; i <= x; i++) {
166157
*(ptr + (i * j)) = i;
167-
SERIAL_ECHOPGM("\nCorrupting address: 0x");
168-
prt_hex_word((unsigned int)(ptr + (i * j)));
158+
SERIAL_ECHOPAIR("\nCorrupting address: 0x", hex_word((uint16_t)(ptr + i * j)));
169159
}
170160
SERIAL_ECHOLNPGM("\n");
171161
return;

Marlin/Marlin.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,10 @@ float code_value_temp_diff();
363363
#endif
364364

365365
#if ENABLED(HOST_KEEPALIVE_FEATURE)
366-
extern uint8_t host_keepalive_interval;
366+
extern MarlinBusyState busy_state;
367+
#define KEEPALIVE_STATE(n) do{ busy_state = n; }while(0)
368+
#else
369+
#define KEEPALIVE_STATE(n) NOOP
367370
#endif
368371

369372
#if FAN_COUNT > 0

Marlin/Marlin_main.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,9 @@ static bool send_ok[BUFSIZE];
655655
static MarlinBusyState busy_state = NOT_BUSY;
656656
static millis_t next_busy_signal_ms = 0;
657657
uint8_t host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
658-
#define KEEPALIVE_STATE(n) do{ busy_state = n; }while(0)
659658
#else
660-
#define host_keepalive() ;
661-
#define KEEPALIVE_STATE(n) ;
662-
#endif // HOST_KEEPALIVE_FEATURE
659+
#define host_keepalive() NOOP
660+
#endif
663661

664662
#define DEFINE_PGM_READ_ANY(type, reader) \
665663
static inline type pgm_read_any(const type *p) \
@@ -1031,7 +1029,7 @@ inline void get_serial_commands() {
10311029
// send "wait" to indicate Marlin is still waiting.
10321030
#if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
10331031
static millis_t last_command_time = 0;
1034-
millis_t ms = millis();
1032+
const millis_t ms = millis();
10351033
if (commands_in_queue == 0 && !MYSERIAL.available() && ELAPSED(ms, last_command_time + NO_TIMEOUTS)) {
10361034
SERIAL_ECHOLNPGM(MSG_WAIT);
10371035
last_command_time = ms;
@@ -4710,8 +4708,8 @@ inline void gcode_G92() {
47104708

47114709
#endif
47124710

4713-
wait_for_user = true;
47144711
KEEPALIVE_STATE(PAUSED_FOR_USER);
4712+
wait_for_user = true;
47154713

47164714
stepper.synchronize();
47174715
refresh_cmd_timeout();
@@ -5050,7 +5048,7 @@ inline void gcode_M42() {
50505048
if (first_pin > NUM_DIGITAL_PINS - 1) return;
50515049
}
50525050

5053-
bool ignore_protection = code_seen('I') ? code_value_bool() : false;
5051+
const bool ignore_protection = code_seen('I') ? code_value_bool() : false;
50545052

50555053
// Watch until click, M108, or reset
50565054
if (code_seen('W') && code_value_bool()) { // watch digital pins
@@ -6324,8 +6322,8 @@ inline void gcode_M121() { endstops.enable_globally(false); }
63246322

63256323
#if DISABLED(SDSUPPORT)
63266324
// Wait for lcd click or M108
6327-
wait_for_user = true;
63286325
KEEPALIVE_STATE(PAUSED_FOR_USER);
6326+
wait_for_user = true;
63296327
while (wait_for_user) idle();
63306328
KEEPALIVE_STATE(IN_HANDLER);
63316329

@@ -7591,7 +7589,7 @@ inline void gcode_M503() {
75917589
disable_e_steppers();
75927590
safe_delay(100);
75937591

7594-
millis_t nozzle_timeout = millis() + (millis_t)(FILAMENT_CHANGE_NOZZLE_TIMEOUT) * 1000L;
7592+
const millis_t nozzle_timeout = millis() + (millis_t)(FILAMENT_CHANGE_NOZZLE_TIMEOUT) * 1000UL;
75957593
bool nozzle_timed_out = false;
75967594
float temps[4];
75977595

@@ -7606,25 +7604,25 @@ inline void gcode_M503() {
76067604

76077605
HOTEND_LOOP() temps[e] = thermalManager.target_temperature[e]; // Save nozzle temps
76087606

7607+
KEEPALIVE_STATE(PAUSED_FOR_USER);
76097608
wait_for_user = true; // LCD click or M108 will clear this
76107609
while (wait_for_user) {
7611-
millis_t current_ms = millis();
7610+
76127611
if (nozzle_timed_out)
76137612
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_CLICK_TO_HEAT_NOZZLE);
76147613

76157614
#if HAS_BUZZER
76167615
filament_change_beep();
76177616
#endif
76187617

7619-
if (current_ms >= nozzle_timeout) {
7620-
if (!nozzle_timed_out) {
7621-
nozzle_timed_out = true; // on nozzle timeout remember the nozzles need to be reheated
7622-
HOTEND_LOOP() thermalManager.setTargetHotend(0, e); // Turn off all the nozzles
7623-
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_CLICK_TO_HEAT_NOZZLE);
7624-
}
7618+
if (!nozzle_timed_out && ELAPSED(millis(), nozzle_timeout)) {
7619+
nozzle_timed_out = true; // on nozzle timeout remember the nozzles need to be reheated
7620+
HOTEND_LOOP() thermalManager.setTargetHotend(0, e); // Turn off all the nozzles
7621+
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_CLICK_TO_HEAT_NOZZLE);
76257622
}
76267623
idle(true);
76277624
}
7625+
KEEPALIVE_STATE(IN_HANDLER);
76287626

76297627
if (nozzle_timed_out) // Turn nozzles back on if they were turned off
76307628
HOTEND_LOOP() thermalManager.setTargetHotend(temps[e], e);
@@ -7652,13 +7650,15 @@ inline void gcode_M503() {
76527650
filament_change_beep(true);
76537651
#endif
76547652

7653+
KEEPALIVE_STATE(PAUSED_FOR_USER);
76557654
wait_for_user = true; // LCD click or M108 will clear this
76567655
while (wait_for_user && nozzle_timed_out) {
76577656
#if HAS_BUZZER
76587657
filament_change_beep();
76597658
#endif
76607659
idle(true);
76617660
}
7661+
KEEPALIVE_STATE(IN_HANDLER);
76627662

76637663
// Show "load" message
76647664
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_LOAD);
@@ -10137,9 +10137,9 @@ void prepare_move_to_destination() {
1013710137
#if HAS_CONTROLLERFAN
1013810138

1013910139
void controllerFan() {
10140-
static millis_t lastMotorOn = 0; // Last time a motor was turned on
10141-
static millis_t nextMotorCheck = 0; // Last time the state was checked
10142-
millis_t ms = millis();
10140+
static millis_t lastMotorOn = 0, // Last time a motor was turned on
10141+
nextMotorCheck = 0; // Last time the state was checked
10142+
const millis_t ms = millis();
1014310143
if (ELAPSED(ms, nextMotorCheck)) {
1014410144
nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
1014510145
if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || thermalManager.soft_pwm_bed > 0
@@ -10472,7 +10472,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
1047210472

1047310473
if (commands_in_queue < BUFSIZE) get_available_commands();
1047410474

10475-
millis_t ms = millis();
10475+
const millis_t ms = millis();
1047610476

1047710477
if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) {
1047810478
SERIAL_ERROR_START;
@@ -10686,7 +10686,7 @@ void kill(const char* lcd_msg) {
1068610686

1068710687
thermalManager.disable_all_heaters();
1068810688
disable_all_steppers();
10689-
10689+
1069010690
#if ENABLED(ULTRA_LCD)
1069110691
kill_screen(lcd_msg);
1069210692
#else
@@ -10695,7 +10695,7 @@ void kill(const char* lcd_msg) {
1069510695

1069610696
_delay_ms(250); // Wait a short time
1069710697
cli(); // Stop interrupts
10698-
10698+
1069910699
_delay_ms(250); //Wait to ensure all interrupts routines stopped
1070010700
thermalManager.disable_all_heaters(); //turn off heaters again
1070110701

0 commit comments

Comments
 (0)