forked from Mirrors/Marlin
🎨 Negation without repetition
This commit is contained in:
@@ -228,7 +228,7 @@ struct SerialBase {
|
||||
// Handle negative numbers
|
||||
if (number < 0.0) {
|
||||
write('-');
|
||||
number = -number;
|
||||
number *= -1;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
|
||||
@@ -390,7 +390,7 @@ void GcodeSuite::G34() {
|
||||
// Decreasing accuracy was detected so move was inverted.
|
||||
// Will match reversed Z steppers on dual steppers. Triple will need more work to map.
|
||||
if (adjustment_reverse) {
|
||||
z_align_move = -z_align_move;
|
||||
z_align_move *= -1;
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", zstepper + 1, " correction reversed to ", z_align_move);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -205,7 +205,7 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
|
||||
const uint16_t backup_speed = MMS_TO_MMM(feedrate_mm_s);
|
||||
char sign[] = "\0";
|
||||
int16_t value = movevalue / 100;
|
||||
if (movevalue < 0) { value = -value; sign[0] = '-'; }
|
||||
if (movevalue < 0) { value *= -1; sign[0] = '-'; }
|
||||
int16_t fraction = ABS(movevalue) % 100;
|
||||
snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed);
|
||||
queue.enqueue_one_now(buf);
|
||||
|
||||
@@ -207,7 +207,7 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
|
||||
const uint16_t backup_speed = MMS_TO_MMM(feedrate_mm_s);
|
||||
char sign[] = "\0";
|
||||
int16_t value = movevalue / 100;
|
||||
if (movevalue < 0) { value = -value; sign[0] = '-'; }
|
||||
if (movevalue < 0) { value *= -1; sign[0] = '-'; }
|
||||
int16_t fraction = ABS(movevalue) % 100;
|
||||
snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed);
|
||||
queue.enqueue_one_now(buf);
|
||||
|
||||
@@ -778,7 +778,7 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
|
||||
char buf[32]; // G1 X9999.99 F12345
|
||||
char sign[] = "\0";
|
||||
int16_t value = movevalue / 100;
|
||||
if (movevalue < 0) { value = -value; sign[0] = '-'; }
|
||||
if (movevalue < 0) { value *= -1; sign[0] = '-'; }
|
||||
const int16_t fraction = ABS(movevalue) % 100;
|
||||
snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed);
|
||||
queue.enqueue_one_now(buf);
|
||||
|
||||
@@ -207,7 +207,7 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
|
||||
const uint16_t backup_speed = MMS_TO_MMM(feedrate_mm_s);
|
||||
char sign[] = "\0";
|
||||
int16_t value = movevalue / 100;
|
||||
if (movevalue < 0) { value = -value; sign[0] = '-'; }
|
||||
if (movevalue < 0) { value *= -1; sign[0] = '-'; }
|
||||
int16_t fraction = ABS(movevalue) % 100;
|
||||
snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed);
|
||||
queue.enqueue_one_now(buf);
|
||||
|
||||
@@ -676,11 +676,11 @@ void DGUSRxHandler::moveStep(DGUS_VP &vp, void *data_ptr) {
|
||||
|
||||
switch (direction) {
|
||||
default: return;
|
||||
case DGUS_Data::MoveDirection::XM: offset = -offset;
|
||||
case DGUS_Data::MoveDirection::XM: offset *= -1;
|
||||
case DGUS_Data::MoveDirection::XP: axis = ExtUI::X; break;
|
||||
case DGUS_Data::MoveDirection::YM: offset = -offset;
|
||||
case DGUS_Data::MoveDirection::YM: offset *= -1;
|
||||
case DGUS_Data::MoveDirection::YP: axis = ExtUI::Y; break;
|
||||
case DGUS_Data::MoveDirection::ZM: offset = -offset;
|
||||
case DGUS_Data::MoveDirection::ZM: offset *= -1;
|
||||
case DGUS_Data::MoveDirection::ZP: axis = ExtUI::Z; break;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ void reset_ball() {
|
||||
bdat.ballv = FTOF(1.3f);
|
||||
bdat.ballh = -FTOF(1.25f);
|
||||
uint8_t bx = bdat.paddle_x + (PADDLE_W) / 2 + ball_dist;
|
||||
if (bx >= GAME_WIDTH - 10) { bx -= ball_dist * 2; bdat.ballh = -bdat.ballh; }
|
||||
if (bx >= GAME_WIDTH - 10) { bx -= ball_dist * 2; bdat.ballh *= -1; }
|
||||
bdat.ballx = BTOF(bx);
|
||||
bdat.hit_dir = -1;
|
||||
}
|
||||
@@ -71,10 +71,10 @@ void BrickoutGame::game_screen() {
|
||||
// Provisionally update the ball position
|
||||
const fixed_t newx = bdat.ballx + bdat.ballh, newy = bdat.bally + bdat.ballv; // current next position
|
||||
if (!WITHIN(newx, 0, BTOF(GAME_WIDTH - 1))) { // out in x?
|
||||
bdat.ballh = -bdat.ballh; _BUZZ(5, 220); // bounce x
|
||||
bdat.ballh *= -1; _BUZZ(5, 220); // bounce x
|
||||
}
|
||||
if (newy < 0) { // out in y?
|
||||
bdat.ballv = -bdat.ballv; _BUZZ(5, 280); // bounce v
|
||||
bdat.ballv *= -1; _BUZZ(5, 280); // bounce v
|
||||
bdat.hit_dir = 1;
|
||||
}
|
||||
// Did the ball go below the bottom?
|
||||
@@ -96,8 +96,8 @@ void BrickoutGame::game_screen() {
|
||||
// If bricks are gone, go to reset state
|
||||
if (!--bdat.brick_count) game_state = 2;
|
||||
// Bounce the ball cleverly
|
||||
if ((bdat.ballv < 0) == (bdat.hit_dir < 0)) { bdat.ballv = -bdat.ballv; bdat.ballh += fixed_t(random(-16, 16)); _BUZZ(5, 880); }
|
||||
else { bdat.ballh = -bdat.ballh; bdat.ballv += fixed_t(random(-16, 16)); _BUZZ(5, 640); }
|
||||
if ((bdat.ballv < 0) == (bdat.hit_dir < 0)) { bdat.ballv *= -1; bdat.ballh += fixed_t(random(-16, 16)); _BUZZ(5, 880); }
|
||||
else { bdat.ballh *= -1; bdat.ballv += fixed_t(random(-16, 16)); _BUZZ(5, 640); }
|
||||
}
|
||||
}
|
||||
// Is the ball moving down and in paddle range?
|
||||
@@ -107,13 +107,13 @@ void BrickoutGame::game_screen() {
|
||||
if (WITHIN(diff, 0, PADDLE_W - 1)) {
|
||||
|
||||
// Reverse Y direction
|
||||
bdat.ballv = -bdat.ballv; _BUZZ(3, 880);
|
||||
bdat.ballv *= -1; _BUZZ(3, 880);
|
||||
bdat.hit_dir = -1;
|
||||
|
||||
// Near edges affects X velocity
|
||||
const bool is_left_edge = (diff <= 1);
|
||||
if (is_left_edge || diff >= PADDLE_W-1 - 1) {
|
||||
if ((bdat.ballh > 0) == is_left_edge) bdat.ballh = -bdat.ballh;
|
||||
if ((bdat.ballh > 0) == is_left_edge) bdat.ballh *= -1;
|
||||
}
|
||||
else if (diff <= 3) {
|
||||
bdat.ballh += fixed_t(random(-64, 0));
|
||||
|
||||
@@ -2515,7 +2515,7 @@ hal_timer_t Stepper::block_phase_isr() {
|
||||
|
||||
if (forward_e != motor_direction(E_AXIS)) {
|
||||
last_direction_bits.toggle(E_AXIS);
|
||||
count_direction.e = -count_direction.e;
|
||||
count_direction.e *= -1;
|
||||
|
||||
DIR_WAIT_BEFORE();
|
||||
|
||||
@@ -2876,7 +2876,7 @@ hal_timer_t Stepper::block_phase_isr() {
|
||||
la_interval = calc_timer_interval(uint32_t(ABS(step_rate)));
|
||||
if (forward_e != motor_direction(E_AXIS)) {
|
||||
last_direction_bits.toggle(E_AXIS);
|
||||
count_direction.e = -count_direction.e;
|
||||
count_direction.e *= -1;
|
||||
DIR_WAIT_BEFORE();
|
||||
E_APPLY_DIR(forward_e, false);
|
||||
TERN_(FT_MOTION, last_set_direction = last_direction_bits);
|
||||
|
||||
Reference in New Issue
Block a user