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

@@ -1731,16 +1731,36 @@
#endif
#endif
#define DO_DRAW_LOGO (STATUS_LOGO_WIDTH && ENABLED(CUSTOM_STATUS_SCREEN_IMAGE))
#define DO_DRAW_HOTENDS (HOTENDS > 0)
#define DO_DRAW_BED (HAS_HEATED_BED && HOTENDS <= 4)
#define DO_DRAW_CUTTER (HAS_CUTTER && !DO_DRAW_BED)
#define DO_DRAW_CHAMBER (HAS_TEMP_CHAMBER && STATUS_CHAMBER_WIDTH && HOTENDS <= 4)
#define DO_DRAW_FAN (HAS_FAN0 && STATUS_FAN_WIDTH && HOTENDS <= 4 && defined(STATUS_FAN_FRAMES))
#define ANIM_HOTEND (HOTENDS && ENABLED(STATUS_HOTEND_ANIM))
#define ANIM_BED (DO_DRAW_BED && ENABLED(STATUS_BED_ANIM))
#define ANIM_CHAMBER (DO_DRAW_CHAMBER && ENABLED(STATUS_CHAMBER_ANIM))
#define ANIM_CUTTER (DO_DRAW_CUTTER && ENABLED(STATUS_CUTTER_ANIM))
#define ANIM_HBCC (ANIM_HOTEND || ANIM_BED || ANIM_CHAMBER || ANIM_CUTTER)
#if STATUS_LOGO_WIDTH && ENABLED(CUSTOM_STATUS_SCREEN_IMAGE)
#define DO_DRAW_LOGO 1
#endif
#if HOTENDS > 0
#define DO_DRAW_HOTENDS 1
#endif
#if HAS_HEATED_BED && HOTENDS <= 4
#define DO_DRAW_BED 1
#endif
#if HAS_CUTTER && !DO_DRAW_BED
#define DO_DRAW_CUTTER 1
#endif
#if HAS_TEMP_CHAMBER && STATUS_CHAMBER_WIDTH && HOTENDS <= 4
#define DO_DRAW_CHAMBER 1
#endif
#if HAS_FAN0 && STATUS_FAN_WIDTH && HOTENDS <= 4 && defined(STATUS_FAN_FRAMES)
#define DO_DRAW_FAN 1
#endif
#if HOTENDS && ENABLED(STATUS_HOTEND_ANIM)
#define ANIM_HOTEND 1
#endif
#if DO_DRAW_BED && ENABLED(STATUS_BED_ANIM)
#define ANIM_BED 1
#endif
#if DO_DRAW_CHAMBER && ENABLED(STATUS_CHAMBER_ANIM)
#define ANIM_CHAMBER 1
#endif
#if DO_DRAW_CUTTER && ENABLED(STATUS_CUTTER_ANIM)
#define ANIM_CUTTER 1
#endif
#if ANIM_HOTEND || ANIM_BED || ANIM_CHAMBER || ANIM_CUTTER
#define ANIM_HBCC 1
#endif

View File

