Browse Source

Synchronize on M204, M205 (#12302)

* Add parser.seen for multiple parameters
* Fix M666, use !seen for report
* Synchronize on M204, M205
pull/1/head
Scott Lahteine 6 years ago
committed by GitHub
parent
commit
e4cf175163
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      Marlin/src/gcode/calibrate/M666.cpp
  2. 40
      Marlin/src/gcode/config/M200-M205.cpp
  3. 22
      Marlin/src/gcode/config/M217.cpp
  4. 18
      Marlin/src/gcode/config/M218.cpp
  5. 2
      Marlin/src/gcode/gcode.h
  6. 52
      Marlin/src/gcode/parser.h

25
Marlin/src/gcode/calibrate/M666.cpp

@ -22,7 +22,7 @@
#include "../../inc/MarlinConfig.h"
#if ENABLED(DELTA) || ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
#if ENABLED(DELTA) || ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || Z_MULTI_ENDSTOPS
#include "../gcode.h"
@ -73,34 +73,23 @@
* Set Both: M666 Z<offset>
*/
void GcodeSuite::M666() {
bool report = true;
#if ENABLED(X_DUAL_ENDSTOPS)
if (parser.seen('X')) {
endstops.x2_endstop_adj = parser.value_linear_units();
report = false;
}
if (parser.seenval('X')) endstops.x2_endstop_adj = parser.value_linear_units();
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
if (parser.seen('Y')) {
endstops.y2_endstop_adj = parser.value_linear_units();
report = false;
}
if (parser.seenval('Y')) endstops.y2_endstop_adj = parser.value_linear_units();
#endif
#if ENABLED(Z_TRIPLE_ENDSTOPS)
if (parser.seen('Z')) {
const int ind = parser.intval('S');
if (parser.seenval('Z')) {
const float z_adj = parser.value_linear_units();
const int ind = parser.intval('S');
if (!ind || ind == 2) endstops.z2_endstop_adj = z_adj;
if (!ind || ind == 3) endstops.z3_endstop_adj = z_adj;
report = false;
}
#elif Z_MULTI_ENDSTOPS
if (parser.seen('Z')) {
endstops.z2_endstop_adj = parser.value_linear_units();
report = false;
}
if (parser.seen('Z')) endstops.z2_endstop_adj = parser.value_linear_units();
#endif
if (report) {
if (!parser.seen("XYZ")) {
SERIAL_ECHOPGM("Dual Endstop Adjustment (mm): ");
#if ENABLED(X_DUAL_ENDSTOPS)
SERIAL_ECHOPAIR(" X2:", endstops.x2_endstop_adj);

40
Marlin/src/gcode/config/M200-M205.cpp

@ -91,28 +91,19 @@ void GcodeSuite::M203() {
* T = Travel (non printing) moves
*/
void GcodeSuite::M204() {
bool report = true;
if (parser.seenval('S')) { // Kept for legacy compatibility. Should NOT BE USED for new developments.
planner.settings.travel_acceleration = planner.settings.acceleration = parser.value_linear_units();
report = false;
}
if (parser.seenval('P')) {
planner.settings.acceleration = parser.value_linear_units();
report = false;
}
if (parser.seenval('R')) {
planner.settings.retract_acceleration = parser.value_linear_units();
report = false;
}
if (parser.seenval('T')) {
planner.settings.travel_acceleration = parser.value_linear_units();
report = false;
}
if (report) {
if (!parser.seen("PRST")) {
SERIAL_ECHOPAIR("Acceleration: P", planner.settings.acceleration);
SERIAL_ECHOPAIR(" R", planner.settings.retract_acceleration);
SERIAL_ECHOLNPAIR(" T", planner.settings.travel_acceleration);
}
else {
planner.synchronize();
// 'S' for legacy compatibility. Should NOT BE USED for new development
if (parser.seenval('S')) planner.settings.travel_acceleration = planner.settings.acceleration = parser.value_linear_units();
if (parser.seenval('P')) planner.settings.acceleration = parser.value_linear_units();
if (parser.seenval('R')) planner.settings.retract_acceleration = parser.value_linear_units();
if (parser.seenval('T')) planner.settings.travel_acceleration = parser.value_linear_units();
}
}
/**
@ -128,6 +119,19 @@ void GcodeSuite::M204() {
* J = Junction Deviation (mm) (Requires JUNCTION_DEVIATION)
*/
void GcodeSuite::M205() {
#if ENABLED(JUNCTION_DEVIATION)
#define J_PARAM "J"
#else
#define J_PARAM
#endif
#if HAS_CLASSIC_JERK
#define XYZE_PARAM "XYZE"
#else
#define XYZE_PARAM
#endif
if (!parser.seen("BST" J_PARAM XYZE_PARAM)) return;
planner.synchronize();
if (parser.seen('B')) planner.settings.min_segment_time_us = parser.value_ulong();
if (parser.seen('S')) planner.settings.min_feedrate_mm_s = parser.value_linear_units();
if (parser.seen('T')) planner.settings.min_travel_feedrate_mm_s = parser.value_linear_units();

22
Marlin/src/gcode/config/M217.cpp

@ -66,24 +66,30 @@ void M217_report(const bool eeprom=false) {
*/
void GcodeSuite::M217() {
bool report = true;
#define SPR_PARAM
#define XY_PARAM
#if ENABLED(SINGLENOZZLE)
if (parser.seenval('S')) { report = false; const float v = parser.value_linear_units(); toolchange_settings.swap_length = constrain(v, 0, 500); }
if (parser.seenval('P')) { report = false; const int16_t v = parser.value_linear_units(); toolchange_settings.prime_speed = constrain(v, 10, 5400); }
if (parser.seenval('R')) { report = false; const int16_t v = parser.value_linear_units(); toolchange_settings.retract_speed = constrain(v, 10, 5400); }
#undef SPR_PARAM
#define SPR_PARAM "SPR"
if (parser.seenval('S')) { const float v = parser.value_linear_units(); toolchange_settings.swap_length = constrain(v, 0, 500); }
if (parser.seenval('P')) { const int16_t v = parser.value_linear_units(); toolchange_settings.prime_speed = constrain(v, 10, 5400); }
if (parser.seenval('R')) { const int16_t v = parser.value_linear_units(); toolchange_settings.retract_speed = constrain(v, 10, 5400); }
#if ENABLED(SINGLENOZZLE_SWAP_PARK)
if (parser.seenval('X')) { report = false; toolchange_settings.change_point.x = parser.value_linear_units(); }
if (parser.seenval('Y')) { report = false; toolchange_settings.change_point.y = parser.value_linear_units(); }
#undef XY_PARAM
#define XY_PARAM "XY"
if (parser.seenval('X')) { toolchange_settings.change_point.x = parser.value_linear_units(); }
if (parser.seenval('Y')) { toolchange_settings.change_point.y = parser.value_linear_units(); }
#endif
#endif
if (parser.seenval('Z')) { report = false; toolchange_settings.z_raise = parser.value_linear_units(); }
if (parser.seenval('Z')) { toolchange_settings.z_raise = parser.value_linear_units(); }
if (report) M217_report();
if (!parser.seen(SPR_PARAM XY_PARAM "Z")) M217_report();
}

18
Marlin/src/gcode/config/M218.cpp

@ -42,21 +42,11 @@
void GcodeSuite::M218() {
if (get_target_extruder_from_command() || target_extruder == 0) return;
bool report = true;
if (parser.seenval('X')) {
hotend_offset[X_AXIS][target_extruder] = parser.value_linear_units();
report = false;
}
if (parser.seenval('Y')) {
hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units();
report = false;
}
if (parser.seenval('Z')) {
hotend_offset[Z_AXIS][target_extruder] = parser.value_linear_units();
report = false;
}
if (parser.seenval('X')) hotend_offset[X_AXIS][target_extruder] = parser.value_linear_units();
if (parser.seenval('Y')) hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units();
if (parser.seenval('Z')) hotend_offset[Z_AXIS][target_extruder] = parser.value_linear_units();
if (report) {
if (!parser.seen("XYZ")) {
SERIAL_ECHO_START();
SERIAL_ECHOPGM(MSG_HOTEND_OFFSET);
HOTEND_LOOP() {

2
Marlin/src/gcode/gcode.h

@ -749,7 +749,7 @@ private:
static void M665();
#endif
#if ENABLED(DELTA) || ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
#if ENABLED(DELTA) || ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || Z_MULTI_ENDSTOPS
static void M666();
#endif

52
Marlin/src/gcode/parser.h

@ -19,6 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
/**
* parser.h - Parser for a GCode line, providing a parameter interface.
@ -26,9 +27,6 @@
* so settings for these codes are located in this class.
*/
#ifndef _PARSER_H_
#define _PARSER_H_
#include "../inc/MarlinConfig.h"
//#define DEBUG_GCODE_PARSER
@ -115,7 +113,7 @@ public:
}
// Set the flag and pointer for a parameter
static void set(const char c, char * const ptr) {
static inline void set(const char c, char * const ptr) {
const uint8_t ind = LETTER_BIT(c);
if (ind >= COUNT(param)) return; // Only A-Z
SBI32(codebits, ind); // parameter exists
@ -132,7 +130,7 @@ public:
// Code seen bit was set. If not found, value_ptr is unchanged.
// This allows "if (seen('A')||seen('B'))" to use the last-found value.
static bool seen(const char c) {
static inline bool seen(const char c) {
const uint8_t ind = LETTER_BIT(c);
if (ind >= COUNT(param)) return false; // Only A-Z
const bool b = TEST32(codebits, ind);
@ -143,7 +141,34 @@ public:
return b;
}
static bool seen_any() { return !!codebits; }
FORCE_INLINE static constexpr uint32_t letter_bits(const char * const str) {
return (str[0] ? _BV32(LETTER_BIT(str[0])) |
(str[1] ? _BV32(LETTER_BIT(str[1])) |
(str[2] ? _BV32(LETTER_BIT(str[2])) |
(str[3] ? _BV32(LETTER_BIT(str[3])) |
(str[4] ? _BV32(LETTER_BIT(str[4])) |
(str[5] ? _BV32(LETTER_BIT(str[5])) |
(str[6] ? _BV32(LETTER_BIT(str[6])) |
(str[7] ? _BV32(LETTER_BIT(str[7])) |
(str[8] ? _BV32(LETTER_BIT(str[8])) |
(str[9] ? _BV32(LETTER_BIT(str[9]))
: 0) : 0) : 0) : 0) : 0) : 0) : 0) : 0) : 0) : 0);
}
// At least one of a list of code letters was seen
#ifdef CPU_32_BIT
FORCE_INLINE static bool seen(const char * const str) { return !!(codebits & letter_bits(str)); }
#else
// At least one of a list of code letters was seen
FORCE_INLINE static bool seen(const char * const str) {
const uint32_t letrbits = letter_bits(str);
const uint8_t * const cb = (uint8_t*)&codebits;
const uint8_t * const lb = (uint8_t*)&letrbits;
return (cb[0] & lb[0]) || (cb[1] & lb[1]) || (cb[2] & lb[2]) || (cb[3] & lb[3]);
}
#endif
static inline bool seen_any() { return !!codebits; }
#define SEEN_TEST(L) TEST32(codebits, LETTER_BIT(L))
@ -151,21 +176,28 @@ public:
// Code is found in the string. If not found, value_ptr is unchanged.
// This allows "if (seen('A')||seen('B'))" to use the last-found value.
static bool seen(const char c) {
static inline bool seen(const char c) {
char *p = strchr(command_args, c);
const bool b = !!p;
if (b) value_ptr = valid_float(&p[1]) ? &p[1] : (char*)NULL;
return b;
}
static bool seen_any() { return *command_args == '\0'; }
static inline bool seen_any() { return *command_args == '\0'; }
#define SEEN_TEST(L) !!strchr(command_args, L)
// At least one of a list of code letters was seen
static inline bool seen(const char * const str) {
for (uint8_t i = 0; const char c = str[i]; i++)
if (SEEN_TEST(c)) return true;
return false;
}
#endif // !FASTER_GCODE_PARSER
// Seen any axis parameter
static bool seen_axis() {
static inline bool seen_axis() {
return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
}
@ -348,5 +380,3 @@ public:
};
extern GCodeParser parser;
#endif // _PARSER_H_

Loading…
Cancel
Save