Apply TERN to compact code (#17619)

This commit is contained in:
Scott Lahteine
2020-04-22 16:35:03 -05:00
committed by GitHub
parent 88bdd26c99
commit 6d90d1e1f5
162 changed files with 1493 additions and 3530 deletions

View File

@ -734,9 +734,7 @@ void DGUSScreenVariableHandler::HandleSettings(DGUS_VP_Variable &var, void *val_
switch (value) {
default: break;
case 1:
#if ENABLED(PRINTCOUNTER)
print_job_timer.initStats();
#endif
TERN_(PRINTCOUNTER, print_job_timer.initStats());
queue.enqueue_now_P(PSTR("M502\nM500"));
break;
case 2: queue.enqueue_now_P(PSTR("M501")); break;
@ -958,17 +956,13 @@ void DGUSScreenVariableHandler::HandleHeaterControl(DGUS_VP_Variable &var, void
#if HOTENDS >= 1
case VP_E0_BED_PREHEAT:
thermalManager.setTargetHotend(e_temp, 0);
#if HAS_HEATED_BED
thermalManager.setTargetBed(bed_temp);
#endif
TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(bed_temp));
break;
#endif
#if HOTENDS >= 2
case VP_E1_BED_PREHEAT:
thermalManager.setTargetHotend(e_temp, 1);
#if HAS_HEATED_BED
thermalManager.setTargetBed(bed_temp);
#endif
TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(bed_temp));
break;
#endif
}
@ -1002,9 +996,7 @@ void DGUSScreenVariableHandler::HandleHeaterControl(DGUS_VP_Variable &var, void
#endif
break;
case 1: // Load ABS
#if ENABLED(PREHEAT_2_TEMP_HOTEND)
e_temp = PREHEAT_2_TEMP_HOTEND;
#endif
TERN_(PREHEAT_2_TEMP_HOTEND, e_temp = PREHEAT_2_TEMP_HOTEND);
break;
case 2: // Load PET
#ifdef PREHEAT_3_TEMP_HOTEND
@ -1227,9 +1219,8 @@ bool DGUSScreenVariableHandler::loop() {
#if ENABLED(SHOW_BOOTSCREEN)
static bool booted = false;
#if ENABLED(POWER_LOSS_RECOVERY)
if (!booted && recovery.valid()) booted = true;
#endif
if (!booted && TERN0(POWER_LOSS_RECOVERY, recovery.valid()))
booted = true;
if (!booted && ELAPSED(ms, BOOTSCREEN_TIMEOUT)) {
booted = true;
GotoScreen(DGUSLCD_SCREEN_MAIN);

View File

@ -453,9 +453,7 @@ bool UIFlashStorage::is_present = false;
if (nBytes != write_page_size)
break;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::yield();
#endif
TERN_(EXTENSIBLE_UI, ExtUI::yield());
}
SERIAL_ECHOLNPGM("DONE");
@ -493,9 +491,7 @@ bool UIFlashStorage::is_present = false;
addr += nBytes;
if (nBytes != write_page_size) break;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::yield();
#endif
TERN_(EXTENSIBLE_UI, ExtUI::yield());
};
if (verifyOk) {

View File

@ -922,9 +922,8 @@ template <class T> bool CLCD::CommandFifo::_write_unaligned(T data, uint16_t len
uint32_t command_read_ptr;
#if ENABLED(TOUCH_UI_DEBUG)
if (command_write_ptr == 0xFFFFFFFFul) {
SERIAL_ECHO_MSG("Attempt to write to FIFO before CommandFifo::Cmd_Start().");
}
if (command_write_ptr == 0xFFFFFFFFul)
SERIAL_ECHO_MSG("Attempt to write to FIFO before CommandFifo::Cmd_Start().");
#endif
/* Wait until there is enough space in the circular buffer for the transfer */
@ -1160,24 +1159,15 @@ void CLCD::default_display_orientation() {
// processor to do this since it will also update the transform matrices.
if (FTDI::ftdi_chip >= 810) {
CommandFifo cmd;
cmd.setrotate(0
#if ENABLED(TOUCH_UI_MIRRORED)
+ 4
#endif
#if ENABLED(TOUCH_UI_PORTRAIT)
+ 2
#endif
#if ENABLED(TOUCH_UI_INVERTED)
+ 1
#endif
cmd.setrotate(
ENABLED(TOUCH_UI_MIRRORED) * 4
+ ENABLED(TOUCH_UI_PORTRAIT) * 2
+ ENABLED(TOUCH_UI_INVERTED) * 1
);
cmd.execute();
}
else {
#if ENABLED(TOUCH_UI_INVERTED)
mem_write_32(REG::ROTATE, 1);
#endif
}
else
TERN_(TOUCH_UI_INVERTED, mem_write_32(REG::ROTATE, 1));
#elif ANY(TOUCH_UI_PORTRAIT, TOUCH_UI_MIRRORED)
#error "PORTRAIT or MIRRORED orientation not supported on the FT800."
#elif ENABLED(TOUCH_UI_INVERTED)

View File

@ -206,14 +206,58 @@
// Define macros for compatibility
#define _CAT(a, ...) a ## __VA_ARGS__
#define SWITCH_ENABLED_ 1
#define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
#define DISABLED(b) !ENABLED(b)
#define ANY(A,B) (ENABLED(A) || ENABLED(B))
#define EITHER(A,B) (ENABLED(A) || ENABLED(B))
#define BOTH(A,B) (ENABLED(A) && ENABLED(B))
#define NONE(A,B) (DISABLED(A) && DISABLED(B))
#define _CAT(a,V...) a##V
#define CAT(a,V...) _CAT(a,V)
#define FIRST(a,...) a
#define SECOND(a,b,...) b
#define THIRD(a,b,c,...) c
#define IS_PROBE(V...) SECOND(V, 0) // Get the second item passed, or 0
#define PROBE() ~, 1 // Second item will be 1 if this is passed
#define _NOT_0 PROBE()
#define NOT(x) IS_PROBE(_CAT(_NOT_, x)) // NOT('0') gets '1'. Anything else gets '0'.
#define _BOOL(x) NOT(NOT(x)) // NOT('0') gets '0'. Anything else gets '1'.
#define _DO_1(W,C,A) (_##W##_1(A))
#define _DO_2(W,C,A,B) (_##W##_1(A) C _##W##_1(B))
#define _DO_3(W,C,A,V...) (_##W##_1(A) C _DO_2(W,C,V))
#define _DO_4(W,C,A,V...) (_##W##_1(A) C _DO_3(W,C,V))
#define _DO_5(W,C,A,V...) (_##W##_1(A) C _DO_4(W,C,V))
#define _DO_6(W,C,A,V...) (_##W##_1(A) C _DO_5(W,C,V))
#define _DO_7(W,C,A,V...) (_##W##_1(A) C _DO_6(W,C,V))
#define _DO_8(W,C,A,V...) (_##W##_1(A) C _DO_7(W,C,V))
#define _DO_9(W,C,A,V...) (_##W##_1(A) C _DO_8(W,C,V))
#define _DO_10(W,C,A,V...) (_##W##_1(A) C _DO_9(W,C,V))
#define _DO_11(W,C,A,V...) (_##W##_1(A) C _DO_10(W,C,V))
#define _DO_12(W,C,A,V...) (_##W##_1(A) C _DO_11(W,C,V))
#define __DO_N(W,C,N,V...) _DO_##N(W,C,V)
#define _DO_N(W,C,N,V...) __DO_N(W,C,N,V)
#define DO(W,C,V...) _DO_N(W,C,NUM_ARGS(V),V)
#define _ISENA_ ~,1
#define _ISENA_1 ~,1
#define _ISENA_0x1 ~,1
#define _ISENA_true ~,1
#define _ISENA(V...) IS_PROBE(V)
#define _ENA_1(O) _ISENA(CAT(_IS,CAT(ENA_, O)))
#define _DIS_1(O) NOT(_ENA_1(O))
#define ENABLED(V...) DO(ENA,&&,V)
#define DISABLED(V...) DO(DIS,&&,V)
#define TERN(O,A,B) _TERN(_ENA_1(O),B,A) // OPTION converted to '0' or '1'
#define TERN0(O,A) _TERN(_ENA_1(O),0,A) // OPTION converted to A or '0'
#define TERN1(O,A) _TERN(_ENA_1(O),1,A) // OPTION converted to A or '1'
#define TERN_(O,A) _TERN(_ENA_1(O),,A) // OPTION converted to A or '<nul>'
#define _TERN(E,V...) __TERN(_CAT(T_,E),V) // Prepend 'T_' to get 'T_0' or 'T_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 ANY(V...) !DISABLED(V)
#define NONE(V...) DISABLED(V)
#define ALL(V...) ENABLED(V)
#define BOTH(V1,V2) ALL(V1,V2)
#define EITHER(V1,V2) ANY(V1,V2)
// Remove compiler warning on an unused variable
#ifndef UNUSED

View File

@ -78,9 +78,7 @@ void BaseScreen::onIdle() {
}
void BaseScreen::reset_menu_timeout() {
#if LCD_TIMEOUT_TO_STATUS
last_interaction = millis();
#endif
TERN_(LCD_TIMEOUT_TO_STATUS, last_interaction = millis());
}
#if LCD_TIMEOUT_TO_STATUS

View File

@ -198,16 +198,14 @@ void StatusScreen::draw_temperature(draw_mode_t what) {
void StatusScreen::draw_syringe(draw_mode_t what) {
int16_t x, y, h, v;
#ifdef E_MAX_POS
const float fill_level = 1.0 - min(1.0, max(0.0, getAxisPosition_mm(E0) / E_MAX_POS));
#else
const float fill_level = 0.75;
#endif
const bool e_homed = (true
#if ENABLED(TOUCH_UI_LULZBOT_BIO)
&& isAxisPositionKnown(E0)
const float fill_level = (
#ifdef E_MAX_POS
1.0 - min(1.0, max(0.0, getAxisPosition_mm(E0) / E_MAX_POS))
#else
0.75
#endif
);
const bool e_homed = TERN0(TOUCH_UI_LULZBOT_BIO, isAxisPositionKnown(E0));
CommandProcessor cmd;
PolyUI ui(cmd, what);
@ -237,12 +235,8 @@ void StatusScreen::draw_syringe(draw_mode_t what) {
}
void StatusScreen::draw_arrows(draw_mode_t what) {
const bool e_homed = (true
#if ENABLED(TOUCH_UI_LULZBOT_BIO)
&& isAxisPositionKnown(E0)
#endif
);
const bool z_homed = isAxisPositionKnown(Z);
const bool e_homed = TERN1(TOUCH_UI_LULZBOT_BIO, isAxisPositionKnown(E0)),
z_homed = isAxisPositionKnown(Z);
CommandProcessor cmd;
PolyUI ui(cmd, what);
@ -299,12 +293,8 @@ void StatusScreen::draw_fine_motion(draw_mode_t what) {
}
void StatusScreen::draw_overlay_icons(draw_mode_t what) {
const bool e_homed = (true
#if ENABLED(TOUCH_UI_LULZBOT_BIO)
&& isAxisPositionKnown(E0)
#endif
);
const bool z_homed = isAxisPositionKnown(Z);
const bool e_homed = TERN1(TOUCH_UI_LULZBOT_BIO, isAxisPositionKnown(E0)),
z_homed = isAxisPositionKnown(Z);
CommandProcessor cmd;
PolyUI ui(cmd, what);

View File

@ -50,11 +50,7 @@ void TuneMenu::onRedraw(draw_mode_t what) {
.font(font_medium)
.enabled( isPrinting()).tag(2).button( BTN_POS(1,2), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_SPEED))
.tag(3).button( BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_BED_TEMPERATURE))
.enabled(
#if ENABLED(BABYSTEPPING)
true
#endif
)
.enabled(TERN_(BABYSTEPPING, true))
.tag(4).button( BTN_POS(1,4), BTN_SIZE(2,1), GET_TEXT_F(MSG_NUDGE_NOZZLE))
.enabled(!isPrinting()).tag(5).button( BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_MOVE_TO_HOME))
.enabled(!isPrinting()).tag(6).button( BTN_POS(1,6), BTN_SIZE(2,1), GET_TEXT_F(MSG_RAISE_PLUNGER))

View File

@ -89,11 +89,7 @@ void FilesScreen::drawFileButton(const char* filename, uint8_t tag, bool is_dir,
cmd.cmd(MACRO(0));
}
#endif
cmd.text (BTN_POS(1,header_h+line), BTN_SIZE(6,1), filename, OPT_CENTERY
#if ENABLED(SCROLL_LONG_FILENAMES)
| OPT_NOFIT
#endif
);
cmd.text (BTN_POS(1,header_h+line), BTN_SIZE(6,1), filename, OPT_CENTERY | TERN0(SCROLL_LONG_FILENAMES, OPT_NOFIT));
if (is_dir) {
cmd.text(BTN_POS(1,header_h+line), BTN_SIZE(6,1), F("> "), OPT_CENTERY | OPT_RIGHTX);
}

View File

@ -252,9 +252,7 @@ void InterfaceSettingsScreen::loadSettings(const char *buff) {
for(uint8_t i = 0; i < InterfaceSoundsScreen::NUM_EVENTS; i++)
InterfaceSoundsScreen::event_sounds[i] = eeprom.event_sounds[i];
#if ENABLED(TOUCH_UI_DEVELOPER_MENU)
StressTestScreen::startupCheck();
#endif
TERN_(TOUCH_UI_DEVELOPER_MENU, StressTestScreen::startupCheck());
}
#ifdef ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE

View File

@ -97,12 +97,8 @@ bool TemperatureScreen::onTouchHeld(uint8_t tag) {
case 30:
#define _HOTEND_OFF(N) setTargetTemp_celsius(0,E##N);
REPEAT(HOTENDS, _HOTEND_OFF);
#if HAS_HEATED_BED
setTargetTemp_celsius(0,BED);
#endif
#if HAS_HEATED_CHAMBER
setTargetTemp_celsius(0,CHAMBER);
#endif
TERN_(HAS_HEATED_BED, setTargetTemp_celsius(0,BED));
TERN_(HAS_HEATED_CHAMBER, setTargetTemp_celsius(0,CHAMBER));
#if FAN_COUNT > 0
setTargetFan_percent(0,FAN0);
#endif

View File

@ -109,12 +109,8 @@
namespace ExtUI {
static struct {
uint8_t printer_killed : 1;
#if ENABLED(JOYSTICK)
uint8_t jogging : 1;
#endif
#if ENABLED(SDSUPPORT)
uint8_t was_sd_printing : 1;
#endif
TERN_(JOYSTICK, uint8_t jogging : 1);
TERN_(SDSUPPORT, uint8_t was_sd_printing : 1);
} flags;
#ifdef __SAM3X8E__
@ -192,9 +188,7 @@ namespace ExtUI {
case CHAMBER: return; // Chamber has no idle timer
#endif
default:
#if HAS_HOTEND
thermalManager.reset_hotend_idle_timer(heater - H0);
#endif
TERN_(HAS_HOTEND, thermalManager.reset_hotend_idle_timer(heater - H0));
break;
}
#else
@ -251,9 +245,7 @@ namespace ExtUI {
bool isHeaterIdle(const heater_t heater) {
#if HEATER_IDLE_HANDLER
switch (heater) {
#if HAS_HEATED_BED
case BED: return thermalManager.bed_idle.timed_out;
#endif
TERN_(HAS_HEATED_BED, case BED: return thermalManager.bed_idle.timed_out);
#if HAS_HEATED_CHAMBER
case CHAMBER: return false; // Chamber has no idle timer
#endif
@ -278,12 +270,8 @@ namespace ExtUI {
float getActualTemp_celsius(const heater_t heater) {
switch (heater) {
#if HAS_HEATED_BED
case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degBed());
#endif
#if HAS_HEATED_CHAMBER
case CHAMBER: return GET_TEMP_ADJUSTMENT(thermalManager.degChamber());
#endif
TERN_(HAS_HEATED_BED, case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degBed()));
TERN_(HAS_HEATED_CHAMBER, case CHAMBER: return GET_TEMP_ADJUSTMENT(thermalManager.degChamber()));
default: return GET_TEMP_ADJUSTMENT(thermalManager.degHotend(heater - H0));
}
}
@ -294,12 +282,8 @@ namespace ExtUI {
float getTargetTemp_celsius(const heater_t heater) {
switch (heater) {
#if HAS_HEATED_BED
case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetBed());
#endif
#if HAS_HEATED_CHAMBER
case CHAMBER: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetChamber());
#endif
TERN_(HAS_HEATED_BED, case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetBed()));
TERN_(HAS_HEATED_CHAMBER, case CHAMBER: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetChamber()));
default: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetHotend(heater - H0));
}
}
@ -356,28 +340,16 @@ namespace ExtUI {
#if HAS_SOFTWARE_ENDSTOPS
if (soft_endstops_enabled) switch (axis) {
case X_AXIS:
#if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
min = soft_endstop.min.x;
#endif
#if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
max = soft_endstop.max.x;
#endif
TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x);
TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x);
break;
case Y_AXIS:
#if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
min = soft_endstop.min.y;
#endif
#if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
max = soft_endstop.max.y;
#endif
TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y);
TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y);
break;
case Z_AXIS:
#if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
min = soft_endstop.min.z;
#endif
#if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
max = soft_endstop.max.z;
#endif
TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z);
TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z);
default: break;
}
#endif // HAS_SOFTWARE_ENDSTOPS
@ -541,15 +513,9 @@ namespace ExtUI {
int getTMCBumpSensitivity(const axis_t axis) {
switch (axis) {
#if X_SENSORLESS
case X: return stepperX.homing_threshold();
#endif
#if Y_SENSORLESS
case Y: return stepperY.homing_threshold();
#endif
#if Z_SENSORLESS
case Z: return stepperZ.homing_threshold();
#endif
TERN_(X_SENSORLESS, case X: return stepperX.homing_threshold());
TERN_(Y_SENSORLESS, case Y: return stepperY.homing_threshold());
TERN_(Z_SENSORLESS, case Z: return stepperZ.homing_threshold());
default: return 0;
}
}
@ -673,9 +639,7 @@ namespace ExtUI {
void setJunctionDeviation_mm(const float value) {
planner.junction_deviation_mm = constrain(value, 0.01, 0.3);
#if ENABLED(LIN_ADVANCE)
planner.recalculate_max_e_jerk();
#endif
TERN_(LIN_ADVANCE, planner.recalculate_max_e_jerk());
}
#else
@ -871,9 +835,7 @@ namespace ExtUI {
void setMeshPoint(const xy_uint8_t &pos, const float zoff) {
if (WITHIN(pos.x, 0, GRID_MAX_POINTS_X) && WITHIN(pos.y, 0, GRID_MAX_POINTS_Y)) {
Z_VALUES(pos.x, pos.y) = zoff;
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
bed_level_virt_interpolate();
#endif
TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
}
}
#endif
@ -1020,9 +982,7 @@ namespace ExtUI {
}
void setUserConfirmed() {
#if HAS_RESUME_CONTINUE
wait_for_user = false;
#endif
TERN_(HAS_RESUME_CONTINUE, wait_for_user = false);
}
void printFile(const char *filename) {