@@ -56,7 +56,7 @@
#include "../../module/printcounter.h"
#endif
#if DUAL_MIXING_EXTRUDER
#if HAS_DUAL_MIXING
#include "../../feature/mixing.h"
#endif
@@ -365,15 +365,11 @@ void MarlinUI::draw_status_screen() {
#if ANIM_HOTEND
HOTEND_LOOP() if (thermalManager.isHeatingHotend(e)) SBI(new_bits, HEATBIT_HOTEND + e);
#endif
#if ANIM_BED
if (thermalManager.isHeatingBed()) SBI(new_bits, HEATBIT_BED);
#endif
if (TERN0(ANIM_BED, thermalManager.isHeatingBed())) SBI(new_bits, HEATBIT_BED);
#if DO_DRAW_CHAMBER && HAS_HEATED_CHAMBER
if (thermalManager.isHeatingChamber()) SBI(new_bits, HEATBIT_CHAMBER);
#endif
#if ANIM_CUTTER
if (cutter.enabled()) SBI(new_bits, HEATBIT_CUTTER);
#endif
if (TERN0(ANIM_CUTTER, cutter.enabled())) SBI(new_bits, HEATBIT_CUTTER);
heat_bits = new_bits;
#endif
@@ -555,14 +551,10 @@ void MarlinUI::draw_status_screen() {
#endif
// Heated Bed
#if DO_DRAW_BED
_draw_bed_status(blink);
#endif
TERN_(DO_DRAW_BED, _draw_bed_status(blink));
// Heated Chamber
#if DO_DRAW_CHAMBER
_draw_chamber_status();
#endif
TERN_(DO_DRAW_CHAMBER, _draw_chamber_status());
// Fan, if a bitmap was provided
#if DO_DRAW_FAN
@@ -695,7 +687,7 @@ void MarlinUI::draw_status_screen() {
u8g.setColorIndex(0); // white on black
#endif
#if DUAL_MIXING_EXTRUDER
#if HAS_DUAL_MIXING
// Two-component mix / gradient instead of XY

View File

@@ -537,14 +537,9 @@ void ST7920_Lite_Status_Screen::draw_heat_icon(const bool whichIcon, const bool
static struct {
bool E1_show_target : 1;
bool E2_show_target : 1;
#if HAS_HEATED_BED
bool bed_show_target : 1;
#endif
TERN_(HAS_HEATED_BED, bool bed_show_target : 1);
} display_state = {
true, true
#if HAS_HEATED_BED
, true
#endif
true, true, TERN_(HAS_HEATED_BED, true)
};
void ST7920_Lite_Status_Screen::draw_temps(uint8_t line, const int16_t temp, const int16_t target, bool showTarget, bool targetStateChange) {
@@ -672,11 +667,7 @@ void ST7920_Lite_Status_Screen::draw_position(const xyze_pos_t &pos, const bool
// If position is unknown, flash the labels.
const unsigned char alt_label = position_known ? 0 : (ui.get_blink() ? ' ' : 0);
if (true
#if ENABLED(LCD_SHOW_E_TOTAL)
&& !printingIsActive()
#endif
) {
if (TERN1(LCD_SHOW_E_TOTAL, !printingIsActive())) {
write_byte(alt_label ? alt_label : 'X');
write_str(dtostrf(pos.x, -4, 0, str), 4);
@@ -712,13 +703,8 @@ bool ST7920_Lite_Status_Screen::indicators_changed() {
#endif
static uint16_t last_checksum = 0;
const uint16_t checksum = blink ^ feedrate_perc ^ fs ^ extruder_1_target
#if HOTENDS > 1
^ extruder_2_target
#endif
#if HAS_HEATED_BED
^ bed_target
#endif
;
^ TERN0(HAS_MULTI_HOTEND, extruder_2_target)
^ TERN0(HAS_HEATED_BED, bed_target);
if (last_checksum == checksum) return false;
last_checksum = checksum;
return true;
@@ -741,12 +727,8 @@ void ST7920_Lite_Status_Screen::update_indicators(const bool forceUpdate) {
#endif
draw_extruder_1_temp(extruder_1_temp, extruder_1_target, forceUpdate);
#if HAS_MULTI_HOTEND
draw_extruder_2_temp(extruder_2_temp, extruder_2_target, forceUpdate);
#endif
#if HAS_HEATED_BED
draw_bed_temp(bed_temp, bed_target, forceUpdate);
#endif
TERN_(HAS_MULTI_HOTEND, draw_extruder_2_temp(extruder_2_temp, extruder_2_target, forceUpdate));
TERN_(HAS_HEATED_BED, draw_bed_temp(bed_temp, bed_target, forceUpdate));
uint16_t spd = thermalManager.fan_speed[0];
@@ -761,9 +743,7 @@ void ST7920_Lite_Status_Screen::update_indicators(const bool forceUpdate) {
// Update the fan and bed animations
if (spd) draw_fan_icon(blink);
#if HAS_HEATED_BED
draw_heat_icon(bed_target > 0 && blink, bed_target > 0);
#endif
TERN_(HAS_HEATED_BED, draw_heat_icon(bed_target > 0 && blink, bed_target > 0));
}
}
@@ -813,9 +793,7 @@ void ST7920_Lite_Status_Screen::update_status_or_position(bool forceUpdate) {
* If STATUS_EXPIRE_SECONDS is zero, only the status is shown.
*/
if (forceUpdate || status_changed()) {
#if ENABLED(STATUS_MESSAGE_SCROLLING)
ui.status_scroll_offset = 0;
#endif
TERN_(STATUS_MESSAGE_SCROLLING, ui.status_scroll_offset = 0);
#if STATUS_EXPIRE_SECONDS
countdown = ui.status_message[0] ? STATUS_EXPIRE_SECONDS : 0;
#endif
@@ -823,26 +801,20 @@ void ST7920_Lite_Status_Screen::update_status_or_position(bool forceUpdate) {
blink_changed(); // Clear changed flag
}
#if !STATUS_EXPIRE_SECONDS
#if ENABLED(STATUS_MESSAGE_SCROLLING)
else if (blink_changed())
draw_status_message();
#endif
else if (TERN0(STATUS_MESSAGE_SCROLLING, blink_changed()))
draw_status_message();
#else
else if (blink_changed()) {
if (countdown > 1) {
countdown--;
#if ENABLED(STATUS_MESSAGE_SCROLLING)
draw_status_message();
#endif
TERN_(STATUS_MESSAGE_SCROLLING, draw_status_message());
}
else if (countdown > 0) {
if (position_changed()) {
countdown--;
forceUpdate = true;
}
#if ENABLED(STATUS_MESSAGE_SCROLLING)
draw_status_message();
#endif
TERN_(STATUS_MESSAGE_SCROLLING, draw_status_message());
}
}

View File

@@ -227,9 +227,7 @@ bool MarlinUI::detected() { return true; }
}
void MarlinUI::show_bootscreen() {
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
show_custom_bootscreen();
#endif
TERN_(SHOW_CUSTOM_BOOTSCREEN, show_custom_bootscreen());
show_marlin_bootscreen();
}
@@ -267,17 +265,11 @@ void MarlinUI::init_lcd() {
WRITE(LCD_BACKLIGHT_PIN, HIGH);
#endif
#if HAS_LCD_CONTRAST
refresh_contrast();
#endif
TERN_(HAS_LCD_CONTRAST, refresh_contrast());
#if ENABLED(LCD_SCREEN_ROT_90)
u8g.setRot90();
#elif ENABLED(LCD_SCREEN_ROT_180)
u8g.setRot180();
#elif ENABLED(LCD_SCREEN_ROT_270)
u8g.setRot270();
#endif
TERN_(LCD_SCREEN_ROT_90, u8g.setRot90());
TERN_(LCD_SCREEN_ROT_180, u8g.setRot180());
TERN_(LCD_SCREEN_ROT_270, u8g.setRot270());
#endif // !MKS_LCD12864B
@@ -286,9 +278,7 @@ void MarlinUI::init_lcd() {
// The kill screen is displayed for unrecoverable conditions
void MarlinUI::draw_kill_screen() {
#if ENABLED(LIGHTWEIGHT_UI)
ST7920_Lite_Status_Screen::clear_text_buffer();
#endif
TERN_(LIGHTWEIGHT_UI, ST7920_Lite_Status_Screen::clear_text_buffer());
const u8g_uint_t h4 = u8g.getHeight() / 4;
u8g.firstPage();
do {