ENH: support AMS switching for A series; clean class AMSSetting
jira: [STUDIO-14068] [STUDIO-14330] Change-Id: I6281fbf56f3bf406ef28103998790a2a98c3f5c0 (cherry picked from commit 8ee02ec73076691c482ea6d089a49ea1c99ad10c)
This commit is contained in:
@@ -22,10 +22,12 @@ list(APPEND SLIC3R_GUI_SOURCES
|
||||
GUI/DeviceCore/DevFan.h
|
||||
GUI/DeviceCore/DevFilaAmsSetting.h
|
||||
GUI/DeviceCore/DevFilaAmsSetting.cpp
|
||||
GUI/DeviceCore/DevFilaAmsSettingCtrl.cpp
|
||||
GUI/DeviceCore/DevFilaBlackList.h
|
||||
GUI/DeviceCore/DevFilaBlackList.cpp
|
||||
GUI/DeviceCore/DevFilaSystem.h
|
||||
GUI/DeviceCore/DevFilaSystem.cpp
|
||||
GUI/DeviceCore/DevFilaSystemCtrl.cpp
|
||||
GUI/DeviceCore/DevFirmware.h
|
||||
GUI/DeviceCore/DevFirmware.cpp
|
||||
GUI/DeviceCore/DevPrintOptions.h
|
||||
|
||||
@@ -9,6 +9,53 @@ using namespace nlohmann;
|
||||
|
||||
namespace Slic3r
|
||||
{
|
||||
|
||||
DevCtrlInfo::DevCtrlInfo(MachineObject* obj, int sequence_id, const json& req_json,
|
||||
int interval_max, int interval_min)
|
||||
{
|
||||
m_request_dev_id = obj->get_dev_id();
|
||||
m_request_seq = sequence_id;
|
||||
m_request_time = time(nullptr);
|
||||
m_request_json = req_json;
|
||||
m_request_interval_max = interval_max;
|
||||
m_request_interval_min = interval_min;
|
||||
}
|
||||
|
||||
bool DevCtrlInfo::CheckCanUpdateData(const nlohmann::json& jj)
|
||||
{
|
||||
if (m_request_json.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_time_out) {
|
||||
return true;
|
||||
}
|
||||
if (time(nullptr) - m_request_time > m_request_interval_max) {
|
||||
OnTimeOut();
|
||||
return true;
|
||||
}
|
||||
if (time(nullptr) - m_request_time < m_request_interval_min) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_received) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
if (jj.contains("sequence_id") && jj["sequence_id"].is_string()) {
|
||||
int sequence_id = stoi(jj["sequence_id"].get<std::string>());
|
||||
if (sequence_id >= m_request_seq) {
|
||||
OnReceived();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int DevCtrl::command_select_extruder(int id)
|
||||
{
|
||||
json j;
|
||||
|
||||
@@ -10,6 +10,33 @@ namespace Slic3r
|
||||
//Previous definitions
|
||||
class MachineObject;
|
||||
|
||||
class DevCtrlInfo
|
||||
{
|
||||
public:
|
||||
DevCtrlInfo() {};
|
||||
DevCtrlInfo(MachineObject* obj, int sequence_id, const json& req_json, int interval_max = 3, int interval_min = 0);
|
||||
|
||||
public:
|
||||
bool CheckCanUpdateData(const nlohmann::json& jj);
|
||||
|
||||
private:
|
||||
void OnTimeOut() { m_time_out = true;}
|
||||
void OnReceived() { m_received = true;} ;
|
||||
|
||||
private:
|
||||
bool m_time_out = false;
|
||||
bool m_received = false;
|
||||
|
||||
std::string m_request_dev_id = "";
|
||||
|
||||
time_t m_request_time = 0;
|
||||
int m_request_seq = 0;
|
||||
json m_request_json = json();
|
||||
|
||||
// check
|
||||
int m_request_interval_max = 3;
|
||||
int m_request_interval_min = 0;
|
||||
};
|
||||
|
||||
class DevCtrl
|
||||
{
|
||||
|
||||
@@ -1,13 +1,70 @@
|
||||
#include "DevFilaAmsSetting.h"
|
||||
#include "DevUtil.h"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
void DevAmsSystemSetting::Reset()
|
||||
{
|
||||
SetDetectOnInsertEnabled(false);
|
||||
m_enable_detect_on_insert.reset();
|
||||
SetDetectOnPowerupEnabled(false);
|
||||
SetDetectRemainEnabled(false);
|
||||
SetAutoRefillEnabled(false);
|
||||
}
|
||||
|
||||
void DevAmsSystemFirmwareSwitch::Reset()
|
||||
{
|
||||
m_status.clear();
|
||||
m_current_firmware_run = DevAmsSystemFirmware();
|
||||
m_current_firmware_sel = DevAmsSystemFirmware();
|
||||
m_firmwares.clear();
|
||||
}
|
||||
|
||||
void DevAmsSystemFirmwareSwitch::ParseFirmwareSwitch(const nlohmann::json& j)
|
||||
{
|
||||
if (!m_ctrl_switching.CheckCanUpdateData(j.contains("upgrade") ? j["upgrade"] :j)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (j.contains("print")) {
|
||||
const auto& print_jj = j["print"];
|
||||
if (print_jj.contains("upgrade_state")) {
|
||||
const auto& upgrade_jj = print_jj["upgrade_state"];
|
||||
if (upgrade_jj.contains("mc_for_ams_firmware")) {
|
||||
const auto& mc_for_ams_firmware_jj = upgrade_jj["mc_for_ams_firmware"];
|
||||
if (mc_for_ams_firmware_jj.contains("firmware")) {
|
||||
m_firmwares.clear();
|
||||
const auto& firmwares = mc_for_ams_firmware_jj["firmware"];
|
||||
for (auto item : firmwares) {
|
||||
DevAmsSystemFirmware firmware;
|
||||
DevJsonValParser::ParseVal(item, "id", firmware.m_firmare_idx);
|
||||
DevJsonValParser::ParseVal(item, "name", firmware.m_name);
|
||||
DevJsonValParser::ParseVal(item, "version", firmware.m_version);
|
||||
m_firmwares[firmware.m_firmare_idx] = firmware;
|
||||
}
|
||||
}
|
||||
|
||||
if (mc_for_ams_firmware_jj.contains("current_firmware_id")) {
|
||||
int idx = DevJsonValParser::GetVal(mc_for_ams_firmware_jj, "current_firmware_id", -1);
|
||||
if (m_firmwares.count(idx) != 0) {
|
||||
m_current_firmware_sel = m_firmwares[idx];
|
||||
} else {
|
||||
m_current_firmware_sel = DevAmsSystemFirmware();
|
||||
}
|
||||
}
|
||||
|
||||
if (mc_for_ams_firmware_jj.contains("current_run_firmware_id")) {
|
||||
auto idx = DevJsonValParser::GetVal(mc_for_ams_firmware_jj, "current_run_firmware_id", IDX_DC);
|
||||
if (m_firmwares.count(idx) != 0) {
|
||||
m_current_firmware_run = m_firmwares[idx];
|
||||
} else {
|
||||
m_current_firmware_run = DevAmsSystemFirmware();
|
||||
}
|
||||
}
|
||||
|
||||
DevJsonValParser::ParseVal(mc_for_ams_firmware_jj, "status", m_status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "DevCtrl.h"
|
||||
|
||||
namespace Slic3r
|
||||
{
|
||||
@@ -11,7 +13,7 @@ public:
|
||||
|
||||
public:
|
||||
// getters
|
||||
bool IsDetectOnInsertEnabled() const { return m_enable_detect_on_insert; };
|
||||
std::optional<bool> IsDetectOnInsertEnabled() const { return m_enable_detect_on_insert; };
|
||||
bool IsDetectOnPowerupEnabled() const { return m_enable_detect_on_powerup; }
|
||||
bool IsDetectRemainEnabled() const { return m_enable_detect_remain; }
|
||||
bool IsAutoRefillEnabled() const { return m_enable_auto_refill; }
|
||||
@@ -26,10 +28,74 @@ public:
|
||||
private:
|
||||
DevFilaSystem* m_owner = nullptr;
|
||||
|
||||
bool m_enable_detect_on_insert = false;
|
||||
std::optional<bool> m_enable_detect_on_insert = false;
|
||||
bool m_enable_detect_on_powerup = false;
|
||||
bool m_enable_detect_remain = false;
|
||||
bool m_enable_auto_refill = false;
|
||||
};
|
||||
|
||||
class DevAmsSystemFirmwareSwitch
|
||||
{
|
||||
public:
|
||||
enum DevAmsSystemIdx : int
|
||||
{
|
||||
IDX_DC = -1,
|
||||
IDX_LITE = 0,
|
||||
IDX_AMS_AMS2_AMSHT = 1,
|
||||
};
|
||||
|
||||
struct DevAmsSystemFirmware
|
||||
{
|
||||
DevAmsSystemIdx m_firmare_idx = IDX_DC;
|
||||
std::string m_name;
|
||||
std::string m_version;
|
||||
|
||||
public:
|
||||
bool operator==(const DevAmsSystemFirmware& o) const
|
||||
{
|
||||
return (m_firmare_idx == o.m_firmare_idx) &&
|
||||
(m_name == o.m_name) &&
|
||||
(m_version == o.m_version);
|
||||
};
|
||||
};
|
||||
|
||||
public:
|
||||
static std::shared_ptr<DevAmsSystemFirmwareSwitch> Create(DevFilaSystem* owner)
|
||||
{
|
||||
return std::shared_ptr<DevAmsSystemFirmwareSwitch>(new DevAmsSystemFirmwareSwitch(owner));
|
||||
};
|
||||
|
||||
protected:
|
||||
DevAmsSystemFirmwareSwitch(DevFilaSystem* owner) : m_owner(owner) {};
|
||||
|
||||
public:
|
||||
DevFilaSystem* GetFilaSystem() const { return m_owner; };
|
||||
bool SupportSwitchFirmware() const { return !m_firmwares.empty();};
|
||||
|
||||
DevAmsSystemIdx GetCurrentFirmwareIdxSel() const { return m_current_firmware_sel.m_firmare_idx; };
|
||||
DevAmsSystemIdx GetCurrentFirmwareIdxRun() const { return m_current_firmware_run.m_firmare_idx; };
|
||||
std::unordered_map<int, DevAmsSystemFirmware> GetSuppotedFirmwares() const { return m_firmwares;};
|
||||
|
||||
bool IsSwitching() const { return m_status == "SWITCHING";};
|
||||
bool IsIdle() const { return m_status == "IDLE";};
|
||||
|
||||
// commands
|
||||
int CrtlSwitchFirmware(int firmware_idx);
|
||||
|
||||
// setters
|
||||
void Reset();
|
||||
void ParseFirmwareSwitch(const nlohmann::json& j);
|
||||
|
||||
private:
|
||||
DevFilaSystem* m_owner = nullptr;
|
||||
|
||||
std::string m_status;
|
||||
|
||||
DevAmsSystemFirmware m_current_firmware_run;
|
||||
DevAmsSystemFirmware m_current_firmware_sel;
|
||||
std::unordered_map<int, DevAmsSystemFirmware> m_firmwares;
|
||||
|
||||
DevCtrlInfo m_ctrl_switching;
|
||||
};
|
||||
|
||||
}// namespace Slic3r
|
||||
29
src/slic3r/GUI/DeviceCore/DevFilaAmsSettingCtrl.cpp
Normal file
29
src/slic3r/GUI/DeviceCore/DevFilaAmsSettingCtrl.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "DevFilaAmsSetting.h"
|
||||
#include "DevFilaSystem.h"
|
||||
|
||||
#include "slic3r/GUI/DeviceManager.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
int DevAmsSystemFirmwareSwitch::CrtlSwitchFirmware(int firmware_idx)
|
||||
{
|
||||
if (!m_owner) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
MachineObject* obj_ = m_owner->GetOwner();
|
||||
|
||||
json command_json;
|
||||
command_json["upgrade"]["command"] = "mc_for_ams_firmware_upgrade";
|
||||
command_json["upgrade"]["sequence_id"] = std::to_string(obj_->m_sequence_id++);
|
||||
command_json["upgrade"]["src_id"] = 1;// 1-Studio
|
||||
command_json["upgrade"]["id"] = firmware_idx;
|
||||
|
||||
int rtn = obj_->publish_json(command_json);
|
||||
if (rtn == 0) {
|
||||
m_status = "SWITCHING";
|
||||
m_ctrl_switching = DevCtrlInfo(obj_, obj_->m_sequence_id - 1, command_json, 3, 1);
|
||||
}
|
||||
|
||||
return rtn;
|
||||
};
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "DevFilaAmsSetting.h"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <wx/string.h>
|
||||
#include <wx/colour.h>
|
||||
|
||||
@@ -150,6 +151,8 @@ public:
|
||||
~DevFilaSystem();
|
||||
|
||||
public:
|
||||
MachineObject* GetOwner() const { return m_owner; }
|
||||
|
||||
bool HasAms() const { return !amsList.empty(); }
|
||||
bool IsAmsSettingUp() const;
|
||||
|
||||
@@ -167,10 +170,16 @@ public:
|
||||
|
||||
/* AMS settings*/
|
||||
DevAmsSystemSetting& GetAmsSystemSetting() { return m_ams_system_setting; }
|
||||
bool IsDetectOnInsertEnabled() const { return m_ams_system_setting.IsDetectOnInsertEnabled(); };
|
||||
std::optional<bool> IsDetectOnInsertEnabled() const { return m_ams_system_setting.IsDetectOnInsertEnabled(); };
|
||||
bool IsDetectOnPowerupEnabled() const { return m_ams_system_setting.IsDetectOnPowerupEnabled(); }
|
||||
bool IsDetectRemainEnabled() const { return m_ams_system_setting.IsDetectRemainEnabled(); }
|
||||
bool IsAutoRefillEnabled() const { return m_ams_system_setting.IsAutoRefillEnabled(); }
|
||||
|
||||
std::weak_ptr<DevAmsSystemFirmwareSwitch> GetAmsFirmwareSwitch() const { return m_ams_firmware_switch;}
|
||||
|
||||
public:
|
||||
// ctrls
|
||||
int CtrlAmsReset() const;
|
||||
|
||||
public:
|
||||
static bool IsBBL_Filament(std::string tag_uid);
|
||||
@@ -184,6 +193,7 @@ private:
|
||||
std::map<std::string, DevAms*> amsList; // key: ams[id], start with 0
|
||||
|
||||
DevAmsSystemSetting m_ams_system_setting{ this };
|
||||
std::shared_ptr<DevAmsSystemFirmwareSwitch> m_ams_firmware_switch = DevAmsSystemFirmwareSwitch::Create(this);
|
||||
};// class DevFilaSystem
|
||||
|
||||
|
||||
|
||||
19
src/slic3r/GUI/DeviceCore/DevFilaSystemCtrl.cpp
Normal file
19
src/slic3r/GUI/DeviceCore/DevFilaSystemCtrl.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "DevFilaSystem.h"
|
||||
|
||||
#include "slic3r/GUI/DeviceManager.hpp"// TODO: remove this include
|
||||
#include "DevUtil.h"
|
||||
|
||||
using namespace nlohmann;
|
||||
namespace Slic3r
|
||||
{
|
||||
|
||||
int DevFilaSystem::CtrlAmsReset() const
|
||||
{
|
||||
json jj_command;
|
||||
jj_command["print"]["command"] = "ams_reset";
|
||||
jj_command["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
|
||||
return m_owner->publish_json(jj_command);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user