Bläddra i källkod

Merge pull request #4779 from thinkyhead/rc_cleanups_1

Minor code cleanup, tweak M109/M190
Scott Lahteine 8 år sedan
förälder
incheckning
2e8fd70fb1
4 ändrade filer med 42 tillägg och 43 borttagningar
  1. 6
    6
      Marlin/Marlin.h
  2. 29
    30
      Marlin/Marlin_main.cpp
  3. 6
    6
      Marlin/planner.cpp
  4. 1
    1
      Marlin/temperature.cpp

+ 6
- 6
Marlin/Marlin.h Visa fil

@@ -342,12 +342,12 @@ float code_value_temp_diff();
342 342
 #endif
343 343
 
344 344
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
345
-  extern float filament_width_nominal;  //holds the theoretical filament diameter i.e., 3.00 or 1.75
346
-  extern bool filament_sensor;  //indicates that filament sensor readings should control extrusion
347
-  extern float filament_width_meas; //holds the filament diameter as accurately measured
348
-  extern int8_t measurement_delay[];  //ring buffer to delay measurement
349
-  extern int filwidth_delay_index1, filwidth_delay_index2;  //ring buffer index. used by planner, temperature, and main code
350
-  extern int meas_delay_cm; //delay distance
345
+  extern bool filament_sensor;         // Flag that filament sensor readings should control extrusion
346
+  extern float filament_width_nominal, // Theoretical filament diameter i.e., 3.00 or 1.75
347
+               filament_width_meas;    // Measured filament diameter
348
+  extern int8_t measurement_delay[];   // Ring buffer to delay measurement
349
+  extern int filwidth_delay_index[2];  // Ring buffer indexes. Used by planner, temperature, and main code
350
+  extern int meas_delay_cm;            // Delay distance
351 351
 #endif
352 352
 
353 353
 #if ENABLED(FILAMENT_CHANGE_FEATURE)

+ 29
- 30
Marlin/Marlin_main.cpp Visa fil

@@ -500,13 +500,11 @@ static uint8_t target_extruder;
500 500
 #endif
501 501
 
502 502
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
503
-  //Variables for Filament Sensor input
504
-  float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA;  //Set nominal filament width, can be changed with M404
505 503
   bool filament_sensor = false;  //M405 turns on filament_sensor control, M406 turns it off
506
-  float filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter
507
-  int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; //ring buffer to delay measurement  store extruder factor after subtracting 100
508
-  int filwidth_delay_index1 = 0;  //index into ring buffer
509
-  int filwidth_delay_index2 = -1;  //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized
504
+  float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA,  // Nominal filament width. Change with M404
505
+        filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA;    // Measured filament diameter
506
+  int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
507
+  int filwidth_delay_index[2] = { 0, -1 };  // Indexes into ring buffer
510 508
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
511 509
 #endif
512 510
 
@@ -555,6 +553,26 @@ static bool send_ok[BUFSIZE];
555 553
   #define KEEPALIVE_STATE(n) ;
556 554
 #endif // HOST_KEEPALIVE_FEATURE
557 555
 
