Browse Source

Fix and tweak POWER_LOSS_RECOVERY (#11151)

Scott Lahteine 7 years ago
parent
commit
fbf1c9b496
No account linked to committer's email address

+ 25
- 14
Marlin/src/feature/power_loss_recovery.cpp View File

53
     SERIAL_PROTOCOLLNPAIR(" valid_foot:", (int)job_recovery_info.valid_foot);
53
     SERIAL_PROTOCOLLNPAIR(" valid_foot:", (int)job_recovery_info.valid_foot);
54
     if (job_recovery_info.valid_head) {
54
     if (job_recovery_info.valid_head) {
55
       if (job_recovery_info.valid_head == job_recovery_info.valid_foot) {
55
       if (job_recovery_info.valid_head == job_recovery_info.valid_foot) {
56
-        SERIAL_PROTOCOLPGM("current_position");
57
-        LOOP_XYZE(i) SERIAL_PROTOCOLPAIR(": ", job_recovery_info.current_position[i]);
56
+        SERIAL_PROTOCOLPGM("current_position: ");
57
+        LOOP_XYZE(i) {
58
+          SERIAL_PROTOCOL(job_recovery_info.current_position[i]);
59
+          if (i < E_AXIS) SERIAL_CHAR(',');
60
+        }
58
         SERIAL_EOL();
61
         SERIAL_EOL();
59
         SERIAL_PROTOCOLLNPAIR("feedrate: ", job_recovery_info.feedrate);
62
         SERIAL_PROTOCOLLNPAIR("feedrate: ", job_recovery_info.feedrate);
60
-        SERIAL_PROTOCOLPGM("target_temperature");
61
-        HOTEND_LOOP() SERIAL_PROTOCOLPAIR(": ", job_recovery_info.target_temperature[e]);
63
+        SERIAL_PROTOCOLPGM("target_temperature: ");
64
+        HOTEND_LOOP() {
65
+          SERIAL_PROTOCOL(job_recovery_info.target_temperature[e]);
66
+          if (e < HOTENDS - 1) SERIAL_CHAR(',');
67
+        }
62
         SERIAL_EOL();
68
         SERIAL_EOL();
63
-        SERIAL_PROTOCOLPGM("fanSpeeds");
64
-        for(uint8_t i = 0; i < FAN_COUNT; i++) SERIAL_PROTOCOLPAIR(": ", job_recovery_info.fanSpeeds[i]);
69
+        SERIAL_PROTOCOLPGM("fanSpeeds: ");
70
+        for (uint8_t i = 0; i < FAN_COUNT; i++) {
71
+          SERIAL_PROTOCOL(job_recovery_info.fanSpeeds[i]);
72
+          if (i < FAN_COUNT - 1) SERIAL_CHAR(',');
73
+        }
65
         SERIAL_EOL();
74
         SERIAL_EOL();
75
+        #if HAS_HEATED_BED
76
+          SERIAL_PROTOCOLLNPAIR("target_temperature_bed: ", job_recovery_info.target_temperature_bed);
77
+        #endif
66
         #if HAS_LEVELING
78
         #if HAS_LEVELING
67
           SERIAL_PROTOCOLPAIR("leveling: ", int(job_recovery_info.leveling));
79
           SERIAL_PROTOCOLPAIR("leveling: ", int(job_recovery_info.leveling));
68
           SERIAL_PROTOCOLLNPAIR(" fade: ", int(job_recovery_info.fade));
80
           SERIAL_PROTOCOLLNPAIR(" fade: ", int(job_recovery_info.fade));
69
         #endif
81
         #endif
70
-        #if HAS_HEATED_BED
71
-          SERIAL_PROTOCOLLNPAIR("target_temperature_bed: ", job_recovery_info.target_temperature_bed);
72
-        #endif
73
         SERIAL_PROTOCOLLNPAIR("cmd_queue_index_r: ", job_recovery_info.cmd_queue_index_r);
82
         SERIAL_PROTOCOLLNPAIR("cmd_queue_index_r: ", job_recovery_info.cmd_queue_index_r);
74
         SERIAL_PROTOCOLLNPAIR("commands_in_queue: ", job_recovery_info.commands_in_queue);
83
         SERIAL_PROTOCOLLNPAIR("commands_in_queue: ", job_recovery_info.commands_in_queue);
75
         if (recovery)
84
         if (recovery)
76
           for (uint8_t i = 0; i < job_recovery_commands_count; i++) SERIAL_PROTOCOLLNPAIR("> ", job_recovery_commands[i]);
85
           for (uint8_t i = 0; i < job_recovery_commands_count; i++) SERIAL_PROTOCOLLNPAIR("> ", job_recovery_commands[i]);
77
         else
86
         else
78
           for (uint8_t i = 0; i < job_recovery_info.commands_in_queue; i++) SERIAL_PROTOCOLLNPAIR("> ", job_recovery_info.command_queue[i]);
87
           for (uint8_t i = 0; i < job_recovery_info.commands_in_queue; i++) SERIAL_PROTOCOLLNPAIR("> ", job_recovery_info.command_queue[i]);
79
-        SERIAL_PROTOCOLLNPAIR("sd_filename: ", sd_filename);
88
+        SERIAL_PROTOCOLLNPAIR("sd_filename: ", job_recovery_info.sd_filename);
80
         SERIAL_PROTOCOLLNPAIR("sdpos: ", job_recovery_info.sdpos);
89
         SERIAL_PROTOCOLLNPAIR("sdpos: ", job_recovery_info.sdpos);
81
         SERIAL_PROTOCOLLNPAIR("print_job_elapsed: ", job_recovery_info.print_job_elapsed);
90
         SERIAL_PROTOCOLLNPAIR("print_job_elapsed: ", job_recovery_info.print_job_elapsed);
82
       }
91
       }
125
           #endif
134
           #endif
126
         ));
135
         ));
