Browse Source

Add ADC helpers to temp_info_t

Scott Lahteine 6 years ago
parent
commit
4cdf7a1b93
2 changed files with 16 additions and 13 deletions
  1. 13
    13
      Marlin/src/module/temperature.cpp
  2. 3
    0
      Marlin/src/module/temperature.h

+ 13
- 13
Marlin/src/module/temperature.cpp View File

@@ -2164,23 +2164,23 @@ void Temperature::disable_all_heaters() {
2164 2164
 void Temperature::set_current_temp_raw() {
2165 2165
 
2166 2166
   #if HAS_TEMP_ADC_0 && DISABLED(HEATER_0_USES_MAX6675)
2167
-    temp_hotend[0].raw = temp_hotend[0].acc;
2167
+    temp_hotend[0].update();
2168 2168
   #endif
2169 2169
 
2170 2170
   #if HAS_TEMP_ADC_1
2171 2171
     #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
2172 2172
       redundant_temperature_raw = temp_hotend[1].acc;
2173 2173
     #elif DISABLED(HEATER_1_USES_MAX6675)
2174
-      temp_hotend[1].raw = temp_hotend[1].acc;
2174
+      temp_hotend[1].update();
2175 2175
     #endif
2176 2176
     #if HAS_TEMP_ADC_2
2177
-      temp_hotend[2].raw = temp_hotend[2].acc;
2177
+      temp_hotend[2].update();
2178 2178
       #if HAS_TEMP_ADC_3
2179
-        temp_hotend[3].raw = temp_hotend[3].acc;
2179
+        temp_hotend[3].update();
2180 2180
         #if HAS_TEMP_ADC_4
2181
-          temp_hotend[4].raw = temp_hotend[4].acc;
2181
+          temp_hotend[4].update();
2182 2182
           #if HAS_TEMP_ADC_5
2183
-            temp_hotend[5].raw = temp_hotend[5].acc;
2183
+            temp_hotend[5].update();
2184 2184
           #endif // HAS_TEMP_ADC_5
2185 2185
         #endif // HAS_TEMP_ADC_4
2186 2186
       #endif // HAS_TEMP_ADC_3
@@ -2188,11 +2188,11 @@ void Temperature::set_current_temp_raw() {
2188 2188
   #endif // HAS_TEMP_ADC_1
2189 2189
 
2190 2190
   #if HAS_HEATED_BED
2191
-    temp_bed.raw = temp_bed.acc;
2191
+    temp_bed.update();
2192 2192
   #endif
2193 2193
 
2194 2194
   #if HAS_TEMP_CHAMBER
2195
-    temp_chamber.raw = temp_chamber.acc;
2195
+    temp_chamber.update();
2196 2196
   #endif
2197 2197
 
2198 2198
   temp_meas_ready = true;
@@ -2212,17 +2212,17 @@ void Temperature::readings_ready() {
2212 2212
     current_raw_filwidth = raw_filwidth_value >> 10;  // Divide to get to 0-16384 range since we used 1/128 IIR filter approach
2213 2213
   #endif
2214 2214
 
2215
-  HOTEND_LOOP() temp_hotend[e].acc = 0;
2215
+  HOTEND_LOOP() temp_hotend[e].reset();
2216 2216
   #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
2217
-    temp_hotend[1].acc = 0;
2217
+    temp_hotend[1].reset();
2218 2218
   #endif
2219 2219
 
2220 2220
   #if HAS_HEATED_BED
2221
-    temp_bed.acc = 0;
2221
+    temp_bed.reset();
2222 2222
   #endif
2223 2223
 
2224 2224
   #if HAS_TEMP_CHAMBER
2225
-    temp_chamber.acc = 0;
2225
+    temp_chamber.reset();
2226 2226
   #endif
2227 2227
 
2228 2228
   static constexpr int8_t temp_dir[] = {
@@ -2638,7 +2638,7 @@ void Temperature::isr() {
2638 2638
    */
2639 2639
   #define ACCUMULATE_ADC(obj) do{ \
2640 2640
     if (!HAL_ADC_READY()) next_sensor_state = adc_sensor_state; \
2641
-    else obj.acc += HAL_READ_ADC(); \
2641
+    else obj.sample(HAL_READ_ADC()); \
2642 2642
   }while(0)
2643 2643
 
2644 2644
   ADCSensorState next_sensor_state = adc_sensor_state < SensorsReady ? (ADCSensorState)(int(adc_sensor_state) + 1) : StartSampling;

+ 3
- 0
Marlin/src/module/temperature.h View File

@@ -160,6 +160,9 @@ typedef struct TempInfo {
160 160
   uint16_t acc;
161 161
   int16_t raw;
162 162
   float current;
163
+  inline void reset() { acc = 0; }
164
+  inline void sample(const uint16_t s) { acc += s; }
165
+  inline void update() { raw = acc; }
163 166
 } temp_info_t;
164 167
 
165 168
 // A PWM heater with temperature sensor

Loading…
Cancel
Save