Redo HAS_* macros to fix define error

2.0.x
Scott Lahteine 10 years ago
parent 864dddc878
commit 1a7b0d9a37

@ -53,20 +53,23 @@
#define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 } #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 }
#endif #endif
#define PIN_EXISTS(PIN) (defined(PIN) && PIN >= 0) #define HAS_TEMP_0 (defined(TEMP_0_PIN) && TEMP_0_PIN >= 0)
#define HAS_TEMP_0 PIN_EXISTS(TEMP_0_PIN) #define HAS_TEMP_1 (defined(TEMP_1_PIN) && TEMP_1_PIN >= 0)
#define HAS_TEMP_1 PIN_EXISTS(TEMP_1_PIN) #define HAS_TEMP_2 (defined(TEMP_2_PIN) && TEMP_2_PIN >= 0)
#define HAS_TEMP_2 PIN_EXISTS(TEMP_2_PIN) #define HAS_TEMP_3 (defined(TEMP_3_PIN) && TEMP_3_PIN >= 0)
#define HAS_TEMP_3 PIN_EXISTS(TEMP_3_PIN) #define HAS_TEMP_BED (defined(TEMP_BED_PIN) && TEMP_BED_PIN >= 0)
#define HAS_TEMP_BED PIN_EXISTS(TEMP_BED_PIN) #define HAS_FILAMENT_SENSOR (defined(FILAMENT_SENSOR) && defined(FILWIDTH_PIN) && FILWIDTH_PIN >= 0)
#define HAS_FILAMENT_SENSOR (defined(FILAMENT_SENSOR) && PIN_EXISTS(FILWIDTH_PIN)) #define HAS_HEATER_0 (defined(HEATER_0_PIN) && HEATER_0_PIN >= 0)
#define HAS_HEATER_0 PIN_EXISTS(HEATER_0_PIN) #define HAS_HEATER_1 (defined(HEATER_1_PIN) && HEATER_1_PIN >= 0)
#define HAS_HEATER_1 PIN_EXISTS(HEATER_1_PIN) #define HAS_HEATER_2 (defined(HEATER_2_PIN) && HEATER_2_PIN >= 0)
#define HAS_HEATER_2 PIN_EXISTS(HEATER_2_PIN) #define HAS_HEATER_3 (defined(HEATER_3_PIN) && HEATER_3_PIN >= 0)
#define HAS_HEATER_3 PIN_EXISTS(HEATER_3_PIN) #define HAS_HEATER_BED (defined(HEATER_BED_PIN) && HEATER_BED_PIN >= 0)
#define HAS_HEATER_BED PIN_EXISTS(HEATER_BED_PIN) #define HAS_AUTO_FAN_0 (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN >= 0)
#define HAS_AUTO_FAN PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \ #define HAS_AUTO_FAN_1 (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN >= 0)
PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN) #define HAS_AUTO_FAN_2 (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN >= 0)
#define HAS_AUTO_FAN_3 (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN >= 0)
#define HAS_AUTO_FAN HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3
#define HAS_FAN (defined(FAN_PIN) && FAN_PIN >= 0)
//=========================================================================== //===========================================================================
//============================= public variables ============================ //============================= public variables ============================
@ -147,8 +150,7 @@ static volatile bool temp_meas_ready = false;
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
static unsigned char soft_pwm_fan; static unsigned char soft_pwm_fan;
#endif #endif
#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \ #if HAS_AUTO_FAN
PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
static unsigned long extruder_autofan_last_check; static unsigned long extruder_autofan_last_check;
#endif #endif
@ -227,8 +229,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
float Kp, Ki, Kd; float Kp, Ki, Kd;
float max = 0, min = 10000; float max = 0, min = 10000;
#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \ #if HAS_AUTO_FAN
PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
unsigned long extruder_autofan_last_check = temp_millis; unsigned long extruder_autofan_last_check = temp_millis;
#endif #endif
@ -263,8 +264,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
max = max(max, input); max = max(max, input);
min = min(min, input); min = min(min, input);
#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \ #if HAS_AUTO_FAN
PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
if (ms > extruder_autofan_last_check + 2500) { if (ms > extruder_autofan_last_check + 2500) {
checkExtruderAutoFans(); checkExtruderAutoFans();
extruder_autofan_last_check = ms; extruder_autofan_last_check = ms;
@ -387,19 +387,21 @@ int getHeaterPower(int heater) {
return heater < 0 ? soft_pwm_bed : soft_pwm[heater]; return heater < 0 ? soft_pwm_bed : soft_pwm[heater];
} }
#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \ #if HAS_AUTO_FAN
PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN)
#if PIN_EXISTS(FAN_PIN) #if HAS_FAN
#if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN
#error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN" #error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN"
#endif #endif
#if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN
#error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN" #error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN"
#endif #endif
#if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN
#error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN" #error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN"
#endif #endif
#if EXTRUDER_3_AUTO_FAN_PIN == FAN_PIN
#error "You cannot set EXTRUDER_3_AUTO_FAN_PIN equal to FAN_PIN"
#endif
#endif #endif
void setExtruderAutoFanState(int pin, bool state) void setExtruderAutoFanState(int pin, bool state)
@ -416,20 +418,20 @@ void checkExtruderAutoFans()
uint8_t fanState = 0; uint8_t fanState = 0;
// which fan pins need to be turned on? // which fan pins need to be turned on?
#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) #if HAS_AUTO_FAN_0
if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE)
fanState |= 1; fanState |= 1;
#endif #endif
#if PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) #if HAS_AUTO_FAN_1
if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE)
{ {
if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
fanState |= 1; fanState |= 1;
else else
fanState |= 2; fanState |= 2;
} }
#endif #endif
#if PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) #if HAS_AUTO_FAN_2
if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)
{ {
if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
@ -440,7 +442,7 @@ void checkExtruderAutoFans()
fanState |= 4; fanState |= 4;
} }
#endif #endif
#if PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN) #if HAS_AUTO_FAN_3
if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE)
{ {
if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
@ -455,19 +457,19 @@ void checkExtruderAutoFans()
#endif #endif
// update extruder auto fan states // update extruder auto fan states
#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) #if HAS_AUTO_FAN_0
setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0); setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0);
#endif #endif
#if PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) #if HAS_AUTO_FAN_1
if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN)
setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0); setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0);
#endif #endif
#if PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) #if HAS_AUTO_FAN_2
if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
&& EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN)
setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0); setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0);
#endif #endif
#if PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN) #if HAS_AUTO_FAN_3
if (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN if (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
&& EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN
&& EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_2_AUTO_FAN_PIN)
@ -510,6 +512,9 @@ void checkExtruderAutoFans()
#if HAS_HEATER_BED #if HAS_HEATER_BED
#define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, v) #define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, v)
#endif #endif
#if HAS_FAN
#define WRITE_FAN(v) WRITE(FAN_PIN, v)
#endif
void manage_heater() { void manage_heater() {
@ -631,8 +636,7 @@ void manage_heater() {
} // Extruders Loop } // Extruders Loop
#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \ #if HAS_AUTO_FAN
PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
if (ms > extruder_autofan_last_check + 2500) { // only need to check fan state very infrequently if (ms > extruder_autofan_last_check + 2500) { // only need to check fan state very infrequently
checkExtruderAutoFans(); checkExtruderAutoFans();
extruder_autofan_last_check = ms; extruder_autofan_last_check = ms;
@ -884,7 +888,7 @@ void tp_init()
#if HAS_HEATER_BED #if HAS_HEATER_BED
SET_OUTPUT(HEATER_BED_PIN); SET_OUTPUT(HEATER_BED_PIN);
#endif #endif
#if PIN_EXISTS(FAN_PIN) #if HAS_FAN
SET_OUTPUT(FAN_PIN); SET_OUTPUT(FAN_PIN);
#ifdef FAST_PWM_FAN #ifdef FAST_PWM_FAN
setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8 setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
@ -1327,7 +1331,7 @@ ISR(TIMER0_COMPB_vect) {
#endif #endif
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
soft_pwm_fan = fanSpeedSoftPwm / 2; soft_pwm_fan = fanSpeedSoftPwm / 2;
WRITE(FAN_PIN, soft_pwm_fan > 0 ? 1 : 0); WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
#endif #endif
} }
@ -1347,7 +1351,7 @@ ISR(TIMER0_COMPB_vect) {
#endif #endif
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN, 0); if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
#endif #endif
pwm_count += (1 << SOFT_PWM_SCALE); pwm_count += (1 << SOFT_PWM_SCALE);
@ -1426,9 +1430,9 @@ ISR(TIMER0_COMPB_vect) {
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
if (pwm_count == 0) { if (pwm_count == 0) {
soft_pwm_fan = fanSpeedSoftPwm / 2; soft_pwm_fan = fanSpeedSoftPwm / 2;
WRITE(FAN_PIN, soft_pwm_fan > 0 ? 1 : 0); WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
} }
if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN, 0); if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
#endif //FAN_SOFT_PWM #endif //FAN_SOFT_PWM
pwm_count += (1 << SOFT_PWM_SCALE); pwm_count += (1 << SOFT_PWM_SCALE);

Loading…
Cancel
Save