Skip to content

Commit

Permalink
Prepare custom filament temperatures
Browse files Browse the repository at this point in the history
  • Loading branch information
bkerler committed Jan 21, 2024
1 parent d1c6b42 commit a53d18d
Show file tree
Hide file tree
Showing 24 changed files with 465 additions and 26 deletions.
1 change: 1 addition & 0 deletions lib/Marlin/Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
#if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
case 701: M701(); break; // M701: Load Filament
case 702: M702(); break; // M702: Unload Filament
case 703: M703(); break; // M703: Set custom filament name
#endif

#if ENABLED(MAX7219_GCODE)
Expand Down
1 change: 1 addition & 0 deletions lib/Marlin/Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ class GcodeSuite {
#if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
static void M701();
static void M702();
static void M703();
#endif

#if ENABLED(GCODE_MACROS)
Expand Down
3 changes: 2 additions & 1 deletion src/common/client_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ class ClientResponses {
#if PRINTER_IS_PRUSA_iX
Response::PETG_NH,
#endif
Response::ASA, Response::ABS, Response::PC, Response::FLEX, Response::HIPS, Response::PP, Response::PVB, Response::PA }, // UserTempSelection
Response::ASA, Response::ABS, Response::PC, Response::FLEX, Response::HIPS, Response::PP, Response::PVB, Response::PA,
Response::CUSTOM_1, Response::CUSTOM_2, Response::CUSTOM_3, Response::CUSTOM_4 }, // UserTempSelection
};
static_assert(std::size(ClientResponses::PreheatResponses) == CountPhases<PhasesPreheat>());

Expand Down
4 changes: 4 additions & 0 deletions src/common/client_response_texts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const std::array<BtnResource, ftrstd::to_underlying(Response::_count)> BtnRespon
std::make_pair( N_("CHANGE"), nullptr ), // Change
std::make_pair( N_("CONTINUE"), &img::resume_48x48 ), // Continue
std::make_pair( N_("COOLDOWN"), nullptr ), // Cooldown
std::make_pair( "CUSTOM_1", &img::spool_58x58 ), // Custom slot 1 filament, do not translate
std::make_pair( "CUSTOM_2", &img::spool_58x58 ), // Custom slot 2 filament, do not translate
std::make_pair( "CUSTOM_3", &img::spool_58x58 ), // Custom slot 3 filament, do not translate
std::make_pair( "CUSTOM_4", &img::spool_58x58 ), // Custom slot 4 filament, do not translate
std::make_pair( N_("DISABLE"), nullptr ), // Disable
std::make_pair( N_("FILAMENT"), nullptr ), // Filament
std::make_pair( N_("FILAMENT REMOVED"), nullptr ), // Filament_removed
Expand Down
46 changes: 46 additions & 0 deletions src/common/filament.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ const filament::Description filaments[size_t(filament::Type::_last) + 1] = {
#endif
};

filament::Description custom_filaments[4] = {
{ BtnResponse::GetText(Response::CUSTOM_1), 215, 170, 60, Response::CUSTOM_1 },
{ BtnResponse::GetText(Response::CUSTOM_2), 215, 170, 60, Response::CUSTOM_2 },
{ BtnResponse::GetText(Response::CUSTOM_3), 215, 170, 60, Response::CUSTOM_3 },
{ BtnResponse::GetText(Response::CUSTOM_4), 215, 170, 60, Response::CUSTOM_4 }
};

static_assert(sizeof(filaments) / sizeof(filaments[0]) == size_t(filament::Type::_last) + 1, "Filament count error.");

filament::Type filament::get_type(const char *name, size_t name_len) {
Expand All @@ -42,6 +49,11 @@ filament::Type filament::get_type(const char *name, size_t name_len) {
return static_cast<filament::Type>(i);
}
}
for (size_t i = 0; i <= size_t(custom_filaments); ++i) {
if ((strlen(custom_filaments[i].name) == name_len) && (!strncmp(name, custom_filaments[i].name, name_len))) {
return static_cast<filament::Type>(size_t(filament::Type::_last) + 1 + i);
}
}
return filament::Type::NONE;
}

Expand All @@ -51,10 +63,44 @@ filament::Type filament::get_type(Response resp) {
return static_cast<filament::Type>(i);
}
}
for (size_t i = 0; i <= size_t(custom_filaments); ++i) {
if (custom_filaments[i].response == resp) {
return static_cast<filament::Type>(size_t(filament::Type::_last) + 1 + i);
}
}
return filament::Type::NONE;
}

