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

Add configuration option to disable spoolman integration #61

Open
wants to merge 1 commit into
base: main
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
7 changes: 7 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void Config::init(std::string config_path) {
};

json cooldown_conf = {{ "cooldown", "SET_HEATER_TEMPERATURE HEATER=extruder TARGET=0\nSET_HEATER_TEMPERATURE HEATER=heater_bed TARGET=0"}};

json default_macros_conf = {
{"load_filament", "LOAD_MATERIAL"},
{"unload_filament", "QUIT_MATERIAL"}
Expand All @@ -82,6 +83,7 @@ void Config::init(std::string config_path) {
{"monitored_sensors", sensors_conf},
{"fans", fans_conf},
{"default_macros", default_macros_conf},
{"disable_spoolman", false}
}
}}
}
Expand Down Expand Up @@ -112,6 +114,11 @@ void Config::init(std::string config_path) {
}
}

auto &disable_spoolman = data[json::json_pointer(df() + "disable_spoolman")];
if (disable_spoolman.is_null()) {
data[json::json_pointer(df() + "disable_spoolman")] = false;
}

auto &guppy_init = data["/guppy_init_script"_json_pointer];
if (guppy_init.is_null()) {
data["/guppy_init_script"_json_pointer] = "/etc/init.d/S99guppyscreen";
Expand Down
32 changes: 21 additions & 11 deletions src/init_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,28 @@ void InitPanel::connected(KWebSocketClient &ws) {
this->main_panel.subscribe();

// spoolman
ws.send_jsonrpc("server.info", [this](json &j) {
spdlog::debug("server_info {}", j.dump());
State::get_instance()->set_data("server_info", j, "/result");

auto &components = j["/result/components"_json_pointer];
if (!components.is_null()) {
const auto &has_spoolman = components.template get<std::vector<std::string>>();
if (std::find(has_spoolman.begin(), has_spoolman.end(), "spoolman") != has_spoolman.end()) {
this->main_panel.enable_spoolman();
}
Config *conf = Config::get_instance();
auto v = conf->get_json(conf->df() + "disable_spoolman");
auto disable_spoolman = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 74 to 79 can be replaced with auto disable_spoolman = !v.is_null() && v.template get<bool>();

Copy link
Author

@adec adec Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better than my code… which is why I should stick to architecture (boxes and fluffy clouds). 🤣 I'll update my pull request.

if (!v.is_null()) {
if (v.template get<bool>()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be disable_spoolman = v.template get<bool>() because even if he attribute exists, it can be either true/false.

disable_spoolman = true;
}
});
}
if (!disable_spoolman) {
ws.send_jsonrpc("server.info", [this](json &j) {
spdlog::debug("server_info {}", j.dump());
State::get_instance()->set_data("server_info", j, "/result");

auto &components = j["/result/components"_json_pointer];
if (!components.is_null()) {
const auto &has_spoolman = components.template get<std::vector<std::string>>();
if (std::find(has_spoolman.begin(), has_spoolman.end(), "spoolman") != has_spoolman.end()) {
this->main_panel.enable_spoolman();
}
}
});
}

auto display_sensors = state->get_display_sensors();
this->main_panel.create_sensors(display_sensors);
Expand Down