Browse Source

Add fan percent accessors

Scott Lahteine 4 years ago
parent
commit
fd99ea09ec

+ 1
- 1
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp View File

944
               #if ENABLED(ADAPTIVE_FAN_SLOWING)
944
               #if ENABLED(ADAPTIVE_FAN_SLOWING)
945
                 else { c = '*'; spd = thermalManager.scaledFanSpeed(0, spd); }
945
                 else { c = '*'; spd = thermalManager.scaledFanSpeed(0, spd); }
946
               #endif
946
               #endif
947
-              per = thermalManager.fanPercent(spd);
947
+              per = thermalManager.pwmToPercent(spd);
948
             }
948
             }
949
             else
949
             else
950
           #endif
950
           #endif

+ 3
- 4
Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp View File

750
     #if HOTENDS > 2
750
     #if HOTENDS > 2
751
       _draw_heater_status(H_E2, "HE3", blink); // Hotend 3 Temperature
751
       _draw_heater_status(H_E2, "HE3", blink); // Hotend 3 Temperature
752
     #endif
752
     #endif
753
-  #endif // HOTENDS <= 1
753
+  #endif
754
 
754
 
755
   #if HAS_HEATED_BED
755
   #if HAS_HEATED_BED
756
     #if HAS_LEVELING
756
     #if HAS_LEVELING
758
     #else
758
     #else
759
       _draw_heater_status(H_BED, "BED", blink);
759
       _draw_heater_status(H_BED, "BED", blink);
760
     #endif
760
     #endif
761
-  #endif // HAS_HEATED_BED
761
+  #endif
762
 
762
 
763
   #if HAS_FAN
763
   #if HAS_FAN
764
     uint16_t spd = thermalManager.fan_speed[0];
764
     uint16_t spd = thermalManager.fan_speed[0];
765
-
766
     #if ENABLED(ADAPTIVE_FAN_SLOWING)
765
     #if ENABLED(ADAPTIVE_FAN_SLOWING)
767
       if (!blink) spd = thermalManager.scaledFanSpeed(0, spd);
766
       if (!blink) spd = thermalManager.scaledFanSpeed(0, spd);
768
     #endif
767
     #endif
768
+    uint16_t per = thermalManager.pwmToPercent(spd);
769
 
769
 
770
-    uint16_t per = thermalManager.fanPercent(spd);
771
     #if HOTENDS < 2
770
     #if HOTENDS < 2
772
       #define FANX 11
771
       #define FANX 11
773
     #else
772
     #else

+ 1
- 1
Marlin/src/lcd/dogm/status_screen_DOGM.cpp View File

696
               c = '*';
696
               c = '*';
697
             }
697
             }
698
           #endif
698
           #endif
699
-          lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3rj(thermalManager.fanPercent(spd)));
699
+          lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3rj(thermalManager.pwmToPercent(spd)));
700
           lcd_put_wchar(c);
700
           lcd_put_wchar(c);
701
         }
701
         }
702
       }
702
       }

+ 2
- 4
Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp View File

733
     TERN_(HAS_MULTI_HOTEND, draw_extruder_2_temp(extruder_2_temp, extruder_2_target, forceUpdate));
733
     TERN_(HAS_MULTI_HOTEND, draw_extruder_2_temp(extruder_2_temp, extruder_2_target, forceUpdate));
734
     TERN_(HAS_HEATED_BED, draw_bed_temp(bed_temp, bed_target, forceUpdate));
734
     TERN_(HAS_HEATED_BED, draw_bed_temp(bed_temp, bed_target, forceUpdate));
735
 
735
 
736
-    uint16_t spd = thermalManager.fan_speed[0];
737
-
736
+    uint8_t spd = thermalManager.fan_speed[0];
738
     #if ENABLED(ADAPTIVE_FAN_SLOWING)
737
     #if ENABLED(ADAPTIVE_FAN_SLOWING)
739
       if (!blink && thermalManager.fan_speed_scaler[0] < 128)
738
       if (!blink && thermalManager.fan_speed_scaler[0] < 128)
740
         spd = thermalManager.scaledFanSpeed(0, spd);
739
         spd = thermalManager.scaledFanSpeed(0, spd);
741
     #endif
740
     #endif
742
-
743
-    draw_fan_speed(thermalManager.fanPercent(spd));
741
+    draw_fan_speed(thermalManager.pwmToPercent(spd));
744
 
742
 
745
     // Draw elapsed/remaining time
743
     // Draw elapsed/remaining time
746
     const bool show_remaining = ENABLED(SHOW_REMAINING_TIME) && (DISABLED(ROTATE_PROGRESS_DISPLAY) || blink);
