Skip to content

Commit

Permalink
Auto report position separately
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 14, 2021
1 parent c5a78df commit c20ed7f
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 19 deletions.
5 changes: 5 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3416,6 +3416,11 @@
*/
#define AUTO_REPORT_TEMPERATURES

/**
* Auto-report position with M154 S<seconds>
*/
//#define AUTO_REPORT_POSITION

/**
* Include capabilities in M115 output
*/
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,10 @@ void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {

// Auto-report Temperatures / SD Status
#if HAS_AUTO_REPORTING
if (!gcode.autoreport.paused) {
if (!gcode.autoreport_paused) {
TERN_(AUTO_REPORT_TEMPERATURES, thermalManager.auto_reporter.tick());
TERN_(AUTO_REPORT_SD_STATUS, card.auto_reporter.tick());
TERN_(AUTO_REPORT_POSITION, position_auto_reporter.tick());
}
#endif

Expand Down
8 changes: 6 additions & 2 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ uint8_t GcodeSuite::axis_relative = (
);

#if EITHER(HAS_AUTO_REPORTING, HOST_KEEPALIVE_FEATURE)
GcodeSuite::autoreport_t GcodeSuite::autoreport{0};
bool GcodeSuite::autoreport_paused; // = false
#endif

#if ENABLED(HOST_KEEPALIVE_FEATURE)
Expand Down Expand Up @@ -561,6 +561,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 193: M193(); break; // M193: Wait for cooler temperature to reach target
#endif

#if ENABLED(AUTO_REPORT_POSITION)
case 154: M154(); break; // M155: Set position auto-report interval
#endif

#if BOTH(AUTO_REPORT_TEMPERATURES, HAS_TEMP_SENSOR)
case 155: M155(); break; // M155: Set temperature auto-report interval
#endif
Expand Down Expand Up @@ -1094,7 +1098,7 @@ void GcodeSuite::process_subcommands_now(char * gcode) {
void GcodeSuite::host_keepalive() {
const millis_t ms = millis();
static millis_t next_busy_signal_ms = 0;
if (!autoreport.paused && host_keepalive_interval && busy_state != NOT_BUSY) {
if (!autoreport_paused && host_keepalive_interval && busy_state != NOT_BUSY) {
if (PENDING(ms, next_busy_signal_ms)) return;
PORT_REDIRECT(SerialMask::All);
switch (busy_state) {
Expand Down
19 changes: 9 additions & 10 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
* M145 - Set heatup values for materials on the LCD. H<hotend> B<bed> F<fan speed> for S<material> (0=PLA, 1=ABS)
* M149 - Set temperature units. (Requires TEMPERATURE_UNITS_SUPPORT)
* M150 - Set Status LED Color as R<red> U<green> B<blue> W<white> P<bright>. Values 0-255. (Requires BLINKM, RGB_LED, RGBW_LED, NEOPIXEL_LED, PCA9533, or PCA9632).
* M154 - Auto-report position with interval of S<seconds>. (Requires AUTO_REPORT_POSITION)
* M155 - Auto-report temperatures with interval of S<seconds>. (Requires AUTO_REPORT_TEMPERATURES)
* M163 - Set a single proportion for a mixing extruder. (Requires MIXING_EXTRUDER)
* M164 - Commit the mix and save to a virtual tool (current, or as specified by 'S'). (Requires MIXING_EXTRUDER)
Expand Down Expand Up @@ -381,21 +382,15 @@ class GcodeSuite {
process_subcommands_now_P(keep_leveling ? G28_STR : TERN(G28_L0_ENSURES_LEVELING_OFF, PSTR("G28L0"), G28_STR));
}

typedef struct {
bool paused:1;
bool position:1;
} autoreport_t;

#if EITHER(HAS_AUTO_REPORTING, HOST_KEEPALIVE_FEATURE)
static autoreport_t autoreport;

static bool autoreport_paused;
static inline bool set_autoreport_paused(const bool p) {
const bool was = autoreport.paused;
autoreport.paused = p;
const bool was = autoreport_paused;
autoreport_paused = p;
return was;
}
#else
static constexpr autoreport_t{false};
static constexpr bool autoreport_paused = false;
static inline bool set_autoreport_paused(const bool) { return false; }
#endif

Expand Down Expand Up @@ -727,6 +722,10 @@ class GcodeSuite {
static void M150();
#endif

#if ENABLED(AUTO_REPORT_POSITION)
static void M154();
#endif

#if BOTH(AUTO_REPORT_TEMPERATURES, HAS_TEMP_SENSOR)
static void M155();
#endif
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/gcode/host/M115.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void GcodeSuite::M115() {
// Volumetric Extrusion (M200)
cap_line(PSTR("VOLUMETRIC"), DISABLED(NO_VOLUMETRICS));

// AUTOREPORT_POS (M154)
cap_line(PSTR("AUTOREPORT_POS"), ENABLED(AUTO_REPORT_POSITION));

// AUTOREPORT_TEMP (M155)
cap_line(PSTR("AUTOREPORT_TEMP"), ENABLED(AUTO_REPORT_TEMPERATURES));

Expand Down
40 changes: 40 additions & 0 deletions Marlin/src/gcode/host/M154.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#include "../../inc/MarlinConfigPre.h"

#if ENABLED(AUTO_REPORT_POSITION)

#include "../gcode.h"
#include "../../module/motion.h"

/**
* M154: Set position auto-report interval. M154 S<seconds>
*/
void GcodeSuite::M154() {

if (parser.seenval('S'))
position_auto_reporter.set_interval(parser.value_byte());

}

#endif // AUTO_REPORT_POSITION
3 changes: 0 additions & 3 deletions Marlin/src/gcode/temp/M155.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
*/
void GcodeSuite::M155() {

if (parser.seen('P'))
autoreport.position = parser.value_bool();

if (parser.seenval('S'))
thermalManager.auto_reporter.set_interval(parser.value_byte());

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@
#if !HAS_TEMP_SENSOR
#undef AUTO_REPORT_TEMPERATURES
#endif
#if EITHER(AUTO_REPORT_TEMPERATURES, AUTO_REPORT_SD_STATUS)
#if ANY(AUTO_REPORT_TEMPERATURES, AUTO_REPORT_SD_STATUS, AUTO_REPORT_POSITION)
#define HAS_AUTO_REPORTING 1
#endif

Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ void report_current_position_projected() {
stepper.report_a_position(planner.position);
}

#if ENABLED(AUTO_REPORT_POSITION)
//struct PositionReport { void report() { report_current_position_projected(); } };
AutoReporter<PositionReport> position_auto_reporter;
#endif

#if EITHER(FULL_REPORT_TO_HOST_FEATURE, REALTIME_REPORTING_COMMANDS)

M_StateEnum M_State_grbl = M_INIT;
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/module/motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ void report_real_position();
void report_current_position();
void report_current_position_projected();

#if ENABLED(AUTO_REPORT_POSITION)
#include "../libs/autoreport.h"
struct PositionReport { static void report() { report_current_position_projected(); } };
extern AutoReporter<PositionReport> position_auto_reporter;
#endif

#if EITHER(FULL_REPORT_TO_HOST_FEATURE, REALTIME_REPORTING_COMMANDS)
#define HAS_GRBL_STATE 1
/**
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3468,7 +3468,6 @@ void Temperature::isr() {
void Temperature::AutoReportTemp::report() {
print_heater_states(active_extruder);
SERIAL_EOL();
if (gcode.autoreport.position) report_current_position_projected();
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion buildroot/tests/mega2560
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO NUM_SERVOS 1 \
FIL_RUNOUT3_STATE HIGH
opt_enable VIKI2 BOOT_MARLIN_LOGO_ANIMATED SDSUPPORT AUTO_REPORT_SD_STATUS \
Z_PROBE_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE \
EEPROM_SETTINGS EEPROM_CHITCHAT M114_DETAIL \
EEPROM_SETTINGS EEPROM_CHITCHAT M114_DETAIL AUTO_REPORT_POSITION \
NO_VOLUMETRICS EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES AUTOTEMP G38_PROBE_TARGET JOYSTICK \
DIRECT_STEPPING DETECT_BROKEN_ENDSTOP \
FILAMENT_RUNOUT_SENSOR NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE Z_SAFE_HOMING FIL_RUNOUT3_PULLUP
Expand Down
1 change: 1 addition & 0 deletions ini/features.ini
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ CNC_COORDINATE_SYSTEMS = src_filter=+<src/gcode/geometry/G53-G59
HAS_M206_COMMAND = src_filter=+<src/gcode/geometry/M206_M428.cpp>
EXPECTED_PRINTER_CHECK = src_filter=+<src/gcode/host/M16.cpp>
HOST_KEEPALIVE_FEATURE = src_filter=+<src/gcode/host/M113.cpp>
AUTO_REPORT_POSITION = src_filter=+<src/gcode/host/M154.cpp>
REPETIER_GCODE_M360 = src_filter=+<src/gcode/host/M360.cpp>
HAS_GCODE_M876 = src_filter=+<src/gcode/host/M876.cpp>
HAS_RESUME_CONTINUE = src_filter=+<src/gcode/lcd/M0_M1.cpp>
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
-<src/gcode/geometry/M206_M428.cpp>
-<src/gcode/host/M16.cpp>
-<src/gcode/host/M113.cpp>
-<src/gcode/host/M154.cpp>
-<src/gcode/host/M360.cpp>
-<src/gcode/host/M876.cpp>
-<src/gcode/lcd/M0_M1.cpp>
Expand Down

0 comments on commit c20ed7f

Please sign in to comment.