Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 14, 2021
1 parent 2d425ca commit 3a93bfa
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 22 deletions.
8 changes: 4 additions & 4 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2934,9 +2934,9 @@
* Set this manually if there are extra servos needing manual control.
* Set to 0 to turn off servo support.
*/
//#define NUM_SERVOS 3 // Servo index starts with 0 for M280 and M282 commands
//#define NUM_SERVOS 3 // Note: Servo index starts with 0 for M280-M282 commands

// (ms) Delay before the next move will start, to give the servo time to reach its target angle.
// (ms) Delay before the next move will start, to give the servo time to reach its target angle.
// 300ms is a good value but you can try less delay.
// If the servo can't reach the requested position, increase it.
#define SERVO_DELAY { 300 }
Expand All @@ -2947,5 +2947,5 @@
// Edit servo angles with M281 and save to EEPROM with M500
//#define EDITABLE_SERVO_ANGLES

// Disable servo with M282 to reduce power consumption, noise and heat when not necessary
//#define SERVOS_CAN_BE_DISABLED
// Disable servo with M282 to reduce power consumption, noise, and heat when not in use
//#define SERVOS_CAN_BE_DISABLED
2 changes: 1 addition & 1 deletion Marlin/src/gcode/control/M280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void GcodeSuite::M280() {
if (parser.seen('S')) {
const int a = parser.value_int();
if (a == -1)
servo[servo_index].detach();
DETACH_SERVO(servo_index);
else
MOVE_SERVO(servo_index, a);
}
Expand Down
9 changes: 4 additions & 5 deletions Marlin/src/gcode/control/M282.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "../../inc/MarlinConfig.h"

#if HAS_SERVOS && ENABLED(SERVOS_CAN_BE_DISABLED)
#if ENABLED(SERVOS_CAN_BE_DISABLED)

#include "../gcode.h"
#include "../../module/servo.h"
Expand All @@ -35,12 +35,11 @@ void GcodeSuite::M282() {
if (!parser.seen('P')) return;

const int servo_index = parser.value_int();
if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
if (WITHIN(servo_index, 0, NUM_SERVOS - 1))
DETACH_SERVO(servo_index);
}
else
SERIAL_ECHO("Servo ", servo_index, " out of range");
SERIAL_ECHO_MSG("Servo ", servo_index, " out of range");

}

#endif // HAS_SERVOS && SERVOS_CAN_BE_DISABLED
#endif // SERVOS_CAN_BE_DISABLED
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 281: M281(); break; // M281: Set servo angles
#endif
#if ENABLED(SERVOS_CAN_BE_DISABLED)
case 282: M282(); break; // M282: Detach servo
case 282: M282(); break; // M282: Detach servo
#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
* M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
* M280 - Set servo position absolute: "M280 P<index> S<angle|µs>". (Requires servos)
* M281 - Set servo min|max position: "M281 P<index> L<min> U<max>". (Requires EDITABLE_SERVO_ANGLES)
* M282 - Detach servo: "M282 P<index>". (Requires servos and SERVOS_CAN_BE_DISABLED)
* M282 - Detach servo: "M282 P<index>". (Requires SERVOS_CAN_BE_DISABLED)
* M290 - Babystepping (Requires BABYSTEPPING)
* M300 - Play beep sound S<frequency Hz> P<duration ms>
* M301 - Set PID parameters P I and D. (Requires PIDTEMP)
Expand Down
11 changes: 8 additions & 3 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2593,9 +2593,14 @@
#endif
#if NUM_SERVOS > 0
#define HAS_SERVOS 1
#endif
#if HAS_SERVOS && defined(PAUSE_SERVO_OUTPUT) && defined(RESUME_SERVO_OUTPUT)
#define HAS_PAUSE_SERVO_OUTPUT 1
#if defined(PAUSE_SERVO_OUTPUT) && defined(RESUME_SERVO_OUTPUT)
#define HAS_PAUSE_SERVO_OUTPUT 1
#endif
#else
#undef SERVO_DELAY
#undef DEACTIVATE_SERVOS_AFTER_MOVE
#undef EDITABLE_SERVO_ANGLES
#undef SERVOS_CAN_BE_DISABLED
#endif