127
 
136
 
137
+        char str_1[16], str_2[16];
138
+
128
         #if HAS_LEVELING
139
         #if HAS_LEVELING
129
           // Restore leveling state before G92 sets Z
140
           // Restore leveling state before G92 sets Z
130
           // This ensures the steppers correspond to the native Z
141
           // This ensures the steppers correspond to the native Z
131
-          sprintf_P(job_recovery_commands[ind++], PSTR("M420 S%i Z%s"), int(job_recovery_info.leveling), job_recovery_info.fade);
142
+          dtostrf(job_recovery_info.fade, 1, 1, str_1);
143
+          sprintf_P(job_recovery_commands[ind++], PSTR("M420 S%i Z%s"), int(job_recovery_info.leveling), str_1);
132
         #endif
144
         #endif
133
 
145
 
134
-        char str_1[16], str_2[16];
135
         dtostrf(job_recovery_info.current_position[Z_AXIS] + 2, 1, 3, str_1);
146
         dtostrf(job_recovery_info.current_position[Z_AXIS] + 2, 1, 3, str_1);
136
         dtostrf(job_recovery_info.current_position[E_AXIS]
147
         dtostrf(job_recovery_info.current_position[E_AXIS]
137
           #if ENABLED(SAVE_EACH_CMD_MODE)
148
           #if ENABLED(SAVE_EACH_CMD_MODE)
156
           debug_print_job_recovery(true);
167
           debug_print_job_recovery(true);
157
         #endif
168
         #endif
158
 
169
 
159
-        card.openFile(sd_filename, true);
170
+        card.openFile(job_recovery_info.sd_filename, true);
160
         card.setIndex(job_recovery_info.sdpos);
171
         card.setIndex(job_recovery_info.sdpos);
161
       }
172
       }
