Files
OrcaSlicer/src/slic3r/GUI/DeviceCore/DevFilaAmsSetting.h
T
Lam Wei Lun a5210459ee FIX: Show the connected AMS type in the AMS settings dialog (#17159)
The supported AMS firmwares were stored in an unordered_map, so the AMS
type combo listed them in an unspecified order and then selected the
current firmware by treating its id as a combo row. With an AMS Lite
(id 0) the dialog showed "AMS/AMS 2 Pro/AMS HT", and choosing a type
sent the row index as the firmware id, so it could request the opposite
firmware.

Store the firmwares in a std::map, so iteration is ordered by firmware
id and the id stays a valid combo row index.

Fixes #17125
2026-11-02 23:19:33 +08:00

106 lines
3.1 KiB
C++

#pragma once
#include <memory>
#include <optional>
#include <string>
#include <map>
#include <nlohmann/json.hpp>
#include "DevCtrl.h"
namespace Slic3r
{
class DevFilaSystem;
class DevAmsSystemSetting
{
public:
DevAmsSystemSetting(DevFilaSystem* owner) : m_owner(owner) {};
public:
// getters
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; }
// setters
void Reset();
void SetDetectOnInsertEnabled(bool enable) { m_enable_detect_on_insert = enable; }
void SetDetectOnPowerupEnabled(bool enable) { m_enable_detect_on_powerup = enable; }
void SetDetectRemainEnabled(bool enable) { m_enable_detect_remain = enable; }
void SetAutoRefillEnabled(bool enable) { m_enable_auto_refill = enable; }
private:
[[maybe_unused]] DevFilaSystem* m_owner = nullptr;
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; };
// Ordered by firmware id: the AMS type combo lists these in order and uses the id as its row index.
std::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::map<int, DevAmsSystemFirmware> m_firmwares;
DevCtrlInfo m_ctrl_switching;
};
}// namespace Slic3r