744
     const bool show_remaining = ENABLED(SHOW_REMAINING_TIME) && (DISABLED(ROTATE_PROGRESS_DISPLAY) || blink);

+ 1
- 1
Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp View File

236
 }
236
 }
237
 
237
 
238
 void disp_fan_speed() {
238
 void disp_fan_speed() {
239
-  sprintf_P(public_buf_l, PSTR("%d%%"), thermalManager.fanPercent(thermalManager.fan_speed[0]));
239
+  sprintf_P(public_buf_l, PSTR("%d%%"), thermalManager.fanSpeedPercent(0));
240
   lv_label_set_text(labelFan, public_buf_l);
240
   lv_label_set_text(labelFan, public_buf_l);
241
 }
241
 }
242
 
242
 

+ 1
- 1
Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp View File

241
       lv_obj_align(labelBedTarget, buttonBedstate, LV_ALIGN_CENTER, 0, TARGET_LABEL_MOD_Y);
241
       lv_obj_align(labelBedTarget, buttonBedstate, LV_ALIGN_CENTER, 0, TARGET_LABEL_MOD_Y);
242
     #endif
242
     #endif
243
 
243
 
244
-    sprintf_P(buf, PSTR("%d%%"), thermalManager.fanPercent(thermalManager.fan_speed[0]));
244
+    sprintf_P(buf, PSTR("%d%%"), (int)thermalManager.fanSpeedPercent(0));
245
     lv_label_set_text(labelFan, buf);
245
     lv_label_set_text(labelFan, buf);
246
     lv_obj_align(labelFan, buttonFanstate, LV_ALIGN_CENTER, 0, LABEL_MOD_Y);
246
     lv_obj_align(labelFan, buttonFanstate, LV_ALIGN_CENTER, 0, LABEL_MOD_Y);
247
   }
247
   }

+ 2
- 2
Marlin/src/lcd/extui/ui_api.cpp View File

297
 
297
 
