Skip to content

Commit de9d2cd

Browse files
authored
Merge pull request #6152 from thinkyhead/rc_cleanup_6150_etc
UBL cleanup, optimization
2 parents 9924199 + 9217e4b commit de9d2cd

12 files changed

+461
-551
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
static inline float pgm_read_any(const float *p) { return pgm_read_float_near(p); }
665663
static inline signed char pgm_read_any(const signed char *p) { return pgm_read_byte_near(p); }
@@ -1021,7 +1019,7 @@ inline void get_serial_commands() {
10211019
// send "wait" to indicate Marlin is still waiting.
10221020
#if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
10231021
static millis_t last_command_time = 0;
1024-
millis_t ms = millis();
1022+
const millis_t ms = millis();
10251023
if (commands_in_queue == 0 && !MYSERIAL.available() && ELAPSED(ms, last_command_time + NO_TIMEOUTS)) {
10261024
SERIAL_ECHOLNPGM(MSG_WAIT);
10271025
last_command_time = ms;
@@ -4700,8 +4698,8 @@ inline void gcode_G92() {
47004698

47014699
#endif
47024700

4703-
wait_for_user = true;
47044701
KEEPALIVE_STATE(PAUSED_FOR_USER);
4702+
wait_for_user = true;
47054703

47064704
stepper.synchronize();
47074705
refresh_cmd_timeout();
@@ -5040,7 +5038,7 @@ inline void gcode_M42() {
50405038
if (first_pin > NUM_DIGITAL_PINS - 1) return;
50415039
}
50425040

5043-
bool ignore_protection = code_seen('I') ? code_value_bool() : false;
5041+
const bool ignore_protection = code_seen('I') ? code_value_bool() : false;
50445042

50455043
// Watch until click, M108, or reset
50465044
if (code_seen('W') && code_value_bool()) { // watch digital pins
@@ -6314,8 +6312,8 @@ inline void gcode_M121() { endstops.enable_globally(false); }
63146312

63156313
#if DISABLED(SDSUPPORT)
63166314
// Wait for lcd click or M108
6317-
wait_for_user = true;
63186315
KEEPALIVE_STATE(PAUSED_FOR_USER);
6316+
wait_for_user = true;
63196317
while (wait_for_user) idle();
63206318
KEEPALIVE_STATE(IN_HANDLER);
63216319

@@ -7581,7 +7579,7 @@ inline void gcode_M503() {
75817579
disable_e_steppers();
75827580
safe_delay(100);
75837581

7584-
millis_t nozzle_timeout = millis() + (millis_t)(FILAMENT_CHANGE_NOZZLE_TIMEOUT) * 1000L;
7582+
const millis_t nozzle_timeout = millis() + (millis_t)(FILAMENT_CHANGE_NOZZLE_TIMEOUT) * 1000UL;
75857583
bool nozzle_timed_out = false;
75867584
float temps[4];
75877585

@@ -7596,25 +7594,25 @@ inline void gcode_M503() {
75967594

75977595
HOTEND_LOOP() temps[e] = thermalManager.target_temperature[e]; // Save nozzle temps
75987596

7597+
KEEPALIVE_STATE(PAUSED_FOR_USER);
75997598
wait_for_user = true; // LCD click or M108 will clear this
76007599
while (wait_for_user) {
7601-
millis_t current_ms = millis();
7600+
76027601
if (nozzle_timed_out)
76037602
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_CLICK_TO_HEAT_NOZZLE);
76047603

76057604
#if HAS_BUZZER
76067605
filament_change_beep();
76077606
#endif
76087607

7609-
if (current_ms >= nozzle_timeout) {
7610-
if (!nozzle_timed_out) {
7611-
nozzle_timed_out = true; // on nozzle timeout remember the nozzles need to be reheated
7612-
HOTEND_LOOP() thermalManager.setTargetHotend(0, e); // Turn off all the nozzles
7613-
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_CLICK_TO_HEAT_NOZZLE);
7614-
}
7608+
if (!nozzle_timed_out && ELAPSED(millis(), nozzle_timeout)) {
7609+
nozzle_timed_out = true; // on nozzle timeout remember the nozzles need to be reheated
7610+
HOTEND_LOOP() thermalManager.setTargetHotend(0, e); // Turn off all the nozzles
7611+
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_CLICK_TO_HEAT_NOZZLE);
76157612
}
76167613
idle(true);
76177614
}
7615+
KEEPALIVE_STATE(IN_HANDLER);
76187616

76197617
if (nozzle_timed_out) // Turn nozzles back on if they were turned off
76207618
HOTEND_LOOP() thermalManager.setTargetHotend(temps[e], e);
@@ -7642,13 +7640,15 @@ inline void gcode_M503() {
76427640
filament_change_beep(true);
76437641
#endif
76447642

7643+
KEEPALIVE_STATE(PAUSED_FOR_USER);
76457644
wait_for_user = true; // LCD click or M108 will clear this
76467645
while (wait_for_user && nozzle_timed_out) {
76477646
#if HAS_BUZZER
76487647
filament_change_beep();
76497648
#endif
76507649
idle(true);
76517650
}
7651+
KEEPALIVE_STATE(IN_HANDLER);
76527652

76537653
// Show "load" message
76547654
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_LOAD);
@@ -10160,9 +10160,9 @@ void prepare_move_to_destination() {
1016010160
#if HAS_CONTROLLERFAN
1016110161

1016210162
void controllerFan() {
10163-
static millis_t lastMotorOn = 0; // Last time a motor was turned on
10164-
static millis_t nextMotorCheck = 0; // Last time the state was checked
10165-
millis_t ms = millis();
10163+
static millis_t lastMotorOn = 0, // Last time a motor was turned on
10164+
nextMotorCheck = 0; // Last time the state was checked
10165+
const millis_t ms = millis();
1016610166
if (ELAPSED(ms, nextMotorCheck)) {
1016710167
nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
1016810168
if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || thermalManager.soft_pwm_bed > 0
@@ -10495,7 +10495,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
1049510495

1049610496
if (commands_in_queue < BUFSIZE) get_available_commands();
1049710497

10498-
millis_t ms = millis();
10498+
const millis_t ms = millis();
1049910499

1050010500
if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) {
1050110501
SERIAL_ERROR_START;
@@ -10709,7 +10709,7 @@ void kill(const char* lcd_msg) {
1070910709

1071010710
thermalManager.disable_all_heaters();
1071110711
disable_all_steppers();
10712-
10712+
1071310713
#if ENABLED(ULTRA_LCD)
1071410714
kill_screen(lcd_msg);
1071510715
#else
@@ -10718,7 +10718,7 @@ void kill(const char* lcd_msg) {
1071810718

1071910719
_delay_ms(250); // Wait a short time
1072010720
cli(); // Stop interrupts
10721-
10721+
1072210722
_delay_ms(250); //Wait to ensure all interrupts routines stopped
1072310723
thermalManager.disable_all_heaters(); //turn off heaters again
1072410724

0 commit comments

Comments
 (0)