Skip to content

Commit

Permalink
Apply ternary macros
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Apr 27, 2020
1 parent 967c1d8 commit c536b8d
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 230 deletions.
46 changes: 11 additions & 35 deletions Marlin/src/feature/runout.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ class TFilamentMonitor : public FilamentMonitorBase {

// Give the response a chance to update its counter.
static inline void run() {
if (enabled && !filament_ran_out && (printingIsActive()
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|| did_pause_print
#endif
)) {
if ( enabled && !filament_ran_out
&& (printingIsActive() || TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print))
) {
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
cli(); // Prevent RunoutResponseDelayed::block_completed from accumulating here
#endif
Expand Down Expand Up @@ -153,11 +151,7 @@ class FilamentSensorBase {

// Return a bitmask of runout flag states (1 bits always indicates runout)
static inline uint8_t poll_runout_states() {
return (poll_runout_pins()
#if DISABLED(FIL_RUNOUT_INVERTING)
^ uint8_t(_BV(NUM_RUNOUT_SENSORS) - 1)
#endif
);
return poll_runout_pins() ^ uint8_t(TERN0(FIL_RUNOUT_INVERTING, _BV(NUM_RUNOUT_SENSORS) - 1));

This comment has been minimized.

Copy link
@studiodyne

studiodyne Apr 27, 2020

Contributor

@thinkyhead Since this commit , runout detection is inverted
This line is inverted. 'just suggestion'

This comment has been minimized.

Copy link
@thinkyhead

thinkyhead May 6, 2020

Author Member

I don't understand why you post a comment in an obscure location when a patch would be so much kinder, both to me and to the community which has had to wait 8 days for this random discovery.

}

#undef INIT_RUNOUT_PIN
Expand Down Expand Up @@ -217,26 +211,14 @@ class FilamentSensorBase {
private:
static inline bool poll_runout_state(const uint8_t extruder) {
const uint8_t runout_states = poll_runout_states();

#if NUM_RUNOUT_SENSORS == 1
UNUSED(extruder);
#else
if ( !TERN0(DUAL_X_CARRIAGE, dxc_is_duplicating())
&& !TERN0(MULTI_NOZZLE_DUPLICATION, extruder_duplication_enabled)
) return TEST(runout_states, extruder); // A specific extruder ran out
#endif

if (true
#if NUM_RUNOUT_SENSORS > 1
#if ENABLED(DUAL_X_CARRIAGE)
&& (dual_x_carriage_mode == DXC_DUPLICATION_MODE || dual_x_carriage_mode == DXC_MIRRORED_MODE)
#elif ENABLED(MULTI_NOZZLE_DUPLICATION)
&& extruder_duplication_enabled
#else
&& false
#endif
#endif
) return runout_states; // Any extruder

#if NUM_RUNOUT_SENSORS > 1
return TEST(runout_states, extruder); // Specific extruder
#endif
return !!runout_states; // Any extruder ran out
}

public:
Expand Down Expand Up @@ -302,9 +284,7 @@ class FilamentSensorBase {

static inline void block_completed(const block_t* const b) {
if (b->steps.x || b->steps.y || b->steps.z
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|| did_pause_print // Allow pause purge move to re-trigger runout state
#endif
|| TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print) // Allow pause purge move to re-trigger runout state
) {
// Only trigger on extrusion with XYZ movement to allow filament change and retract/recover.
const uint8_t e = b->extruder;
Expand Down Expand Up @@ -338,11 +318,7 @@ class FilamentSensorBase {
typedef TFilamentMonitor<
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
RunoutResponseDelayed,
#if ENABLED(FILAMENT_MOTION_SENSOR)
FilamentSensorEncoder
#else
FilamentSensorSwitch
#endif
TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch)
#else
RunoutResponseDebounced, FilamentSensorSwitch
#endif
Expand Down
8 changes: 2 additions & 6 deletions Marlin/src/gcode/feature/pause/M600.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,8 @@ void GcodeSuite::M600() {
#if EXTRUDERS > 1
// Change toolhead if specified
const uint8_t active_extruder_before_filament_change = active_extruder;
if (
active_extruder != target_extruder
#if ENABLED(DUAL_X_CARRIAGE)
&& dual_x_carriage_mode != DXC_DUPLICATION_MODE && dual_x_carriage_mode != DXC_MIRRORED_MODE
#endif
) tool_change(target_extruder, false);
if (active_extruder != target_extruder && TERN1(DUAL_X_CARRIAGE, !dxc_is_duplicating()))
tool_change(target_extruder, false);
#endif

// Initial retract before move to filament change position
Expand Down
77 changes: 21 additions & 56 deletions Marlin/src/lcd/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ void MarlinUI::save_previous_screen() {
screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items };
}

void MarlinUI::_goto_previous_screen(
#if ENABLED(TURBO_BACK_MENU_ITEM)
const bool is_back/*=false*/
#endif
) {
void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) {
#if DISABLED(TURBO_BACK_MENU_ITEM)
constexpr bool is_back = false;
#endif
Expand Down Expand Up @@ -233,33 +229,15 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
}
else if (screen == status_screen && currentScreen == menu_main && PENDING(millis(), doubleclick_expire_ms)) {

#if ENABLED(BABYSTEP_WITHOUT_HOMING)
constexpr bool can_babystep = true;
#else
const bool can_babystep = all_axes_known();
#endif
#if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
constexpr bool should_babystep = true;
#else
const bool should_babystep = printer_busy();
#endif

if (should_babystep && can_babystep) {
screen =
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
lcd_babystep_zoffset
#else
lcd_babystep_z
#endif
;
}
#if ENABLED(MOVE_Z_WHEN_IDLE)
else {
if ( (ENABLED(BABYSTEP_WITHOUT_HOMING) || all_axes_known())
&& (ENABLED(BABYSTEP_ALWAYS_AVAILABLE) || printer_busy()) )
screen = TERN(BABYSTEP_ZPROBE_OFFSET, lcd_babystep_zoffset, lcd_babystep_z);
else {
#if ENABLED(MOVE_Z_WHEN_IDLE)
move_menu_scale = MOVE_Z_IDLE_MULTIPLICATOR;
screen = lcd_move_z;
}
#endif
#endif
}
}
#endif

Expand All @@ -277,11 +255,8 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co

// Re-initialize custom characters that may be re-used
#if HAS_CHARACTER_LCD
if (true
#if ENABLED(AUTO_BED_LEVELING_UBL)
&& !ubl.lcd_map_control
#endif
) set_custom_characters(screen == status_screen ? CHARSET_INFO : CHARSET_MENU);
if (TERN1(AUTO_BED_LEVELING_UBL, !ubl.lcd_map_control))
set_custom_characters(screen == status_screen ? CHARSET_INFO : CHARSET_MENU);
#endif

refresh(LCDVIEW_CALL_REDRAW_NEXT);
Expand Down Expand Up @@ -377,13 +352,10 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {

const float diff = planner.steps_to_mm[Z_AXIS] * babystep_increment,
new_probe_offset = probe.offset.z + diff,
new_offs =
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
do_probe ? new_probe_offset : hotend_offset[active_extruder].z - diff
#else
new_probe_offset
#endif
;
new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET
, do_probe ? new_probe_offset : hotend_offset[active_extruder].z - diff
, new_probe_offset
);
if (WITHIN(new_offs, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {

babystep.add_steps(Z_AXIS, babystep_increment);
Expand All @@ -397,30 +369,23 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
}
}
if (ui.should_draw()) {
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
if (!do_probe)
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), ftostr54sign(hotend_offset[active_extruder].z));
#endif
if (do_probe) {
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), BABYSTEP_TO_STR(probe.offset.z));
TERN_(BABYSTEP_ZPROBE_GFX_OVERLAY, _lcd_zoffset_overlay_gfx(probe.offset.z));
}
else {
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), ftostr54sign(hotend_offset[active_extruder].z));
#endif
}
}
}

#endif // BABYSTEP_ZPROBE_OFFSET

#if ENABLED(EEPROM_SETTINGS)
void lcd_store_settings() {
const bool saved = settings.save();
ui.completion_feedback(saved);
UNUSED(saved);
}
void lcd_load_settings() {
const bool loaded = settings.load();
ui.completion_feedback(loaded);
UNUSED(loaded);
}
void lcd_store_settings() { ui.completion_feedback(settings.save()); }
void lcd_load_settings() { ui.completion_feedback(settings.load()); }
#endif

void _lcd_draw_homing() {
Expand Down
8 changes: 1 addition & 7 deletions Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,7 @@ void menu_cancelobject();
#endif

#if ENABLED(ADVANCED_PAUSE_FEATURE)
constexpr float extrude_maxlength =
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
EXTRUDE_MAXLENGTH
#else
999
#endif
;
constexpr float extrude_maxlength = TERN(PREVENT_LENGTHY_EXTRUDE, EXTRUDE_MAXLENGTH, 999);

EDIT_ITEM_FAST(float3, MSG_FILAMENT_UNLOAD, &fc_settings[active_extruder].unload_length, 0, extrude_maxlength);
#if EXTRUDERS > 1
Expand Down
14 changes: 2 additions & 12 deletions Marlin/src/lcd/menu/menu_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,7 @@ void menu_advanced_settings();
#if ENABLED(BLTOUCH_LCD_VOLTAGE_MENU)
void bltouch_report() {
SERIAL_ECHOLNPAIR("EEPROM Last BLTouch Mode - ", (int)bltouch.last_written_mode);
SERIAL_ECHOLNPGM("Configuration BLTouch Mode - "
#if ENABLED(BLTOUCH_SET_5V_MODE)
"5V"
#else
"OD"
#endif
);
SERIAL_ECHOLNPGM("Configuration BLTouch Mode - " TERN(BLTOUCH_SET_5V_MODE, "5V", "OD"));
char mess[21];
strcpy_P(mess, PSTR("BLTouch Mode - "));
strcpy_P(&mess[15], bltouch.last_written_mode ? PSTR("5V") : PSTR("OD"));
Expand Down Expand Up @@ -411,11 +405,7 @@ void menu_configuration() {
//
#if ENABLED(CASE_LIGHT_MENU)
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
if (true
#if DISABLED(CASE_LIGHT_USE_NEOPIXEL)
&& PWM_PIN(CASE_LIGHT_PIN)
#endif
)
if (TERN1(CASE_LIGHT_USE_NEOPIXEL, PWM_PIN(CASE_LIGHT_PIN)))
SUBMENU(MSG_CASE_LIGHT, menu_case_light);
else
#endif
Expand Down
8 changes: 1 addition & 7 deletions Marlin/src/lcd/menu/menu_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@

void menu_game() {
START_MENU();
BACK_ITEM(
#if ENABLED(LCD_INFO_MENU)
MSG_INFO_MENU
#else
MSG_MAIN
#endif
);
BACK_ITEM(TERN(LCD_INFO_MENU, MSG_INFO_MENU, MSG_MAIN));
#if ENABLED(MARLIN_BRICKOUT)
SUBMENU(MSG_BRICKOUT, brickout.enter_game);
#endif
Expand Down
61 changes: 17 additions & 44 deletions Marlin/src/lcd/menu/menu_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,24 @@

printStatistics stats = print_job_timer.getStats();

START_SCREEN(); // 12345678901234567890
VALUE_ITEM(MSG_INFO_PRINT_COUNT, i16tostr3left(stats.totalPrints), SS_LEFT); // Print Count: 999
VALUE_ITEM(MSG_INFO_COMPLETED_PRINTS, i16tostr3left(stats.finishedPrints), SS_LEFT); // Completed : 666
char buffer[21];

START_SCREEN(); // 12345678901234567890
VALUE_ITEM(MSG_INFO_PRINT_COUNT, i16tostr3left(stats.totalPrints), SS_LEFT); // Print Count: 999
VALUE_ITEM(MSG_INFO_COMPLETED_PRINTS, i16tostr3left(stats.finishedPrints), SS_LEFT); // Completed : 666

STATIC_ITEM(MSG_INFO_PRINT_TIME, SS_LEFT); // Total print Time:
STATIC_ITEM(MSG_INFO_PRINT_TIME, SS_LEFT); // Total print Time:
STATIC_ITEM_P(PSTR("> "), SS_LEFT, duration_t(stats.printTime).toString(buffer)); // > 99y 364d 23h 59m 59s

STATIC_ITEM(MSG_INFO_PRINT_LONGEST, SS_LEFT); // Longest job time:
STATIC_ITEM(MSG_INFO_PRINT_LONGEST, SS_LEFT); // Longest job time:
STATIC_ITEM_P(PSTR("> "), SS_LEFT, duration_t(stats.longestPrint).toString(buffer)); // > 99y 364d 23h 59m 59s

STATIC_ITEM(MSG_INFO_PRINT_FILAMENT, SS_LEFT); // Extruded total:
sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int16_t(stats.filamentUsed / 100) % 10);
STATIC_ITEM_P(PSTR("> "), SS_LEFT, buffer); // > 125m
STATIC_ITEM(MSG_INFO_PRINT_FILAMENT, SS_LEFT); // Extruded total:
sprintf_P(buffer, PSTR("%ld.%im")
, long(stats.filamentUsed / 1000)
, int16_t(stats.filamentUsed / 100) % 10
);
STATIC_ITEM_P(PSTR("> "), SS_LEFT, buffer); // > 125m

#if SERVICE_INTERVAL_1 > 0 || SERVICE_INTERVAL_2 > 0 || SERVICE_INTERVAL_3 > 0
strcpy_P(buffer, GET_TEXT(MSG_SERVICE_IN));
Expand Down Expand Up @@ -171,16 +176,7 @@ void menu_info_thermistors() {
#endif

#if EXTRUDERS
{
STATIC_ITEM(
#if WATCH_HOTENDS
MSG_INFO_RUNAWAY_ON
#else
MSG_INFO_RUNAWAY_OFF
#endif
, SS_LEFT
);
}
STATIC_ITEM(TERN(WATCH_HOTENDS, MSG_INFO_RUNAWAY_ON, MSG_INFO_RUNAWAY_OFF), SS_LEFT);
#endif

#if HAS_HEATED_BED
Expand All @@ -191,34 +187,17 @@ void menu_info_thermistors() {
STATIC_ITEM_P(PSTR("BED:" THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(BED_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(BED_MAXTEMP), SS_LEFT);
STATIC_ITEM(
#if WATCH_BED
MSG_INFO_RUNAWAY_ON
#else
MSG_INFO_RUNAWAY_OFF
#endif
, SS_LEFT
);
}
STATIC_ITEM(TERN(WATCH_BED, MSG_INFO_RUNAWAY_ON, MSG_INFO_RUNAWAY_OFF), SS_LEFT);
#endif

#if HAS_HEATED_CHAMBER
{
#undef THERMISTOR_ID
#define THERMISTOR_ID TEMP_SENSOR_CHAMBER
#include "../thermistornames.h"
STATIC_ITEM_P(PSTR("CHAM:" THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(CHAMBER_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(CHAMBER_MAXTEMP), SS_LEFT);
STATIC_ITEM(
#if WATCH_CHAMBER
MSG_INFO_RUNAWAY_ON
#else
MSG_INFO_RUNAWAY_OFF
#endif
, SS_LEFT
);
}
STATIC_ITEM(TERN(WATCH_CHAMBER, MSG_INFO_RUNAWAY_ON, MSG_INFO_RUNAWAY_OFF), SS_LEFT);
#endif

END_SCREEN();
Expand Down Expand Up @@ -295,13 +274,7 @@ void menu_info() {
START_MENU();
BACK_ITEM(MSG_MAIN);
#if ENABLED(LCD_PRINTER_INFO_IS_BOOTSCREEN)
SUBMENU(MSG_INFO_PRINTER_MENU, (
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
menu_show_custom_bootscreen
#else
menu_show_marlin_bootscreen
#endif
));
SUBMENU(MSG_INFO_PRINTER_MENU, TERN(SHOW_CUSTOM_BOOTSCREEN, menu_show_custom_bootscreen, menu_show_marlin_bootscreen));
#else
SUBMENU(MSG_INFO_PRINTER_MENU, menu_info_printer); // Printer Info >
SUBMENU(MSG_INFO_BOARD_MENU, menu_info_board); // Board Info >
Expand Down
6 changes: 1 addition & 5 deletions Marlin/src/lcd/menu/menu_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,7 @@ void menu_mixer() {
BACK_ITEM(MSG_MAIN);

v_index = mixer.get_current_vtool();
EDIT_ITEM(uint8, MSG_ACTIVE_VTOOL, &v_index, 0, MIXING_VIRTUAL_TOOLS - 1, _lcd_mixer_select_vtool
#if HAS_DUAL_MIXING
, true
#endif
);
EDIT_ITEM(uint8, MSG_ACTIVE_VTOOL, &v_index, 0, MIXING_VIRTUAL_TOOLS - 1, _lcd_mixer_select_vtool, ENABLED(HAS_DUAL_MIXING));

#if HAS_DUAL_MIXING
{
Expand Down
Loading

0 comments on commit c536b8d

Please sign in to comment.