Skip to content

Commit

Permalink
🎨 Standard logical FLIP(X)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Feb 3, 2025
1 parent cd3997f commit 99c3a71
Show file tree
Hide file tree
Showing 26 changed files with 41 additions and 38 deletions.
3 changes: 3 additions & 0 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#define CBI32(n,b) (n &= ~_BV32(b))
#define TBI32(N,B) (N ^= _BV32(B))

// Macros for common maths operations
#define cu(x) ({__typeof__(x) _x = (x); (_x)*(_x)*(_x);})
#define RADIANS(d) ((d)*float(M_PI)/180.0f)
#define DEGREES(r) ((r)*180.0f/float(M_PI))
Expand All @@ -93,6 +94,8 @@
#define SIGN(a) ({__typeof__(a) _a = (a); (_a>0)-(_a<0);})
#define IS_POWER_OF_2(x) ((x) && !((x) & ((x) - 1)))

#define FLIP(X) (X = !(X))

// Macros to constrain values
#ifdef __cplusplus

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/bedlevel/bedlevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {

// Get the corrected leveled / unleveled position
planner.apply_modifiers(current_position, true); // Physical position with all modifiers
planner.leveling_active ^= true; // Toggle leveling between apply and unapply
FLIP(planner.leveling_active); // Toggle leveling between apply and unapply
planner.unapply_modifiers(current_position, true); // Logical position with modifiers removed

sync_plan_position();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ void unified_bed_leveling::smart_fill_mesh() {
}

if (abort_flag) break;
zig_zag ^= true;
FLIP(zig_zag);
}
}
probe.stow();
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/cooler.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Cooler {
static bool enabled;
static void enable() { enabled = true; }
static void disable() { enabled = false; }
static void toggle() { enabled = !enabled; }
static void toggle() { FLIP(enabled); }

static uint8_t mode; // 0 = CO2 Liquid cooling, 1 = Laser Diode TEC Heatsink Cooling
static void set_mode(const uint8_t m) { mode = m; }
Expand Down Expand Up @@ -96,7 +96,7 @@ class Cooler {
#if ENABLED(FLOWMETER_SAFETY)
static bool flowfault; // Flag that the cooler is in a fault state
static bool flowsafety_enabled; // Flag to disable the cutter if flow rate is too low
static void flowsafety_toggle() { flowsafety_enabled = !flowsafety_enabled; }
static void flowsafety_toggle() { FLIP(flowsafety_enabled); }
static bool check_flow_too_low() {
const bool too_low = flowsafety_enabled && flowrate < (FLOWMETER_MIN_LITERS_PER_MINUTE);
flowfault = too_low;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/fancheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FanCheck {
static void compute_speed(uint16_t elapsedTime);
static void print_fan_states();
#if HAS_PWMFANCHECK
static void toggle_measuring() { measuring = !measuring; }
static void toggle_measuring() { FLIP(measuring); }
static bool is_measuring() { return measuring; }
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/max7219.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ void Max7219::register_setup() {
}
else
sweepx -= MAX7219_X_LEDS * sweep_dir;
patt_on ^= true;
FLIP(patt_on);
next_patt_ms += 100;
if (++test_mode > 4) test_mode = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/mmu3/SpoolJoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void SpoolJoin::initStatus() {

void SpoolJoin::toggle() {
// Toggle enabled value.
enabled = !enabled;
FLIP(enabled);

// Following Prusa's implementation let's save the value to the EEPROM
// TODO: Move to settings.cpp
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ G29_TYPE GcodeSuite::G29() {
inInc = -1; // Zag left
}

zig ^= true; // zag
FLIP(zig); // zag

// An index to print current state
grid_count_t pt_index = (PR_OUTER_VAR) * (PR_INNER_SIZE) + 1;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static bool probe_calibration_points(float z_pt[NPP + 1], const int8_t probe_poi
z_pt[uint8_t(LROUND(rad - interpol + NPP - 1)) % NPP + 1] += z_temp * sq(cos(RADIANS(interpol * 90)));
z_pt[uint8_t(LROUND(rad - interpol)) % NPP + 1] += z_temp * sq(sin(RADIANS(interpol * 90)));
}
zig_zag = !zig_zag;
FLIP(zig_zag);
}
if (_7p_intermed_points)
LOOP_CAL_RAD(rad)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G34_M422.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void GcodeSuite::G34() {
if (decreasing_accuracy(last_z_align_move[zstepper], z_align_abs)) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", zstepper + 1, " last_z_align_move = ", last_z_align_move[zstepper]);
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", zstepper + 1, " z_align_abs = ", z_align_abs);
adjustment_reverse = !adjustment_reverse;
FLIP(adjustment_reverse);
}

// Remember the alignment for the next iteration, but only if steppers move,
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/temp/M303.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void GcodeSuite::M303() {

#if HAS_PID_DEBUG
if (parser.seen_test('D')) {
thermalManager.pid_debug_flag ^= true;
FLIP(thermalManager.pid_debug_flag);
SERIAL_ECHO_START();
SERIAL_ECHOPGM("PID Debug ");
serialprintln_onoff(thermalManager.pid_debug_flag);
Expand Down
22 changes: 11 additions & 11 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
drawCheckbox(row, probe_deployed);
}
else {
probe_deployed ^= true;
FLIP(probe_deployed);
probe.set_deployed(probe_deployed);
drawCheckbox(row, probe_deployed);
}
Expand All @@ -1355,7 +1355,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
drawCheckbox(row, livemove);
}
else {
livemove ^= true;
FLIP(livemove);
drawCheckbox(row, livemove);
}
break;
Expand Down Expand Up @@ -1400,7 +1400,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
drawCheckbox(row, use_probe);
}
else {
use_probe ^= true;
FLIP(use_probe);
drawCheckbox(row, use_probe);
if (use_probe) {
popupHandler(Popup_Level);
Expand Down Expand Up @@ -1616,7 +1616,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
planner.synchronize();
redrawMenu();
}
liveadjust ^= true;
FLIP(liveadjust);
drawCheckbox(row, liveadjust);
}
break;
Expand Down Expand Up @@ -2719,7 +2719,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
drawCheckbox(row, eeprom_settings.time_format_textual);
}
else {
eeprom_settings.time_format_textual ^= true;
FLIP(eeprom_settings.time_format_textual);
drawCheckbox(row, eeprom_settings.time_format_textual);
}
break;
Expand Down Expand Up @@ -2877,7 +2877,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
drawCheckbox(row, ui.sound_on);
}
else {
ui.sound_on ^= true;
FLIP(ui.sound_on);
drawCheckbox(row, ui.sound_on);
}
break;
Expand Down Expand Up @@ -2960,7 +2960,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
drawCheckbox(row, runout.enabled);
}
else {
runout.enabled ^= true;
FLIP(runout.enabled);
drawCheckbox(row, runout.enabled);
}
break;
Expand Down Expand Up @@ -3403,7 +3403,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
drawCheckbox(row, mesh_conf.viewer_print_value);
}
else {
mesh_conf.viewer_print_value ^= true;
FLIP(mesh_conf.viewer_print_value);
drawCheckbox(row, mesh_conf.viewer_print_value);
}
break;
Expand All @@ -3413,7 +3413,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
drawCheckbox(row, mesh_conf.viewer_asymmetric_range);
}
else {
mesh_conf.viewer_asymmetric_range ^= true;
FLIP(mesh_conf.viewer_asymmetric_range);
drawCheckbox(row, mesh_conf.viewer_asymmetric_range);
}
break;
Expand Down Expand Up @@ -3596,7 +3596,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
drawCheckbox(row, mesh_conf.goto_mesh_value);
}
else {
mesh_conf.goto_mesh_value ^= true;
FLIP(mesh_conf.goto_mesh_value);
current_position.z = 0;
mesh_conf.manual_mesh_move(true);
drawCheckbox(row, mesh_conf.goto_mesh_value);
Expand Down Expand Up @@ -3957,7 +3957,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
drawCheckbox(row, runout.enabled);
}
else {
runout.enabled ^= true;
FLIP(runout.enabled);
drawCheckbox(row, runout.enabled);
}
break;
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/e3v2/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ void eachMomentUpdate() {

if (ELAPSED(ms, next_var_update_ms)) {
next_var_update_ms = ms + DWIN_VAR_UPDATE_INTERVAL;
blink = !blink;
FLIP(blink);
updateVariable();
#if HAS_ESDIAG
if (checkkey == ID_ESDiagProcess) esDiag.update();
Expand Down Expand Up @@ -2232,7 +2232,7 @@ void setMoveZ() { hmiValue.axis = Z_AXIS; setPFloatOnClick(Z_MIN_POS, Z_MAX_POS,
#if ENABLED(BAUD_RATE_GCODE)
void hmiSetBaudRate() { hmiData.baud115K ? setBaud115K() : setBaud250K(); }
void setBaudRate() {
hmiData.baud115K ^= true;
FLIP(hmiData.baud115K);
hmiSetBaudRate();
drawCheckboxLine(currentMenu->line(), hmiData.baud115K);
dwinUpdateLCD();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/proui/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void showCheckboxLine(const bool checked) {
}

void toggleCheckboxLine(bool &checked) {
checked = !checked;
FLIP(checked);
showCheckboxLine(checked);
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ namespace Anycubic {
}

void DgusTFT::toggle_audio() {
lcd_info.audio_on = !lcd_info.audio_on;
FLIP(lcd_info.audio_on);
goto_system_page();
lcdAudioSet(lcd_info.audio_on);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ bool StatusScreen::onTouchEnd(uint8_t tag) {
case 13: GOTO_SCREEN(BioConfirmHomeE); break;
case 14: SpinnerDialogBox::enqueueAndWait(F("G28Z")); break;
case 15: GOTO_SCREEN(TemperatureScreen); break;
case 16: fine_motion = !fine_motion; break;
case 16: FLIP(fine_motion); break;
default: return false;
}
// If a passcode is enabled, the LockScreen will prevent the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool LoadChocolateScreen::onTouchEnd(uint8_t tag) {
switch (tag) {
case 2: mydata.repeat_tag = 5; break;
case 3: mydata.repeat_tag = 6; break;
case 4: mydata.repeating = !mydata.repeating; break;
case 4: FLIP(mydata.repeating); break;
case 1: GOTO_PREVIOUS(); break;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool NudgeNozzleScreen::onTouchHeld(uint8_t tag) {
#if HAS_MULTI_EXTRUDER
case 8: mydata.link_nozzles = !link; break;
#endif
case 9: mydata.show_offsets = !mydata.show_offsets; break;
case 9: FLIP(mydata.show_offsets); break;
case 10: GOTO_SCREEN(SaveSettingsDialogBox); break;
default: return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool WidgetsScreen::onTouchStart(uint8_t tag) {
case 5: cmd.track_linear (BTN_POS(3,4), BTN_SIZE(2,1), 5).execute(); break;
case 6: cmd.track_linear (BTN_POS(3,5), BTN_SIZE(2,1), 6).execute(); break;
#endif
case 7: show_grid = !show_grid; break;
case 7: FLIP(show_grid); break;
default:
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/ia_creality/ia_creality_rts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ void RTS::handleData() {
setTouchScreenConfiguration();
break;
case 21:
dwin_settings.display_standby ^= true;
FLIP(dwin_settings.display_standby);
setTouchScreenConfiguration();
break;
case 22:
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/mks_ui/draw_encoder_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
draw_return_ui();
break;
case ID_ENCODER_STATE:
gCfgItems.encoder_enable ^= true;
FLIP(gCfgItems.encoder_enable);
lv_screen_menu_item_onoff_update(buttonEncoderState, gCfgItems.encoder_enable);
update_spi_flash();
break;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/mks_ui/draw_filament_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
break;
case ID_FILAMNT_TYPE:
#if HAS_MULTI_EXTRUDER
uiCfg.extruderIndex = !uiCfg.extruderIndex;
FLIP(uiCfg.extruderIndex);
#endif
disp_filament_type();
break;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/game/invaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void InvadersGame::game_screen() {

const bool did_blink = (++idat.blink_count > idat.count >> 1);
if (did_blink) {
idat.game_blink = !idat.game_blink;
FLIP(idat.game_blink);
idat.blink_count = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class MenuItem_bool : public MenuEditItemBase {
draw(sel, row, fstr, pget());
}
static void action(FSTR_P const fstr, bool * const ptr, const screenFunc_t callbackFunc=nullptr) {
*ptr ^= true; ui.refresh();
FLIP(*ptr); ui.refresh();
if (callbackFunc) (*callbackFunc)();
}
};
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void menu_move() {

bool show_state = c.active;
EDIT_ITEM(bool, MSG_FIXED_TIME_MOTION, &show_state, []{
ftMotion.cfg.active ^= true;
FLIP(ftMotion.cfg.active);
ftMotion.update_shaping_params();
});

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/sovol_rts/sovol_rts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void RTS::init() {
inStop = -1;
inInc = -1;
}
zig ^= true;
FLIP(zig);
for (int8_t x = inStart; x != inStop; x += inInc) {
sendData(bedlevel.z_values[x][y] * 100, AUTO_BED_LEVEL_1POINT_VP + showcount * 2);
showcount++;
Expand Down Expand Up @@ -1207,7 +1207,7 @@ void RTS::handleData() {
inStop = -1;
inInc = -1;
}
zig ^= true;
FLIP(zig);
for (int8_t x = inStart; x != inStop; x += inInc) {
sendData(bedlevel.z_values[x][y] * 100, AUTO_BED_LEVEL_1POINT_VP + showcount * 2);
showcount++;
Expand Down

0 comments on commit 99c3a71

Please sign in to comment.