2314234
This commit is contained in:
165
src/main.cpp
165
src/main.cpp
@@ -106,6 +106,9 @@ struct UiRefs
|
||||
lv_obj_t *mode_label = nullptr;
|
||||
lv_obj_t *weight_note_label = nullptr;
|
||||
lv_obj_t *weight_raw_value = nullptr;
|
||||
lv_obj_t *workflow_batch_ta = nullptr;
|
||||
lv_obj_t *workflow_stock_name_label = nullptr;
|
||||
lv_obj_t *workflow_stock_meta_label = nullptr;
|
||||
|
||||
lv_obj_t *cal_offset_value = nullptr;
|
||||
lv_obj_t *cal_scale_value = nullptr;
|
||||
@@ -159,6 +162,10 @@ constexpr size_t pageIndex(PageId page)
|
||||
return static_cast<size_t>(page);
|
||||
}
|
||||
|
||||
void clearInventreeMatches();
|
||||
void findInventreeStockByBatch();
|
||||
void updateInventreeLabels();
|
||||
|
||||
void setLabelTextIfChanged(lv_obj_t *label, const char *text)
|
||||
{
|
||||
if (label == nullptr || text == nullptr)
|
||||
@@ -204,6 +211,7 @@ void setWifiNote(const char *text)
|
||||
void setInventreeNote(const char *text)
|
||||
{
|
||||
setLabelTextIfChanged(ui.inventree_note_label, text);
|
||||
setLabelTextIfChanged(ui.weight_note_label, text);
|
||||
}
|
||||
|
||||
void hideKeyboard()
|
||||
@@ -235,6 +243,37 @@ void applyTextEditorChanges()
|
||||
}
|
||||
|
||||
lv_textarea_set_text(ui.text_editor_target, lv_textarea_get_text(ui.text_editor_ta));
|
||||
|
||||
if (ui.text_editor_target == ui.workflow_batch_ta || ui.text_editor_target == ui.inventree_batch_ta)
|
||||
{
|
||||
const char *batch_text = lv_textarea_get_text(ui.text_editor_target);
|
||||
|
||||
if (ui.workflow_batch_ta != nullptr && ui.text_editor_target != ui.workflow_batch_ta)
|
||||
{
|
||||
lv_textarea_set_text(ui.workflow_batch_ta, batch_text);
|
||||
}
|
||||
|
||||
if (ui.inventree_batch_ta != nullptr && ui.text_editor_target != ui.inventree_batch_ta)
|
||||
{
|
||||
lv_textarea_set_text(ui.inventree_batch_ta, batch_text);
|
||||
}
|
||||
|
||||
inventree_data.batch = batch_text;
|
||||
inventree_data.batch.trim();
|
||||
clearInventreeMatches();
|
||||
|
||||
if (inventree_data.batch.isEmpty())
|
||||
{
|
||||
inventree_data.status_text = "Batch empty";
|
||||
inventree_data.result_text = "Enter Batch Code to find the stock item.";
|
||||
setInventreeNote("Enter Batch Code, then confirm input to load the stock item.");
|
||||
updateInventreeLabels();
|
||||
}
|
||||
else
|
||||
{
|
||||
findInventreeStockByBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void openTextEditor(lv_obj_t *target, const char *title)
|
||||
@@ -455,7 +494,7 @@ void refreshUi()
|
||||
const int32_t stable_grams = applyWeightHysteresis(grams);
|
||||
setLabelLongText(ui.weight_label, "%ld", static_cast<long>(stable_grams));
|
||||
setLabelTextIfChanged(ui.weight_unit_label, "g");
|
||||
setLabelTextIfChanged(ui.mode_label, "Main scale view, filtered 1 g");
|
||||
setLabelTextIfChanged(ui.mode_label, "Filtered weight, ready for Batch workflow");
|
||||
setWeightStatus("LIVE", lv_color_hex(0x1E7A55));
|
||||
}
|
||||
else
|
||||
@@ -812,11 +851,35 @@ void syncInventreeInputs(bool persist)
|
||||
: inventree_data.token;
|
||||
inventree_data.token.trim();
|
||||
|
||||
inventree_data.batch = ui.inventree_batch_ta != nullptr
|
||||
? String(lv_textarea_get_text(ui.inventree_batch_ta))
|
||||
lv_obj_t *batch_input = nullptr;
|
||||
if (active_page == PageId::Weight && ui.workflow_batch_ta != nullptr)
|
||||
{
|
||||
batch_input = ui.workflow_batch_ta;
|
||||
}
|
||||
else if (ui.inventree_batch_ta != nullptr)
|
||||
{
|
||||
batch_input = ui.inventree_batch_ta;
|
||||
}
|
||||
else
|
||||
{
|
||||
batch_input = ui.workflow_batch_ta;
|
||||
}
|
||||
|
||||
inventree_data.batch = batch_input != nullptr
|
||||
? String(lv_textarea_get_text(batch_input))
|
||||
: inventree_data.batch;
|
||||
inventree_data.batch.trim();
|
||||
|
||||
if (ui.workflow_batch_ta != nullptr && batch_input != ui.workflow_batch_ta)
|
||||
{
|
||||
lv_textarea_set_text(ui.workflow_batch_ta, inventree_data.batch.c_str());
|
||||
}
|
||||
|
||||
if (ui.inventree_batch_ta != nullptr && batch_input != ui.inventree_batch_ta)
|
||||
{
|
||||
lv_textarea_set_text(ui.inventree_batch_ta, inventree_data.batch.c_str());
|
||||
}
|
||||
|
||||
if (persist)
|
||||
{
|
||||
saveInventreeConfig();
|
||||
@@ -846,6 +909,46 @@ void updateInventreeLabels()
|
||||
inventree_data.status_text.isEmpty() ? "Not configured" : inventree_data.status_text.c_str());
|
||||
setLabelTextIfChanged(ui.inventree_result_value,
|
||||
inventree_data.result_text.isEmpty() ? "No stock item selected." : inventree_data.result_text.c_str());
|
||||
|
||||
if (ui.workflow_stock_name_label != nullptr && ui.workflow_stock_meta_label != nullptr)
|
||||
{
|
||||
if (inventree_data.selected_match >= 0 && inventree_data.selected_match < inventree_data.stored_matches)
|
||||
{
|
||||
const InventreeMatch &match = inventree_data.matches[inventree_data.selected_match];
|
||||
|
||||
String title = match.part_name.isEmpty()
|
||||
? "Stock item ID " + String(match.id)
|
||||
: match.part_name;
|
||||
|
||||
String meta;
|
||||
meta.reserve(192);
|
||||
meta += "Batch ";
|
||||
meta += match.batch.isEmpty() ? "--" : match.batch;
|
||||
meta += " | Qty ";
|
||||
meta += String(match.quantity, 1);
|
||||
|
||||
if (!match.location.isEmpty())
|
||||
{
|
||||
meta += " | ";
|
||||
meta += match.location;
|
||||
}
|
||||
|
||||
setLabelTextIfChanged(ui.workflow_stock_name_label, title.c_str());
|
||||
setLabelTextIfChanged(ui.workflow_stock_meta_label, meta.c_str());
|
||||
}
|
||||
else if (!inventree_data.batch.isEmpty())
|
||||
{
|
||||
setLabelTextIfChanged(ui.workflow_stock_name_label, "Stock item not selected");
|
||||
setLabelTextIfChanged(ui.workflow_stock_meta_label,
|
||||
inventree_data.result_text.isEmpty() ? "No matches for the entered Batch Code." : inventree_data.result_text.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
setLabelTextIfChanged(ui.workflow_stock_name_label, "Enter Batch Code");
|
||||
setLabelTextIfChanged(ui.workflow_stock_meta_label,
|
||||
"The device will load the stock item and prepare the current weight for writeback.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateInventreeSelectionSummary()
|
||||
@@ -1693,13 +1796,13 @@ void buildWeightPage()
|
||||
lv_obj_set_pos(title, 24, 18);
|
||||
lv_obj_set_style_text_color(title, lv_color_hex(0xF5FAFC), 0);
|
||||
lv_obj_set_style_text_font(title, &lv_font_montserrat_20, 0);
|
||||
lv_label_set_text(title, "Scale");
|
||||
lv_label_set_text(title, "Main");
|
||||
|
||||
lv_obj_t *subtitle = lv_label_create(page);
|
||||
lv_obj_set_pos(subtitle, 24, 48);
|
||||
lv_obj_set_style_text_color(subtitle, lv_color_hex(0x6F8893), 0);
|
||||
lv_obj_set_style_text_font(subtitle, &lv_font_montserrat_14, 0);
|
||||
lv_label_set_text(subtitle, "Main page with filtered HX711 weight");
|
||||
lv_label_set_text(subtitle, "Weigh filament spools by Batch Code and write grams to InvenTree");
|
||||
|
||||
ui.status_chip = lv_obj_create(page);
|
||||
lv_obj_set_size(ui.status_chip, 110, 40);
|
||||
@@ -1717,7 +1820,7 @@ void buildWeightPage()
|
||||
lv_obj_center(ui.status_label);
|
||||
|
||||
ui.weight_label = lv_label_create(page);
|
||||
lv_obj_set_pos(ui.weight_label, 18, 132);
|
||||
lv_obj_set_pos(ui.weight_label, 18, 92);
|
||||
lv_obj_set_width(ui.weight_label, 470);
|
||||
lv_obj_set_style_text_color(ui.weight_label, lv_color_hex(0xF8FEFF), 0);
|
||||
lv_obj_set_style_text_font(ui.weight_label, &lv_font_montserrat_48, 0);
|
||||
@@ -1725,13 +1828,13 @@ void buildWeightPage()
|
||||
lv_label_set_text(ui.weight_label, "--");
|
||||
|
||||
ui.weight_unit_label = lv_label_create(page);
|
||||
lv_obj_set_pos(ui.weight_unit_label, 500, 170);
|
||||
lv_obj_set_pos(ui.weight_unit_label, 500, 130);
|
||||
lv_obj_set_style_text_color(ui.weight_unit_label, lv_color_hex(0x8FA3AC), 0);
|
||||
lv_obj_set_style_text_font(ui.weight_unit_label, &lv_font_montserrat_24, 0);
|
||||
lv_label_set_text(ui.weight_unit_label, "g");
|
||||
|
||||
ui.mode_label = lv_label_create(page);
|
||||
lv_obj_set_pos(ui.mode_label, 24, 246);
|
||||
lv_obj_set_pos(ui.mode_label, 24, 166);
|
||||
lv_obj_set_width(ui.mode_label, 550);
|
||||
lv_obj_set_style_text_color(ui.mode_label, lv_color_hex(0x7FA1B2), 0);
|
||||
lv_obj_set_style_text_font(ui.mode_label, &lv_font_montserrat_18, 0);
|
||||
@@ -1740,14 +1843,50 @@ void buildWeightPage()
|
||||
lv_label_set_text(ui.mode_label, "Waiting for HX711...");
|
||||
ui.weight_raw_value = nullptr;
|
||||
|
||||
lv_obj_t *batch_label = lv_label_create(page);
|
||||
lv_obj_set_pos(batch_label, 24, 212);
|
||||
lv_obj_set_style_text_color(batch_label, lv_color_hex(0x7FA1B2), 0);
|
||||
lv_obj_set_style_text_font(batch_label, &lv_font_montserrat_14, 0);
|
||||
lv_label_set_text(batch_label, "Batch Code");
|
||||
|
||||
ui.workflow_batch_ta = createTextInput(page, 24, 236, 560, "Main Batch Code", "Scan or type Batch Code", false);
|
||||
if (!inventree_data.batch.isEmpty())
|
||||
{
|
||||
lv_textarea_set_text(ui.workflow_batch_ta, inventree_data.batch.c_str());
|
||||
}
|
||||
|
||||
lv_obj_t *stock_title = lv_label_create(page);
|
||||
lv_obj_set_pos(stock_title, 24, 296);
|
||||
lv_obj_set_style_text_color(stock_title, lv_color_hex(0x7FA1B2), 0);
|
||||
lv_obj_set_style_text_font(stock_title, &lv_font_montserrat_14, 0);
|
||||
lv_label_set_text(stock_title, "Stock Item");
|
||||
|
||||
ui.workflow_stock_name_label = lv_label_create(page);
|
||||
lv_obj_set_pos(ui.workflow_stock_name_label, 24, 320);
|
||||
lv_obj_set_width(ui.workflow_stock_name_label, 560);
|
||||
lv_obj_set_style_text_color(ui.workflow_stock_name_label, lv_color_hex(0xF5FAFC), 0);
|
||||
lv_obj_set_style_text_font(ui.workflow_stock_name_label, &lv_font_montserrat_20, 0);
|
||||
lv_label_set_long_mode(ui.workflow_stock_name_label, LV_LABEL_LONG_WRAP);
|
||||
lv_label_set_text(ui.workflow_stock_name_label, "Enter Batch Code");
|
||||
|
||||
ui.workflow_stock_meta_label = lv_label_create(page);
|
||||
lv_obj_set_pos(ui.workflow_stock_meta_label, 24, 352);
|
||||
lv_obj_set_width(ui.workflow_stock_meta_label, 560);
|
||||
lv_obj_set_style_text_color(ui.workflow_stock_meta_label, lv_color_hex(0x8FA3AC), 0);
|
||||
lv_obj_set_style_text_font(ui.workflow_stock_meta_label, &lv_font_montserrat_14, 0);
|
||||
lv_label_set_long_mode(ui.workflow_stock_meta_label, LV_LABEL_LONG_WRAP);
|
||||
lv_label_set_text(ui.workflow_stock_meta_label, "The device will load the stock item and prepare the current weight for writeback.");
|
||||
|
||||
createActionButton(page, "Write Weight", 24, 392, 560, 44, lv_color_hex(0x7A3A2A), inventreePushButtonEvent);
|
||||
|
||||
ui.weight_note_label = lv_label_create(page);
|
||||
lv_obj_set_pos(ui.weight_note_label, 24, 338);
|
||||
lv_obj_set_width(ui.weight_note_label, 550);
|
||||
lv_obj_set_pos(ui.weight_note_label, 24, 438);
|
||||
lv_obj_set_width(ui.weight_note_label, 560);
|
||||
lv_obj_set_style_text_color(ui.weight_note_label, lv_color_hex(0x8FA3AC), 0);
|
||||
lv_obj_set_style_text_font(ui.weight_note_label, &lv_font_montserrat_14, 0);
|
||||
lv_obj_set_style_text_align(ui.weight_note_label, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_label_set_long_mode(ui.weight_note_label, LV_LABEL_LONG_WRAP);
|
||||
lv_label_set_text(ui.weight_note_label, "Open Calibration to tare and set the 100 g reference. Open Wi-Fi to configure the network.");
|
||||
lv_label_set_text(ui.weight_note_label, "Enter Batch Code, confirm input, then tap Write Weight.");
|
||||
}
|
||||
|
||||
void buildCalibrationPage()
|
||||
@@ -1991,7 +2130,7 @@ void buildUi()
|
||||
lv_obj_set_style_text_align(nav_title, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_label_set_text(nav_title, "Menu");
|
||||
|
||||
createNavButton(ui.nav_panel, "Scale", 96, navWeightEvent, PageId::Weight);
|
||||
createNavButton(ui.nav_panel, "Main", 96, navWeightEvent, PageId::Weight);
|
||||
createNavButton(ui.nav_panel, "Cal", 166, navCalibrationEvent, PageId::Calibration);
|
||||
createNavButton(ui.nav_panel, "Wi-Fi", 236, navWifiEvent, PageId::Wifi);
|
||||
createNavButton(ui.nav_panel, "Inv", 306, navInventreeEvent, PageId::Inventree);
|
||||
@@ -2078,7 +2217,7 @@ void buildUi()
|
||||
lv_obj_add_event_cb(ui.wifi_keyboard, textEditorKeyboardEvent, LV_EVENT_ALL, nullptr);
|
||||
|
||||
lv_screen_load(ui.screen);
|
||||
setWeightNote("Open Calibration to tare and set the 100 g reference. Open Wi-Fi to configure the network.");
|
||||
setWeightNote("Enter Batch Code, confirm input, then tap Write Weight.");
|
||||
setCalibrationNote("Empty the platform, tap Tare, place the 100 g reference weight, then tap Cal.");
|
||||
|
||||
if (wifi_data.ssid.isEmpty())
|
||||
|
||||
Reference in New Issue
Block a user