556
+#define DEFINE_PGM_READ_ANY(type, reader)       \
557
+  static inline type pgm_read_any(const type *p)  \
558
+  { return pgm_read_##reader##_near(p); }
559
+
560
+DEFINE_PGM_READ_ANY(float,       float);
561
+DEFINE_PGM_READ_ANY(signed char, byte);
562
+
563
+#define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \
564
+  static const PROGMEM type array##_P[XYZ] =        \
565
+      { X_##CONFIG, Y_##CONFIG, Z_##CONFIG };     \
566
+  static inline type array(int axis)          \
567
+  { return pgm_read_any(&array##_P[axis]); }
568
+
569
+XYZ_CONSTS_FROM_CONFIG(float, base_min_pos,   MIN_POS);
570
+XYZ_CONSTS_FROM_CONFIG(float, base_max_pos,   MAX_POS);
571
+XYZ_CONSTS_FROM_CONFIG(float, base_home_pos,  HOME_POS);
572
+XYZ_CONSTS_FROM_CONFIG(float, max_length,     MAX_LENGTH);
573
+XYZ_CONSTS_FROM_CONFIG(float, home_bump_mm,   HOME_BUMP_MM);
574
+XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR);
575
+
558 576
 /**
559 577
  * ***************************************************************************
560 578
  * ******************************** FUNCTIONS ********************************
@@ -1406,26 +1424,6 @@ bool get_target_extruder_from_command(int code) {
1406 1424
   return false;
1407 1425
 }
1408 1426
 
1409
-#define DEFINE_PGM_READ_ANY(type, reader)       \
1410
-  static inline type pgm_read_any(const type *p)  \
1411
-  { return pgm_read_##reader##_near(p); }
1412
-
1413
-DEFINE_PGM_READ_ANY(float,       float);
1414
-DEFINE_PGM_READ_ANY(signed char, byte);
1415
-
1416
-#define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \
1417
-  static const PROGMEM type array##_P[XYZ] =        \
1418
-      { X_##CONFIG, Y_##CONFIG, Z_##CONFIG };     \
1419
-  static inline type array(int axis)          \
1420
-  { return pgm_read_any(&array##_P[axis]); }
1421
-
1422
-XYZ_CONSTS_FROM_CONFIG(float, base_min_pos,   MIN_POS);
1423
-XYZ_CONSTS_FROM_CONFIG(float, base_max_pos,   MAX_POS);
1424
-XYZ_CONSTS_FROM_CONFIG(float, base_home_pos,  HOME_POS);
1425
-XYZ_CONSTS_FROM_CONFIG(float, max_length,     MAX_LENGTH);
1426
-XYZ_CONSTS_FROM_CONFIG(float, home_bump_mm,   HOME_BUMP_MM);
1427
-XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR);
1428
-
1429 1427
 #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
1430 1428
   bool extruder_duplication_enabled = false; // Used in Dual X mode 2
1431 1429
 #endif
@@ -4816,7 +4814,8 @@ inline void gcode_M109() {
4816 4814
 
4817 4815
   } while (wait_for_heatup && TEMP_CONDITIONS);
4818 4816
 
4819
-  LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
4817
+  if (wait_for_heatup) LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
4818
+
4820 4819
   KEEPALIVE_STATE(IN_HANDLER);
4821 4820
 }
4822 4821
 
@@ -4934,7 +4933,7 @@ inline void gcode_M109() {
4934 4933
 
4935 4934
     } while (wait_for_heatup && TEMP_BED_CONDITIONS);
4936 4935
 
4937
-    LCD_MESSAGEPGM(MSG_BED_DONE);
4936
+    if (wait_for_heatup) LCD_MESSAGEPGM(MSG_BED_DONE);
4938 4937
     KEEPALIVE_STATE(IN_HANDLER);
4939 4938
   }
4940 4939
 
@@ -6136,13 +6135,13 @@ inline void gcode_M400() { stepper.synchronize(); }
6136 6135
     if (code_seen('D')) meas_delay_cm = code_value_int();
6137 6136
     NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
6138 6137
 
6139
-    if (filwidth_delay_index2 == -1) { // Initialize the ring buffer if not done since startup
6138
+    if (filwidth_delay_index[1] == -1) { // Initialize the ring buffer if not done since startup
6140 6139
       int temp_ratio = thermalManager.widthFil_to_size_ratio();
6141 6140
 
6142 6141
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
6143 6142
         measurement_delay[i] = temp_ratio - 100;  // Subtract 100 to scale within a signed byte
6144 6143
 
6145
-      filwidth_delay_index1 = filwidth_delay_index2 = 0;
6144
+      filwidth_delay_index[0] = filwidth_delay_index[1] = 0;
6146 6145
     }
6147 6146
 
6148 6147
     filament_sensor = true;

+ 6
- 6
Marlin/planner.cpp Visa fil

@@ -868,7 +868,7 @@ void Planner::check_axes_activity() {
868 868
     static float filwidth_e_count = 0, filwidth_delay_dist = 0;
869 869
 
870 870
     //FMM update ring buffer used for delay with filament measurements
871
-    if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index2 >= 0) {  //only for extruder with filament sensor and if ring buffer is initialized
871
+    if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index[1] >= 0) {  //only for extruder with filament sensor and if ring buffer is initialized
872 872
 
873 873
       const int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10;
874 874
 
@@ -883,16 +883,16 @@ void Planner::check_axes_activity() {
883 883
         while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
884 884
 
885 885
         // Convert into an index into the measurement array
886
-        filwidth_delay_index1 = (int)(filwidth_delay_dist * 0.1 + 0.0001);
886
+        filwidth_delay_index[0] = (int)(filwidth_delay_dist * 0.1 + 0.0001);
887 887
 
888 888
         // If the index has changed (must have gone forward)...
889
-        if (filwidth_delay_index1 != filwidth_delay_index2) {
889
+        if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
890 890
           filwidth_e_count = 0; // Reset the E movement counter
891 891
           int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
892 892
           do {
893
-            filwidth_delay_index2 = (filwidth_delay_index2 + 1) % MMD_CM; // The next unused slot
894
-            measurement_delay[filwidth_delay_index2] = meas_sample;       // Store the measurement
895
-          } while (filwidth_delay_index1 != filwidth_delay_index2);       // More slots to fill?
893
+            filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
894
+            measurement_delay[filwidth_delay_index[1]] = meas_sample;         // Store the measurement
895
+          } while (filwidth_delay_index[0] != filwidth_delay_index[1]);       // More slots to fill?
896 896
         }
897 897
       }
898 898
     }

+ 1
- 1
Marlin/temperature.cpp Visa fil

@@ -755,7 +755,7 @@ void Temperature::manage_heater() {
755 755
   // Control the extruder rate based on the width sensor
756 756
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
757 757
     if (filament_sensor) {
758
-      meas_shift_index = filwidth_delay_index1 - meas_delay_cm;
758
+      meas_shift_index = filwidth_delay_index[0] - meas_delay_cm;
759 759
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
760 760
 
761 761
       // Get the delayed info and add 100 to reconstitute to a percent of

Laddar…
Avbryt
Spara