const filament::Description &filament::get_description(filament::Type filament) {
if (filament == filament::Type::CUSTOM_1) {
custom_filaments[0].name = config_store().filament_name_1.get_c_str();
custom_filaments[0].nozzle = config_store().filament_nozzle_temp_1.get();
custom_filaments[0].nozzle_preheat = config_store().filament_nozzle_preheat_temp_1.get();
custom_filaments[0].heatbed = config_store().filament_heatbed_temp_1.get();
const filament::Description &filamentsetting = custom_filaments[0];
return filamentsetting;
} else if (filament == filament::Type::CUSTOM_2) {
custom_filaments[1].name = config_store().filament_name_2.get_c_str();
custom_filaments[1].nozzle = config_store().filament_nozzle_temp_2.get();
custom_filaments[1].nozzle_preheat = config_store().filament_nozzle_preheat_temp_2.get();
custom_filaments[1].heatbed = config_store().filament_heatbed_temp_2.get();
const filament::Description &filamentsetting = custom_filaments[1];
return filamentsetting;
} else if (filament == filament::Type::CUSTOM_3) {
custom_filaments[2].name = config_store().filament_name_3.get_c_str();
custom_filaments[2].nozzle = config_store().filament_nozzle_temp_3.get();
custom_filaments[2].nozzle_preheat = config_store().filament_nozzle_preheat_temp_3.get();
custom_filaments[2].heatbed = config_store().filament_heatbed_temp_3.get();
const filament::Description &filamentsetting = custom_filaments[2];
return filamentsetting;
} else if (filament == filament::Type::CUSTOM_4) {
custom_filaments[3].name = config_store().filament_name_4.get_c_str();
custom_filaments[3].nozzle = config_store().filament_nozzle_temp_4.get();
custom_filaments[3].nozzle_preheat = config_store().filament_nozzle_preheat_temp_4.get();
custom_filaments[3].heatbed = config_store().filament_heatbed_temp_4.get();
const filament::Description &filamentsetting = custom_filaments[3];
return filamentsetting;
}
return filaments[size_t(filament)];
}

Expand Down
4 changes: 4 additions & 0 deletions src/common/filament.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ enum class Type : uint8_t {
PP,
FLEX,
PA,
CUSTOM_1,
CUSTOM_2,
CUSTOM_3,
CUSTOM_4,
_last = PA
};

Expand Down
3 changes: 1 addition & 2 deletions src/common/gcode/gcode_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @date 2021-03-25
*/
#pragma once

