Browse Source

Apply three more commits

Scott Lahteine 9 years ago
parent
commit
ccddc280be

+ 10
- 6
Marlin/Marlin.h View File

@@ -31,6 +31,10 @@
31 31
 #define TEST(n,b) (((n)&BIT(b))!=0)
32 32
 #define RADIANS(d) ((d)*M_PI/180.0)
33 33
 #define DEGREES(r) ((d)*180.0/M_PI)
34
+#define NOLESS(v,n) do{ if (v < n) v = n; }while(0)
35
+#define NOMORE(v,n) do{ if (v > n) v = n; }while(0)
36
+
37
+typedef unsigned long millis_t;
34 38
 
35 39
 // Arduino < 1.0.0 does not define this, so we need to do it ourselves
36 40
 #ifndef analogInputToDigitalPin
@@ -223,14 +227,14 @@ extern bool Running;
223 227
 inline bool IsRunning() { return  Running; }
224 228
 inline bool IsStopped() { return !Running; }
225 229
 
226
-bool enquecommand(const char *cmd); //put a single ASCII command at the end of the current buffer or return false when it is full
227
-void enquecommands_P(const char *cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
230
+bool enqueuecommand(const char *cmd); //put a single ASCII command at the end of the current buffer or return false when it is full
231
+void enqueuecommands_P(const char *cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
228 232
 
229 233
 void prepare_arc_move(char isclockwise);
230 234
 void clamp_to_software_endstops(float target[3]);
231 235
 
232
-extern unsigned long previous_millis_cmd;
233
-inline void refresh_cmd_timeout() { previous_millis_cmd = millis(); }
236
+extern millis_t previous_cmd_ms;
237
+inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
234 238
 
235 239
 #ifdef FAST_PWM_FAN
236 240
   void setPwmFrequency(uint8_t pin, int val);
@@ -305,8 +309,8 @@ extern int fanSpeed;
305 309
   extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate;
306 310
 #endif
307 311
 
308
-extern unsigned long starttime;
309
-extern unsigned long stoptime;
312
+extern millis_t starttime;
313
+extern millis_t stoptime;
310 314
 
311 315
 // Handling multiple extruders pins
312 316
 extern uint8_t active_extruder;

+ 202
- 243
Marlin/Marlin_main.cpp View File

@@ -244,11 +244,11 @@ static char *strchr_pointer; ///< A pointer to find chars in the command string
244 244
 const char* queued_commands_P= NULL; /* pointer to the current line in the active sequence of commands, or NULL when none */
245 245
 const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42
246 246
 // Inactivity shutdown
247
-unsigned long previous_millis_cmd = 0;
248
-static unsigned long max_inactive_time = 0;
249
-static unsigned long stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME*1000l;
250
-unsigned long starttime = 0; ///< Print job start time
251
-unsigned long stoptime = 0;  ///< Print job stop time
247
+millis_t previous_cmd_ms = 0;
248
+static millis_t max_inactive_time = 0;
249
+static millis_t stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME * 1000L;
250
+millis_t starttime = 0; ///< Print job start time
251
+millis_t stoptime = 0;  ///< Print job stop time
252 252
 static uint8_t target_extruder;
253 253
 bool CooldownNoWait = true;
254 254
 bool target_direction;
@@ -425,7 +425,7 @@ static bool drain_queued_commands_P() {
425 425
   char c;
426 426
   while((c = cmd[i]) && c != '\n') i++; // find the end of this gcode command
427 427
   cmd[i] = '\0';
428
-  if (enquecommand(cmd)) {        // buffer was not full (else we will retry later)
428
+  if (enqueuecommand(cmd)) {        // buffer was not full (else we will retry later)
429 429
     if (c)
430 430
       queued_commands_P += i + 1; // move to next command
431 431
     else
@@ -437,7 +437,7 @@ static bool drain_queued_commands_P() {
437 437
 //Record one or many commands to run from program memory.
438 438
 //Aborts the current queue, if any.
439 439
 //Note: drain_queued_commands_P() must be called repeatedly to drain the commands afterwards
440
-void enquecommands_P(const char* pgcode) {
440
+void enqueuecommands_P(const char* pgcode) {
441 441
     queued_commands_P = pgcode;
442 442
     drain_queued_commands_P(); // first command executed asap (when possible)
443 443
 }
@@ -446,7 +446,7 @@ void enquecommands_P(const char* pgcode) {
446 446
 //that is really done in a non-safe way.
447 447
 //needs overworking someday
448 448
 //Returns false if it failed to do so
449
-bool enquecommand(const char *cmd)
449
+bool enqueuecommand(const char *cmd)
450 450
 {
451 451
   if(*cmd==';')
452 452
     return false;
@@ -666,33 +666,30 @@ void loop() {
666 666
   lcd_update();
667 667
 }
668 668
 
669
-void get_command()
670
-{
671
-  if (drain_queued_commands_P()) // priority is given to non-serial commands
672
-    return;
669
+void get_command() {
670
+
671
+  if (drain_queued_commands_P()) return; // priority is given to non-serial commands
673 672
   
674
-  while( MYSERIAL.available() > 0  && buflen < BUFSIZE) {
673
+  while (MYSERIAL.available() > 0 && buflen < BUFSIZE) {
675 674
     serial_char = MYSERIAL.read();
676
-    if(serial_char == '\n' ||
677
-       serial_char == '\r' ||
678
-       serial_count >= (MAX_CMD_SIZE - 1) )
679
-    {
675
+    if (serial_char == '\n' || serial_char == '\r' ||
676
+       serial_count >= (MAX_CMD_SIZE - 1)
677
+    ) {
680 678
       // end of line == end of comment
681 679
       comment_mode = false;
682 680
 
683
-      if(!serial_count) {
684
-        // short cut for empty lines
685
-        return;
686
-      }
687
-      cmdbuffer[bufindw][serial_count] = 0; //terminate string
681
+      if (!serial_count) return; // shortcut for empty lines
682
+
683
+      cmdbuffer[bufindw][serial_count] = 0; // terminate string
684
+
688 685
       #ifdef SDSUPPORT
689
-      fromsd[bufindw] = false;
690
-      #endif //!SDSUPPORT
691
-      if(strchr(cmdbuffer[bufindw], 'N') != NULL)
692
-      {
686
+        fromsd[bufindw] = false;
687
+      #endif
688
+
689
+      if (strchr(cmdbuffer[bufindw], 'N') != NULL) {
693 690
         strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
694 691
         gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
695
-        if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
692
+        if (gcode_N != gcode_LastN + 1 && strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) {
696 693
           SERIAL_ERROR_START;
697 694
           SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
698 695
           SERIAL_ERRORLN(gcode_LastN);
@@ -702,14 +699,13 @@ void get_command()
702 699
           return;
703 700
         }
704 701
 
705
-        if(strchr(cmdbuffer[bufindw], '*') != NULL)
706
-        {
702
+        if (strchr(cmdbuffer[bufindw], '*') != NULL) {
707 703
           byte checksum = 0;
708 704
           byte count = 0;
709
-          while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
705
+          while (cmdbuffer[bufindw][count] != '*') checksum ^= cmdbuffer[bufindw][count++];
710 706
           strchr_pointer = strchr(cmdbuffer[bufindw], '*');
711 707
 
712
-          if(strtol(strchr_pointer + 1, NULL, 10) != checksum) {
708
+          if (strtol(strchr_pointer + 1, NULL, 10) != checksum) {
713 709
             SERIAL_ERROR_START;
714 710
             SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
715 711
             SERIAL_ERRORLN(gcode_LastN);
@@ -719,8 +715,7 @@ void get_command()
719 715
           }
720 716
           //if no errors, continue parsing
721 717
         }
722
-        else
723
-        {
718
+        else {
724 719
           SERIAL_ERROR_START;
725 720
           SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
726 721
           SERIAL_ERRORLN(gcode_LastN);
@@ -732,10 +727,8 @@ void get_command()
732 727
         gcode_LastN = gcode_N;
733 728
         //if no errors, continue parsing
734 729
       }
735
-      else  // if we don't receive 'N' but still see '*'
736
-      {
737
-        if((strchr(cmdbuffer[bufindw], '*') != NULL))
738
-        {
730
+      else {  // if we don't receive 'N' but still see '*'
731
+        if ((strchr(cmdbuffer[bufindw], '*') != NULL)) {
739 732
           SERIAL_ERROR_START;
740 733
           SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
741 734
           SERIAL_ERRORLN(gcode_LastN);
@@ -743,111 +736,99 @@ void get_command()
743 736
           return;
744 737
         }
745 738
       }
746
-      if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
739
+
740
+      if (strchr(cmdbuffer[bufindw], 'G') != NULL) {
747 741
         strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
748
-        switch(strtol(strchr_pointer + 1, NULL, 10)){
749
-        case 0:
750
-        case 1:
751
-        case 2:
752
-        case 3:
753
-          if (IsStopped()) {
754
-            SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
755
-            LCD_MESSAGEPGM(MSG_STOPPED);
756
-          }
757
-          break;
758
-        default:
759
-          break;
742
+        switch (strtol(strchr_pointer + 1, NULL, 10)) {
743
+          case 0:
744
+          case 1:
745
+          case 2:
746
+          case 3:
747
+            if (IsStopped()) {
748
+              SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
749
+              LCD_MESSAGEPGM(MSG_STOPPED);
750
+            }
751
+            break;
752
+          default:
753
+            break;
760 754
         }
761
-
762 755
       }
763 756
 
764
-      //If command was e-stop process now
765
-      if(strcmp(cmdbuffer[bufindw], "M112") == 0)
766
-        kill();
757
+      // If command was e-stop process now
758
+      if (strcmp(cmdbuffer[bufindw], "M112") == 0) kill();
767 759
 
768
-      bufindw = (bufindw + 1)%BUFSIZE;
760
+      bufindw = (bufindw + 1) % BUFSIZE;
769 761
       buflen += 1;
770 762
 
771 763
       serial_count = 0; //clear buffer
772 764
     }
773
-    else if(serial_char == '\\') {  //Handle escapes
774
-       
775
-        if(MYSERIAL.available() > 0  && buflen < BUFSIZE) {
776
-            // if we have one more character, copy it over
777
-            serial_char = MYSERIAL.read();
778
-            cmdbuffer[bufindw][serial_count++] = serial_char;
779
-        }
780
-
781
-        //otherwise do nothing        
765
+    else if (serial_char == '\\') {  // Handle escapes
766
+      if (MYSERIAL.available() > 0  && buflen < BUFSIZE) {
767
+        // if we have one more character, copy it over
768
+        serial_char = MYSERIAL.read();
769
+        cmdbuffer[bufindw][serial_count++] = serial_char;
770
+      }
771
+      // otherwise do nothing
782 772
     }
783 773
     else { // its not a newline, carriage return or escape char
784
-        if(serial_char == ';') comment_mode = true;
785
-        if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
774
+      if (serial_char == ';') comment_mode = true;
775
+      if (!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
786 776
     }
787 777
   }
788
-  #ifdef SDSUPPORT
789
-  if(!card.sdprinting || serial_count!=0){
790
-    return;
791
-  }
792 778
 
793
-  //'#' stops reading from SD to the buffer prematurely, so procedural macro calls are possible
794
-  // if it occurs, stop_buffering is triggered and the buffer is ran dry.
795
-  // this character _can_ occur in serial com, due to checksums. however, no checksums are used in SD printing
796
-
797
-  static bool stop_buffering=false;
798
-  if(buflen==0) stop_buffering=false;
799
-
800
-  while( !card.eof()  && buflen < BUFSIZE && !stop_buffering) {
801
-    int16_t n=card.get();
802
-    serial_char = (char)n;
803
-    if(serial_char == '\n' ||
804
-       serial_char == '\r' ||
805
-       (serial_char == '#' && comment_mode == false) ||
806
-       (serial_char == ':' && comment_mode == false) ||
807
-       serial_count >= (MAX_CMD_SIZE - 1)||n==-1)
808
-    {
809
-      if(card.eof()){
810
-        SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
811
-        stoptime=millis();
812
-        char time[30];
813
-        unsigned long t=(stoptime-starttime)/1000;
814
-        int hours, minutes;
815
-        minutes=(t/60)%60;
816
-        hours=t/60/60;
817
-        sprintf_P(time, PSTR("%i "MSG_END_HOUR" %i "MSG_END_MINUTE),hours, minutes);
818
-        SERIAL_ECHO_START;
819
-        SERIAL_ECHOLN(time);
820
-        lcd_setstatus(time, true);
821
-        card.printingHasFinished();
822
-        card.checkautostart(true);
779
+  #ifdef SDSUPPORT
823 780
 
824
-      }
825
-      if(serial_char=='#')
826
-        stop_buffering=true;
781
+    if (!card.sdprinting || serial_count) return;
782
+
783
+    // '#' stops reading from SD to the buffer prematurely, so procedural macro calls are possible
784
+    // if it occurs, stop_buffering is triggered and the buffer is ran dry.
785
+    // this character _can_ occur in serial com, due to checksums. however, no checksums are used in SD printing
786
+
787
+    static bool stop_buffering = false;
788
+    if (buflen == 0) stop_buffering = false;
789
+
790
+    while (!card.eof() && buflen < BUFSIZE && !stop_buffering) {
791
+      int16_t n = card.get();
792
+      serial_char = (char)n;
793
+      if (serial_char == '\n' || serial_char == '\r' ||
794
+          ((serial_char == '#' || serial_char == ':') && !comment_mode) ||
795
+          serial_count >= (MAX_CMD_SIZE - 1) || n == -1
796
+      ) {
797
+        if (card.eof()) {
798
+          SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
799
+          stoptime = millis();
800
+          char time[30];
801
+          millis_t t = (stoptime - starttime) / 1000;
802
+          int hours = t / 60 / 60, minutes = (t / 60) % 60;
803
+          sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
804
+          SERIAL_ECHO_START;
805
+          SERIAL_ECHOLN(time);
806
+          lcd_setstatus(time, true);
807
+          card.printingHasFinished();
808
+          card.checkautostart(true);
809
+        }
810
+        if (serial_char == '#') stop_buffering = true;
827 811
 
828
-      if(!serial_count)
829
-      {
830
-        comment_mode = false; //for new command
831
-        return; //if empty line
832
-      }
833
-      cmdbuffer[bufindw][serial_count] = 0; //terminate string
834
-//      if(!comment_mode){
812
+        if (!serial_count) {
813
+          comment_mode = false; //for new command
814
+          return; //if empty line
815
+        }
816
+        cmdbuffer[bufindw][serial_count] = 0; //terminate string
817
+        // if (!comment_mode) {
835 818
         fromsd[bufindw] = true;
836 819
         buflen += 1;
837 820
         bufindw = (bufindw + 1)%BUFSIZE;
838
-//      }
839
-      comment_mode = false; //for new command
840
-      serial_count = 0; //clear buffer
841
-    }
842
-    else
843
-    {
844
-      if(serial_char == ';') comment_mode = true;
845
-      if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
821
+        // }
822
+        comment_mode = false; //for new command
823
+        serial_count = 0; //clear buffer
824
+      }
825
+      else {
826
+        if (serial_char == ';') comment_mode = true;
827
+        if (!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
828
+      }
846 829
     }
847
-  }
848
-
849
-  #endif //SDSUPPORT
850 830
 
831
+  #endif // SDSUPPORT
851 832
 }
852 833
 
853 834
 float code_has_value() {
@@ -923,7 +904,7 @@ XYZ_CONSTS_FROM_CONFIG(signed char, home_dir,  HOME_DIR);
923 904
   static float inactive_extruder_x_pos = X2_MAX_POS; // used in mode 0 & 1
924 905
   static bool active_extruder_parked = false; // used in mode 1 & 2
925 906
   static float raised_parked_position[NUM_AXIS]; // used in mode 1
926
-  static unsigned long delayed_move_time = 0; // used in mode 1
907
+  static millis_t delayed_move_time = 0; // used in mode 1
927 908
   static float duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // used in mode 2
928 909
   static float duplicate_extruder_temp_offset = 0; // used in mode 2
929 910
   bool extruder_duplication_enabled = false; // used in mode 2
@@ -1111,7 +1092,7 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1111 1092
       // move down slowly until you find the bed
1112 1093
       feedrate = homing_feedrate[Z_AXIS] / 4;
1113 1094
       destination[Z_AXIS] = -10;
1114
-      prepare_move_raw();
1095
+      prepare_move_raw(); // this will also set_current_to_destination
1115 1096
       st_synchronize();
1116 1097
       endstops_hit_on_purpose(); // clear endstop hit flags
1117 1098
       
@@ -1157,7 +1138,8 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1157 1138
   }
1158 1139
 
1159 1140
   /**
1160
-   * 
1141
+   *  Plan a move to (X, Y, Z) and set the current_position
1142
+   *  The final current_position may not be the one that was requested
1161 1143
    */
1162 1144
   static void do_blocking_move_to(float x, float y, float z) {
1163 1145
     float oldFeedRate = feedrate;
@@ -1169,7 +1151,7 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1169 1151
       destination[X_AXIS] = x;
1170 1152
       destination[Y_AXIS] = y;
1171 1153
       destination[Z_AXIS] = z;
1172
-      prepare_move_raw();
1154
+      prepare_move_raw(); // this will also set_current_to_destination
1173 1155
       st_synchronize();
1174 1156
 
1175 1157
     #else
@@ -1233,17 +1215,17 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1233 1215
       destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_X;
1234 1216
       destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_Y;
1235 1217
       destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_Z;
1236
-      prepare_move_raw();
1218
+      prepare_move_raw(); // this will also set_current_to_destination
1237 1219
 
1238 1220
       // Home X to touch the belt
1239 1221
       feedrate = homing_feedrate[X_AXIS]/10;
1240 1222
       destination[X_AXIS] = 0;
1241
-      prepare_move_raw();
1223
+      prepare_move_raw(); // this will also set_current_to_destination
1242 1224
       
1243 1225
       // Home Y for safety
1244 1226
       feedrate = homing_feedrate[X_AXIS]/2;
1245 1227
       destination[Y_AXIS] = 0;
1246
-      prepare_move_raw();
1228
+      prepare_move_raw(); // this will also set_current_to_destination
1247 1229
       
1248 1230
       st_synchronize();
1249 1231
 
@@ -1275,7 +1257,7 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1275 1257
       if (servo_endstops[Z_AXIS] >= 0) {
1276 1258
 
1277 1259
         #if Z_RAISE_AFTER_PROBING > 0
1278
-          do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING);
1260
+          do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING); // this also updates current_position
1279 1261
           st_synchronize();
1280 1262
         #endif
1281 1263
 
@@ -1296,29 +1278,29 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1296 1278
       // Move up for safety
1297 1279
       feedrate = homing_feedrate[X_AXIS];
1298 1280
       destination[Z_AXIS] = current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING;
1299
-      prepare_move_raw();
1281
+      prepare_move_raw(); // this will also set_current_to_destination
1300 1282
 
1301 1283
       // Move to the start position to initiate retraction
1302 1284
       destination[X_AXIS] = Z_PROBE_ALLEN_KEY_STOW_X;
1303 1285
       destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_STOW_Y;
1304 1286
       destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_STOW_Z;
1305
-      prepare_move_raw();
1287
+      prepare_move_raw(); // this will also set_current_to_destination
1306 1288
 
1307 1289
       // Move the nozzle down to push the probe into retracted position
1308 1290
       feedrate = homing_feedrate[Z_AXIS]/10;
1309 1291
       destination[Z_AXIS] = current_position[Z_AXIS] - Z_PROBE_ALLEN_KEY_STOW_DEPTH;
1310
-      prepare_move_raw();
1292
+      prepare_move_raw(); // this will also set_current_to_destination
1311 1293
       
1312 1294
       // Move up for safety
1313 1295
       feedrate = homing_feedrate[Z_AXIS]/2;
1314 1296
       destination[Z_AXIS] = current_position[Z_AXIS] + Z_PROBE_ALLEN_KEY_STOW_DEPTH * 2;
1315
-      prepare_move_raw();
1297
+      prepare_move_raw(); // this will also set_current_to_destination
1316 1298
       
1317 1299
       // Home XY for safety
1318 1300
       feedrate = homing_feedrate[X_AXIS]/2;
1319 1301
       destination[X_AXIS] = 0;
1320 1302
       destination[Y_AXIS] = 0;
1321
-      prepare_move_raw();
1303
+      prepare_move_raw(); // this will also set_current_to_destination
1322 1304
       
1323 1305
       st_synchronize();
1324 1306
 
@@ -1352,8 +1334,8 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1352 1334
   // Probe bed height at position (x,y), returns the measured z value
1353 1335
   static float probe_pt(float x, float y, float z_before, ProbeAction retract_action=ProbeDeployAndStow, int verbose_level=1) {
1354 1336
     // move to right place
1355
-    do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before);
1356
-    do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
1337
+    do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before); // this also updates current_position
1338
+    do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]); // this also updates current_position
1357 1339
 
1358 1340
     #if !defined(Z_PROBE_SLED) && !defined(Z_PROBE_ALLEN_KEY)
1359 1341
       if (retract_action & ProbeDeploy) deploy_z_probe();
@@ -1364,7 +1346,7 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1364 1346
 
1365 1347
     #if Z_RAISE_BETWEEN_PROBINGS > 0
1366 1348
       if (retract_action == ProbeStay) {
1367
-        do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1349
+        do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS); // this also updates current_position
1368 1350
         st_synchronize();
1369 1351
       }
1370 1352
     #endif
@@ -1643,12 +1625,12 @@ static void homeaxis(AxisEnum axis) {
1643 1625
     }
1644 1626
 
1645 1627
     if (dock) {
1646
-      do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, current_position[Y_AXIS], current_position[Z_AXIS]);
1628
+      do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, current_position[Y_AXIS], current_position[Z_AXIS]); // this also updates current_position
1647 1629
       digitalWrite(SERVO0_PIN, LOW); // turn off magnet
1648 1630
     } else {
1649 1631
       float z_loc = current_position[Z_AXIS];
1650 1632
       if (z_loc < Z_RAISE_BEFORE_PROBING + 5) z_loc = Z_RAISE_BEFORE_PROBING;
1651
-      do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, Y_PROBE_OFFSET_FROM_EXTRUDER, z_loc);
1633
+      do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, Y_PROBE_OFFSET_FROM_EXTRUDER, z_loc); // this also updates current_position
1652 1634
       digitalWrite(SERVO0_PIN, HIGH); // turn on magnet
1653 1635
     }
1654 1636
   }
@@ -1700,7 +1682,7 @@ inline void gcode_G2_G3(bool clockwise) {
1700 1682
  * G4: Dwell S<seconds> or P<milliseconds>
1701 1683
  */
1702 1684
 inline void gcode_G4() {
1703
-  unsigned long codenum = 0;
1685
+  millis_t codenum = 0;
1704 1686
 
1705 1687
   LCD_MESSAGEPGM(MSG_DWELL);
1706 1688
 
@@ -1709,7 +1691,7 @@ inline void gcode_G4() {
1709 1691
 
1710 1692
   st_synchronize();
1711 1693
   refresh_cmd_timeout();
1712
-  codenum += previous_millis_cmd;  // keep track of when we started waiting
1694
+  codenum += previous_cmd_ms;  // keep track of when we started waiting
1713 1695
   while (millis() < codenum) {
1714 1696
     manage_heater();
1715 1697
     manage_inactivity();
@@ -2096,7 +2078,7 @@ inline void gcode_G28() {
2096 2078
       case MeshStart:
2097 2079
         mbl.reset();
2098 2080
         probe_point = 0;
2099
-        enquecommands_P(PSTR("G28\nG29 S2"));
2081
+        enqueuecommands_P(PSTR("G28\nG29 S2"));
2100 2082
         break;
2101 2083
 
2102 2084
       case MeshNext:
@@ -2135,7 +2117,7 @@ inline void gcode_G28() {
2135 2117
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
2136 2118
           probe_point = -1;
2137 2119
           mbl.active = 1;
2138
-          enquecommands_P(PSTR("G28"));
2120
+          enqueuecommands_P(PSTR("G28"));
2139 2121
         }
2140 2122
         break;
2141 2123
 
@@ -2517,7 +2499,7 @@ inline void gcode_G28() {
2517 2499
     #endif
2518 2500
 
2519 2501
     #ifdef Z_PROBE_END_SCRIPT
2520
-      enquecommands_P(PSTR(Z_PROBE_END_SCRIPT));
2502
+      enqueuecommands_P(PSTR(Z_PROBE_END_SCRIPT));
2521 2503
       st_synchronize();
2522 2504
     #endif
2523 2505
   }
@@ -2579,7 +2561,7 @@ inline void gcode_G92() {
2579 2561
   inline void gcode_M0_M1() {
2580 2562
     char *src = strchr_pointer + 2;
2581 2563
 
2582
-    unsigned long codenum = 0;
2564
+    millis_t codenum = 0;
2583 2565
     bool hasP = false, hasS = false;
2584 2566
     if (code_seen('P')) {
2585 2567
       codenum = code_value_short(); // milliseconds to wait
@@ -2605,7 +2587,7 @@ inline void gcode_G92() {
2605 2587
     st_synchronize();
2606 2588
     refresh_cmd_timeout();
2607 2589
     if (codenum > 0) {
2608
-      codenum += previous_millis_cmd;  // keep track of when we started waiting
2590
+      codenum += previous_cmd_ms;  // keep track of when we started waiting
2609 2591
       while(millis() < codenum && !lcd_clicked()) {
2610 2592
         manage_heater();
2611 2593
         manage_inactivity();
@@ -2747,7 +2729,7 @@ inline void gcode_M17() {
2747 2729
  */
2748 2730
 inline void gcode_M31() {
2749 2731
   stoptime = millis();
2750
-  unsigned long t = (stoptime - starttime) / 1000;
2732
+  millis_t t = (stoptime - starttime) / 1000;
2751 2733
   int min = t / 60, sec = t % 60;
2752 2734
   char time[30];
2753 2735
   sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
@@ -2980,11 +2962,11 @@ inline void gcode_M42() {
2980 2962
     if (deploy_probe_for_each_reading) stow_z_probe();
2981 2963
 
2982 2964
     for (uint8_t n=0; n < n_samples; n++) {
2983
-
2984
-      do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // Make sure we are at the probe location
2965
+      // Make sure we are at the probe location
2966
+      do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // this also updates current_position
2985 2967
 
2986 2968
       if (n_legs) {
2987
-        unsigned long ms = millis();
2969
+        millis_t ms = millis();
2988 2970
         double radius = ms % (X_MAX_LENGTH / 4),       // limit how far out to go
2989 2971
                theta = RADIANS(ms % 360L);
2990 2972
         float dir = (ms & 0x0001) ? 1 : -1;            // clockwise or counter clockwise
@@ -3011,11 +2993,12 @@ inline void gcode_M42() {
3011 2993
             SERIAL_EOL;
3012 2994
           }
3013 2995
 
3014
-          do_blocking_move_to(X_current, Y_current, Z_current);
2996
+          do_blocking_move_to(X_current, Y_current, Z_current); // this also updates current_position
3015 2997
 
3016 2998
         } // n_legs loop
3017 2999
 
3018
-        do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // Go back to the probe location
3000
+        // Go back to the probe location
3001
+        do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // this also updates current_position
3019 3002
 
3020 3003
       } // n_legs
3021 3004
 
@@ -3221,7 +3204,7 @@ inline void gcode_M109() {
3221 3204
 
3222 3205
   setWatch();
3223 3206
 
3224
-  unsigned long timetemp = millis();
3207
+  millis_t temp_ms = millis();
3225 3208
 
3226 3209
   /* See if we are heating up or cooling down */
3227 3210
   target_direction = isHeatingHotend(target_extruder); // true if heating, false if cooling
@@ -3229,26 +3212,26 @@ inline void gcode_M109() {
3229 3212
   cancel_heatup = false;
3230 3213
 
3231 3214
   #ifdef TEMP_RESIDENCY_TIME
3232
-    long residencyStart = -1;
3215
+    long residency_start_ms = -1;
3233 3216
     /* continue to loop until we have reached the target temp
3234 3217
       _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
3235
-    while((!cancel_heatup)&&((residencyStart == -1) ||
3236
-          (residencyStart >= 0 && (((unsigned int) (millis() - residencyStart)) < (TEMP_RESIDENCY_TIME * 1000UL)))) )
3218
+    while((!cancel_heatup)&&((residency_start_ms == -1) ||
3219
+          (residency_start_ms >= 0 && (((unsigned int) (millis() - residency_start_ms)) < (TEMP_RESIDENCY_TIME * 1000UL)))) )
3237 3220
   #else
3238 3221
     while ( target_direction ? (isHeatingHotend(target_extruder)) : (isCoolingHotend(target_extruder)&&(CooldownNoWait==false)) )
3239 3222
   #endif //TEMP_RESIDENCY_TIME
3240 3223
 
3241 3224
     { // while loop
3242
-      if (millis() > timetemp + 1000UL) { //Print temp & remaining time every 1s while waiting
3225
+      if (millis() > temp_ms + 1000UL) { //Print temp & remaining time every 1s while waiting
3243 3226
         SERIAL_PROTOCOLPGM("T:");
3244 3227
         SERIAL_PROTOCOL_F(degHotend(target_extruder),1);
3245 3228
         SERIAL_PROTOCOLPGM(" E:");
3246 3229
         SERIAL_PROTOCOL((int)target_extruder);
3247 3230
         #ifdef TEMP_RESIDENCY_TIME
3248 3231
           SERIAL_PROTOCOLPGM(" W:");
3249
-          if (residencyStart > -1) {
3250
-            timetemp = ((TEMP_RESIDENCY_TIME * 1000UL) - (millis() - residencyStart)) / 1000UL;
3251
-            SERIAL_PROTOCOLLN( timetemp );
3232
+          if (residency_start_ms > -1) {
3233
+            temp_ms = ((TEMP_RESIDENCY_TIME * 1000UL) - (millis() - residency_start_ms)) / 1000UL;
3234
+            SERIAL_PROTOCOLLN(temp_ms);
3252 3235
           }
3253 3236
           else {
3254 3237
             SERIAL_PROTOCOLLNPGM("?");
@@ -3256,7 +3239,7 @@ inline void gcode_M109() {
3256 3239
         #else
3257 3240
           SERIAL_EOL;
3258 3241
         #endif
3259
-        timetemp = millis();
3242
+        temp_ms = millis();
3260 3243
       }
3261 3244
       manage_heater();
3262 3245
       manage_inactivity();
@@ -3264,18 +3247,18 @@ inline void gcode_M109() {
3264 3247
       #ifdef TEMP_RESIDENCY_TIME
3265 3248
         // start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
3266 3249
         // or when current temp falls outside the hysteresis after target temp was reached
3267
-        if ((residencyStart == -1 &&  target_direction && (degHotend(target_extruder) >= (degTargetHotend(target_extruder)-TEMP_WINDOW))) ||
3268
-            (residencyStart == -1 && !target_direction && (degHotend(target_extruder) <= (degTargetHotend(target_extruder)+TEMP_WINDOW))) ||
3269
-            (residencyStart > -1 && labs(degHotend(target_extruder) - degTargetHotend(target_extruder)) > TEMP_HYSTERESIS) )
3250
+        if ((residency_start_ms == -1 &&  target_direction && (degHotend(target_extruder) >= (degTargetHotend(target_extruder)-TEMP_WINDOW))) ||
3251
+            (residency_start_ms == -1 && !target_direction && (degHotend(target_extruder) <= (degTargetHotend(target_extruder)+TEMP_WINDOW))) ||
3252
+            (residency_start_ms > -1 && labs(degHotend(target_extruder) - degTargetHotend(target_extruder)) > TEMP_HYSTERESIS) )
3270 3253
         {
3271
-          residencyStart = millis();
3254
+          residency_start_ms = millis();
3272 3255
         }
3273 3256
       #endif //TEMP_RESIDENCY_TIME
3274 3257
     }
3275 3258
 
3276 3259
   LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
3277 3260
   refresh_cmd_timeout();
3278
-  starttime = previous_millis_cmd;
3261
+  starttime = previous_cmd_ms;
3279 3262
 }
3280 3263
 
3281 3264
 #if HAS_TEMP_BED
@@ -3290,15 +3273,15 @@ inline void gcode_M109() {
3290 3273
     if (CooldownNoWait || code_seen('R'))
3291 3274
       setTargetBed(code_value());
3292 3275
 
3293
-    unsigned long timetemp = millis();
3276
+    millis_t temp_ms = millis();
3294 3277
     
3295 3278
     cancel_heatup = false;
3296 3279
     target_direction = isHeatingBed(); // true if heating, false if cooling
3297 3280
 
3298 3281
     while ( (target_direction)&&(!cancel_heatup) ? (isHeatingBed()) : (isCoolingBed()&&(CooldownNoWait==false)) ) {
3299
-      unsigned long ms = millis();
3300
-      if (ms > timetemp + 1000UL) { //Print Temp Reading every 1 second while heating up.
3301
-        timetemp = ms;
3282
+      millis_t ms = millis();
3283
+      if (ms > temp_ms + 1000UL) { //Print Temp Reading every 1 second while heating up.
3284
+        temp_ms = ms;
3302 3285
         float tt = degHotend(active_extruder);
3303 3286
         SERIAL_PROTOCOLPGM("T:");
3304 3287
         SERIAL_PROTOCOL(tt);
@@ -3974,14 +3957,14 @@ inline void gcode_M226() {
3974 3957
 
3975 3958
 #endif // NUM_SERVOS > 0
3976 3959
 
3977
-#if defined(LARGE_FLASH) && (BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER))
3960
+#if BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)
3978 3961
 
3979 3962
   /**
3980 3963
    * M300: Play beep sound S<frequency Hz> P<duration ms>
3981 3964
    */
3982 3965
   inline void gcode_M300() {
3983
-    int beepS = code_seen('S') ? code_value() : 110;
3984
-    int beepP = code_seen('P') ? code_value() : 1000;
3966
+    uint16_t beepS = code_seen('S') ? code_value_short() : 110;
3967
+    uint32_t beepP = code_seen('P') ? code_value_long() : 1000;
3985 3968
     if (beepS > 0) {
3986 3969
       #if BEEPER > 0
3987 3970
         tone(BEEPER, beepS);
@@ -3998,7 +3981,7 @@ inline void gcode_M226() {
3998 3981
     }
3999 3982
   }
4000 3983
 
4001
-#endif // LARGE_FLASH && (BEEPER>0 || ULTRALCD || LCD_USE_I2C_BUZZER)
3984
+#endif // BEEPER>0 || ULTRALCD || LCD_USE_I2C_BUZZER
4002 3985
 
4003 3986
 #ifdef PIDTEMP
4004 3987
 
@@ -4472,24 +4455,10 @@ inline void gcode_M503() {
4472 4455
     LCD_ALERTMESSAGEPGM(MSG_FILAMENTCHANGE);
4473 4456
     uint8_t cnt = 0;
4474 4457
     while (!lcd_clicked()) {
4475
-      cnt++;
4458
+      if (++cnt == 0) lcd_quick_feedback(); // every 256th frame till the lcd is clicked
4476 4459
       manage_heater();
4477 4460
       manage_inactivity(true);
4478 4461
       lcd_update();
4479
-      if (cnt == 0) {
4480
-        #if BEEPER > 0
4481
-          OUT_WRITE(BEEPER,HIGH);
4482
-          delay(3);
4483
-          WRITE(BEEPER,LOW);
4484
-          delay(3);
4485
-        #else
4486
-          #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
4487
-            lcd_buzz(1000/6, 100);
4488
-          #else
4489
-            lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
4490
-          #endif
4491
-        #endif
4492
-      }
4493 4462
     } // while(!lcd_clicked)
4494 4463
 
4495 4464
     //return to normal
@@ -5078,11 +5047,11 @@ void process_commands() {
5078 5047
           break;
5079 5048
       #endif // NUM_SERVOS > 0
5080 5049
 
5081
-      #if defined(LARGE_FLASH) && (BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER))
5050
+      #if BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)
5082 5051
         case 300: // M300 - Play beep tone
5083 5052
           gcode_M300();
5084 5053
           break;
5085
-      #endif // LARGE_FLASH && (BEEPER>0 || ULTRALCD || LCD_USE_I2C_BUZZER)
5054
+      #endif // BEEPER > 0 || ULTRALCD || LCD_USE_I2C_BUZZER
5086 5055
 
5087 5056
       #ifdef PIDTEMP
5088 5057
         case 301: // M301
@@ -5289,25 +5258,23 @@ void get_arc_coordinates() {
5289 5258
   offset[1] = code_seen('J') ? code_value() : 0;
5290 5259
 }
5291 5260
 
5292
-void clamp_to_software_endstops(float target[3])
5293
-{
5261
+void clamp_to_software_endstops(float target[3]) {
5294 5262
   if (min_software_endstops) {
5295
-    if (target[X_AXIS] < min_pos[X_AXIS]) target[X_AXIS] = min_pos[X_AXIS];
5296
-    if (target[Y_AXIS] < min_pos[Y_AXIS]) target[Y_AXIS] = min_pos[Y_AXIS];
5263
+    NOLESS(target[X_AXIS], min_pos[X_AXIS]);
5264
+    NOLESS(target[Y_AXIS], min_pos[Y_AXIS]);
5297 5265
     
5298 5266
     float negative_z_offset = 0;
5299 5267
     #ifdef ENABLE_AUTO_BED_LEVELING
5300
-      if (Z_PROBE_OFFSET_FROM_EXTRUDER < 0) negative_z_offset = negative_z_offset + Z_PROBE_OFFSET_FROM_EXTRUDER;
5301
-      if (home_offset[Z_AXIS] < 0) negative_z_offset = negative_z_offset + home_offset[Z_AXIS];
5268
+      if (Z_PROBE_OFFSET_FROM_EXTRUDER < 0) negative_z_offset += Z_PROBE_OFFSET_FROM_EXTRUDER;
5269
+      if (home_offset[Z_AXIS] < 0) negative_z_offset += home_offset[Z_AXIS];
5302 5270
     #endif
5303
-    
5304
-    if (target[Z_AXIS] < min_pos[Z_AXIS]+negative_z_offset) target[Z_AXIS] = min_pos[Z_AXIS]+negative_z_offset;
5271
+    NOLESS(target[Z_AXIS], min_pos[Z_AXIS] + negative_z_offset);
5305 5272
   }
5306 5273
 
5307 5274
   if (max_software_endstops) {
5308
-    if (target[X_AXIS] > max_pos[X_AXIS]) target[X_AXIS] = max_pos[X_AXIS];
5309
-    if (target[Y_AXIS] > max_pos[Y_AXIS]) target[Y_AXIS] = max_pos[Y_AXIS];
5310
-    if (target[Z_AXIS] > max_pos[Z_AXIS]) target[Z_AXIS] = max_pos[Z_AXIS];
5275
+    NOMORE(target[X_AXIS], max_pos[X_AXIS]);
5276
+    NOMORE(target[Y_AXIS], max_pos[Y_AXIS]);
5277
+    NOMORE(target[Z_AXIS], max_pos[Z_AXIS]);
5311 5278
   }
5312 5279
 }
5313 5280
 
@@ -5522,7 +5489,7 @@ void prepare_move() {
5522 5489
       //SERIAL_ECHOPGM("delta[Y_AXIS]="); SERIAL_ECHOLN(delta[Y_AXIS]);
5523 5490
       //SERIAL_ECHOPGM("delta[Z_AXIS]="); SERIAL_ECHOLN(delta[Z_AXIS]);
5524 5491
 
5525
-      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
5492
+      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], feedrate/60*feedmultiply/100.0, active_extruder);
5526 5493
     }
5527 5494
 
5528 5495
   #endif // SCARA
@@ -5549,7 +5516,7 @@ void prepare_move() {
5549 5516
       #ifdef ENABLE_AUTO_BED_LEVELING
5550 5517
         adjust_delta(destination);
5551 5518
       #endif
5552
-      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
5519
+      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], feedrate/60*feedmultiply/100.0, active_extruder);
5553 5520
     }
5554 5521
 
5555 5522
   #endif // DELTA
@@ -5573,7 +5540,7 @@ void prepare_move() {
5573 5540
           // (so it can be used as the start of the next non-travel move)
5574 5541
           if (delayed_move_time != 0xFFFFFFFFUL) {
5575 5542
             set_current_to_destination();
5576
-            if (destination[Z_AXIS] > raised_parked_position[Z_AXIS]) raised_parked_position[Z_AXIS] = destination[Z_AXIS];
5543
+            NOLESS(raised_parked_position[Z_AXIS], destination[Z_AXIS]);
5577 5544
             delayed_move_time = millis();
5578 5545
             return;
5579 5546
           }
@@ -5621,11 +5588,11 @@ void prepare_arc_move(char isclockwise) {
5621 5588
 
5622 5589
 #if HAS_CONTROLLERFAN
5623 5590
 
5624
-unsigned long lastMotor = 0; // Last time a motor was turned on
5625
-unsigned long lastMotorCheck = 0; // Last time the state was checked
5591
+millis_t lastMotor = 0; // Last time a motor was turned on
5592
+millis_t lastMotorCheck = 0; // Last time the state was checked
5626 5593
 
5627 5594
 void controllerFan() {
5628
-  uint32_t ms = millis();
5595
+  millis_t ms = millis();
5629 5596
   if (ms >= lastMotorCheck + 2500) { // Not a time critical function, so we only check every 2500ms
5630 5597
     lastMotorCheck = ms;
5631 5598
     if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || soft_pwm_bed > 0
@@ -5732,36 +5699,28 @@ void calculate_delta(float cartesian[3]){
5732 5699
 #endif
5733 5700
 
5734 5701
 #ifdef TEMP_STAT_LEDS
5735
-static bool blue_led = false;
5736
-static bool red_led = false;
5737
-static uint32_t stat_update = 0;
5738
-
5739
-void handle_status_leds(void) {
5740
-  float max_temp = 0.0;
5741
-  if(millis() > stat_update) {
5742
-    stat_update += 500; // Update every 0.5s
5743
-    for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) {
5744
-       max_temp = max(max_temp, degHotend(cur_extruder));
5745
-       max_temp = max(max_temp, degTargetHotend(cur_extruder));
5746
-    }
5747
-    #if HAS_TEMP_BED
5748
-      max_temp = max(max_temp, degTargetBed());
5749
-      max_temp = max(max_temp, degBed());
5750
-    #endif
5751
-    if((max_temp > 55.0) && (red_led == false)) {
5752
-      digitalWrite(STAT_LED_RED, 1);
5753
-      digitalWrite(STAT_LED_BLUE, 0);
5754
-      red_led = true;
5755
-      blue_led = false;
5756
-    }
5757
-    if((max_temp < 54.0) && (blue_led == false)) {
5758
-      digitalWrite(STAT_LED_RED, 0);
5759
-      digitalWrite(STAT_LED_BLUE, 1);
5760
-      red_led = false;
5761
-      blue_led = true;
5702
+
5703
+  static bool red_led = false;
5704
+  static millis_t next_status_led_update_ms = 0;
5705
+
5706
+  void handle_status_leds(void) {
5707
+    float max_temp = 0.0;
5708
+    if (millis() > next_status_led_update_ms) {
5709
+      next_status_led_update_ms += 500; // Update every 0.5s
5710
+      for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder)
5711
+         max_temp = max(max(max_temp, degHotend(cur_extruder)), degTargetHotend(cur_extruder));
5712
+      #if HAS_TEMP_BED
5713
+        max_temp = max(max(max_temp, degTargetBed()), degBed());
5714
+      #endif
5715
+      bool new_led = (max_temp > 55.0) ? true : (max_temp < 54.0) ? false : red_led;
5716
+      if (new_led != red_led) {
5717
+        red_led = new_led;
5718
+        digitalWrite(STAT_LED_RED, new_led ? HIGH : LOW);
5719
+        digitalWrite(STAT_LED_BLUE, new_led ? LOW : HIGH);
5720
+      }
5762 5721
     }
5763 5722
   }
5764
-}
5723
+
5765 5724
 #endif
5766 5725
 
5767 5726
 void enable_all_steppers() {
@@ -5805,11 +5764,11 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
5805 5764
 
5806 5765
   if (buflen < BUFSIZE - 1) get_command();
5807 5766
 
5808
-  unsigned long ms = millis();
5767
+  millis_t ms = millis();
5809 5768
 
5810
-  if (max_inactive_time && ms > previous_millis_cmd + max_inactive_time) kill();
5769
+  if (max_inactive_time && ms > previous_cmd_ms + max_inactive_time) kill();
5811 5770
 
5812
-  if (stepper_inactive_time && ms > previous_millis_cmd + stepper_inactive_time
5771
+  if (stepper_inactive_time && ms > previous_cmd_ms + stepper_inactive_time
5813 5772
       && !ignore_stepper_queue && !blocks_queued())
5814 5773
     disable_all_steppers();
5815 5774
 
@@ -5845,7 +5804,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
5845 5804
     const int HOME_DEBOUNCE_DELAY = 750;
5846 5805
     if (!READ(HOME_PIN)) {
5847 5806
       if (!homeDebounceCount) {
5848
-        enquecommands_P(PSTR("G28"));
5807
+        enqueuecommands_P(PSTR("G28"));
5849 5808
         LCD_ALERTMESSAGEPGM(MSG_AUTO_HOME);
5850 5809
       }
5851 5810
       if (homeDebounceCount < HOME_DEBOUNCE_DELAY)
@@ -5860,7 +5819,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
5860 5819
   #endif
5861 5820
 
5862 5821
   #ifdef EXTRUDER_RUNOUT_PREVENT
5863
-    if (ms > previous_millis_cmd + EXTRUDER_RUNOUT_SECONDS * 1000)
5822
+    if (ms > previous_cmd_ms + EXTRUDER_RUNOUT_SECONDS * 1000)
5864 5823
     if (degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP) {
5865 5824
       bool oldstatus;
5866 5825
       switch(active_extruder) {
@@ -5894,7 +5853,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
5894 5853
       current_position[E_AXIS] = oldepos;
5895 5854
       destination[E_AXIS] = oldedes;
5896 5855
       plan_set_e_position(oldepos);
5897
-      previous_millis_cmd = ms; // refresh_cmd_timeout()
5856
+      previous_cmd_ms = ms; // refresh_cmd_timeout()
5898 5857
       st_synchronize();
5899 5858
       switch(active_extruder) {
5900 5859
         case 0:
@@ -5964,7 +5923,7 @@ void kill()
5964 5923
    {
5965 5924
       if filrunoutEnqued == false {
5966 5925
          filrunoutEnqued = true;
5967
-         enquecommand("M600");
5926
+         enqueuecommand("M600");
5968 5927
       }
5969 5928
    }
5970 5929
 #endif

+ 5
- 5
Marlin/cardreader.cpp View File

@@ -25,7 +25,7 @@ CardReader::CardReader() {
25 25
     OUT_WRITE(SDPOWER, HIGH);
26 26
   #endif //SDPOWER
27 27
 
28
-  autostart_atmillis = millis() + 5000;
28
+  next_autostart_ms = millis() + 5000;
29 29
 }
30 30
 
31 31
 char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
@@ -397,7 +397,7 @@ void CardReader::write_command(char *buf) {
397 397
 }
398 398
 
399 399
 void CardReader::checkautostart(bool force) {
400
-  if (!force && (!autostart_stilltocheck || autostart_atmillis < millis()))
400
+  if (!force && (!autostart_stilltocheck || next_autostart_ms < millis()))
401 401
     return;
402 402
 
403 403
   autostart_stilltocheck = false;
@@ -421,8 +421,8 @@ void CardReader::checkautostart(bool force) {
421 421
     if (p.name[9] != '~' && strncmp((char*)p.name, autoname, 5) == 0) {
422 422
       char cmd[30];
423 423
       sprintf_P(cmd, PSTR("M23 %s"), autoname);
424
-      enquecommand(cmd);
425
-      enquecommands_P(PSTR("M24"));
424
+      enqueuecommand(cmd);
425
+      enqueuecommands_P(PSTR("M24"));
426 426
       found = true;
427 427
     }
428 428
   }
@@ -508,7 +508,7 @@ void CardReader::printingHasFinished() {
508 508
     sdprinting = false;
509 509
     if (SD_FINISHED_STEPPERRELEASE) {
510 510
       //finishAndDisableSteppers();
511
-      enquecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
511
+      enqueuecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
512 512
     }
513 513
     autotempShutdown();
514 514
   }

+ 1
- 1
Marlin/cardreader.h View File

@@ -62,7 +62,7 @@ private:
62 62
   uint32_t filespos[SD_PROCEDURE_DEPTH];
63 63
   char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
64 64
   uint32_t filesize;
65
-  unsigned long autostart_atmillis;
65
+  millis_t next_autostart_ms;
66 66
   uint32_t sdpos;
67 67
 
68 68
   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.

+ 1
- 1
Marlin/dogm_lcd_implementation.h View File

@@ -350,7 +350,7 @@ static void lcd_implementation_status_screen() {
350 350
   #ifndef FILAMENT_LCD_DISPLAY
351 351
     lcd_print(lcd_status_message);
352 352
   #else
353
-    if (millis() < message_millis + 5000) {  //Display both Status message line and Filament display on the last line
353
+    if (millis() < previous_lcd_status_ms + 5000) {  //Display both Status message line and Filament display on the last line
354 354
       lcd_print(lcd_status_message);
355 355
     }
356 356
     else {

+ 1
- 3
Marlin/example_configurations/Hephestos/Configuration.h View File

@@ -58,9 +58,7 @@ Here are some standard links for getting your machine calibrated:
58 58
 
59 59
 // The following define selects which electronics board you have.
60 60
 // Please choose the name from boards.h that matches your setup
61
-#ifndef MOTHERBOARD
62
-  #define MOTHERBOARD BOARD_HEPHESTOS
63
-#endif
61
+#define MOTHERBOARD BOARD_HEPHESTOS
64 62
 
65 63
 // Optional custom name for your RepStrap or other custom machine
66 64
 // Displayed in the LCD "Ready" message

+ 1
- 3
Marlin/example_configurations/WITBOX/Configuration.h View File

@@ -58,9 +58,7 @@ Here are some standard links for getting your machine calibrated:
58 58
 
59 59
 // The following define selects which electronics board you have.
60 60
 // Please choose the name from boards.h that matches your setup
61
-#ifndef MOTHERBOARD
62
-  #define MOTHERBOARD BOARD_WITBOX
63
-#endif
61
+#define MOTHERBOARD BOARD_WITBOX
64 62
 
65 63
 // Optional custom name for your RepStrap or other custom machine
66 64
 // Displayed in the LCD "Ready" message

+ 14
- 12
Marlin/planner.cpp View File

@@ -60,13 +60,13 @@
60 60
 
61 61
 #ifdef MESH_BED_LEVELING
62 62
   #include "mesh_bed_leveling.h"
63
-#endif  // MESH_BED_LEVELING
63
+#endif
64 64
 
65 65
 //===========================================================================
66 66
 //============================= public variables ============================
67 67
 //===========================================================================
68 68
 
69
-unsigned long minsegmenttime;
69
+millis_t minsegmenttime;
70 70
 float max_feedrate[NUM_AXIS]; // Max speeds in mm per minute
71 71
 float axis_steps_per_unit[NUM_AXIS];
72 72
 unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
@@ -159,8 +159,8 @@ void calculate_trapezoid_for_block(block_t *block, float entry_factor, float exi
159 159
   unsigned long final_rate = ceil(block->nominal_rate * exit_factor); // (step/min)
160 160
 
161 161
   // Limit minimal step rate (Otherwise the timer will overflow.)
162
-  if (initial_rate < 120) initial_rate = 120;
163
-  if (final_rate < 120) final_rate = 120;
162
+  NOLESS(initial_rate, 120);
163
+  NOLESS(final_rate, 120);
164 164
 
165 165
   long acceleration = block->acceleration_st;
166 166
   int32_t accelerate_steps = ceil(estimate_acceleration_distance(initial_rate, block->nominal_rate, acceleration));
@@ -382,9 +382,11 @@ void plan_init() {
382 382
     }
383 383
 
384 384
     float t = autotemp_min + high * autotemp_factor;
385
-    if (t < autotemp_min) t = autotemp_min;
386
-    if (t > autotemp_max) t = autotemp_max;
387
-    if (oldt > t) t = AUTOTEMP_OLDWEIGHT * oldt + (1 - AUTOTEMP_OLDWEIGHT) * t;
385
+    t = constrain(t, autotemp_min, autotemp_max);
386
+    if (oldt > t) {
387
+      t *= (1 - AUTOTEMP_OLDWEIGHT);
388
+      t += AUTOTEMP_OLDWEIGHT * oldt;
389
+    }
388 390
     oldt = t;
389 391
     setTargetHotend0(t);
390 392
   }
@@ -426,7 +428,7 @@ void check_axes_activity() {
426 428
 
427 429
   #if HAS_FAN
428 430
     #ifdef FAN_KICKSTART_TIME
429
-      static unsigned long fan_kick_end;
431
+      static millis_t fan_kick_end;
430 432
       if (tail_fan_speed) {
431 433
         if (fan_kick_end == 0) {
432 434
           // Just starting up fan - run at full power.
@@ -651,10 +653,10 @@ float junction_deviation = 0.1;
651 653
     }
652 654
   }
653 655
 
654
-  if (block->steps[E_AXIS]) {
655
-    if (feed_rate < minimumfeedrate) feed_rate = minimumfeedrate;
656
-  }
657
-  else if (feed_rate < mintravelfeedrate) feed_rate = mintravelfeedrate;
656
+  if (block->steps[E_AXIS])
657
+    NOLESS(feed_rate, minimumfeedrate);
658
+  else
659
+    NOLESS(feed_rate, mintravelfeedrate);
658 660
 
659 661
   /**
660 662
    * This part of the code calculates the total length of the movement. 

+ 1
- 1
Marlin/planner.h View File

@@ -115,7 +115,7 @@ FORCE_INLINE uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block
115 115
 
116 116
 void plan_set_e_position(const float &e);
117 117
 
118
-extern unsigned long minsegmenttime;
118
+extern millis_t minsegmenttime;
119 119
 extern float max_feedrate[NUM_AXIS]; // set the max speeds
120 120
 extern float axis_steps_per_unit[NUM_AXIS];
121 121
 extern unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software

+ 3
- 3
Marlin/stepper.cpp View File

@@ -400,7 +400,7 @@ ISR(TIMER1_COMPA_vect) {
400 400
     current_block = NULL;
401 401
     plan_discard_current_block();
402 402
     #ifdef SD_FINISHED_RELEASECOMMAND
403
-      if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enquecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
403
+      if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enqueuecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
404 404
     #endif
405 405
     cleaning_buffer_counter--;
406 406
     OCR1A = 200;
@@ -718,7 +718,7 @@ ISR(TIMER1_COMPA_vect) {
718 718
     // Calculate new timer value
719 719
     unsigned short timer;
720 720
     unsigned short step_rate;
721
-    if (step_events_completed <= (unsigned long int)current_block->accelerate_until) {
721
+    if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
722 722
 
723 723
       MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
724 724
       acc_step_rate += current_block->initial_rate;
@@ -742,7 +742,7 @@ ISR(TIMER1_COMPA_vect) {
742 742
 
743 743
       #endif
744 744
     }
745
-    else if (step_events_completed > (unsigned long int)current_block->decelerate_after) {
745
+    else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
746 746
       MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
747 747
 
748 748
       if (step_rate > acc_step_rate) { // Check step_rate stays positive

+ 24
- 24
Marlin/temperature.cpp View File

@@ -77,14 +77,14 @@ unsigned char soft_pwm_bed;
77 77
 #define HAS_BED_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 && TEMP_SENSOR_BED != 0)
78 78
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
79 79
   enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway };
80
-  void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
80
+  void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
81 81
   #if HAS_HEATER_THERMAL_PROTECTION
82 82
     static TRState thermal_runaway_state_machine[4] = { TRReset, TRReset, TRReset, TRReset };
83
-    static unsigned long thermal_runaway_timer[4]; // = {0,0,0,0};
83
+    static millis_t thermal_runaway_timer[4]; // = {0,0,0,0};
84 84
   #endif
85 85
   #if HAS_BED_THERMAL_PROTECTION
86 86
     static TRState thermal_runaway_bed_state_machine = TRReset;
87
-    static unsigned long thermal_runaway_bed_timer;
87
+    static millis_t thermal_runaway_bed_timer;
88 88
   #endif
89 89
 #endif
90 90
 
@@ -118,7 +118,7 @@ static volatile bool temp_meas_ready = false;
118 118
   static float temp_iState_min_bed;
119 119
   static float temp_iState_max_bed;
120 120
 #else //PIDTEMPBED
121
-  static unsigned long  previous_millis_bed_heater;
121
+  static millis_t  previous_bed_check_ms;
122 122
 #endif //PIDTEMPBED
123 123
   static unsigned char soft_pwm[EXTRUDERS];
124 124
 
@@ -126,7 +126,7 @@ static volatile bool temp_meas_ready = false;
126 126
   static unsigned char soft_pwm_fan;
127 127
 #endif
128 128
 #if HAS_AUTO_FAN
129
-  static unsigned long extruder_autofan_last_check;
129
+  static millis_t previous_auto_fan_check_ms;
130 130
 #endif  
131 131
 
132 132
 #ifdef PIDTEMP
@@ -171,7 +171,7 @@ static void updateTemperaturesFromRawValues();
171 171
 
172 172
 #ifdef WATCH_TEMP_PERIOD
173 173
   int watch_start_temp[EXTRUDERS] = { 0 };
174
-  unsigned long watchmillis[EXTRUDERS] = { 0 };
174
+  millis_t watchmillis[EXTRUDERS] = { 0 };
175 175
 #endif //WATCH_TEMP_PERIOD
176 176
 
177 177
 #ifndef SOFT_PWM_SCALE
@@ -196,7 +196,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
196 196
   int cycles = 0;
197 197
   bool heating = true;
198 198
 
199
-  unsigned long temp_millis = millis(), t1 = temp_millis, t2 = temp_millis;
199
+  millis_t temp_ms = millis(), t1 = temp_ms, t2 = temp_ms;
200 200
   long t_high = 0, t_low = 0;
201 201
 
202 202
   long bias, d;
@@ -205,7 +205,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
205 205
   float max = 0, min = 10000;
206 206
 
207 207
   #if HAS_AUTO_FAN
208
-        unsigned long extruder_autofan_last_check = temp_millis;
208
+    millis_t previous_auto_fan_check_ms = temp_ms;
209 209
   #endif
210 210
 
211 211
   if (extruder >= EXTRUDERS
@@ -229,7 +229,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
229 229
   // PID Tuning loop
230 230
   for (;;) {
231 231
 
232
-    unsigned long ms = millis();
232
+    millis_t ms = millis();
233 233
 
234 234
     if (temp_meas_ready) { // temp sample ready
235 235
       updateTemperaturesFromRawValues();
@@ -240,9 +240,9 @@ void PID_autotune(float temp, int extruder, int ncycles)
240 240
       min = min(min, input);
241 241
 
242 242
       #if HAS_AUTO_FAN
243
-        if (ms > extruder_autofan_last_check + 2500) {
243
+        if (ms > previous_auto_fan_check_ms + 2500) {
244 244
           checkExtruderAutoFans();
245
-          extruder_autofan_last_check = ms;
245
+          previous_auto_fan_check_ms = ms;
246 246
         }
247 247
       #endif
248 248
 
@@ -317,7 +317,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
317 317
       return;
318 318
     }
319 319
     // Every 2 seconds...
320
-    if (ms > temp_millis + 2000) {
320
+    if (ms > temp_ms + 2000) {
321 321
       int p;
322 322
       if (extruder < 0) {
323 323
         p = soft_pwm_bed;
@@ -332,7 +332,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
332 332
       SERIAL_PROTOCOLPGM(MSG_AT);
333 333
       SERIAL_PROTOCOLLN(p);
334 334
 
335
-      temp_millis = ms;
335
+      temp_ms = ms;
336 336
     } // every 2 seconds
337 337
     // Over 2 minutes?
338 338
     if (((ms - t1) + (ms - t2)) > (10L*60L*1000L*2L)) {
@@ -592,7 +592,7 @@ void manage_heater() {
592 592
   #endif //HEATER_0_USES_MAX6675
593 593
 
594 594
   #if defined(WATCH_TEMP_PERIOD) || !defined(PIDTEMPBED) || HAS_AUTO_FAN
595
-    unsigned long ms = millis();
595
+    millis_t ms = millis();
596 596
   #endif
597 597
 
598 598
   // Loop through all extruders
@@ -631,15 +631,15 @@ void manage_heater() {
631 631
   } // Extruders Loop
632 632
 
633 633
   #if HAS_AUTO_FAN
634
-    if (ms > extruder_autofan_last_check + 2500) { // only need to check fan state very infrequently
634
+    if (ms > previous_auto_fan_check_ms + 2500) { // only need to check fan state very infrequently
635 635
       checkExtruderAutoFans();
636
-      extruder_autofan_last_check = ms;
636
+      previous_auto_fan_check_ms = ms;
637 637
     }
638 638
   #endif       
639 639
   
640 640
   #ifndef PIDTEMPBED
641
-    if (ms < previous_millis_bed_heater + BED_CHECK_INTERVAL) return;
642
-    previous_millis_bed_heater = ms;
641
+    if (ms < previous_bed_check_ms + BED_CHECK_INTERVAL) return;
642
+    previous_bed_check_ms = ms;
643 643
   #endif //PIDTEMPBED
644 644
 
645 645
   #if TEMP_SENSOR_BED != 0
@@ -992,7 +992,7 @@ void tp_init()
992 992
 
993 993
 void setWatch() {
994 994
   #ifdef WATCH_TEMP_PERIOD
995
-    unsigned long ms = millis();
995
+    millis_t ms = millis();
996 996
     for (int e = 0; e < EXTRUDERS; e++) {
997 997
       if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE * 2)) {
998 998
         watch_start_temp[e] = degHotend(e);
@@ -1004,7 +1004,7 @@ void setWatch() {
1004 1004
 
1005 1005
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
1006 1006
 
1007
-  void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1007
+  void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1008 1008
 
1009 1009
     static float tr_target_temperature[EXTRUDERS+1] = { 0.0 };
1010 1010
 
@@ -1109,16 +1109,16 @@ void disable_heater() {
1109 1109
 
1110 1110
 #ifdef HEATER_0_USES_MAX6675
1111 1111
   #define MAX6675_HEAT_INTERVAL 250u
1112
-  unsigned long max6675_previous_millis = MAX6675_HEAT_INTERVAL;
1112
+  millis_t previous_max6675_ms = MAX6675_HEAT_INTERVAL;
1113 1113
   int max6675_temp = 2000;
1114 1114
 
1115 1115
   static int read_max6675() {
1116 1116
 
1117
-    unsigned long ms = millis();
1118
-    if (ms < max6675_previous_millis + MAX6675_HEAT_INTERVAL)
1117
+    millis_t ms = millis();
1118
+    if (ms < previous_max6675_ms + MAX6675_HEAT_INTERVAL)
1119 1119
       return max6675_temp;
1120 1120
     
1121
-    max6675_previous_millis = ms;
1121
+    previous_max6675_ms = ms;
1122 1122
     max6675_temp = 0;
1123 1123
 
1124 1124
     #ifdef PRR

+ 39
- 34
Marlin/ultralcd.cpp View File

@@ -22,7 +22,7 @@ int absPreheatHPBTemp;
22 22
 int absPreheatFanSpeed;
23 23
 
24 24
 #ifdef FILAMENT_LCD_DISPLAY
25
-  unsigned long message_millis = 0;
25
+  millis_t previous_lcd_status_ms = 0;
26 26
 #endif
27 27
 
28 28
 /* !Configuration settings */
@@ -77,8 +77,6 @@ static void lcd_status_screen();
77 77
     static void lcd_level_bed();
78 78
   #endif
79 79
 
80
-  static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
81
-
82 80
   /* Different types of actions that can be used in menu items. */
83 81
   static void menu_action_back(menuFunc_t data);
84 82
   static void menu_action_submenu(menuFunc_t data);
@@ -220,7 +218,7 @@ static void lcd_status_screen();
220 218
     volatile uint8_t slow_buttons; // Bits of the pressed buttons.
221 219
   #endif
222 220
   uint8_t currentMenuViewOffset;              /* scroll offset in the current menu */
223
-  uint32_t blocking_enc;
221
+  millis_t next_button_update_ms;
224 222
   uint8_t lastEncoderBits;
225 223
   uint32_t encoderPosition;
226 224
   #if (SDCARDDETECT > 0)
@@ -230,7 +228,7 @@ static void lcd_status_screen();
230 228
 #endif // ULTIPANEL
231 229
 
232 230
 menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
233
-uint32_t lcd_next_update_millis;
231
+millis_t next_lcd_update_ms;
234 232
 uint8_t lcd_status_update_delay;
235 233
 bool ignore_click = false;
236 234
 bool wait_for_unclick;
@@ -267,7 +265,7 @@ static void lcd_status_screen() {
267 265
 	encoderRateMultiplierEnabled = false;
268 266
 
269 267
   #ifdef LCD_PROGRESS_BAR
270
-    unsigned long ms = millis();
268
+    millis_t ms = millis();
271 269
     #ifndef PROGRESS_MSG_ONCE
272 270
       if (ms > progressBarTick + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
273 271
         progressBarTick = ms;
@@ -324,7 +322,7 @@ static void lcd_status_screen() {
324 322
         #endif
325 323
       );
326 324
       #ifdef FILAMENT_LCD_DISPLAY
327
-        message_millis = millis();  // get status message to show up for a while
325
+        previous_lcd_status_ms = millis();  // get status message to show up for a while
328 326
       #endif
329 327
     }
330 328
 
@@ -433,7 +431,7 @@ void lcd_set_home_offsets() {
433 431
   plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
434 432
 
435 433
   // Audio feedback
436
-  enquecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
434
+  enqueuecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
437 435
   lcd_return_to_status();
438 436
 }
439 437
 
@@ -1114,15 +1112,15 @@ menu_edit_type(unsigned long, long5, ftostr5, 0.01)
1114 1112
     lcd_move_y();
1115 1113
   }
1116 1114
   static void reprapworld_keypad_move_home() {
1117
-    enquecommands_P((PSTR("G28"))); // move all axis home
1115
+    enqueuecommands_P((PSTR("G28"))); // move all axis home
1118 1116
   }
1119 1117
 #endif //REPRAPWORLD_KEYPAD
1120 1118
 
1121 1119
 /** End of menus **/
1122 1120
 
1123
-static void lcd_quick_feedback() {
1121
+void lcd_quick_feedback() {
1124 1122
   lcdDrawUpdate = 2;
1125
-  blocking_enc = millis() + 500;
1123
+  next_button_update_ms = millis() + 500;
1126 1124
     
1127 1125
   #ifdef LCD_USE_I2C_BUZZER
1128 1126
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
@@ -1140,15 +1138,15 @@ static void lcd_quick_feedback() {
1140 1138
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1141 1139
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
1142 1140
     #endif
1143
-    const unsigned int delay = 1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2;
1144
-    int i = LCD_FEEDBACK_FREQUENCY_DURATION_MS * LCD_FEEDBACK_FREQUENCY_HZ / 1000;
1141
+    const uint16_t delay = 1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2;
1142
+    uint16_t i = LCD_FEEDBACK_FREQUENCY_DURATION_MS * LCD_FEEDBACK_FREQUENCY_HZ / 1000;
1145 1143
     while (i--) {
1146 1144
       WRITE(BEEPER,HIGH);
1147 1145
       delayMicroseconds(delay);
1148 1146
       WRITE(BEEPER,LOW);
1149 1147
       delayMicroseconds(delay);
1150 1148
     }
1151
-    const int j = max(10000 - LCD_FEEDBACK_FREQUENCY_DURATION_MS * 1000, 0);
1149
+    const uint16_t j = max(10000 - LCD_FEEDBACK_FREQUENCY_DURATION_MS * 1000, 0);
1152 1150
     if (j) delayMicroseconds(j);
1153 1151
   #endif
1154 1152
 }
@@ -1156,15 +1154,15 @@ static void lcd_quick_feedback() {
1156 1154
 /** Menu action functions **/
1157 1155
 static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
1158 1156
 static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
1159
-static void menu_action_gcode(const char* pgcode) { enquecommands_P(pgcode); }
1157
+static void menu_action_gcode(const char* pgcode) { enqueuecommands_P(pgcode); }
1160 1158
 static void menu_action_function(menuFunc_t data) { (*data)(); }
1161 1159
 static void menu_action_sdfile(const char* filename, char* longFilename) {
1162 1160
   char cmd[30];
1163 1161
   char* c;
1164 1162
   sprintf_P(cmd, PSTR("M23 %s"), filename);
1165 1163
   for(c = &cmd[4]; *c; c++) *c = tolower(*c);
1166
-  enquecommand(cmd);
1167
-  enquecommands_P(PSTR("M24"));
1164
+  enqueuecommand(cmd);
1165
+  enqueuecommands_P(PSTR("M24"));
1168 1166
   lcd_return_to_status();
1169 1167
 }
1170 1168
 static void menu_action_sddirectory(const char* filename, char* longFilename) {
@@ -1252,7 +1250,7 @@ int lcd_strlen_P(const char *s) {
1252 1250
 
1253 1251
 void lcd_update() {
1254 1252
   #ifdef ULTIPANEL
1255
-    static unsigned long timeoutToStatus = 0;
1253
+    static millis_t return_to_status_ms = 0;
1256 1254
   #endif
1257 1255
 
1258 1256
   #ifdef LCD_HAS_SLOW_BUTTONS
@@ -1282,8 +1280,8 @@ void lcd_update() {
1282 1280
     }
1283 1281
   #endif//CARDINSERTED
1284 1282
   
1285
-  uint32_t ms = millis();
1286
-  if (ms > lcd_next_update_millis) {
1283
+  millis_t ms = millis();
1284
+  if (ms > next_lcd_update_ms) {
1287 1285
 
1288 1286
     #ifdef ULTIPANEL
1289 1287
 
@@ -1335,7 +1333,7 @@ void lcd_update() {
1335 1333
           encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
1336 1334
           encoderDiff = 0;
1337 1335
         }
1338
-        timeoutToStatus = ms + LCD_TIMEOUT_TO_STATUS;
1336
+        return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
1339 1337
         lcdDrawUpdate = 1;
1340 1338
       }
1341 1339
     #endif //ULTIPANEL
@@ -1371,20 +1369,24 @@ void lcd_update() {
1371 1369
     #endif
1372 1370
 
1373 1371
     #ifdef ULTIPANEL
1372
+
1373
+      // Return to Status Screen after a timeout
1374 1374
       if (currentMenu != lcd_status_screen &&
1375
-        #if defined(MANUAL_BED_LEVELING)
1376
-          currentMenu != _lcd_level_bed && 
1377
-          currentMenu != _lcd_level_bed_homing && 
1378
-        #endif  // MANUAL_BED_LEVELING
1379
-          millis() > timeoutToStatus) {
1375
+        #ifdef MANUAL_BED_LEVELING
1376
+          currentMenu != _lcd_level_bed &&
1377
+          currentMenu != _lcd_level_bed_homing &&
1378
+        #endif
1379
+        millis() > return_to_status_ms
1380
+      ) {
1380 1381
         lcd_return_to_status();
1381 1382
         lcdDrawUpdate = 2;
1382 1383
       }
1383
-    #endif //ULTIPANEL
1384
+
1385
+    #endif // ULTIPANEL
1384 1386
 
1385 1387
     if (lcdDrawUpdate == 2) lcd_implementation_clear();
1386 1388
     if (lcdDrawUpdate) lcdDrawUpdate--;
1387
-    lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
1389
+    next_lcd_update_ms = millis() + LCD_UPDATE_INTERVAL;
1388 1390
   }
1389 1391
 }
1390 1392
 
@@ -1403,7 +1405,7 @@ void lcd_finishstatus(bool persist=false) {
1403 1405
   lcdDrawUpdate = 2;
1404 1406
 
1405 1407
   #ifdef FILAMENT_LCD_DISPLAY
1406
-    message_millis = millis();  //get status message to show up for a while
1408
+    previous_lcd_status_ms = millis();  //get status message to show up for a while
1407 1409
   #endif
1408 1410
 }
1409 1411
 
@@ -1473,7 +1475,7 @@ void lcd_buttons_update() {
1473 1475
     if (READ(BTN_EN1) == 0) newbutton |= EN_A;
1474 1476
     if (READ(BTN_EN2) == 0) newbutton |= EN_B;
1475 1477
     #if BTN_ENC > 0
1476
-      if (millis() > blocking_enc && READ(BTN_ENC) == 0) newbutton |= EN_C;
1478
+      if (millis() > next_button_update_ms && READ(BTN_ENC) == 0) newbutton |= EN_C;
1477 1479
     #endif
1478 1480
     buttons = newbutton;
1479 1481
     #ifdef LCD_HAS_SLOW_BUTTONS
@@ -1797,7 +1799,7 @@ char *ftostr52(const float &x) {
1797 1799
       if (max_software_endstops && current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS;
1798 1800
       encoderPosition = 0;
1799 1801
       line_to_current();
1800
-      lcdDrawUpdate = 1;
1802
+      lcdDrawUpdate = 2;
1801 1803
     }
1802 1804
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("Z"), ftostr43(current_position[Z_AXIS]));
1803 1805
     static bool debounce_click = false;
@@ -1815,7 +1817,7 @@ char *ftostr52(const float &x) {
1815 1817
           current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1816 1818
           line_to_current();
1817 1819
           mbl.active = 1;
1818
-          enquecommands_P(PSTR("G28"));
1820
+          enqueuecommands_P(PSTR("G28"));
1819 1821
           lcd_return_to_status();
1820 1822
         } else {
1821 1823
           current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
@@ -1828,7 +1830,7 @@ char *ftostr52(const float &x) {
1828 1830
           current_position[X_AXIS] = mbl.get_x(ix);
1829 1831
           current_position[Y_AXIS] = mbl.get_y(iy);
1830 1832
           line_to_current();
1831
-          lcdDrawUpdate = 1;
1833
+          lcdDrawUpdate = 2;
1832 1834
         }
1833 1835
       }
1834 1836
     } else {
@@ -1837,6 +1839,7 @@ char *ftostr52(const float &x) {
1837 1839
   }
1838 1840
 
1839 1841
   static void _lcd_level_bed_homing() {
1842
+    if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("XYZ"), "Homing");
1840 1843
     if (axis_known_position[X_AXIS] &&
1841 1844
         axis_known_position[Y_AXIS] &&
1842 1845
         axis_known_position[Z_AXIS]) {
@@ -1848,6 +1851,7 @@ char *ftostr52(const float &x) {
1848 1851
       _lcd_level_bed_position = 0;
1849 1852
       lcd_goto_menu(_lcd_level_bed);
1850 1853
     }
1854
+    lcdDrawUpdate = 2;
1851 1855
   }
1852 1856
 
1853 1857
   static void lcd_level_bed() {
@@ -1855,7 +1859,8 @@ char *ftostr52(const float &x) {
1855 1859
     axis_known_position[Y_AXIS] = false;
1856 1860
     axis_known_position[Z_AXIS] = false;
1857 1861
     mbl.reset();
1858
-    enquecommands_P(PSTR("G28"));
1862
+    enqueuecommands_P(PSTR("G28"));
1863
+    lcdDrawUpdate = 2;
1859 1864
     lcd_goto_menu(_lcd_level_bed_homing);
1860 1865
   }
1861 1866
 

+ 2
- 1
Marlin/ultralcd.h View File

@@ -49,10 +49,11 @@
49 49
   extern bool cancel_heatup;
50 50
   
51 51
   #ifdef FILAMENT_LCD_DISPLAY
52
-    extern unsigned long message_millis;
52
+    extern millis_t previous_lcd_status_ms;
53 53
   #endif
54 54
 
55 55
   void lcd_buzz(long duration,uint16_t freq);
56
+  void lcd_quick_feedback(); // Audible feedback for a button click - could also be visual
56 57
   bool lcd_clicked();
57 58
 
58 59
   void lcd_ignore_click(bool b=true);

+ 36
- 37
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

@@ -610,7 +610,7 @@ static void lcd_implementation_status_screen() {
610 610
 
611 611
     // Show Filament Diameter and Volumetric Multiplier %
612 612
     // After allowing lcd_status_message to show for 5 seconds
613
-    if (millis() >= message_millis + 5000) {
613
+    if (millis() >= previous_lcd_status_ms + 5000) {
614 614
       lcd_printPGM(PSTR("Dia "));
615 615
       lcd.print(ftostr12ns(filament_width_meas));
616 616
       lcd_printPGM(PSTR(" V"));
@@ -724,46 +724,45 @@ static void lcd_implementation_drawmenu_sddirectory(bool sel, uint8_t row, const
724 724
 #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
725 725
 
726 726
 #ifdef LCD_HAS_STATUS_INDICATORS
727
-static void lcd_implementation_update_indicators()
728
-{
729
-  #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
730
-    //set the LEDS - referred to as backlights by the LiquidTWI2 library 
731
-    static uint8_t ledsprev = 0;
732
-    uint8_t leds = 0;
733
-    if (target_temperature_bed > 0) leds |= LED_A;
734
-    if (target_temperature[0] > 0) leds |= LED_B;
735
-    if (fanSpeed) leds |= LED_C;
736
-    #if EXTRUDERS > 1  
737
-      if (target_temperature[1] > 0) leds |= LED_C;
727
+
728
+  static void lcd_implementation_update_indicators() {
729
+    #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
730
+      //set the LEDS - referred to as backlights by the LiquidTWI2 library 
731
+      static uint8_t ledsprev = 0;
732
+      uint8_t leds = 0;
733
+      if (target_temperature_bed > 0) leds |= LED_A;
734
+      if (target_temperature[0] > 0) leds |= LED_B;
735
+      if (fanSpeed) leds |= LED_C;
736
+      #if EXTRUDERS > 1  
737
+        if (target_temperature[1] > 0) leds |= LED_C;
738
+      #endif
739
+      if (leds != ledsprev) {
740
+        lcd.setBacklight(leds);
741
+        ledsprev = leds;
742
+      }
738 743
     #endif
739
-    if (leds != ledsprev) {
740
-      lcd.setBacklight(leds);
741
-      ledsprev = leds;
742
-    }
743
-  #endif
744
-}
745
-#endif
744
+  }
745
+
746
+#endif // LCD_HAS_STATUS_INDICATORS
746 747
 
747 748
 #ifdef LCD_HAS_SLOW_BUTTONS
748
-extern uint32_t blocking_enc;
749 749
 
750
-static uint8_t lcd_implementation_read_slow_buttons()
751
-{
752
-  #ifdef LCD_I2C_TYPE_MCP23017
753
-  uint8_t slow_buttons;
754
-    // Reading these buttons this is likely to be too slow to call inside interrupt context
755
-    // so they are called during normal lcd_update
756
-    slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET; 
757
-    #if defined(LCD_I2C_VIKI)
758
-    if(slow_buttons & (B_MI|B_RI)) { //LCD clicked
759
-       if(blocking_enc > millis()) {
760
-         slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
761
-       }
762
-    }
750
+  extern millis_t next_button_update_ms;
751
+
752
+  static uint8_t lcd_implementation_read_slow_buttons() {
753
+    #ifdef LCD_I2C_TYPE_MCP23017
754
+      uint8_t slow_buttons;
755
+      // Reading these buttons this is likely to be too slow to call inside interrupt context
756
+      // so they are called during normal lcd_update
757
+      slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET; 
758
+      #ifdef LCD_I2C_VIKI
759
+        if ((slow_buttons & (B_MI|B_RI)) && millis() < next_button_update_ms) // LCD clicked
760
+          slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
761
+      #endif
762
+      return slow_buttons;
763 763
     #endif
764
-    return slow_buttons; 
765
-  #endif
766
-}
767
-#endif
764
+  }
765
+
766
+#endif // LCD_HAS_SLOW_BUTTONS
768 767
 
769 768
 #endif //__ULTRALCD_IMPLEMENTATION_HITACHI_HD44780_H

Loading…
Cancel
Save