Skip to content

Commit

Permalink
Optimize G-code / feature dependencies (#18919)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored Aug 6, 2020
1 parent 6bcfb58 commit 99ba866
Show file tree
Hide file tree
Showing 26 changed files with 632 additions and 189 deletions.
6 changes: 3 additions & 3 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
#include "feature/leds/tempstat.h"
#endif

#if HAS_CASE_LIGHT
#if ENABLED(CASE_LIGHT_ENABLE)
#include "feature/caselight.h"
#endif

Expand Down Expand Up @@ -1082,11 +1082,11 @@ void setup() {
OUT_WRITE(STAT_LED_BLUE_PIN, LOW); // OFF
#endif

#if HAS_CASE_LIGHT
#if ENABLED(CASE_LIGHT_ENABLE)
#if DISABLED(CASE_LIGHT_USE_NEOPIXEL)
if (PWM_PIN(CASE_LIGHT_PIN)) SET_PWM(CASE_LIGHT_PIN); else SET_OUTPUT(CASE_LIGHT_PIN);
#endif
SETUP_RUN(update_case_light());
SETUP_RUN(caselight.update_brightness());
#endif

#if ENABLED(MK2_MULTIPLEXER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
#if ENABLED(BINARY_FILE_TRANSFER)

#include "../sd/cardreader.h"
#include "binary_protocol.h"
#include "binary_stream.h"

char* SDFileTransferProtocol::Packet::Open::data = nullptr;
size_t SDFileTransferProtocol::data_waiting, SDFileTransferProtocol::transfer_timeout, SDFileTransferProtocol::idle_timeout;
bool SDFileTransferProtocol::transfer_active, SDFileTransferProtocol::dummy_transfer, SDFileTransferProtocol::compression;

BinaryStream binaryStream[NUM_SERIAL];

#endif // BINARY_FILE_TRANSFER
#endif
File renamed without changes.
48 changes: 25 additions & 23 deletions Marlin/src/feature/caselight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@

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

#if HAS_CASE_LIGHT
#if ENABLED(CASE_LIGHT_ENABLE)

uint8_t case_light_brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
bool case_light_on = CASE_LIGHT_DEFAULT_ON;
#include "caselight.h"

CaseLight caselight;

uint8_t CaseLight::brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;

#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
#include "leds/leds.h"
LEDColor case_light_color =
LEDColor CaseLight::color =
#ifdef CASE_LIGHT_NEOPIXEL_COLOR
CASE_LIGHT_NEOPIXEL_COLOR
#else
Expand All @@ -38,34 +41,33 @@ bool case_light_on = CASE_LIGHT_DEFAULT_ON;
;
#endif

/**
* The following are needed because ARM chips ignore a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that
* are directly controlled by the PWM module. In order to turn them off the brightness level needs to be
* set to off. Since we can't use the pwm register to save the last brightness level we need a variable
* to save it.
*/
uint8_t case_light_brightness_sav; // saves brighness info so can restore when "M355 S1" received
bool case_light_arg_flag; // flag to notify if S or P argument type

#ifndef INVERT_CASE_LIGHT
#define INVERT_CASE_LIGHT false
#endif

void update_case_light() {
void CaseLight::update(const bool sflag) {
/**
* The brightness_sav (and sflag) is needed because ARM chips ignore
* a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that are directly
* controlled by the PWM module. In order to turn them off the brightness
* level needs to be set to OFF. Since we can't use the PWM register to
* save the last brightness level we need a variable to save it.
*/
static uint8_t brightness_sav; // Save brightness info for restore on "M355 S1"

if (!(case_light_arg_flag && !case_light_on))
case_light_brightness_sav = case_light_brightness; // save brightness except if this is an S0 argument
if (case_light_arg_flag && case_light_on)
case_light_brightness = case_light_brightness_sav; // restore last brightens if this is an S1 argument
if (on || !sflag)
brightness_sav = brightness; // Save brightness except for M355 S0
if (sflag && on)
brightness = brightness_sav; // Restore last brightness for M355 S1

#if ENABLED(CASE_LIGHT_USE_NEOPIXEL) || DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
const uint8_t i = case_light_on ? case_light_brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
#endif

#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)

leds.set_color(
MakeLEDColor(case_light_color.r, case_light_color.g, case_light_color.b, case_light_color.w, n10ct),
MakeLEDColor(color.r, color.g, color.b, color.w, n10ct),
false
);

Expand All @@ -83,11 +85,11 @@ void update_case_light() {
else
#endif
{
const bool s = case_light_on ? !INVERT_CASE_LIGHT : INVERT_CASE_LIGHT;
const bool s = on ? !INVERT_CASE_LIGHT : INVERT_CASE_LIGHT;
WRITE(CASE_LIGHT_PIN, s ? HIGH : LOW);
}

#endif // !CASE_LIGHT_USE_NEOPIXEL
}

#endif // HAS_CASE_LIGHT
#endif // CASE_LIGHT_ENABLE
26 changes: 21 additions & 5 deletions Marlin/src/feature/caselight.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,25 @@
*/
#pragma once

extern uint8_t case_light_brightness;
extern bool case_light_on;
extern uint8_t case_light_brightness_sav; // saves brighness info when case_light_on is false
extern bool case_light_arg_flag; // flag to notify if S or P argument type
#include "../inc/MarlinConfigPre.h"

void update_case_light();
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
#include "leds/leds.h"
#endif

class CaseLight {
public:
static uint8_t brightness;
static bool on;

static void update(const bool sflag);
static inline void update_brightness() { update(false); }
static inline void update_enabled() { update(true); }

private:
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
static LEDColor color;
#endif
};

extern CaseLight caselight;
2 changes: 1 addition & 1 deletion Marlin/src/feature/e_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

/**
* emergency_parser.cpp - Intercept special commands directly in the serial stream
* e_parser.cpp - Intercept special commands directly in the serial stream
*/

#include "../inc/MarlinConfigPre.h"
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/e_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#pragma once

/**
* emergency_parser.h - Intercept special commands directly in the serial stream
* e_parser.h - Intercept special commands directly in the serial stream
*/

#include "../inc/MarlinConfigPre.h"
Expand Down
76 changes: 39 additions & 37 deletions Marlin/src/gcode/feature/caselight/M355.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
const bool sflag = parser.seenval('S');
if (sflag) {
didset = true;
caselight.on = parser.value_bool();
}
#endif // HAS_CASE_LIGHT
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
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ class GcodeSuite {
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());

Expand Down Expand Up @@ -845,7 +845,7 @@ class GcodeSuite {
TERN_(MAGNETIC_PARKING_EXTRUDER, static void M951());

TERN_(TOUCH_SCREEN_CALIBRATION, static void M995());

TERN_(PLATFORM_M997_SUPPORT, static void M997());

static void M999();
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/host/M115.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 2 additions & 3 deletions Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down
15 changes: 0 additions & 15 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,6 @@
#endif
#endif

#if ENABLED(SR_LCD_3W_NL)
// Feature checks for SR_LCD_3W_NL
#elif EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008)
#define USES_LIQUIDTWI2
#elif ANY(HAS_CHARACTER_LCD, LCD_I2C_TYPE_PCF8575, LCD_I2C_TYPE_PCA8574, SR_LCD_2W_NL, LCM1602)
#define USES_LIQUIDCRYSTAL
#endif

#if ENABLED(ULTIPANEL) && DISABLED(NO_LCD_MENUS)
#define HAS_LCD_MENU 1
#endif
Expand Down Expand Up @@ -774,10 +766,3 @@
#ifndef EXTRUDE_MINTEMP
#define EXTRUDE_MINTEMP 170
#endif

/**
* To check if we need the folder src/features/leds
*/
#if ANY(TEMP_STAT_LEDS, HAS_COLOR_LEDS, HAS_CASE_LIGHT, PRINTER_EVENT_LEDS, LED_BACKLIGHT_TIMEOUT, PCA9632_BUZZER, LED_CONTROL_MENU, NEOPIXEL_LED)
#define HAS_LED_FEATURE 1
#endif
5 changes: 1 addition & 4 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -1944,9 +1944,6 @@
#if PIN_EXISTS(PHOTOGRAPH)
#define HAS_PHOTOGRAPH 1
#endif
#if PIN_EXISTS(CASE_LIGHT) && ENABLED(CASE_LIGHT_ENABLE)
#define HAS_CASE_LIGHT 1
#endif

// Digital control
#if PIN_EXISTS(STEPPER_RESET)
Expand Down Expand Up @@ -2223,7 +2220,7 @@
/**
* MIN/MAX case light PWM scaling
*/
#if HAS_CASE_LIGHT
#if ENABLED(CASE_LIGHT_ENABLE)
#ifndef CASE_LIGHT_MAX_PWM
#define CASE_LIGHT_MAX_PWM 255
#elif !WITHIN(CASE_LIGHT_MAX_PWM, 1, 255)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void AdvancedSettingsMenu::onRedraw(draw_mode_t what) {
}

#ifdef TOUCH_UI_PORTRAIT
#if EITHER(HAS_CASE_LIGHT, SENSORLESS_HOMING)
#if EITHER(CASE_LIGHT_ENABLE, SENSORLESS_HOMING)
#define GRID_ROWS 9
#else
#define GRID_ROWS 8
Expand All @@ -59,7 +59,7 @@ void AdvancedSettingsMenu::onRedraw(draw_mode_t what) {
#define BACKLASH_POS BTN_POS(2,7), BTN_SIZE(1,1)
#define CASE_LIGHT_POS BTN_POS(1,8), BTN_SIZE(1,1)
#define TMC_HOMING_THRS_POS BTN_POS(2,8), BTN_SIZE(1,1)
#if EITHER(HAS_CASE_LIGHT, SENSORLESS_HOMING)
#if EITHER(CASE_LIGHT_ENABLE, SENSORLESS_HOMING)
#define BACK_POS BTN_POS(1,9), BTN_SIZE(2,1)
#else
#define BACK_POS BTN_POS(1,8), BTN_SIZE(2,1)
Expand Down Expand Up @@ -91,7 +91,7 @@ void AdvancedSettingsMenu::onRedraw(draw_mode_t what) {
.font(Theme::font_medium)
.enabled(ENABLED(HAS_BED_PROBE))
.tag(2) .button( ZPROBE_ZOFFSET_POS, GET_TEXT_F(MSG_ZPROBE_ZOFFSET))
.enabled(ENABLED(HAS_CASE_LIGHT))
.enabled(ENABLED(CASE_LIGHT_ENABLE))
.tag(16).button( CASE_LIGHT_POS, GET_TEXT_F(MSG_CASE_LIGHT))
.tag(3) .button( STEPS_PER_MM_POS, GET_TEXT_F(MSG_STEPS_PER_MM))
.enabled(ENABLED(HAS_TRINAMIC_CONFIG))
Expand Down Expand Up @@ -149,7 +149,7 @@ bool AdvancedSettingsMenu::onTouchEnd(uint8_t tag) {
case 14: GOTO_SCREEN(StepperBumpSensitivityScreen); break;
#endif
case 15: GOTO_SCREEN(DisplayTuningScreen); break;
#if HAS_CASE_LIGHT
#if ENABLED(CASE_LIGHT_ENABLE)
case 16: GOTO_SCREEN(CaseLightScreen); break;
#endif
default: return false;
Expand Down
Loading

0 comments on commit 99ba866

Please sign in to comment.