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.

M500-M504.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/settings.h"
  24. #include "../../core/serial.h"
  25. #include "../../inc/MarlinConfig.h"
  26. #if ENABLED(CONFIGURATION_EMBEDDING)
  27. #include "../../sd/SdBaseFile.h"
  28. #include "../../mczip.h"
  29. #endif
  30. /**
  31. * M500: Store settings in EEPROM
  32. */
  33. void GcodeSuite::M500() {
  34. (void)settings.save();
  35. }
  36. /**
  37. * M501: Read settings from EEPROM
  38. */
  39. void GcodeSuite::M501() {
  40. (void)settings.load();
  41. }
  42. /**
  43. * M502: Revert to default settings
  44. */
  45. void GcodeSuite::M502() {
  46. (void)settings.reset();
  47. }
  48. #if DISABLED(DISABLE_M503)
  49. /**
  50. * M503: print settings currently in memory
  51. *
  52. * With CONFIGURATION_EMBEDDING:
  53. * C<flag> : Save the full Marlin configuration to SD Card as "mc.zip"
  54. */
  55. void GcodeSuite::M503() {
  56. (void)settings.report(!parser.boolval('S', true));
  57. #if ENABLED(CONFIGURATION_EMBEDDING)
  58. if (parser.seen_test('C')) {
  59. SdBaseFile file;
  60. const uint16_t size = sizeof(mc_zip);
  61. // Need to create the config size on the SD card
  62. if (file.open("mc.zip", O_WRITE|O_CREAT) && file.write(pgm_read_ptr(mc_zip), size) != -1 && file.close())
  63. SERIAL_ECHO_MSG("Configuration saved as 'mc.zip'");
  64. }
  65. #endif
  66. }
  67. #endif // !DISABLE_M503
  68. #if ENABLED(EEPROM_SETTINGS)
  69. #if ENABLED(MARLIN_DEV_MODE)
  70. #include "../../libs/hex_print.h"
  71. #endif
  72. /**
  73. * M504: Validate EEPROM Contents
  74. */
  75. void GcodeSuite::M504() {
  76. #if ENABLED(MARLIN_DEV_MODE)
  77. const bool dowrite = parser.seenval('W');
  78. if (dowrite || parser.seenval('R')) {
  79. uint8_t val = 0;
  80. int addr = parser.value_ushort();
  81. if (dowrite) {
  82. val = parser.byteval('V');
  83. persistentStore.write_data(addr, &val);
  84. SERIAL_ECHOLNPGM("Wrote address ", addr, " with ", val);
  85. }
  86. else {
  87. if (parser.seenval('T')) {
  88. const int endaddr = parser.value_ushort();
  89. while (addr <= endaddr) {
  90. persistentStore.read_data(addr, &val);
  91. SERIAL_ECHOLNPGM("0x", hex_word(addr), ":", hex_byte(val));
  92. addr++;
  93. safe_delay(10);
  94. }
  95. SERIAL_EOL();
  96. }
  97. else {
  98. persistentStore.read_data(addr, &val);
  99. SERIAL_ECHOLNPGM("Read address ", addr, " and got ", val);
  100. }
  101. }
  102. return;
  103. }
  104. #endif
  105. if (settings.validate())
  106. SERIAL_ECHO_MSG("EEPROM OK");
  107. }
  108. #endif