Password via G-code and MarlinUI (#18399)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
committed by
Scott Lahteine
parent
438a9bb4aa
commit
9e44df9c5f
83
Marlin/src/gcode/feature/password/M510-M512.cpp
Normal file
83
Marlin/src/gcode/feature/password/M510-M512.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(PASSWORD_FEATURE)
|
||||
|
||||
#include "../../../feature/password/password.h"
|
||||
#include "../../../core/serial.h"
|
||||
#include "../../gcode.h"
|
||||
|
||||
//
|
||||
// M510: Lock Printer
|
||||
//
|
||||
void GcodeSuite::M510() {
|
||||
password.lock_machine();
|
||||
}
|
||||
|
||||
//
|
||||
// M511: Unlock Printer
|
||||
//
|
||||
#if ENABLED(PASSWORD_UNLOCK_GCODE)
|
||||
|
||||
void GcodeSuite::M511() {
|
||||
if (password.is_locked) {
|
||||
password.value_entry = parser.ulongval('P');
|
||||
password.authentication_check();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // PASSWORD_UNLOCK_GCODE
|
||||
|
||||
//
|
||||
// M512: Set/Change/Remove Password
|
||||
//
|
||||
#if ENABLED(PASSWORD_CHANGE_GCODE)
|
||||
|
||||
void GcodeSuite::M512() {
|
||||
if (password.is_set && parser.ulongval('P') != password.value) {
|
||||
SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD);
|
||||
return;
|
||||
}
|
||||
|
||||
if (parser.seenval('N')) {
|
||||
password.value_entry = parser.ulongval('N');
|
||||
|
||||
if (password.value_entry < CAT(1e, PASSWORD_LENGTH)) {
|
||||
password.is_set = true;
|
||||
password.value = password.value_entry;
|
||||
SERIAL_ECHOLNPAIR(STR_PASSWORD_SET, password.value); // TODO: Update password.string
|
||||
}
|
||||
else
|
||||
SERIAL_ECHOLNPGM(STR_PASSWORD_TOO_LONG);
|
||||
}
|
||||
else {
|
||||
password.is_set = false;
|
||||
SERIAL_ECHOLNPGM(STR_PASSWORD_REMOVED);
|
||||
}
|
||||
SERIAL_ECHOLNPGM(STR_REMINDER_SAVE_SETTINGS);
|
||||
}
|
||||
|
||||
#endif // PASSWORD_CHANGE_GCODE
|
||||
|
||||
#endif // PASSWORD_FEATURE
|
@ -57,6 +57,10 @@ GcodeSuite gcode;
|
||||
#include "../feature/spindle_laser.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(PASSWORD_FEATURE)
|
||||
#include "../feature/password/password.h"
|
||||
#endif
|
||||
|
||||
#include "../MarlinCore.h" // for idle()
|
||||
|
||||
// Inactivity shutdown
|
||||
@ -241,6 +245,17 @@ void GcodeSuite::dwell(millis_t time) {
|
||||
void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
|
||||
KEEPALIVE_STATE(IN_HANDLER);
|
||||
|
||||
/**
|
||||
* Block all Gcodes except M511 Unlock Printer, if printer is locked
|
||||
* Will still block Gcodes if M511 is disabled, in which case the printer should be unlocked via LCD Menu
|
||||
*/
|
||||
#if ENABLED(PASSWORD_FEATURE)
|
||||
if (password.is_locked && !(parser.command_letter == 'M' && parser.codenum == 511)) {
|
||||
SERIAL_ECHO_MSG(STR_PRINTER_LOCKED);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Handle a known G, M, or T
|
||||
switch (parser.command_letter) {
|
||||
case 'G': switch (parser.codenum) {
|
||||
@ -736,6 +751,16 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
|
||||
case 504: M504(); break; // M504: Validate EEPROM contents
|
||||
#endif
|
||||
|
||||
#if ENABLED(PASSWORD_FEATURE)
|
||||
case 510: M510(); break; // M510: Lock Printer
|
||||
#if ENABLED(PASSWORD_UNLOCK_GCODE)
|
||||
case 511: M511(); break; // M511: Unlock Printer
|
||||
#endif
|
||||
#if ENABLED(PASSWORD_CHANGE_GCODE)
|
||||
case 512: M512(); break;
|
||||
#endif // M512: Set/Change/Remove Password
|
||||
#endif
|
||||
|
||||
#if ENABLED(SDSUPPORT)
|
||||
case 524: M524(); break; // M524: Abort the current SD print job
|
||||
#endif
|
||||
|
@ -225,6 +225,9 @@
|
||||
* M502 - Revert to the default "factory settings". ** Does not write them to EEPROM! **
|
||||
* M503 - Print the current settings (in memory): "M503 S<verbose>". S0 specifies compact output.
|
||||
* M504 - Validate EEPROM contents. (Requires EEPROM_SETTINGS)
|
||||
* M510 - Lock Printer
|
||||
* M511 - Unlock Printer
|
||||
* M512 - Set/Change/Remove Password
|
||||
* M524 - Abort the current SD print job started with M24. (Requires SDSUPPORT)
|
||||
* M540 - Enable/disable SD card abort on endstop hit: "M540 S<state>". (Requires SD_ABORT_ON_ENDSTOP_HIT)
|
||||
* M569 - Enable stealthChop on an axis. (Requires at least one _DRIVER_TYPE to be TMC2130/2160/2208/2209/5130/5160)
|
||||
@ -760,6 +763,16 @@ private:
|
||||
#endif
|
||||
TERN_(EEPROM_SETTINGS, static void M504());
|
||||
|
||||
#if ENABLED(PASSWORD_FEATURE)
|
||||
static void M510();
|
||||
#if ENABLED(PASSWORD_UNLOCK_GCODE)
|
||||
static void M511();
|
||||
#endif
|
||||
#if ENABLED(PASSWORD_CHANGE_GCODE)
|
||||
static void M512();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
TERN_(SDSUPPORT, static void M524());
|
||||
|
||||
TERN_(SD_ABORT_ON_ENDSTOP_HIT, static void M540());
|
||||
|
Reference in New Issue
Block a user