My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

M80_M81.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../gcode.h"
  23. #include "../../module/temperature.h"
  24. #include "../../module/planner.h" // for planner.finish_and_disable
  25. #include "../../module/printcounter.h" // for print_job_timer.stop
  26. #include "../../lcd/marlinui.h" // for LCD_MESSAGE_F
  27. #include "../../inc/MarlinConfig.h"
  28. #if ENABLED(PSU_CONTROL)
  29. #include "../queue.h"
  30. #include "../../feature/power.h"
  31. #endif
  32. #if HAS_SUICIDE
  33. #include "../../MarlinCore.h"
  34. #endif
  35. #if ENABLED(PSU_CONTROL)
  36. /**
  37. * M80 : Turn on the Power Supply
  38. * M80 S : Report the current state and exit
  39. */
  40. void GcodeSuite::M80() {
  41. // S: Report the current power supply state and exit
  42. if (parser.seen('S')) {
  43. SERIAL_ECHOF(powerManager.psu_on ? F("PS:1\n") : F("PS:0\n"));
  44. return;
  45. }
  46. powerManager.power_on();
  47. /**
  48. * If you have a switch on suicide pin, this is useful
  49. * if you want to start another print with suicide feature after
  50. * a print without suicide...
  51. */
  52. #if HAS_SUICIDE
  53. OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_STATE);
  54. #endif
  55. TERN_(HAS_MARLINUI_MENU, ui.reset_status());
  56. }
  57. #endif // PSU_CONTROL
  58. /**
  59. * M81: Turn off Power, including Power Supply, if there is one.
  60. *
  61. * This code should ALWAYS be available for FULL SHUTDOWN!
  62. */
  63. void GcodeSuite::M81() {
  64. planner.finish_and_disable();
  65. thermalManager.cooldown();
  66. print_job_timer.stop();
  67. #if BOTH(HAS_FAN, PROBING_FANS_OFF)
  68. thermalManager.fans_paused = false;
  69. ZERO(thermalManager.saved_fan_speed);
  70. #endif
  71. safe_delay(1000); // Wait 1 second before switching off
  72. LCD_MESSAGE_F(MACHINE_NAME " " STR_OFF ".");
  73. bool delayed_power_off = false;
  74. #if ENABLED(POWER_OFF_TIMER)
  75. if (parser.seenval('D')) {
  76. uint16_t delay = parser.value_ushort();
  77. if (delay > 1) { // skip already observed 1s delay
  78. delayed_power_off = true;
  79. powerManager.setPowerOffTimer(SEC_TO_MS(delay - 1));
  80. }
  81. }
  82. #endif
  83. #if ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
  84. if (parser.boolval('S')) {
  85. delayed_power_off = true;
  86. powerManager.setPowerOffOnCooldown(true);
  87. }
  88. #endif
  89. if (delayed_power_off) {
  90. SERIAL_ECHOLNPGM(STR_DELAYED_POWEROFF);
  91. return;
  92. }
  93. #if HAS_SUICIDE
  94. suicide();
  95. #elif ENABLED(PSU_CONTROL)
  96. powerManager.power_off_soon();
  97. #endif
  98. }