Filament Width Sensor singleton (#15191)

This commit is contained in:
Scott Lahteine
2019-09-10 18:48:58 -05:00
committed by GitHub
parent fe6ba4fd70
commit 75927e17dd
9 changed files with 147 additions and 146 deletions

View File

@@ -301,10 +301,6 @@ volatile bool Temperature::temp_meas_ready = false;
millis_t Temperature::preheat_end_time[HOTENDS] = { 0 };
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
int8_t Temperature::meas_shift_index; // Index of a delayed sample in buffer
#endif
#if HAS_AUTO_FAN
millis_t Temperature::next_auto_fan_check_ms = 0;
#endif
@@ -314,10 +310,6 @@ volatile bool Temperature::temp_meas_ready = false;
Temperature::soft_pwm_count_fan[FAN_COUNT];
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
uint16_t Temperature::current_raw_filwidth = 0; // Measured filament diameter - one extruder only
#endif
#if ENABLED(PROBING_HEATERS_OFF)
bool Temperature::paused;
#endif
@@ -1082,16 +1074,11 @@ void Temperature::manage_heater() {
#if ENABLED(FILAMENT_WIDTH_SENSOR)
/**
* Filament Width Sensor dynamically sets the volumetric multiplier
* based on a delayed measurement of the filament diameter.
* Dynamically set the volumetric multiplier based
* on the delayed Filament Width measurement.
*/
if (filament_sensor) {
meas_shift_index = filwidth_delay_index[0] - meas_delay_cm;
if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1; //loop around buffer if needed
LIMIT(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
planner.calculate_volumetric_for_width_sensor(measurement_delay[meas_shift_index]);
}
#endif // FILAMENT_WIDTH_SENSOR
filwidth.update_volumetric();
#endif
#if HAS_HEATED_BED
@@ -1526,7 +1513,7 @@ void Temperature::updateTemperaturesFromRawValues() {
redundant_temperature = analog_to_celsius_hotend(redundant_temperature_raw, 1);
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
filament_width_meas = analog_to_mm_fil_width();
filwidth.update_measured_mm();
#endif
#if ENABLED(USE_WATCHDOG)
@@ -1537,30 +1524,6 @@ void Temperature::updateTemperaturesFromRawValues() {
temp_meas_ready = false;
}
#if ENABLED(FILAMENT_WIDTH_SENSOR)
// Convert raw Filament Width to millimeters
float Temperature::analog_to_mm_fil_width() {
return current_raw_filwidth * 5.0f * (1.0f / 16383.0f);
}
/**
* Convert Filament Width (mm) to a simple ratio
* and reduce to an 8 bit value.
*
* A nominal width of 1.75 and measured width of 1.73
* gives (100 * 1.75 / 1.73) for a ratio of 101 and
* a return value of 1.
*/
int8_t Temperature::widthFil_to_size_ratio() {
if (ABS(filament_width_nominal - filament_width_meas) <= FILWIDTH_ERROR_MARGIN)
return int(100.0f * filament_width_nominal / filament_width_meas) - 100;
return 0;
}
#endif
#if MAX6675_SEPARATE_SPI
SPIclass<MAX6675_DO_PIN, MOSI_PIN, MAX6675_SCK_PIN> max6675_spi;
#endif
@@ -2241,10 +2204,6 @@ void Temperature::set_current_temp_raw() {
temp_meas_ready = true;
}
#if ENABLED(FILAMENT_WIDTH_SENSOR)
uint32_t raw_filwidth_value; // = 0
#endif
void Temperature::readings_ready() {
// Update the raw values if they've been read. Else we could be updating them during reading.
@@ -2252,7 +2211,7 @@ void Temperature::readings_ready() {
// Filament Sensor - can be read any time since IIR filtering is used
#if ENABLED(FILAMENT_WIDTH_SENSOR)
current_raw_filwidth = raw_filwidth_value >> 10; // Divide to get to 0-16384 range since we used 1/128 IIR filter approach
filwidth.reading_ready();
#endif
#if HOTENDS
@@ -2781,10 +2740,8 @@ void Temperature::isr() {
case Measure_FILWIDTH:
if (!HAL_ADC_READY())
next_sensor_state = adc_sensor_state; // redo this state
else if (HAL_READ_ADC() > 102) { // Make sure ADC is reading > 0.5 volts, otherwise don't read.
raw_filwidth_value -= raw_filwidth_value >> 7; // Subtract 1/128th of the raw_filwidth_value
raw_filwidth_value += uint32_t(HAL_READ_ADC()) << 7; // Add new ADC reading, scaled by 128
}
else
filwidth.accumulate(HAL_READ_ADC());
break;
#endif