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.

M510-M512.cpp 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "../../../inc/MarlinConfigPre.h"
  23. #if ENABLED(PASSWORD_FEATURE)
  24. #include "../../../feature/password/password.h"
  25. #include "../../../core/serial.h"
  26. #include "../../gcode.h"
  27. //
  28. // M510: Lock Printer
  29. //
  30. void GcodeSuite::M510() {
  31. password.lock_machine();
  32. }
  33. //
  34. // M511: Unlock Printer
  35. //
  36. #if ENABLED(PASSWORD_UNLOCK_GCODE)
  37. void GcodeSuite::M511() {
  38. if (password.is_locked) {
  39. password.value_entry = parser.ulongval('P');
  40. password.authentication_check();
  41. }
  42. }
  43. #endif // PASSWORD_UNLOCK_GCODE
  44. //
  45. // M512: Set/Change/Remove Password
  46. //
  47. #if ENABLED(PASSWORD_CHANGE_GCODE)
  48. void GcodeSuite::M512() {
  49. if (password.is_set && parser.ulongval('P') != password.value) {
  50. SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD);
  51. return;
  52. }
  53. if (parser.seenval('S')) {
  54. password.value_entry = parser.ulongval('S');
  55. if (password.value_entry < CAT(1e, PASSWORD_LENGTH)) {
  56. password.is_set = true;
  57. password.value = password.value_entry;
  58. SERIAL_ECHOLNPAIR(STR_PASSWORD_SET, password.value); // TODO: Update password.string
  59. }
  60. else
  61. SERIAL_ECHOLNPGM(STR_PASSWORD_TOO_LONG);
  62. }
  63. else {
  64. password.is_set = false;
  65. SERIAL_ECHOLNPGM(STR_PASSWORD_REMOVED);
  66. }
  67. SERIAL_ECHOLNPGM(STR_REMINDER_SAVE_SETTINGS);
  68. }
  69. #endif // PASSWORD_CHANGE_GCODE
  70. #endif // PASSWORD_FEATURE