Optimize G-code / feature dependencies (#18919)

This commit is contained in:
Scott Lahteine
2020-08-06 08:14:00 -05:00
committed by GitHub
parent 6bcfb58cd4
commit 99ba866d8d
26 changed files with 632 additions and 189 deletions

View File

@ -20,45 +20,47 @@
*
*/
#include "../../gcode.h"
#include "../../../inc/MarlinConfig.h"
#if HAS_CASE_LIGHT
#include "../../../feature/caselight.h"
#if ENABLED(CASE_LIGHT_ENABLE)
/**
* M355: Turn case light on/off and set brightness
*
* P<byte> Set case light brightness (PWM pin required - ignored otherwise)
*
* S<bool> Set case light on/off
*
* When S turns on the light on a PWM pin then the current brightness level is used/restored
*
* M355 P200 S0 turns off the light & sets the brightness level
* M355 S1 turns on the light with a brightness of 200 (assuming a PWM pin)
*/
void GcodeSuite::M355() {
uint8_t args = 0;
if (parser.seenval('P')) {
++args, case_light_brightness = parser.value_byte();
case_light_arg_flag = false;
}
if (parser.seenval('S')) {
++args, case_light_on = parser.value_bool();
case_light_arg_flag = true;
}
if (args) update_case_light();
#include "../../../feature/caselight.h"
#include "../../gcode.h"
// always report case light status
SERIAL_ECHO_START();
if (!case_light_on) {
SERIAL_ECHOLNPGM("Case light: off");
}
else {
if (!PWM_PIN(CASE_LIGHT_PIN)) SERIAL_ECHOLNPGM("Case light: on");
else SERIAL_ECHOLNPAIR("Case light: ", case_light_brightness);
}
/**
* M355: Turn case light on/off and set brightness
*
* P<byte> Set case light brightness (PWM pin required - ignored otherwise)
*
* S<bool> Set case light on/off
*
* When S turns on the light on a PWM pin then the current brightness level is used/restored
*
* M355 P200 S0 turns off the light & sets the brightness level
* M355 S1 turns on the light with a brightness of 200 (assuming a PWM pin)
*/
void GcodeSuite::M355() {
bool didset = false;
if (parser.seenval('P')) {
didset = true;
caselight.brightness = parser.value_byte();
}
#endif // HAS_CASE_LIGHT
const bool sflag = parser.seenval('S');
if (sflag) {
didset = true;
caselight.on = parser.value_bool();
}
if (didset) caselight.update(sflag);
// Always report case light status
SERIAL_ECHO_START();
SERIAL_ECHOPGM("Case light: ");
if (!caselight.on)
SERIAL_ECHOLNPGM(STR_OFF);
else {
if (!PWM_PIN(CASE_LIGHT_PIN)) SERIAL_ECHOLNPGM(STR_ON);
else SERIAL_ECHOLN(int(caselight.brightness));
}
}
#endif // CASE_LIGHT_ENABLE

View File

@ -842,7 +842,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 351: M351(); break; // M351: Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low.
#endif
#if HAS_CASE_LIGHT
#if ENABLED(CASE_LIGHT_ENABLE)
case 355: M355(); break; // M355: Set case light brightness
#endif

View File

@ -702,7 +702,7 @@ private:
static void M351();
#endif
TERN_(HAS_CASE_LIGHT, static void M355());
TERN_(CASE_LIGHT_ENABLE, static void M355());
TERN_(REPETIER_GCODE_M360, static void M360());
@ -845,7 +845,7 @@ private:
TERN_(MAGNETIC_PARKING_EXTRUDER, static void M951());
TERN_(TOUCH_SCREEN_CALIBRATION, static void M995());
TERN_(PLATFORM_M997_SUPPORT, static void M997());
static void M999();

View File

@ -93,8 +93,8 @@ void GcodeSuite::M115() {
cap_line(PSTR("SOFTWARE_POWER"), ENABLED(PSU_CONTROL));
// TOGGLE_LIGHTS (M355)
cap_line(PSTR("TOGGLE_LIGHTS"), ENABLED(HAS_CASE_LIGHT));
cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(HAS_CASE_LIGHT, PWM_PIN(CASE_LIGHT_PIN)));
cap_line(PSTR("TOGGLE_LIGHTS"), ENABLED(CASE_LIGHT_ENABLE));
cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, PWM_PIN(CASE_LIGHT_PIN)));
// EMERGENCY_PARSER (M108, M112, M410, M876)
cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER));

View File

@ -40,7 +40,7 @@ GCodeQueue queue;
#endif
#if ENABLED(BINARY_FILE_TRANSFER)
#include "../feature/binary_protocol.h"
#include "../feature/binary_stream.h"
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
@ -628,11 +628,10 @@ void GCodeQueue::advance() {
#if ENABLED(SERIAL_STATS_DROPPED_RX)
SERIAL_ECHOLNPAIR("Dropped bytes: ", MYSERIAL0.dropped());
#endif
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
SERIAL_ECHOLNPAIR("Max RX Queue Size: ", MYSERIAL0.rxMaxEnqueued());
#endif
#endif // !defined(__AVR__) || !defined(USBCON)
#endif
ok_to_send();
}