298
   float getTargetFan_percent(const fan_t fan) {
298
   float getTargetFan_percent(const fan_t fan) {
299
     #if HAS_FAN
299
     #if HAS_FAN
300
-      return thermalManager.fanPercent(thermalManager.fan_speed[fan - FAN0]);
300
+      return thermalManager.fanSpeedPercent(fan - FAN0);
301
     #else
301
     #else
302
       UNUSED(fan);
302
       UNUSED(fan);
303
       return 0;
303
       return 0;
306
 
306
 
307
   float getActualFan_percent(const fan_t fan) {
307
   float getActualFan_percent(const fan_t fan) {
308
     #if HAS_FAN
308
     #if HAS_FAN
309
-      return thermalManager.fanPercent(thermalManager.scaledFanSpeed(fan - FAN0));
309
+      return thermalManager.scaledFanSpeedPercent(fan - FAN0);
310
     #else
310
     #else
311
       UNUSED(fan);
311
       UNUSED(fan);
312
       return 0;
312
       return 0;

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

315
   /**
315
   /**
316
    * Set the print fan speed for a target extruder
316
    * Set the print fan speed for a target extruder
317
    */
317
    */
318
-  void Temperature::set_fan_speed(uint8_t target, uint16_t speed) {
318
+  void Temperature::set_fan_speed(uint8_t fan, uint16_t speed) {
319
 
319
 
320
     NOMORE(speed, 255U);
320
     NOMORE(speed, 255U);
321
 
321
 
322
     #if ENABLED(SINGLENOZZLE_STANDBY_FAN)
322
     #if ENABLED(SINGLENOZZLE_STANDBY_FAN)
323
-      if (target != active_extruder) {
324
-        if (target < EXTRUDERS) singlenozzle_fan_speed[target] = speed;
323
+      if (fan != active_extruder) {
324
+        if (fan < EXTRUDERS) singlenozzle_fan_speed[fan] = speed;
325
         return;
325
         return;
326
       }
326
       }
327
     #endif
327
     #endif
328
 
328
 
329
-    TERN_(SINGLENOZZLE, target = 0); // Always use fan index 0 with SINGLENOZZLE
329
+    TERN_(SINGLENOZZLE, fan = 0); // Always use fan index 0 with SINGLENOZZLE
330
 
330
 
331
-    if (target >= FAN_COUNT) return;
331
+    if (fan >= FAN_COUNT) return;
332
 
332
 
333
-    fan_speed[target] = speed;
333
+    fan_speed[fan] = speed;
334
 
334
 
335
-    TERN_(REPORT_FAN_CHANGE, report_fan_speed(target));
335
+    TERN_(REPORT_FAN_CHANGE, report_fan_speed(fan));
336
   }
336
   }
337
 
337
 
338
   #if ENABLED(REPORT_FAN_CHANGE)
338
   #if ENABLED(REPORT_FAN_CHANGE)
339
     /**
339
     /**
340
      * Report print fan speed for a target extruder
340
      * Report print fan speed for a target extruder
341
      */
341
      */
342
-    void Temperature::report_fan_speed(const uint8_t target) {
343
-      if (target >= FAN_COUNT) return;
342
+    void Temperature::report_fan_speed(const uint8_t fan) {
343
+      if (fan >= FAN_COUNT) return;
344
       PORT_REDIRECT(SerialMask::All);
344
       PORT_REDIRECT(SerialMask::All);
345
-      SERIAL_ECHOLNPAIR("M106 P", target, " S", fan_speed[target]);
345
+      SERIAL_ECHOLNPAIR("M106 P", fan, " S", fan_speed[fan]);
346
     }
346
     }
347
   #endif
347
   #endif
348
 
348
 

+ 11
- 9
Marlin/src/module/temperature.h View File

553
       static uint8_t fan_speed[FAN_COUNT];
553
       static uint8_t fan_speed[FAN_COUNT];
554
       #define FANS_LOOP(I) LOOP_L_N(I, FAN_COUNT)
554
       #define FANS_LOOP(I) LOOP_L_N(I, FAN_COUNT)
555
 
555
 
556
-      static void set_fan_speed(const uint8_t target, const uint16_t speed);
556
+      static void set_fan_speed(const uint8_t fan, const uint16_t speed);
557
 
557
 
558
       #if ENABLED(REPORT_FAN_CHANGE)
558
       #if ENABLED(REPORT_FAN_CHANGE)
559
-        static void report_fan_speed(const uint8_t target);
559
+        static void report_fan_speed(const uint8_t fan);
560
       #endif
560
       #endif
561
 
561
 
562
       #if EITHER(PROBING_FANS_OFF, ADVANCED_PAUSE_FANS_PAUSE)
562
       #if EITHER(PROBING_FANS_OFF, ADVANCED_PAUSE_FANS_PAUSE)
564
         static uint8_t saved_fan_speed[FAN_COUNT];
564
         static uint8_t saved_fan_speed[FAN_COUNT];
565
       #endif
565
       #endif
566
 
566
 
567
-      static constexpr inline uint8_t fanPercent(const uint8_t speed) { return ui8_to_percent(speed); }
568
-
569
       #if ENABLED(ADAPTIVE_FAN_SLOWING)
567
       #if ENABLED(ADAPTIVE_FAN_SLOWING)
570
         static uint8_t fan_speed_scaler[FAN_COUNT];
568
         static uint8_t fan_speed_scaler[FAN_COUNT];
571
       #endif
569
       #endif
572
 
570
 
573
-      static inline uint8_t scaledFanSpeed(const uint8_t target, const uint8_t fs) {
574
-        UNUSED(target); // Potentially unused!
575
-        return (fs * uint16_t(TERN(ADAPTIVE_FAN_SLOWING, fan_speed_scaler[target], 128))) >> 7;
571
+      static inline uint8_t scaledFanSpeed(const uint8_t fan, const uint8_t fs) {
572
+        UNUSED(fan); // Potentially unused!
573
+        return (fs * uint16_t(TERN(ADAPTIVE_FAN_SLOWING, fan_speed_scaler[fan], 128))) >> 7;
576
       }
574
       }
577
 
575
 
578
-      static inline uint8_t scaledFanSpeed(const uint8_t target) {
579
-        return scaledFanSpeed(target, fan_speed[target]);
576
+      static inline uint8_t scaledFanSpeed(const uint8_t fan) {
577
+        return scaledFanSpeed(fan, fan_speed[fan]);
580
       }
578
       }
581
 
579
 
580
+      static constexpr inline uint8_t pwmToPercent(const uint8_t speed) { return ui8_to_percent(speed); }
581
+      static inline uint8_t fanSpeedPercent(const uint8_t fan)          { return ui8_to_percent(fan_speed[fan]); }
582
+      static inline uint8_t scaledFanSpeedPercent(const uint8_t fan)    { return ui8_to_percent(scaledFanSpeed(fan)); }
583
+
582
       #if ENABLED(EXTRA_FAN_SPEED)
584
       #if ENABLED(EXTRA_FAN_SPEED)
583
         typedef struct { uint8_t saved, speed; } extra_fan_t;
585
         typedef struct { uint8_t saved, speed; } extra_fan_t;
584
         static extra_fan_t extra_fan_speed[FAN_COUNT];
586
         static extra_fan_t extra_fan_speed[FAN_COUNT];

Loading…
Cancel
Save