Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added totally untested persistent z-offset get/set for #3306 #4269

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/common/marlin_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,10 @@ static bool receive_and_process_client_message(marlin_client_t *client, TickType
// not handled events
// do not use default, i want all events listed here, so new event will generate warning, when not added
case Event::MeshUpdate:
case Event::Startup:
case Event::Startup: {
// Set Z Offset on boot as I couldn't find any other place to put it.
set_z_offset(config_store().get_z_offset());
}
case Event::StartProcessing:
case Event::StopProcessing:
case Event::PrinterKilled:
Expand Down
6 changes: 5 additions & 1 deletion src/gui/dialogs/liveadjust_z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "img_resources.hpp"
#include <option/has_sheet_profiles.h>
#include "config_features.h"
#include <config_store/store_instance.hpp>
#include "gui_config_printer.hpp"
#include <guiconfig/guiconfig.h>

Expand Down Expand Up @@ -90,13 +91,16 @@ void WindowLiveAdjustZ::Save() {
/// store new z offset value into a marlin_vars & EEPROM
SteelSheets::SetZOffset(number.GetValue());
#else
// config_store().set_z_offset(number.GetValue());
config_store().set_z_offset(number.GetValue());
marlin_client::set_z_offset(number.GetValue());
#endif
}

void WindowLiveAdjustZ::Change(int dif) {
float old = number.GetValue();
float z_offset = number.GetValue();
// float z_offset = number.GetValue();
float z_offset = config_store().get_z_offset();

z_offset += (float)dif * z_offset_step;
z_offset = dif >= 0 ? std::max(z_offset, old) : std::min(z_offset, old); // check overflow/underflow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

namespace config_store_ns {

// Holds default constants so they can be referenced by store item. Placing these constants in another header where it's more meaningful is welcome. These defaults could be passed directly as template parameter to store items from gcc 11 onwards (and store items would accept them as value instead of as a const ref).
// Holds default constants so they can be referenced by store item.
// Placing these constants in another header where it's more meaningful is welcome.
// These defaults could be passed directly as template parameter to store items from
// gcc 11 onwards (and store items would accept them as value instead of as a const ref).
namespace defaults {
// default values for variables that have distinct requirements
inline constexpr float pid_nozzle_p {
Expand Down Expand Up @@ -238,6 +241,8 @@ namespace defaults {
inline constexpr SelftestResult_pre_gears selftest_result_pre_gears {};
inline constexpr SelftestResult_pre_23 selftest_result_pre_23 {};

inline constexpr float z_offset { 0.0f };

#if (HAS_SHEET_SUPPORT())
static_assert(!HAS_LOADCELL(), "This caused major issues on XL.");
// Sheet[0] is used both as default sheet and as storage for z offset set by LiveAdjust Z. XL have had and issue that caused the tool offset calibration to fail due to aforementioned z offset. Uncalibrated value being float:max caused z offset to be set to 2 mm which lead to printer missing the calibration pin by almost 2 whole mm. This happens to all XLs that do not have a LiveAdjust Z value set and therefore use the default value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,14 @@ void CurrentStore::set_selftest_result_tool(uint8_t index, SelftestTool value) {
}
#endif

void CurrentStore::set_z_offset(float offset) {
z_offset.set(offset);
}

float CurrentStore::get_z_offset() {
return z_offset.get();
}

#if HAS_SHEET_PROFILES()
Sheet CurrentStore::get_sheet(uint8_t index) {
assert(index < config_store_ns::sheets_num);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ struct CurrentStore
StoreItem<float, defaults::loadcell_threshold_continuous, journal::hash("Loadcell Threshold Continuous")> loadcell_threshold_continuous;
#endif

StoreItem<float, 0.0f, journal::hash("Z-Offset")> z_offset;

// filament sensor values:
// ref value: value of filament sensor in moment of calibration (w/o filament present)
// value span: minimal difference of raw values between the two states of the filament sensor
Expand Down Expand Up @@ -387,6 +389,9 @@ struct CurrentStore
SelftestTool get_selftest_result_tool(uint8_t index);
void set_selftest_result_tool(uint8_t index, SelftestTool value);

void set_z_offset(float offset);
float get_z_offset();

#if HAS_SHEET_PROFILES()
StoreItem<uint8_t, 0, journal::hash("Active Sheet")> active_sheet;
StoreItem<Sheet, defaults::sheet_0, journal::hash("Sheet 0")> sheet_0;
Expand Down