Add alternative TERN macros

This commit is contained in:
Scott Lahteine 2020-11-07 18:28:29 -06:00
parent 5bf82b34c6
commit 367e717aeb
15 changed files with 26 additions and 20 deletions

View file

@ -248,7 +248,7 @@ bool wait_for_heatup = true;
bool wait_for_user; // = false; bool wait_for_user; // = false;
void wait_for_user_response(millis_t ms/*=0*/, const bool no_sleep/*=false*/) { void wait_for_user_response(millis_t ms/*=0*/, const bool no_sleep/*=false*/) {
TERN(ADVANCED_PAUSE_FEATURE,,UNUSED(no_sleep)); UNUSED(no_sleep);
KEEPALIVE_STATE(PAUSED_FOR_USER); KEEPALIVE_STATE(PAUSED_FOR_USER);
wait_for_user = true; wait_for_user = true;
if (ms) ms += millis(); // expire time if (ms) ms += millis(); // expire time

View file

@ -196,6 +196,9 @@
#define __TERN(T,V...) ___TERN(_CAT(_NO,T),V) // Prepend '_NO' to get '_NOT_0' or '_NOT_1' #define __TERN(T,V...) ___TERN(_CAT(_NO,T),V) // Prepend '_NO' to get '_NOT_0' or '_NOT_1'
#define ___TERN(P,V...) THIRD(P,V) // If first argument has a comma, A. Else B. #define ___TERN(P,V...) THIRD(P,V) // If first argument has a comma, A. Else B.
#define IF_ENABLED TERN_
#define IF_DISABLED(O,A) TERN(O,,A)
#define ANY(V...) !DISABLED(V) #define ANY(V...) !DISABLED(V)
#define NONE(V...) DISABLED(V) #define NONE(V...) DISABLED(V)
#define ALL(V...) ENABLED(V) #define ALL(V...) ENABLED(V)

View file

@ -54,17 +54,17 @@ public:
#endif #endif
static inline float get_measurement(const AxisEnum a) { static inline float get_measurement(const AxisEnum a) {
UNUSED(a);
// Return the measurement averaged over all readings // Return the measurement averaged over all readings
return TERN(MEASURE_BACKLASH_WHEN_PROBING return TERN(MEASURE_BACKLASH_WHEN_PROBING
, measured_count[a] > 0 ? measured_mm[a] / measured_count[a] : 0 , measured_count[a] > 0 ? measured_mm[a] / measured_count[a] : 0
, 0 , 0
); );
TERN(MEASURE_BACKLASH_WHEN_PROBING,,UNUSED(a));
} }
static inline bool has_measurement(const AxisEnum a) { static inline bool has_measurement(const AxisEnum a) {
UNUSED(a);
return TERN0(MEASURE_BACKLASH_WHEN_PROBING, measured_count[a] > 0); return TERN0(MEASURE_BACKLASH_WHEN_PROBING, measured_count[a] > 0);
TERN(MEASURE_BACKLASH_WHEN_PROBING,,UNUSED(a));
} }
static inline bool has_any_measurement() { static inline bool has_any_measurement() {

View file

@ -110,7 +110,7 @@ public:
#if CONJOINED_NEOPIXEL #if CONJOINED_NEOPIXEL
adaneo2.show(); adaneo2.show();
#else #else
TERN(NEOPIXEL2_SEPARATE,,adaneo1.setPin(NEOPIXEL2_PIN)); IF_DISABLED(NEOPIXEL2_SEPARATE, adaneo1.setPin(NEOPIXEL2_PIN));
adaneo1.show(); adaneo1.show();
adaneo1.setPin(NEOPIXEL_PIN); adaneo1.setPin(NEOPIXEL_PIN);
#endif #endif

View file

@ -123,7 +123,7 @@ bool MarlinUI::detected() { return true; }
custom_start_bmp custom_start_bmp
#endif #endif
; ;
TERN(CUSTOM_BOOTSCREEN_ANIMATED,,UNUSED(frame)); UNUSED(frame);
u8g.drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp); u8g.drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp);

View file

@ -253,6 +253,9 @@
#define __TERN(T,V...) ___TERN(_CAT(_NO,T),V) // Prepend '_NO' to get '_NOT_0' or '_NOT_1' #define __TERN(T,V...) ___TERN(_CAT(_NO,T),V) // Prepend '_NO' to get '_NOT_0' or '_NOT_1'
#define ___TERN(P,V...) THIRD(P,V) // If first argument has a comma, A. Else B. #define ___TERN(P,V...) THIRD(P,V) // If first argument has a comma, A. Else B.
#define IF_ENABLED TERN_
#define IF_DISABLED(O,A) _TERN(_ENA_1(O),,A)
#define ANY(V...) !DISABLED(V) #define ANY(V...) !DISABLED(V)
#define NONE(V...) DISABLED(V) #define NONE(V...) DISABLED(V)
#define ALL(V...) ENABLED(V) #define ALL(V...) ENABLED(V)

View file

@ -81,7 +81,7 @@ void MarlinUI::save_previous_screen() {
} }
void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) { void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) {
TERN(TURBO_BACK_MENU_ITEM,,constexpr bool is_back = false); IF_DISABLED(TURBO_BACK_MENU_ITEM, constexpr bool is_back = false);
TERN_(HAS_TOUCH_XPT2046, on_edit_screen = false); TERN_(HAS_TOUCH_XPT2046, on_edit_screen = false);
if (screen_history_depth > 0) { if (screen_history_depth > 0) {
menuPosition &sh = screen_history[--screen_history_depth]; menuPosition &sh = screen_history[--screen_history_depth];

View file

@ -202,12 +202,12 @@ void menu_backlash();
// Helpers for editing PID Ki & Kd values // Helpers for editing PID Ki & Kd values
// grab the PID value out of the temp variable; scale it; then update the PID driver // grab the PID value out of the temp variable; scale it; then update the PID driver
void copy_and_scalePID_i(int16_t e) { void copy_and_scalePID_i(int16_t e) {
TERN(PID_PARAMS_PER_HOTEND,,UNUSED(e)); UNUSED(e);
PID_PARAM(Ki, e) = scalePID_i(raw_Ki); PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
thermalManager.updatePID(); thermalManager.updatePID();
} }
void copy_and_scalePID_d(int16_t e) { void copy_and_scalePID_d(int16_t e) {
TERN(PID_PARAMS_PER_HOTEND,,UNUSED(e)); UNUSED(e);
PID_PARAM(Kd, e) = scalePID_d(raw_Kd); PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
thermalManager.updatePID(); thermalManager.updatePID();
} }

View file

@ -219,7 +219,7 @@ static PGM_P pause_header() {
#define HOTEND_STATUS_ITEM() do { \ #define HOTEND_STATUS_ITEM() do { \
if (_menuLineNr == _thisItemNr) { \ if (_menuLineNr == _thisItemNr) { \
if (ui.should_draw()) { \ if (ui.should_draw()) { \
TERN(HAS_GRAPHICAL_TFT,, MenuItem_static::draw(_lcdLineNr, GET_TEXT(MSG_FILAMENT_CHANGE_NOZZLE), SS_INVERT)); \ IF_DISABLED(HAS_GRAPHICAL_TFT, MenuItem_static::draw(_lcdLineNr, GET_TEXT(MSG_FILAMENT_CHANGE_NOZZLE), SS_INVERT)); \
ui.draw_hotend_status(_lcdLineNr, hotend_status_extruder); \ ui.draw_hotend_status(_lcdLineNr, hotend_status_extruder); \
} \ } \
if (_skipStatic && encoderLine <= _thisItemNr) { \ if (_skipStatic && encoderLine <= _thisItemNr) { \

View file

@ -64,7 +64,7 @@ static void _lcd_mesh_fine_tune(PGM_P const msg) {
ubl.encoder_diff > 0 ? 0.005f : -0.005f ubl.encoder_diff > 0 ? 0.005f : -0.005f
); );
ubl.encoder_diff = 0; ubl.encoder_diff = 0;
TERN(IS_TFTGLCD_PANEL,,ui.refresh(LCDVIEW_CALL_REDRAW_NEXT)); IF_DISABLED(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
} }
TERN_(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT)); TERN_(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));

View file

@ -1497,7 +1497,7 @@ void MarlinSettings::postprocess() {
} }
DEBUG_ECHO_START(); DEBUG_ECHO_START();
DEBUG_ECHOLNPAIR("EEPROM version mismatch (EEPROM=", stored_ver, " Marlin=" EEPROM_VERSION ")"); DEBUG_ECHOLNPAIR("EEPROM version mismatch (EEPROM=", stored_ver, " Marlin=" EEPROM_VERSION ")");
TERN(EEPROM_AUTO_INIT,,ui.eeprom_alert_version()); IF_DISABLED(EEPROM_AUTO_INIT, ui.eeprom_alert_version());
eeprom_error = true; eeprom_error = true;
} }
else { else {
@ -2325,13 +2325,13 @@ void MarlinSettings::postprocess() {
if (eeprom_error) { if (eeprom_error) {
DEBUG_ECHO_START(); DEBUG_ECHO_START();
DEBUG_ECHOLNPAIR("Index: ", int(eeprom_index - (EEPROM_OFFSET)), " Size: ", datasize()); DEBUG_ECHOLNPAIR("Index: ", int(eeprom_index - (EEPROM_OFFSET)), " Size: ", datasize());
TERN(EEPROM_AUTO_INIT,,ui.eeprom_alert_index()); IF_DISABLED(EEPROM_AUTO_INIT, ui.eeprom_alert_index());
} }
else if (working_crc != stored_crc) { else if (working_crc != stored_crc) {
eeprom_error = true; eeprom_error = true;
DEBUG_ERROR_START(); DEBUG_ERROR_START();
DEBUG_ECHOLNPAIR("EEPROM CRC mismatch - (stored) ", stored_crc, " != ", working_crc, " (calculated)!"); DEBUG_ECHOLNPAIR("EEPROM CRC mismatch - (stored) ", stored_crc, " != ", working_crc, " (calculated)!");
TERN(EEPROM_AUTO_INIT,,ui.eeprom_alert_crc()); IF_DISABLED(EEPROM_AUTO_INIT, ui.eeprom_alert_crc());
} }
else if (!validating) { else if (!validating) {
DEBUG_ECHO_START(); DEBUG_ECHO_START();

View file

@ -180,7 +180,7 @@ bool Stepper::abort_current_block;
uint32_t Stepper::acceleration_time, Stepper::deceleration_time; uint32_t Stepper::acceleration_time, Stepper::deceleration_time;
uint8_t Stepper::steps_per_isr; uint8_t Stepper::steps_per_isr;
TERN(ADAPTIVE_STEP_SMOOTHING,,constexpr) uint8_t Stepper::oversampling_factor; IF_DISABLED(ADAPTIVE_STEP_SMOOTHING, constexpr) uint8_t Stepper::oversampling_factor;
xyze_long_t Stepper::delta_error{0}; xyze_long_t Stepper::delta_error{0};

View file

@ -268,7 +268,7 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY,
int16_t Temperature::maxtemp_raw_BED = HEATER_BED_RAW_HI_TEMP; int16_t Temperature::maxtemp_raw_BED = HEATER_BED_RAW_HI_TEMP;
#endif #endif
TERN_(WATCH_BED, bed_watch_t Temperature::watch_bed); // = { 0 } TERN_(WATCH_BED, bed_watch_t Temperature::watch_bed); // = { 0 }
TERN(PIDTEMPBED,, millis_t Temperature::next_bed_check_ms); IF_DISABLED(PIDTEMPBED, millis_t Temperature::next_bed_check_ms);
#endif // HAS_HEATED_BED #endif // HAS_HEATED_BED
#if HAS_TEMP_CHAMBER #if HAS_TEMP_CHAMBER

View file

@ -392,7 +392,7 @@ class Temperature {
#if HAS_HEATED_BED #if HAS_HEATED_BED
TERN_(WATCH_BED, static bed_watch_t watch_bed); TERN_(WATCH_BED, static bed_watch_t watch_bed);
TERN(PIDTEMPBED,,static millis_t next_bed_check_ms); IF_DISABLED(PIDTEMPBED, static millis_t next_bed_check_ms);
#ifdef BED_MINTEMP #ifdef BED_MINTEMP
static int16_t mintemp_raw_BED; static int16_t mintemp_raw_BED;
#endif #endif

View file

@ -799,8 +799,8 @@ void tool_change_prime() {
// Park // Park
#if ENABLED(TOOLCHANGE_PARK) #if ENABLED(TOOLCHANGE_PARK)
if (ok) { if (ok) {
TERN(TOOLCHANGE_PARK_Y_ONLY,,current_position.x = toolchange_settings.change_point.x); IF_DISABLED(TOOLCHANGE_PARK_Y_ONLY, current_position.x = toolchange_settings.change_point.x);
TERN(TOOLCHANGE_PARK_X_ONLY,,current_position.y = toolchange_settings.change_point.y); IF_DISABLED(TOOLCHANGE_PARK_X_ONLY, current_position.y = toolchange_settings.change_point.y);
planner.buffer_line(current_position, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE), active_extruder); planner.buffer_line(current_position, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE), active_extruder);
planner.synchronize(); planner.synchronize();
} }
@ -998,8 +998,8 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
// Toolchange park // Toolchange park
#if ENABLED(TOOLCHANGE_PARK) && DISABLED(SWITCHING_NOZZLE) #if ENABLED(TOOLCHANGE_PARK) && DISABLED(SWITCHING_NOZZLE)
if (can_move_away && toolchange_settings.enable_park) { if (can_move_away && toolchange_settings.enable_park) {
TERN(TOOLCHANGE_PARK_Y_ONLY,,current_position.x = toolchange_settings.change_point.x); IF_DISABLED(TOOLCHANGE_PARK_Y_ONLY, current_position.x = toolchange_settings.change_point.x);
TERN(TOOLCHANGE_PARK_X_ONLY,,current_position.y = toolchange_settings.change_point.y); IF_DISABLED(TOOLCHANGE_PARK_X_ONLY, current_position.y = toolchange_settings.change_point.y);
planner.buffer_line(current_position, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE), old_tool); planner.buffer_line(current_position, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE), old_tool);
planner.synchronize(); planner.synchronize();
} }