FIX: the humidity display

jira: [STUDIO-10481]
Change-Id: Ib4bec6db6afbe40199c401c539b13a0e8459bbad
(cherry picked from commit 658a8ab7ef1d2149fee58b45ea9455bb188f82f0)
This commit is contained in:
xin.zhang
2025-02-18 10:53:09 +08:00
committed by Noisyfox
parent 795945376c
commit 8f143a1764
15 changed files with 126 additions and 31 deletions

View File

@@ -590,7 +590,6 @@ MachineObject::MachineObject(NetworkAgent* agent, std::string name, std::string
ams_insert_flag = false;
ams_power_on_flag = false;
ams_calibrate_remain_flag = false;
ams_humidity = 5;
/* signals */
wifi_signal = "";
@@ -3961,16 +3960,6 @@ int MachineObject::parse_json(std::string payload, bool key_field_only)
}
if (jj["ams"].contains("ams_rfid_status"))
ams_rfid_status = jj["ams"]["ams_rfid_status"].get<int>();
if (jj["ams"].contains("humidity")) {
if (jj["ams"]["humidity"].is_string()) {
std::string humidity_str = jj["ams"]["humidity"].get<std::string>();
try {
ams_humidity = atoi(humidity_str.c_str());
} catch (...) {
;
}
}
}
if (jj["ams"].contains("insert_flag") || jj["ams"].contains("power_on_flag")
|| jj["ams"].contains("calibrate_remain_flag")) {
@@ -4053,7 +4042,17 @@ int MachineObject::parse_json(std::string payload, bool key_field_only)
;
}
}
if (it->contains("humidity_raw"))
{
std::string humidity_raw = (*it)["humidity_raw"].get<std::string>();
try {
curr_ams->humidity_raw = atoi(humidity_raw.c_str());
} catch (...) {
;
}
}
if (it->contains("tray")) {
std::set<std::string> tray_id_set;

View File

@@ -274,6 +274,7 @@ public:
}
std::string id;
int humidity = 5;
int humidity_raw = -1;// the percentage, -1 means invalid. eg. 100 means 100%
bool startup_read_opt{true};
bool tray_read_opt{false};
bool is_exists{false};
@@ -538,7 +539,6 @@ public:
bool ams_auto_switch_filament_flag { false };
bool ams_air_print_status { false };
bool ams_support_virtual_tray { true };
int ams_humidity;
int ams_user_setting_hold_count = 0;
AmsStatusMain ams_status_main;
int ams_status_sub;

View File

