Browse Source

Merge pull request #3272 from thinkyhead/rc_filament_sensor_scope

Minor cleanup to filament sensor code
Scott Lahteine 9 years ago
parent
commit
9e520ae319
3 changed files with 4 additions and 9 deletions
  1. 1
    1
      Marlin/Marlin.h
  2. 2
    2
      Marlin/Marlin_main.cpp
  3. 1
    6
      Marlin/planner.cpp

+ 1
- 1
Marlin/Marlin.h View File

338
   extern float filament_width_nominal;  //holds the theoretical filament diameter i.e., 3.00 or 1.75
338
   extern float filament_width_nominal;  //holds the theoretical filament diameter i.e., 3.00 or 1.75
339
   extern bool filament_sensor;  //indicates that filament sensor readings should control extrusion
339
   extern bool filament_sensor;  //indicates that filament sensor readings should control extrusion
340
   extern float filament_width_meas; //holds the filament diameter as accurately measured
340
   extern float filament_width_meas; //holds the filament diameter as accurately measured
341
-  extern signed char measurement_delay[];  //ring buffer to delay measurement
341
+  extern int8_t measurement_delay[];  //ring buffer to delay measurement
342
   extern int delay_index1, delay_index2;  //ring buffer index. used by planner, temperature, and main code
342
   extern int delay_index1, delay_index2;  //ring buffer index. used by planner, temperature, and main code
343
   extern float delay_dist; //delay distance counter
343
   extern float delay_dist; //delay distance counter
344
   extern int meas_delay_cm; //delay distance
344
   extern int meas_delay_cm; //delay distance

+ 2
- 2
Marlin/Marlin_main.cpp View File

410
   float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA;  //Set nominal filament width, can be changed with M404
410
   float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA;  //Set nominal filament width, can be changed with M404
411
   bool filament_sensor = false;  //M405 turns on filament_sensor control, M406 turns it off
411
   bool filament_sensor = false;  //M405 turns on filament_sensor control, M406 turns it off
412
   float filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter
412
   float filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter
413
-  signed char measurement_delay[MAX_MEASUREMENT_DELAY + 1]; //ring buffer to delay measurement  store extruder factor after subtracting 100
413
+  int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; //ring buffer to delay measurement  store extruder factor after subtracting 100
414
   int delay_index1 = 0;  //index into ring buffer
414
   int delay_index1 = 0;  //index into ring buffer
415
   int delay_index2 = -1;  //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized
415
   int delay_index2 = -1;  //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized
416
   float delay_dist = 0; //delay distance counter
416
   float delay_dist = 0; //delay distance counter
5464
     if (delay_index2 == -1) { //initialize the ring buffer if it has not been done since startup
5464
     if (delay_index2 == -1) { //initialize the ring buffer if it has not been done since startup
5465
       int temp_ratio = widthFil_to_size_ratio();
5465
       int temp_ratio = widthFil_to_size_ratio();
5466
 
5466
 
5467
-      for (delay_index1 = 0; delay_index1 < MAX_MEASUREMENT_DELAY + 1; ++delay_index1)
5467
+      for (delay_index1 = 0; delay_index1 < COUNT(measurement_delay); ++delay_index1)
5468
         measurement_delay[delay_index1] = temp_ratio - 100;  //subtract 100 to scale within a signed byte
5468
         measurement_delay[delay_index1] = temp_ratio - 100;  //subtract 100 to scale within a signed byte
5469
 
5469
 
5470
       delay_index1 = delay_index2 = 0;
5470
       delay_index1 = delay_index2 = 0;

+ 1
- 6
Marlin/planner.cpp View File

147
   static long axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
147
   static long axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
148
 #endif
148
 #endif
149
 
149
 
150
-#if ENABLED(FILAMENT_SENSOR)
151
-  static char meas_sample; //temporary variable to hold filament measurement sample
152
-#endif
153
-
154
 #if ENABLED(DUAL_X_CARRIAGE)
150
 #if ENABLED(DUAL_X_CARRIAGE)
155
   extern bool extruder_duplication_enabled;
151
   extern bool extruder_duplication_enabled;
156
 #endif
152
 #endif
857
 
853
 
858
   #if ENABLED(FILAMENT_SENSOR)
854
   #if ENABLED(FILAMENT_SENSOR)
859
     //FMM update ring buffer used for delay with filament measurements
855
     //FMM update ring buffer used for delay with filament measurements
860
-
861
     if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && delay_index2 > -1) {  //only for extruder with filament sensor and if ring buffer is initialized
856
     if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && delay_index2 > -1) {  //only for extruder with filament sensor and if ring buffer is initialized
862
 
857
 
863
       const int MMD = MAX_MEASUREMENT_DELAY + 1, MMD10 = MMD * 10;
858
       const int MMD = MAX_MEASUREMENT_DELAY + 1, MMD10 = MMD * 10;
870
       delay_index1 = constrain(delay_index1, 0, MAX_MEASUREMENT_DELAY); // (already constrained above)
865
       delay_index1 = constrain(delay_index1, 0, MAX_MEASUREMENT_DELAY); // (already constrained above)
871
 
866
 
872
       if (delay_index1 != delay_index2) { // moved index
867
       if (delay_index1 != delay_index2) { // moved index
873
-        meas_sample = widthFil_to_size_ratio() - 100;  // Subtract 100 to reduce magnitude - to store in a signed char
868
+        int8_t meas_sample = widthFil_to_size_ratio() - 100;  // Subtract 100 to reduce magnitude - to store in a signed char
874
         while (delay_index1 != delay_index2) {
869
         while (delay_index1 != delay_index2) {
875
           // Increment and loop around buffer
870
           // Increment and loop around buffer
876
           if (++delay_index2 >= MMD) delay_index2 -= MMD;
871
           if (++delay_index2 >= MMD) delay_index2 -= MMD;

Loading…
Cancel
Save