diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index a23e90bc71..80bd3d2adc 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 3cd579741d..2e468a29db 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -176,7 +176,7 @@ * M304 - Set bed PID parameters P I and D. (Requires PIDTEMPBED) * M350 - Set microstepping mode. (Requires digital microstepping pins.) * M351 - Toggle MS1 MS2 pins directly. (Requires digital microstepping pins.) - * M355 - Turn the Case Light on/off and set its brightness. (Requires CASE_LIGHT_PIN) + * M355 - Set Case Light on/off and set brightness. (Requires CASE_LIGHT_PIN) * M380 - Activate solenoid on active extruder. (Requires EXT_SOLENOID) * M381 - Disable all solenoids. (Requires EXT_SOLENOID) * M400 - Finish all moves. @@ -566,16 +566,6 @@ static uint8_t target_extruder; ; #endif -#if HAS_CASE_LIGHT - bool case_light_on = - #if ENABLED(CASE_LIGHT_DEFAULT_ON) - true - #else - false - #endif - ; -#endif - #if ENABLED(DELTA) float delta[ABC], @@ -720,7 +710,8 @@ static void report_current_position(); SERIAL_ECHOPAIR(", ", z); SERIAL_CHAR(')'); - suffix ? serialprintPGM(suffix) : SERIAL_EOL; + if (suffix) {serialprintPGM(suffix);} //won't compile for Teensy with the previous construction + else SERIAL_EOL; } void print_xyz(const char* prefix, const char* suffix, const float xyz[]) { @@ -5263,7 +5254,7 @@ void home_all_axes() { gcode_G28(true); } recalc_delta_settings(delta_radius, delta_diagonal_rod); } - else if(zero_std_dev >= test_precision) { // step one back + else if (zero_std_dev >= test_precision) { // step one back COPY(endstop_adj, e_old); delta_radius = dr_old; home_offset[Z_AXIS] = zh_old; @@ -7678,11 +7669,18 @@ inline void gcode_M115() { SERIAL_PROTOCOLLNPGM("Cap:SOFTWARE_POWER:0"); #endif - // TOGGLE_LIGHTS (M355) + // CASE LIGHTS (M355) #if HAS_CASE_LIGHT SERIAL_PROTOCOLLNPGM("Cap:TOGGLE_LIGHTS:1"); + bool USEABLE_HARDWARE_PWM(uint8_t pin); + if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) { + SERIAL_PROTOCOLLNPGM("Cap:CASE_LIGHT_BRIGHTNESS:1"); + } + else + SERIAL_PROTOCOLLNPGM("Cap:CASE_LIGHT_BRIGHTNESS:0"); #else SERIAL_PROTOCOLLNPGM("Cap:TOGGLE_LIGHTS:0"); + SERIAL_PROTOCOLLNPGM("Cap:CASE_LIGHT_BRIGHTNESS:0"); #endif // EMERGENCY_PARSER (M108, M112, M410) @@ -9472,30 +9470,54 @@ inline void gcode_M907() { #endif // HAS_MICROSTEPS #if HAS_CASE_LIGHT - - uint8_t case_light_brightness = 255; + #ifndef INVERT_CASE_LIGHT + #define INVERT_CASE_LIGHT false + #endif + int case_light_brightness; // LCD routine wants INT + bool case_light_on; void update_case_light() { - WRITE(CASE_LIGHT_PIN, case_light_on != INVERT_CASE_LIGHT ? HIGH : LOW); - analogWrite(CASE_LIGHT_PIN, case_light_on != INVERT_CASE_LIGHT ? case_light_brightness : 0); + pinMode(CASE_LIGHT_PIN, OUTPUT); // digitalWrite doesn't set the port mode + uint8_t case_light_bright = (uint8_t)case_light_brightness; + if (case_light_on) { + if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) { + analogWrite(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? 255 - case_light_brightness : case_light_brightness ); + } + else digitalWrite(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? LOW : HIGH ); + } + else digitalWrite(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? HIGH : LOW); } - #endif // HAS_CASE_LIGHT /** - * M355: Turn case lights on/off and set brightness + * M355: Turn case light on/off and set brightness * - * S Turn case light on or off - * P Set case light brightness (PWM pin required) + * P Set case light brightness (PWM pin required - ignored otherwise) + * + * S 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) */ inline void gcode_M355() { #if HAS_CASE_LIGHT - if (parser.seen('P')) case_light_brightness = parser.value_byte(); - if (parser.seen('S')) case_light_on = parser.value_bool(); - update_case_light(); + uint8_t args = 0; + if (parser.seen('P')) ++args, case_light_brightness = parser.value_byte(); + if (parser.seen('S')) ++args, case_light_on = parser.value_bool(); + if (args) update_case_light(); + + // always report case light status SERIAL_ECHO_START; - SERIAL_ECHOPGM("Case lights "); - case_light_on ? SERIAL_ECHOLNPGM("on") : SERIAL_ECHOLNPGM("off"); + if (!case_light_on) { + SERIAL_ECHOLN("Case light: off"); + } + else { + if (!USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) SERIAL_ECHOLN("Case light: on"); + else SERIAL_ECHOLNPAIR("Case light: ", case_light_brightness); + } + #else SERIAL_ERROR_START; SERIAL_ERRORLNPGM(MSG_ERR_M355_NONE); @@ -10710,7 +10732,7 @@ void process_next_command() { #endif // HAS_MICROSTEPS - case 355: // M355 Turn case lights on/off + case 355: // M355 set case light brightness gcode_M355(); break; @@ -12459,6 +12481,8 @@ void setup() { #endif #if HAS_CASE_LIGHT + case_light_on = CASE_LIGHT_DEFAULT_ON; + case_light_brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS; update_case_light(); #endif diff --git a/Marlin/example_configurations/Cartesio/Configuration_adv.h b/Marlin/example_configurations/Cartesio/Configuration_adv.h index caba55f7e8..210f3de107 100644 --- a/Marlin/example_configurations/Cartesio/Configuration_adv.h +++ b/Marlin/example_configurations/Cartesio/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 35 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/Felix/Configuration_adv.h b/Marlin/example_configurations/Felix/Configuration_adv.h index 6b5718d51f..851a2053e6 100644 --- a/Marlin/example_configurations/Felix/Configuration_adv.h +++ b/Marlin/example_configurations/Felix/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/FolgerTech-i3-2020/Configuration_adv.h b/Marlin/example_configurations/FolgerTech-i3-2020/Configuration_adv.h index 013518b786..ee0ab8c062 100644 --- a/Marlin/example_configurations/FolgerTech-i3-2020/Configuration_adv.h +++ b/Marlin/example_configurations/FolgerTech-i3-2020/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/Hephestos/Configuration_adv.h b/Marlin/example_configurations/Hephestos/Configuration_adv.h index bcef1672ee..92b8e05ec6 100644 --- a/Marlin/example_configurations/Hephestos/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/Hephestos_2/Configuration_adv.h b/Marlin/example_configurations/Hephestos_2/Configuration_adv.h index cb227fd8fb..0a98f395f2 100644 --- a/Marlin/example_configurations/Hephestos_2/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos_2/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/K8200/Configuration_adv.h b/Marlin/example_configurations/K8200/Configuration_adv.h index 692af7fabc..f421c5ea4c 100644 --- a/Marlin/example_configurations/K8200/Configuration_adv.h +++ b/Marlin/example_configurations/K8200/Configuration_adv.h @@ -233,13 +233,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/K8400/Configuration_adv.h b/Marlin/example_configurations/K8400/Configuration_adv.h index 7999653d2d..e6e4a8c207 100644 --- a/Marlin/example_configurations/K8400/Configuration_adv.h +++ b/Marlin/example_configurations/K8400/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/RigidBot/Configuration_adv.h b/Marlin/example_configurations/RigidBot/Configuration_adv.h index 5f84cd8206..793e595c02 100644 --- a/Marlin/example_configurations/RigidBot/Configuration_adv.h +++ b/Marlin/example_configurations/RigidBot/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/SCARA/Configuration_adv.h b/Marlin/example_configurations/SCARA/Configuration_adv.h index fa1c965326..70bda56b44 100644 --- a/Marlin/example_configurations/SCARA/Configuration_adv.h +++ b/Marlin/example_configurations/SCARA/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/TAZ4/Configuration_adv.h b/Marlin/example_configurations/TAZ4/Configuration_adv.h index 9a50d09715..271985f3ae 100644 --- a/Marlin/example_configurations/TAZ4/Configuration_adv.h +++ b/Marlin/example_configurations/TAZ4/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/TinyBoy2/Configuration_adv.h b/Marlin/example_configurations/TinyBoy2/Configuration_adv.h index 0a498ac62b..1d97f76775 100644 --- a/Marlin/example_configurations/TinyBoy2/Configuration_adv.h +++ b/Marlin/example_configurations/TinyBoy2/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/WITBOX/Configuration_adv.h b/Marlin/example_configurations/WITBOX/Configuration_adv.h index bcef1672ee..92b8e05ec6 100644 --- a/Marlin/example_configurations/WITBOX/Configuration_adv.h +++ b/Marlin/example_configurations/WITBOX/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/delta/FLSUN/auto_calibrate/Configuration_adv.h b/Marlin/example_configurations/delta/FLSUN/auto_calibrate/Configuration_adv.h index e60b421a99..e601186a87 100644 --- a/Marlin/example_configurations/delta/FLSUN/auto_calibrate/Configuration_adv.h +++ b/Marlin/example_configurations/delta/FLSUN/auto_calibrate/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/delta/FLSUN/kossel_mini/Configuration_adv.h b/Marlin/example_configurations/delta/FLSUN/kossel_mini/Configuration_adv.h index 05aefb8ba7..f80ca51e5e 100644 --- a/Marlin/example_configurations/delta/FLSUN/kossel_mini/Configuration_adv.h +++ b/Marlin/example_configurations/delta/FLSUN/kossel_mini/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/delta/generic/Configuration_adv.h b/Marlin/example_configurations/delta/generic/Configuration_adv.h index a37cc55727..65ab62be89 100644 --- a/Marlin/example_configurations/delta/generic/Configuration_adv.h +++ b/Marlin/example_configurations/delta/generic/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h index a37cc55727..65ab62be89 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h index 0e428fe65d..a2716415af 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h @@ -225,13 +225,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h index 99be30bf0d..cf8f3ffbd4 100644 --- a/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/gCreate_gMax1.5+/Configuration_adv.h b/Marlin/example_configurations/gCreate_gMax1.5+/Configuration_adv.h index c18723ee69..eded350af2 100644 --- a/Marlin/example_configurations/gCreate_gMax1.5+/Configuration_adv.h +++ b/Marlin/example_configurations/gCreate_gMax1.5+/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/makibox/Configuration_adv.h b/Marlin/example_configurations/makibox/Configuration_adv.h index f667868f1c..98b84c6ddc 100644 --- a/Marlin/example_configurations/makibox/Configuration_adv.h +++ b/Marlin/example_configurations/makibox/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h index 3076378f9a..aed84489be 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/example_configurations/wt150/Configuration_adv.h b/Marlin/example_configurations/wt150/Configuration_adv.h index 1c0a28083d..5612cd240c 100644 --- a/Marlin/example_configurations/wt150/Configuration_adv.h +++ b/Marlin/example_configurations/wt150/Configuration_adv.h @@ -220,13 +220,19 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -// Define a pin to turn case light on/off -//#define CASE_LIGHT_PIN 4 -#if PIN_EXISTS(CASE_LIGHT) - #define INVERT_CASE_LIGHT false // Set to true if HIGH is the OFF state (active low) - //#define CASE_LIGHT_DEFAULT_ON // Uncomment to set default state to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light On / Off entry in main menu -#endif +// M355 Case Light command +// Set case light brightness/on/off + +//#define CASE_LIGHT_ENABLE +#if ENABLED(CASE_LIGHT_ENABLE) + #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board + // pins_XXX.h file overrides this one + #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 + #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM + // and if CASE_LIGHT_DEFAULT is set to on + //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu +#endif //=========================================================================== //============================ Mechanical Settings ========================== diff --git a/Marlin/fastio.h b/Marlin/fastio.h index 402e1ba49e..174e5f9cf6 100644 --- a/Marlin/fastio.h +++ b/Marlin/fastio.h @@ -26,10 +26,11 @@ * Contributed by Triffid_Hunter. Modified by Kliment and the Marlin team. */ -#ifndef _FASTIO_ARDUINO_H +#ifndef _FASTIO_ARDUINO_H #define _FASTIO_ARDUINO_H #include +#include "macros.h" /** * Enable this option to use Teensy++ 2.0 assignments for AT90USB processors. @@ -238,4 +239,93 @@ typedef enum { #define SET_FOCB(T,V) SET_FOC(T,B,V) #define SET_FOCC(T,V) SET_FOC(T,C,V) + +/** + * PWM availability macros + */ +#define AVR_AT90USB1286_FAMILY (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__) || defined(__AVR_AT90USB647__)) +#define AVR_ATmega1284_FAMILY (defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__)) +#define AVR_ATmega2560_FAMILY (defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)) +#define AVR_ATmega2561_FAMILY (defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)) +#define AVR_ATmega328_FAMILY (defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328p__)) + +//find out which harware PWMs are already in use +#if PIN_EXISTS(CONTROLLER_FAN) + #define PWM_CHK_FAN_B(p) (p == CONTROLLER_FAN_PIN || p == E0_AUTO_FAN_PIN || p == E1_AUTO_FAN_PIN || p == E2_AUTO_FAN_PIN || p == E3_AUTO_FAN_PIN || p == E4_AUTO_FAN_PIN) +#else + #define PWM_CHK_FAN_B(p) (p == E0_AUTO_FAN_PIN || p == E1_AUTO_FAN_PIN || p == E2_AUTO_FAN_PIN || p == E3_AUTO_FAN_PIN || p == E4_AUTO_FAN_PIN) +#endif + +#if PIN_EXISTS(FAN) || PIN_EXISTS(FAN1) || PIN_EXISTS(FAN2) + #if PIN_EXISTS(FAN2) + #define PWM_CHK_FAN_A(p) (p == FAN_PIN || p == FAN1_PIN || p == FAN2_PIN) + #elif PIN_EXISTS(FAN1) + #define PWM_CHK_FAN_A(p) (p == FAN_PIN || p == FAN1_PIN) + #else + #define PWM_CHK_FAN_A(p) p == FAN_PIN + #endif +#else + #define PWM_CHK_FAN_A(p) false +#endif + +#if HAS_MOTOR_CURRENT_PWM + #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY) + #define PWM_CHK_MOTOR_CURRENT(p) (p == MOTOR_CURRENT_PWM_E || p == MOTOR_CURRENT_PWM_Z || p == MOTOR_CURRENT_PWM_XY) + #elif PIN_EXISTS(MOTOR_CURRENT_PWM_Z) + #define PWM_CHK_MOTOR_CURRENT(p) (p == MOTOR_CURRENT_PWM_E || p == MOTOR_CURRENT_PWM_Z) + #else + #define PWM_CHK_MOTOR_CURRENT(p) (p == MOTOR_CURRENT_PWM_E) + #endif +#else + #define PWM_CHK_MOTOR_CURRENT(p) false +#endif + +#if defined(NUM_SERVOS) + #if AVR_ATmega2560_FAMILY + #define PWM_CHK_SERVO(p) ( p == 5 || NUM_SERVOS > 12 && p == 6 || NUM_SERVOS > 24 && p == 46) //PWMS 3A, 4A & 5A + #elif AVR_ATmega2561_FAMILY + #define PWM_CHK_SERVO(p) p == 5 //PWM3A + #elif AVR_ATmega1284_FAMILY + #define PWM_CHK_SERVO(p) false + #elif AVR_AT90USB1286_FAMILY + #define PWM_CHK_SERVO(p) p == 16 //PWM3A + #elif AVR_ATmega328_FAMILY + #define PWM_CHK_SERVO(p) false + #endif +#else + #define PWM_CHK_SERVO(p) false +#endif + +#if ENABLED(BARICUDA) + #if HAS_HEATER_1 && HAS_HEATER_2 + #define PWM_CHK_HEATER(p) (p == HEATER_1_PIN || p == HEATER_2_PIN) + #elif HAS_HEATER_1 + #define PWM_CHK_HEATER(p) (p == HEATER_1_PIN) + #endif +#else + #define PWM_CHK_HEATER(p) false +#endif + +#define PWM_CHK(p) (PWM_CHK_HEATER(p) || PWM_CHK_SERVO(p) || PWM_CHK_MOTOR_CURRENT(p)\ + || PWM_CHK_FAN_A(p) || PWM_CHK_FAN_B(p)) + +// define which hardware PWMs are available for the current CPU +// all timer 1 PWMS deleted from this list because they are never available +#if AVR_ATmega2560_FAMILY + #define PWM_PINS(p) ((p >= 2 && p <= 10 ) || p == 13 || p == 44 || p == 45 || p == 46 ) +#elif AVR_ATmega2561_FAMILY + #define PWM_PINS(p) ((p >= 2 && p <= 6 ) || p == 9) +#elif AVR_ATmega1284_FAMILY + #define PWM_PINS(p) (p == 3 || p == 4 || p == 14 || p == 15) +#elif AVR_AT90USB1286_FAMILY + #define PWM_PINS(p) (p == 0 || p == 1 || p == 14 || p == 15 || p == 16 || p == 24) +#elif AVR_ATmega328_FAMILY + #define PWM_PINS(p) (p == 3 || p == 5 || p == 6 || p == 11) +#else + #error "unknown CPU" +#endif + +// finally - the macro that tells us if a pin is an available hardware PWM +#define USEABLE_HARDWARE_PWM(p) (PWM_PINS(p) && !PWM_CHK(p)) + #endif // _FASTIO_ARDUINO_H diff --git a/Marlin/language_en.h b/Marlin/language_en.h index 3190a12a55..4e7256535b 100644 --- a/Marlin/language_en.h +++ b/Marlin/language_en.h @@ -706,7 +706,9 @@ #ifndef MSG_CASE_LIGHT #define MSG_CASE_LIGHT _UxGT("Case light") #endif - +#ifndef MSG_CASE_LIGHT_BRIGHTNESS + #define MSG_CASE_LIGHT_BRIGHTNESS _UxGT("Light BRIGHTNESS") +#endif #if LCD_WIDTH >= 20 #ifndef MSG_INFO_PRINT_COUNT #define MSG_INFO_PRINT_COUNT _UxGT("Print Count") diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 7ce08055ca..990e4f4c59 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -60,6 +60,7 @@ int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2 uint8_t lcd_status_message_level; char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1 + #if ENABLED(STATUS_MESSAGE_SCROLLING) uint8_t status_scroll_pos = 0; #endif @@ -726,6 +727,24 @@ void kill_screen(const char* lcd_msg) { #endif // SDSUPPORT + #if ENABLED(MENU_ITEM_CASE_LIGHT) + + extern int case_light_brightness; + extern bool case_light_on; + extern void update_case_light(); + + void case_light_menu() { + START_MENU(); + // + // ^ Main + // + MENU_BACK(MSG_MAIN); + MENU_ITEM_EDIT_CALLBACK(int3, MSG_CASE_LIGHT_BRIGHTNESS, &case_light_brightness, 0, 255, update_case_light, true); + MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light); + END_MENU(); + } + #endif // MENU_ITEM_CASE_LIGHT + #if ENABLED(BLTOUCH) /** @@ -847,11 +866,6 @@ void kill_screen(const char* lcd_msg) { * */ - #if ENABLED(MENU_ITEM_CASE_LIGHT) - extern bool case_light_on; - extern void update_case_light(); - #endif - void lcd_main_menu() { START_MENU(); MENU_BACK(MSG_WATCH); @@ -868,10 +882,14 @@ void kill_screen(const char* lcd_msg) { #endif // - // Switch case light on/off + // Set Case light on/off/brightness // #if ENABLED(MENU_ITEM_CASE_LIGHT) - MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, &case_light_on, update_case_light); + if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) { + MENU_ITEM(submenu, MSG_CASE_LIGHT, case_light_menu); + } + else + MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light); #endif if (planner.movesplanned() || IS_SD_PRINTING) { @@ -1847,7 +1865,7 @@ void kill_screen(const char* lcd_msg) { */ void _lcd_ubl_validate_custom_mesh() { char UBL_LCD_GCODE[24]; - const int temp = + const int temp = #if WATCH_THE_BED custom_bed_temp #else @@ -2598,7 +2616,7 @@ void kill_screen(const char* lcd_msg) { MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu); #if HAS_LCD_CONTRAST - MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, &lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true); + MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, (int) &lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true); #endif #if ENABLED(FWRETRACT) MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu); diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index a6226652e4..bda80cd48b 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -59,7 +59,7 @@ #if ENABLED(DOGLCD) extern uint16_t lcd_contrast; - void set_lcd_contrast(uint16_t value); + void set_lcd_contrast(const uint16_t value); #elif ENABLED(SHOW_BOOTSCREEN) void bootscreen(); #endif