Skip to content

Commit 99c3a71

Browse files
committed
🎨 Standard logical FLIP(X)
1 parent cd3997f commit 99c3a71

File tree

26 files changed

+41
-38
lines changed

26 files changed

+41
-38
lines changed

Marlin/src/core/macros.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#define CBI32(n,b) (n &= ~_BV32(b))
8181
#define TBI32(N,B) (N ^= _BV32(B))
8282

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

97+
#define FLIP(X) (X = !(X))
98+
9699
// Macros to constrain values
97100
#ifdef __cplusplus
98101

Marlin/src/feature/bedlevel/bedlevel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
7777

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

8383
sync_plan_position();

Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ void unified_bed_leveling::smart_fill_mesh() {
16071607
}
16081608

16091609
if (abort_flag) break;
1610-
zig_zag ^= true;
1610+
FLIP(zig_zag);
16111611
}
16121612
}
16131613
probe.stow();

Marlin/src/feature/cooler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Cooler {
4040
static bool enabled;
4141
static void enable() { enabled = true; }
4242
static void disable() { enabled = false; }
43-
static void toggle() { enabled = !enabled; }
43+
static void toggle() { FLIP(enabled); }
4444

4545
static uint8_t mode; // 0 = CO2 Liquid cooling, 1 = Laser Diode TEC Heatsink Cooling
4646
static void set_mode(const uint8_t m) { mode = m; }
@@ -96,7 +96,7 @@ class Cooler {
9696
#if ENABLED(FLOWMETER_SAFETY)
9797
static bool flowfault; // Flag that the cooler is in a fault state
9898
static bool flowsafety_enabled; // Flag to disable the cutter if flow rate is too low
99-
static void flowsafety_toggle() { flowsafety_enabled = !flowsafety_enabled; }
99+
static void flowsafety_toggle() { FLIP(flowsafety_enabled); }
100100
static bool check_flow_too_low() {
101101
const bool too_low = flowsafety_enabled && flowrate < (FLOWMETER_MIN_LITERS_PER_MINUTE);
102102
flowfault = too_low;

Marlin/src/feature/fancheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class FanCheck {
6767
static void compute_speed(uint16_t elapsedTime);
6868
static void print_fan_states();
6969
#if HAS_PWMFANCHECK
70-
static void toggle_measuring() { measuring = !measuring; }
70+
static void toggle_measuring() { FLIP(measuring); }
7171
static bool is_measuring() { return measuring; }
7272
#endif
7373

Marlin/src/feature/max7219.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ void Max7219::register_setup() {
526526
}
527527
else
528528
sweepx -= MAX7219_X_LEDS * sweep_dir;
529-
patt_on ^= true;
529+
FLIP(patt_on);
530530
next_patt_ms += 100;
531531
if (++test_mode > 4) test_mode = 0;
532532
}

Marlin/src/feature/mmu3/SpoolJoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void SpoolJoin::initStatus() {
4747

4848
void SpoolJoin::toggle() {
4949
// Toggle enabled value.
50-
enabled = !enabled;
50+
FLIP(enabled);
5151

5252
// Following Prusa's implementation let's save the value to the EEPROM
5353
// TODO: Move to settings.cpp

Marlin/src/gcode/bedlevel/abl/G29.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ G29_TYPE GcodeSuite::G29() {
700700
inInc = -1; // Zag left
701701
}
702702

703-
zig ^= true; // zag
703+
FLIP(zig); // zag
704704

705705
// An index to print current state
706706
grid_count_t pt_index = (PR_OUTER_VAR) * (PR_INNER_SIZE) + 1;

Marlin/src/gcode/calibrate/G33.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static bool probe_calibration_points(float z_pt[NPP + 1], const int8_t probe_poi
241241
z_pt[uint8_t(LROUND(rad - interpol + NPP - 1)) % NPP + 1] += z_temp * sq(cos(RADIANS(interpol * 90)));
242242
z_pt[uint8_t(LROUND(rad - interpol)) % NPP + 1] += z_temp * sq(sin(RADIANS(interpol * 90)));
243243
}
244-
zig_zag = !zig_zag;
244+
FLIP(zig_zag);
245245
}
246246
if (_7p_intermed_points)
247247
LOOP_CAL_RAD(rad)

Marlin/src/gcode/calibrate/G34_M422.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void GcodeSuite::G34() {
365365
if (decreasing_accuracy(last_z_align_move[zstepper], z_align_abs)) {
366366
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", zstepper + 1, " last_z_align_move = ", last_z_align_move[zstepper]);
367367
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", zstepper + 1, " z_align_abs = ", z_align_abs);
368-
adjustment_reverse = !adjustment_reverse;
368+
FLIP(adjustment_reverse);
369369
}
370370

371371
// Remember the alignment for the next iteration, but only if steppers move,

0 commit comments

Comments
 (0)