// Sensors
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/module/servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ HAL_SERVO_LIB servo[NUM_SERVOS];
void servo_init() {
#if NUM_SERVOS >= 1 && HAS_SERVO_0
servo[0].attach(SERVO0_PIN);
servo[0].detach(); // Just set up the pin. We don't have a position yet. Don't move to a random position.
DETACH_SERVO(0); // Just set up the pin. We don't have a position yet. Don't move to a random position.
#endif
#if NUM_SERVOS >= 2 && HAS_SERVO_1
servo[1].attach(SERVO1_PIN);
servo[1].detach();
DETACH_SERVO(1);
#endif
#if NUM_SERVOS >= 3 && HAS_SERVO_2
servo[2].attach(SERVO2_PIN);
servo[2].detach();
DETACH_SERVO(2);
#endif
#if NUM_SERVOS >= 4 && HAS_SERVO_3
servo[3].attach(SERVO3_PIN);
servo[3].detach();
DETACH_SERVO(3);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion ini/features.ini
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ NO_VOLUMETRICS = src_filter=-<src/gcode/config/M200-M205
HAS_MULTI_EXTRUDER = src_filter=+<src/gcode/config/M217.cpp>
HAS_HOTEND_OFFSET = src_filter=+<src/gcode/config/M218.cpp>
EDITABLE_SERVO_ANGLES = src_filter=+<src/gcode/config/M281.cpp>
SERVOS_CAN_BE_DISABLED = src_filter=+<src/gcode/config/M282.cpp>
PIDTEMP = src_filter=+<src/gcode/config/M301.cpp>
PREVENT_COLD_EXTRUSION = src_filter=+<src/gcode/config/M302.cpp>
PIDTEMPBED = src_filter=+<src/gcode/config/M304.cpp>
Expand All @@ -174,6 +173,7 @@ HAS_SMART_EFF_MOD = src_filter=+<src/gcode/config/M672.cpp>
COOLANT_CONTROL|AIR_ASSIST = src_filter=+<src/gcode/control/M7-M9.cpp>
AIR_EVACUATION = src_filter=+<src/gcode/control/M10-M11.cpp>
HAS_SOFTWARE_ENDSTOPS = src_filter=+<src/gcode/control/M211.cpp>
SERVOS_CAN_BE_DISABLED = src_filter=+<src/gcode/control/M282.cpp>
HAS_DUPLICATION_MODE = src_filter=+<src/gcode/control/M605.cpp>
LIN_ADVANCE = src_filter=+<src/gcode/feature/advance>
PHOTO_GCODE = src_filter=+<src/gcode/feature/camera>
Expand Down
3 changes: 1 addition & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
-<src/gcode/config/M217.cpp>
-<src/gcode/config/M218.cpp>
-<src/gcode/config/M221.cpp>
-<src/gcode/config/M281.cpp>
-<src/gcode/config/M301.cpp>
-<src/gcode/config/M302.cpp>
-<src/gcode/config/M304.cpp>
Expand Down Expand Up @@ -243,7 +242,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
-<src/module/printcounter.cpp>
-<src/module/probe.cpp>
-<src/module/scara.cpp> -<src/gcode/calibrate/M665.cpp>
-<src/module/servo.cpp> -<src/gcode/control/M280.cpp> -<src/gcode/control/M282.cpp>
-<src/module/servo.cpp> -<src/gcode/control/M280.cpp> -<src/gcode/config/M281.cpp> -<src/gcode/control/M282.cpp>
-<src/module/stepper/TMC26X.cpp>

#
Expand Down

0 comments on commit 3a93bfa

Please sign in to comment.