From a0b421e8757d8176db5dc172588c9b8243f50287 Mon Sep 17 00:00:00 2001 From: Christian Hammacher Date: Mon, 16 Dec 2019 20:28:10 +0100 Subject: Fixed filament functions for usage with SBC --- src/GCodes/GCodes.cpp | 14 ++++++-------- src/GCodes/GCodes2.cpp | 5 +++-- src/Linux/LinuxInterface.cpp | 9 ++++++++- src/Tools/Filament.cpp | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/GCodes/GCodes.cpp b/src/GCodes/GCodes.cpp index 619363a0..7188e1e0 100644 --- a/src/GCodes/GCodes.cpp +++ b/src/GCodes/GCodes.cpp @@ -566,6 +566,12 @@ void GCodes::DoFilePrint(GCodeBuffer& gb, const StringRef& reply) HandleReply(gb, GCodeResult::ok, ""); } } + else if (gb.GetState() == GCodeState::loadingFilament && hadFileError) + { + // Don't perform final filament assignment if the load macro could not be processed + gb.SetState(GCodeState::normal); + HandleReply(gb, GCodeResult::ok, ""); + } else if (gb.GetState() == GCodeState::normal) { UnlockAll(gb); @@ -3505,14 +3511,6 @@ GCodeResult GCodes::LoadFilament(GCodeBuffer& gb, const StringRef& reply) return GCodeResult::error; } -#if HAS_MASS_STORAGE - if (!platform.DirectoryExists(FILAMENTS_DIRECTORY, filamentName.c_str())) - { - reply.copy("Filament configuration directory not found"); - return GCodeResult::error; - } -#endif - if (Filament::IsInUse(filamentName.c_str())) { reply.copy("One filament type can be only assigned to a single tool"); diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp index 3ed98edd..ca2f95e4 100644 --- a/src/GCodes/GCodes2.cpp +++ b/src/GCodes/GCodes2.cpp @@ -3997,10 +3997,11 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) case 703: // Configure Filament if (reprap.GetCurrentTool() != nullptr) { - if (reprap.GetCurrentTool()->GetFilament() != nullptr) + const Filament *filament = reprap.GetCurrentTool()->GetFilament(); + if (filament != nullptr && filament->IsLoaded()) { String scratchString; - scratchString.printf("%s%s/%s", FILAMENTS_DIRECTORY, reprap.GetCurrentTool()->GetFilament()->GetName(), CONFIG_FILAMENT_G); + scratchString.printf("%s%s/%s", FILAMENTS_DIRECTORY, filament->GetName(), CONFIG_FILAMENT_G); DoFileMacro(gb, scratchString.c_str(), false, 703); } } diff --git a/src/Linux/LinuxInterface.cpp b/src/Linux/LinuxInterface.cpp index 3b9f73b7..3535b60c 100644 --- a/src/Linux/LinuxInterface.cpp +++ b/src/Linux/LinuxInterface.cpp @@ -294,7 +294,14 @@ void LinuxInterface::Spin() Filament *filament = Filament::GetFilamentByExtruder(extruder); if (filament != nullptr) { - filament->Load(filamentName.c_str()); + if (filamentName.IsEmpty()) + { + filament->Unload(); + } + else + { + filament->Load(filamentName.c_str()); + } } break; } diff --git a/src/Tools/Filament.cpp b/src/Tools/Filament.cpp index e6321847..2ce3e7b9 100644 --- a/src/Tools/Filament.cpp +++ b/src/Tools/Filament.cpp @@ -42,6 +42,14 @@ void Filament::Unload() noexcept void Filament::LoadAssignment() noexcept { #if HAS_MASS_STORAGE +# if HAS_LINUX_INTERFACE + if (reprap.UsingLinuxInterface()) + { + // Filament configuration is saved on the SBC + return; + } +# endif + FileStore *file = reprap.GetPlatform().OpenSysFile(FilamentAssignmentFile, OpenMode::read); if (file == nullptr) { @@ -81,6 +89,14 @@ void Filament::LoadAssignment() noexcept /*static*/ void Filament::SaveAssignments() noexcept { #if HAS_MASS_STORAGE +# if HAS_LINUX_INTERFACE + if (reprap.UsingLinuxInterface()) + { + // Filament configuration is saved on the SBC + return; + } +# endif + FileStore * const file = reprap.GetPlatform().OpenSysFile(FilamentAssignmentFile, OpenMode::write); if (file == nullptr) { -- cgit v1.2.3