@@ -782,6 +782,7 @@ void AMSControl::msw_rescale()
m_button_guide->SetMinSize(wxSize(-1, FromDIP(24)));
m_button_retry->SetMinSize(wxSize(-1, FromDIP(24)));
m_vams_lib->msw_rescale();
m_vams_road->msw_rescale();
for (auto i = 0; i < m_ams_cans_list.GetCount(); i++) {
AmsCansWindow *cans = m_ams_cans_list[i];

View File

@@ -44,12 +44,14 @@ bool AMSinfo::parse_ams_info(MachineObject *obj, Ams *ams, bool remain_flag, boo
if (humidity_flag) {
this->ams_humidity = ams->humidity;
}
else {
else{
this->ams_humidity = -1;
}
this->humidity_raw = ams->humidity_raw;
cans.clear();
for (int i = 0; i < 4; i++) {
for (int i = 0; i < ams->trayList.size(); i++) {
auto it = ams->trayList.find(std::to_string(i));
Caninfo info;
// tray is exists
@@ -74,7 +76,7 @@ bool AMSinfo::parse_ams_info(MachineObject *obj, Ams *ams, bool remain_flag, boo
} else {
info.material_state = AMSCanType::AMS_CAN_TYPE_THIRDBRAND;
}
if (!MachineObject::is_bbl_filament(it->second->tag_uid) || !remain_flag) {
info.material_remain = 100;
} else {
@@ -1402,13 +1404,11 @@ AMSRoad::AMSRoad(wxWindow *parent, wxWindowID id, Caninfo info, int canindex, in
m_rode_mode = AMSRoadMode::AMS_ROAD_MODE_NONE_ANY_ROAD;
}
for (int i = 1; i <= 5; i++) {
ams_humidity_img.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_light", 32));
}
for (int i = 1; i <= 5; i++) { ams_humidity_imgs.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_light", 32));}
for (int i = 1; i <= 5; i++) { ams_humidity_dark_imgs.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_dark", 32));}
for (int i = 1; i <= 5; i++) { ams_humidity_no_num_imgs.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_no_num_light", 16)); }
for (int i = 1; i <= 5; i++) { ams_humidity_no_num_dark_imgs.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_no_num_dark", 16)); }
for (int i = 1; i <= 5; i++) {
ams_humidity_img.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_dark", 32));
}
if (m_rode_mode != AMSRoadMode::AMS_ROAD_MODE_VIRTUAL_TRAY) {
create(parent, id, pos, size);
}
@@ -1588,15 +1588,52 @@ void AMSRoad::doRender(wxDC &dc)
if (m_amsinfo.ams_humidity >= 1 && m_amsinfo.ams_humidity <= 5) {m_show_humidity = true;}
else {m_show_humidity = false;}
if (m_amsinfo.ams_humidity >= 1 && m_amsinfo.ams_humidity <= 5) {
if (m_show_humidity) {
wxPoint pot;
if (m_amsinfo.humidity_raw != -1) /*image with no number + percentage*/
{
// hum image
ScalableBitmap hum_img;
if (!wxGetApp().dark_mode()) {
hum_img = ams_humidity_no_num_imgs[m_amsinfo.ams_humidity - 1];
} else {
hum_img = ams_humidity_no_num_dark_imgs[m_amsinfo.ams_humidity - 1];
}
int hum_index = m_amsinfo.ams_humidity - 1;
if (wxGetApp().dark_mode()) {
hum_index += 5;
pot = wxPoint(FromDIP(5), size.y - hum_img.GetBmpSize().y - FromDIP(8));
dc.DrawBitmap(hum_img.bmp(), pot);
// percentage
wxString hum_percentage(std::to_string(m_amsinfo.humidity_raw));
auto tsize = dc.GetMultiLineTextExtent(hum_percentage);
dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
dc.SetFont(Label::Body_14);
dc.SetTextForeground(StateColor::darkModeColorFor(AMS_CONTROL_BLACK_COLOUR));
// pot = wxPoint(FromDIP(size.x * 0.3), FromDIP((size.y - tsize.y) / 2));
pot.x = pot.x + hum_img.GetBmpSize().x + FromDIP(3);
dc.DrawText(hum_percentage, pot);
pot.x += (tsize.x + FromDIP(5));
dc.SetFont(Label::Body_12);
tsize = dc.GetMultiLineTextExtent(_L("%"));
pot.y += (tsize.y / 2 - FromDIP(4));
dc.DrawText(_L("%"), pot);
pot.x = pot.x + tsize.x + FromDIP(2);
}
else /*image with number*/
{
// hum image
ScalableBitmap hum_img;
if (!wxGetApp().dark_mode()) {
hum_img = ams_humidity_imgs[m_amsinfo.ams_humidity - 1];
} else {
hum_img = ams_humidity_dark_imgs[m_amsinfo.ams_humidity - 1];
}
if (hum_index >= 0) {
dc.DrawBitmap(ams_humidity_img[hum_index].bmp(), wxPoint(size.x - FromDIP(33), size.y - FromDIP(33)));
pot = wxPoint(size.x - FromDIP(33), size.y - FromDIP(33));
dc.DrawBitmap(hum_img.bmp(), pot);
pot.x = pot.x + hum_img.GetBmpSize().x + FromDIP(3);
}
}
else {
@@ -1658,6 +1695,14 @@ void AMSRoad::OnPassRoad(std::vector<AMSPassRoadMode> prord_list)
}
}
void AMSRoad::msw_rescale()
{
for (auto& img : ams_humidity_imgs) { img.msw_rescale();}
for (auto& img : ams_humidity_dark_imgs) { img.msw_rescale(); }
for (auto &img : ams_humidity_no_num_imgs) { img.msw_rescale(); }
for (auto &img : ams_humidity_no_num_dark_imgs) { img.msw_rescale(); }
}
/*************************************************
Description:AmsCan
@@ -2191,6 +2236,11 @@ void AmsCans::msw_rescale()
CanLibs* lib = m_can_lib_list[i];
lib->canLib->msw_rescale();
}
for (auto i = 0; i < m_can_road_list.GetCount(); i++) {
CanRoads* road = m_can_road_list[i];
road->canRoad->msw_rescale();
}
}
void AmsCans::show_sn_value(bool show)

View File

@@ -159,6 +159,7 @@ public:
AMSAction current_action;
int curreent_filamentstep;
int ams_humidity = 0;
int humidity_raw = -1;
bool parse_ams_info(MachineObject* obj, Ams *ams, bool remain_flag = false, bool humidity_flag = false);
};
@@ -390,8 +391,11 @@ public:
wxColour m_road_color;
void Update(AMSinfo amsinfo, Caninfo info, int canindex, int maxcan);
std::vector<ScalableBitmap> ams_humidity_img;
std::vector<ScalableBitmap> ams_humidity_imgs;
std::vector<ScalableBitmap> ams_humidity_dark_imgs;
std::vector<ScalableBitmap> ams_humidity_no_num_imgs;
std::vector<ScalableBitmap> ams_humidity_no_num_dark_imgs;
int m_humidity = { 0 };
bool m_show_humidity = { false };
@@ -406,7 +410,8 @@ public:
void paintEvent(wxPaintEvent &evt);
void render(wxDC &dc);
void doRender(wxDC &dc);
void doRender(wxDC& dc);
void msw_rescale();
};
/*************************************************