#include "guitypes.hpp"
#include "i18n.h"
#include "marlin_stubs/PrusaGcodeSuite.hpp"
Expand Down Expand Up @@ -76,7 +75,7 @@ class GCodeInfo {
#endif /*PRINTER_IS*/

using time_buff = std::array<char, 16>;
using filament_buff = std::array<char, 8>;
using filament_buff = std::array<char, config_store_ns::max_filament_name_size>;

struct ExtruderInfo {
struct Colour {
Expand Down
4 changes: 4 additions & 0 deletions src/common/general_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ enum class Response : uint8_t {
Change,
Continue,
Cooldown,
CUSTOM_1,
CUSTOM_2,
CUSTOM_3,
CUSTOM_4,
Disable,
Filament,
Filament_removed,
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ endif()
target_sources(
firmware
PRIVATE box_unfinished_selftest.cpp
custom_filament_tools.cpp
file_sort.cpp
fonts.cpp
gcode_description.cpp
Expand Down Expand Up @@ -47,6 +48,7 @@ target_sources(
screen_menu_cancel_object.cpp
screen_menu_connect.cpp
screen_menu_control.cpp
screen_menu_custom_filament.cpp
screen_menu_eeprom.cpp
screen_menu_eeprom_diagnostics.cpp
screen_menu_error_test.cpp
Expand Down
9 changes: 9 additions & 0 deletions src/gui/MItem_menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "screen_menu_factory_reset.hpp"
#include "screen_menu_error_test.hpp"
#include "screen_menu_input_shaper.hpp"
#include "screen_menu_custom_filament.hpp"

#include <printers.h>

Expand Down Expand Up @@ -631,3 +632,11 @@ MI_INPUT_SHAPER::MI_INPUT_SHAPER()
void MI_INPUT_SHAPER::click(IWindowMenu & /*window_menu*/) {
Screens::Access()->Open(ScreenFactory::Screen<ScreenMenuInputShaper>);
}

MI_CUSTOM_FILAMENT::MI_CUSTOM_FILAMENT()
: WI_LABEL_t(_(label), nullptr, is_enabled_t::yes, is_hidden_t::no, expands_t::yes) {
}

void MI_CUSTOM_FILAMENT::click(IWindowMenu & /*window_menu*/) {
Screens::Access()->Open(ScreenFactory::Screen<ScreenMenuCustomFilament>);
}
10 changes: 10 additions & 0 deletions src/gui/MItem_menus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,13 @@ class MI_INPUT_SHAPER : public WI_LABEL_t {
protected:
virtual void click(IWindowMenu &windowMenu) override;
};

class MI_CUSTOM_FILAMENT : public WI_LABEL_t {
constexpr static const char *label = N_("Custom Filament");

public:
MI_CUSTOM_FILAMENT();

protected:
virtual void click(IWindowMenu &windowMenu) override;
};
39 changes: 39 additions & 0 deletions src/gui/MItem_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "config.h"
#include "menu_spin_config.hpp"
#include "time_tools.hpp"
#include "custom_filament_tools.hpp"
#include "footer_eeprom.hpp"
#include "version.h"
#include "../../common/PersistentStorage.h"
Expand Down Expand Up @@ -969,3 +970,41 @@ MI_IS_CALIB::MI_IS_CALIB()
void MI_IS_CALIB::click([[maybe_unused]] IWindowMenu &window_menu) {
// TODO(InputShaper)
}

/*****************************************************************************/
// MI_CUSTOM_FILAMENT_SLOT
/*****************************************************************************/
MI_CUSTOM_FILAMENT_SLOT::MI_CUSTOM_FILAMENT_SLOT()
: WI_SWITCH_t<4>(static_cast<uint8_t>(custom_filament_tools::GetCurrentSlot()), _(label), nullptr, is_enabled_t::yes, is_hidden_t::no, _(custom_filament_tools::GetSlotName(0)), _(custom_filament_tools::GetSlotName(1)), _(custom_filament_tools::GetSlotName(2)), _(custom_filament_tools::GetSlotName(3))) {}

void MI_CUSTOM_FILAMENT_SLOT::OnChange([[maybe_unused]] size_t old_index) {
custom_filament_tools::SetCurrentSlot((int8_t)index);
Screens::Access()->WindowEvent(GUI_event_t::CHILD_CLICK, (void *)&index);
}

/*****************************************************************************/
// MI_CUSTOM_FILAMENT_NOZZLE_TEMP
MI_CUSTOM_FILAMENT_NOZZLE_TEMP::MI_CUSTOM_FILAMENT_NOZZLE_TEMP()
: WiSpinInt(custom_filament_tools::GetSlotTemp(custom_filament_tools::custom_filament_setting::nozzle_temp), SpinCnf::nozzle, _(label), nullptr, is_enabled_t::yes, is_hidden_t::no) {}
void MI_CUSTOM_FILAMENT_NOZZLE_TEMP::OnClick() {
int16_t nozzle_temp = GetVal();
custom_filament_tools::SetSlotTemp(custom_filament_tools::custom_filament_setting::nozzle_temp, nozzle_temp);
}

/*****************************************************************************/
// MI_CUSTOM_FILAMENT_NOZZLE_PREHEAT_TEMP
MI_CUSTOM_FILAMENT_NOZZLE_PREHEAT_TEMP::MI_CUSTOM_FILAMENT_NOZZLE_PREHEAT_TEMP()
: WiSpinInt(custom_filament_tools::GetSlotTemp(custom_filament_tools::custom_filament_setting::nozzle_preheat_temp), SpinCnf::nozzle, _(label), nullptr, is_enabled_t::yes, is_hidden_t::no) {}
void MI_CUSTOM_FILAMENT_NOZZLE_PREHEAT_TEMP::OnClick() {
int16_t nozzle_preheat_temp = GetVal();
custom_filament_tools::SetSlotTemp(custom_filament_tools::custom_filament_setting::nozzle_preheat_temp, nozzle_preheat_temp);
}

/*****************************************************************************/
// MI_CUSTOM_FILAMENT_HEATBED_TEMP
MI_CUSTOM_FILAMENT_HEATBED_TEMP::MI_CUSTOM_FILAMENT_HEATBED_TEMP()
: WiSpinInt(custom_filament_tools::GetSlotTemp(custom_filament_tools::custom_filament_setting::heatbed_temp), SpinCnf::bed, _(label), nullptr, is_enabled_t::yes, is_hidden_t::no) {}
void MI_CUSTOM_FILAMENT_HEATBED_TEMP::OnClick() {
int16_t heatbed_temp = GetVal();
custom_filament_tools::SetSlotTemp(custom_filament_tools::custom_filament_setting::heatbed_temp, heatbed_temp);
}
32 changes: 32 additions & 0 deletions src/gui/MItem_tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,35 @@ class MI_SET_READY : public WI_LABEL_t {
protected:
virtual void click(IWindowMenu &window_menu) override;
};

class MI_CUSTOM_FILAMENT_SLOT : public WI_SWITCH_t<4> {
constexpr static const char *const label = N_("Filament Slot");

public:
MI_CUSTOM_FILAMENT_SLOT();
virtual void OnChange(size_t old_index) override;
};

class MI_CUSTOM_FILAMENT_NOZZLE_TEMP : public WiSpinInt {
constexpr static const char *const label = N_("Nozzle Temperature");

public:
MI_CUSTOM_FILAMENT_NOZZLE_TEMP();
virtual void OnClick() override;
};

class MI_CUSTOM_FILAMENT_NOZZLE_PREHEAT_TEMP : public WiSpinInt {
constexpr static const char *const label = N_("Nozzle Preheat Temperature");

public:
MI_CUSTOM_FILAMENT_NOZZLE_PREHEAT_TEMP();
virtual void OnClick() override;
};

class MI_CUSTOM_FILAMENT_HEATBED_TEMP : public WiSpinInt {
constexpr static const char *const label = N_("Heatbed Temperature");

public:
MI_CUSTOM_FILAMENT_HEATBED_TEMP();
virtual void OnClick() override;
};
Loading

0 comments on commit a53d18d

Please sign in to comment.