162
       else {
173
       else {
223
     job_recovery_info.print_job_elapsed = print_job_timer.duration() * 1000UL;
234
     job_recovery_info.print_job_elapsed = print_job_timer.duration() * 1000UL;
224
 
235
 
225
     // SD file position
236
     // SD file position
226
-    card.getAbsFilename(sd_filename);
237
+    card.getAbsFilename(job_recovery_info.sd_filename);
227
     job_recovery_info.sdpos = card.getIndex();
238
     job_recovery_info.sdpos = card.getIndex();
228
 
239
 
229
     #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
240
     #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)

+ 2
- 1
Marlin/src/feature/power_loss_recovery.h View File

56
   uint8_t cmd_queue_index_r, commands_in_queue;
56
   uint8_t cmd_queue_index_r, commands_in_queue;
57
   char command_queue[BUFSIZE][MAX_CMD_SIZE];
57
   char command_queue[BUFSIZE][MAX_CMD_SIZE];
58
 
58
 
59
-  // SD File position
59
+  // SD Filename and position
60
+  char sd_filename[MAXPATHNAMELENGTH];
60
   uint32_t sdpos;
61
   uint32_t sdpos;
61
 
62
 
62
   // Job elapsed time
63
   // Job elapsed time

+ 1
- 5
Marlin/src/lcd/ultralcd.cpp View File

875
       lcd_return_to_status();
875
       lcd_return_to_status();
876
 
876
 
877
       #if ENABLED(POWER_LOSS_RECOVERY)
877
       #if ENABLED(POWER_LOSS_RECOVERY)
878
-        card.openJobRecoveryFile(false);
879
-        job_recovery_info.valid_head = job_recovery_info.valid_foot = 0;
880
-        (void)card.saveJobRecoveryInfo();
881
-        card.closeJobRecoveryFile();
882
-        job_recovery_commands_count = 0;
878
+        card.removeJobRecoveryFile();
883
       #endif
879
       #endif
884
     }
880
     }
885
 
881
 

+ 9
- 9
Marlin/src/sd/cardreader.cpp View File

937
     sdprinting = false;
937
     sdprinting = false;
938
 
938
 
939
     #if ENABLED(POWER_LOSS_RECOVERY)
939
     #if ENABLED(POWER_LOSS_RECOVERY)
940
-      openJobRecoveryFile(false);
941
-      job_recovery_info.valid_head = job_recovery_info.valid_foot = 0;
942
-      (void)saveJobRecoveryInfo();
943
-      closeJobRecoveryFile();
944
-      job_recovery_commands_count = 0;
940
+      removeJobRecoveryFile();
945
     #endif
941
     #endif
946
 
942
 
947
     #if ENABLED(SD_FINISHED_STEPPERRELEASE) && defined(SD_FINISHED_RELEASECOMMAND)
943
     #if ENABLED(SD_FINISHED_STEPPERRELEASE) && defined(SD_FINISHED_RELEASECOMMAND)
1016
   }
1012
   }
1017
 
1013
 
1018
   void CardReader::removeJobRecoveryFile() {
1014
   void CardReader::removeJobRecoveryFile() {
1019
-    if (jobRecoveryFile.remove(&root, job_recovery_file_name))
1020
-      SERIAL_PROTOCOLLNPGM("Power-loss file deleted.");
1021
-    else
1022
-      SERIAL_PROTOCOLLNPGM("Power-loss file delete failed.");
1015
+    job_recovery_info.valid_head = job_recovery_info.valid_foot = job_recovery_commands_count = 0;
1016
+    const bool success = jobRecoveryFile.remove(&root, job_recovery_file_name);
1017
+    #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
1018
+      SERIAL_PROTOCOLPGM("Power-loss file delete");
1019
+      serialprintPGM(success ? PSTR("d.") : PSTR(" failed."))
1020
+    #else
1021
+      UNUSED(success);
1022
+    #endif
1023
   }
1023
   }
1024
 
1024
 
1025
 #endif // POWER_LOSS_RECOVERY
1025
 #endif // POWER_LOSS_RECOVERY

Loading…
Cancel
Save