|
@@ -99,8 +99,8 @@ static volatile bool temp_meas_ready = false;
|
99
|
99
|
#ifdef FAN_SOFT_PWM
|
100
|
100
|
static unsigned char soft_pwm_fan;
|
101
|
101
|
#endif
|
102
|
|
-#if EXTRUDER_0_AUTO_FAN_PIN > -1 || EXTRUDER_1_AUTO_FAN_PIN > -1 || EXTRUDER_2_AUTO_FAN_PIN > -1
|
103
|
|
- static uint8_t extruderAutoFanState = 0; // extruder auto fan state stored as bitmap
|
|
102
|
+#if EXTRUDER_0_AUTO_FAN_PIN > 0 || EXTRUDER_1_AUTO_FAN_PIN > 0 || EXTRUDER_2_AUTO_FAN_PIN > 0
|
|
103
|
+ static unsigned long extruder_autofan_last_check;
|
104
|
104
|
#endif
|
105
|
105
|
|
106
|
106
|
#if EXTRUDERS > 3
|
|
@@ -307,6 +307,73 @@ int getHeaterPower(int heater) {
|
307
|
307
|
return soft_pwm[heater];
|
308
|
308
|
}
|
309
|
309
|
|
|
310
|
+#if EXTRUDER_0_AUTO_FAN_PIN > 0 || EXTRUDER_1_AUTO_FAN_PIN > 0 || EXTRUDER_2_AUTO_FAN_PIN > 0
|
|
311
|
+
|
|
312
|
+void setExtruderAutoFanState(int pin, bool state)
|
|
313
|
+{
|
|
314
|
+ unsigned char newFanSpeed = (state != 0) ? EXTRUDER_AUTO_FAN_SPEED : 0;
|
|
315
|
+ // this idiom allows both digital and PWM fan outputs (see M42 handling).
|
|
316
|
+ pinMode(pin, OUTPUT);
|
|
317
|
+ digitalWrite(pin, newFanSpeed);
|
|
318
|
+ analogWrite(pin, newFanSpeed);
|
|
319
|
+}
|
|
320
|
+
|
|
321
|
+void checkExtruderAutoFans()
|
|
322
|
+{
|
|
323
|
+ uint8_t fanState = 0;
|
|
324
|
+
|
|
325
|
+ // which fan pins need to be turned on?
|
|
326
|
+ #if EXTRUDER_0_AUTO_FAN_PIN > 0
|
|
327
|
+ #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN
|
|
328
|
+ #error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN"
|
|
329
|
+ #endif
|
|
330
|
+ if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE)
|
|
331
|
+ fanState |= 1;
|
|
332
|
+ #endif
|
|
333
|
+ #if EXTRUDER_1_AUTO_FAN_PIN > 0
|
|
334
|
+ #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN
|
|
335
|
+ #error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN"
|
|
336
|
+ #endif
|
|
337
|
+ if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE)
|
|
338
|
+ {
|
|
339
|
+ if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
|
|
340
|
+ fanState |= 1;
|
|
341
|
+ else
|
|
342
|
+ fanState |= 2;
|
|
343
|
+ }
|
|
344
|
+ #endif
|
|
345
|
+ #if EXTRUDER_2_AUTO_FAN_PIN > 0
|
|
346
|
+ #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN
|
|
347
|
+ #error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN"
|
|
348
|
+ #endif
|
|
349
|
+ if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)
|
|
350
|
+ {
|
|
351
|
+ if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
|
|
352
|
+ fanState |= 1;
|
|
353
|
+ else if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN)
|
|
354
|
+ fanState |= 2;
|
|
355
|
+ else
|
|
356
|
+ fanState |= 4;
|
|
357
|
+ }
|
|
358
|
+ #endif
|
|
359
|
+
|
|
360
|
+ // update extruder auto fan states
|
|
361
|
+ #if EXTRUDER_0_AUTO_FAN_PIN > 0
|
|
362
|
+ setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0);
|
|
363
|
+ #endif
|
|
364
|
+ #if EXTRUDER_1_AUTO_FAN_PIN > 0
|
|
365
|
+ if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN)
|
|
366
|
+ setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0);
|
|
367
|
+ #endif
|
|
368
|
+ #if EXTRUDER_2_AUTO_FAN_PIN > 0
|
|
369
|
+ if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
|
|
370
|
+ && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN)
|
|
371
|
+ setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0);
|
|
372
|
+ #endif
|
|
373
|
+}
|
|
374
|
+
|
|
375
|
+#endif // any extruder auto fan pins set
|
|
376
|
+
|
310
|
377
|
void manage_heater()
|
311
|
378
|
{
|
312
|
379
|
float pid_input;
|
|
@@ -399,56 +466,15 @@ void manage_heater()
|
399
|
466
|
#endif
|
400
|
467
|
|
401
|
468
|
} // End extruder for loop
|
402
|
|
-
|
403
|
|
- #if EXTRUDER_0_AUTO_FAN_PIN > -1 || EXTRUDER_1_AUTO_FAN_PIN > -1 || EXTRUDER_2_AUTO_FAN_PIN > -1
|
404
|
|
- bool newFanState;
|
405
|
|
- #if EXTRUDER_0_AUTO_FAN_PIN > -1
|
406
|
|
- // check the extruder 0 setting (and any ganged auto fan outputs)
|
407
|
|
- newFanState = (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE ||
|
408
|
|
- (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN && current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) ||
|
409
|
|
- (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE));
|
410
|
|
- if ((extruderAutoFanState & 1) != newFanState) // store state in first bit
|
411
|
|
- {
|
412
|
|
- int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0);
|
413
|
|
- if (EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN)
|
414
|
|
- fanSpeed = newFanSpeed;
|
415
|
|
- pinMode(EXTRUDER_0_AUTO_FAN_PIN, OUTPUT);
|
416
|
|
- digitalWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed);
|
417
|
|
- analogWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed);
|
418
|
|
- extruderAutoFanState = newFanState | (extruderAutoFanState & ~1);
|
419
|
|
- }
|
420
|
|
- #endif //EXTRUDER_0_AUTO_FAN_PIN > -1
|
421
|
|
- #if EXTRUDER_1_AUTO_FAN_PIN > -1 && EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
|
422
|
|
- // check the extruder 1 setting (except when extruder 1 is the same as 0)
|
423
|
|
- newFanState = (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE ||
|
424
|
|
- (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE));
|
425
|
|
- if ((extruderAutoFanState & 2) != (newFanState<<1)) // use second bit
|
426
|
|
- {
|
427
|
|
- int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0);
|
428
|
|
- if (EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN)
|
429
|
|
- fanSpeed = newFanSpeed;
|
430
|
|
- pinMode(EXTRUDER_1_AUTO_FAN_PIN, OUTPUT);
|
431
|
|
- digitalWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed);
|
432
|
|
- analogWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed);
|
433
|
|
- extruderAutoFanState = (newFanState<<1) | (extruderAutoFanState & ~2);
|
434
|
|
- }
|
435
|
|
- #endif //EXTRUDER_1_AUTO_FAN_PIN > -1
|
436
|
|
- #if EXTRUDER_2_AUTO_FAN_PIN > -1 && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN
|
437
|
|
- // check the extruder 2 setting (except when extruder 2 is the same as 1 or 0)
|
438
|
|
- newFanState = (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE);
|
439
|
|
- if ((extruderAutoFanState & 4) != (newFanState<<2)) // use third bit
|
440
|
|
- {
|
441
|
|
- int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0);
|
442
|
|
- if (EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN)
|
443
|
|
- fanSpeed = newFanSpeed;
|
444
|
|
- pinMode(EXTRUDER_2_AUTO_FAN_PIN, OUTPUT);
|
445
|
|
- digitalWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed);
|
446
|
|
- analogWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed);
|
447
|
|
- extruderAutoFanState = (newFanState<<2) | (extruderAutoFanState & ~4);
|
448
|
|
- }
|
449
|
|
- #endif //EXTRUDER_2_AUTO_FAN_PIN > -1
|
450
|
|
- #endif // any AUTO_FAN_PIN enabled
|
451
|
469
|
|
|
470
|
+ #if EXTRUDER_0_AUTO_FAN_PIN > 0 || EXTRUDER_1_AUTO_FAN_PIN > 0 || EXTRUDER_2_AUTO_FAN_PIN > 0
|
|
471
|
+ if(millis() - extruder_autofan_last_check > 2500) // only need to check fan state very infrequently
|
|
472
|
+ {
|
|
473
|
+ checkExtruderAutoFans();
|
|
474
|
+ extruder_autofan_last_check = millis();
|
|
475
|
+ }
|
|
476
|
+ #endif
|
|
477
|
+
|
452
|
478
|
#ifndef PIDTEMPBED
|
453
|
479
|
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
|
454
|
480
|
return;
|