feat: add calibration index handling to tray data and update related API and UI components
This commit is contained in:
parent
d1f22c78f7
commit
1c1043ac75
18
html/rfid.js
18
html/rfid.js
@ -266,7 +266,7 @@ function displayAmsData(amsData) {
|
|||||||
|
|
||||||
const trayHTML = ams.tray.map(tray => {
|
const trayHTML = ams.tray.map(tray => {
|
||||||
// Prüfe ob überhaupt Daten vorhanden sind
|
// Prüfe ob überhaupt Daten vorhanden sind
|
||||||
const relevantFields = ['tray_type', 'tray_sub_brands', 'tray_info_idx', 'setting_id'];
|
const relevantFields = ['tray_type', 'tray_sub_brands', 'tray_info_idx', 'setting_id', 'cali_idx'];
|
||||||
const hasAnyContent = relevantFields.some(field =>
|
const hasAnyContent = relevantFields.some(field =>
|
||||||
tray[field] !== null &&
|
tray[field] !== null &&
|
||||||
tray[field] !== undefined &&
|
tray[field] !== undefined &&
|
||||||
@ -324,7 +324,7 @@ function displayAmsData(amsData) {
|
|||||||
{ key: 'tray_sub_brands', label: 'Sub Brands' },
|
{ key: 'tray_sub_brands', label: 'Sub Brands' },
|
||||||
{ key: 'tray_info_idx', label: 'Filament IDX' },
|
{ key: 'tray_info_idx', label: 'Filament IDX' },
|
||||||
{ key: 'setting_id', label: 'Setting ID' },
|
{ key: 'setting_id', label: 'Setting ID' },
|
||||||
{ key: 'cali_idx', label: 'Calibration IDX' } // Add new property
|
{ key: 'cali_idx', label: 'Calibration IDX' }
|
||||||
];
|
];
|
||||||
|
|
||||||
// Nur gültige Felder anzeigen
|
// Nur gültige Felder anzeigen
|
||||||
@ -454,17 +454,23 @@ function handleSpoolIn(amsId, trayId) {
|
|||||||
nozzle_temp_max: parseInt(maxTemp),
|
nozzle_temp_max: parseInt(maxTemp),
|
||||||
type: selectedSpool.filament.material,
|
type: selectedSpool.filament.material,
|
||||||
brand: selectedSpool.filament.vendor.name,
|
brand: selectedSpool.filament.vendor.name,
|
||||||
tray_info_idx: selectedSpool.filament.extra.bambu_idx.replace(/['"]+/g, '').trim()
|
tray_info_idx: selectedSpool.filament.extra.bambu_idx.replace(/['"]+/g, '').trim(),
|
||||||
|
cali_idx: "-1" // Default-Wert setzen
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Prüfe, ob der Key cali_idx vorhanden ist und setze ihn
|
||||||
|
if (selectedSpool.filament.extra.bambu_cali_id) {
|
||||||
|
payload.payload.cali_idx = selectedSpool.filament.extra.bambu_cali_id.replace(/['"]+/g, '').trim();
|
||||||
|
}
|
||||||
|
|
||||||
// Prüfe, ob der Key bambu_setting_id vorhanden ist
|
// Prüfe, ob der Key bambu_setting_id vorhanden ist
|
||||||
if (selectedSpool.filament.extra.bambu_setting_id) {
|
if (selectedSpool.filament.extra.bambu_setting_id) {
|
||||||
payload.payload.cali_idx = selectedSpool.filament.extra.bambu_setting_id.replace(/['"]+/g, '').trim();
|
payload.payload.bambu_setting_id = selectedSpool.filament.extra.bambu_setting_id.replace(/['"]+/g, '').trim();
|
||||||
} else {
|
|
||||||
payload.payload.cali_idx = "-1";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Spool-In Payload:", payload);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
socket.send(JSON.stringify(payload));
|
socket.send(JSON.stringify(payload));
|
||||||
showNotification(`Spool set in AMS ${amsId} Tray ${trayId}. Pls wait`, true);
|
showNotification(`Spool set in AMS ${amsId} Tray ${trayId}. Pls wait`, true);
|
||||||
|
@ -279,6 +279,7 @@ bool checkSpoolmanExtraFields() {
|
|||||||
"price_meter",
|
"price_meter",
|
||||||
"price_gramm",
|
"price_gramm",
|
||||||
"bambu_setting_id",
|
"bambu_setting_id",
|
||||||
|
"bambu_cali_id",
|
||||||
"bambu_idx",
|
"bambu_idx",
|
||||||
"bambu_k",
|
"bambu_k",
|
||||||
"bambu_flow_ratio",
|
"bambu_flow_ratio",
|
||||||
@ -312,7 +313,11 @@ bool checkSpoolmanExtraFields() {
|
|||||||
"\"field_type\": \"text\","
|
"\"field_type\": \"text\","
|
||||||
"\"key\": \"bambu_setting_id\"}",
|
"\"key\": \"bambu_setting_id\"}",
|
||||||
|
|
||||||
"{\"name\": \"Bambu IDX\","
|
"{\"name\": \"Bambu Cali ID\","
|
||||||
|
"\"field_type\": \"text\","
|
||||||
|
"\"key\": \"bambu_cali_id\"}",
|
||||||
|
|
||||||
|
"{\"name\": \"Bambu Filament IDX\","
|
||||||
"\"field_type\": \"text\","
|
"\"field_type\": \"text\","
|
||||||
"\"key\": \"bambu_idx\"}",
|
"\"key\": \"bambu_idx\"}",
|
||||||
|
|
||||||
|
152
src/bambu.cpp
152
src/bambu.cpp
@ -137,43 +137,7 @@ bool sendMqttMessage(String payload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool setBambuSpool(String payload) {
|
bool setBambuSpool(String payload) {
|
||||||
/* payload
|
Serial.println("Spool settings in");
|
||||||
//// set Spool
|
|
||||||
{
|
|
||||||
"print": {
|
|
||||||
"sequence_id": 0,
|
|
||||||
"command": "ams_filament_setting",
|
|
||||||
"ams_id": 0, // AMS ID 0-3 oder externe Spule 255
|
|
||||||
"tray_id": 0, // Tray ID 0-3 oder externe Spule 254
|
|
||||||
"tray_color": "000000FF",
|
|
||||||
"nozzle_temp_min": 170,
|
|
||||||
"nozzle_temp_max": 200,
|
|
||||||
"tray_type": "PETG",
|
|
||||||
"setting_id": "",
|
|
||||||
"tray_info_idx": "GFG99"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//// Remove Spool
|
|
||||||
{
|
|
||||||
"print":{
|
|
||||||
"ams_id":255,
|
|
||||||
"command":"ams_filament_setting",
|
|
||||||
"nozzle_temp_max": 0,
|
|
||||||
"nozzle_temp_min": 0,
|
|
||||||
"sequence_id": 0,
|
|
||||||
"setting_id": "",
|
|
||||||
"tray_color": "FFFFFFFF",
|
|
||||||
"tray_id": 254,
|
|
||||||
"tray_info_idx": "",
|
|
||||||
"tray_type": "",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
Serial.println("Setting spool");
|
|
||||||
Serial.println(payload);
|
Serial.println(payload);
|
||||||
|
|
||||||
// Parse the JSON
|
// Parse the JSON
|
||||||
@ -195,7 +159,8 @@ bool setBambuSpool(String payload) {
|
|||||||
String brand = doc["brand"].as<String>();
|
String brand = doc["brand"].as<String>();
|
||||||
String tray_info_idx = (doc["tray_info_idx"].as<String>() != "-1") ? doc["tray_info_idx"].as<String>() : "";
|
String tray_info_idx = (doc["tray_info_idx"].as<String>() != "-1") ? doc["tray_info_idx"].as<String>() : "";
|
||||||
if (tray_info_idx == "") tray_info_idx = (brand != "" && type != "") ? findFilamentIdx(brand, type) : "";
|
if (tray_info_idx == "") tray_info_idx = (brand != "" && type != "") ? findFilamentIdx(brand, type) : "";
|
||||||
String setting_id = doc["cali_idx"].as<String>();
|
String setting_id = doc["bambu_setting_id"].as<String>();
|
||||||
|
String cali_idx = doc["cali_idx"].as<String>();
|
||||||
|
|
||||||
doc.clear();
|
doc.clear();
|
||||||
|
|
||||||
@ -207,8 +172,9 @@ bool setBambuSpool(String payload) {
|
|||||||
doc["print"]["nozzle_temp_min"] = minTemp;
|
doc["print"]["nozzle_temp_min"] = minTemp;
|
||||||
doc["print"]["nozzle_temp_max"] = maxTemp;
|
doc["print"]["nozzle_temp_max"] = maxTemp;
|
||||||
doc["print"]["tray_type"] = type;
|
doc["print"]["tray_type"] = type;
|
||||||
doc["print"]["setting_id"] = (setting_id != "") ? setting_id : "";
|
doc["print"]["cali_idx"] = (cali_idx != "") ? cali_idx : "";
|
||||||
doc["print"]["tray_info_idx"] = tray_info_idx;
|
doc["print"]["tray_info_idx"] = tray_info_idx;
|
||||||
|
doc["print"]["setting_id"] = setting_id;
|
||||||
|
|
||||||
// Serialize the JSON
|
// Serialize the JSON
|
||||||
String output;
|
String output;
|
||||||
@ -224,31 +190,65 @@ bool setBambuSpool(String payload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doc.clear();
|
doc.clear();
|
||||||
|
yield();
|
||||||
|
|
||||||
if (setting_id != "") {
|
if (cali_idx != "") {
|
||||||
|
yield();
|
||||||
doc["print"]["sequence_id"] = 0;
|
doc["print"]["sequence_id"] = 0;
|
||||||
doc["print"]["command"] = "extrusion_cali_sel";
|
doc["print"]["command"] = "extrusion_cali_sel";
|
||||||
doc["print"]["ams_id"] = amsId < 200 ? amsId : 255;
|
|
||||||
doc["print"]["tray_id"] = trayId < 200 ? trayId : 254;
|
|
||||||
doc["print"]["filament_id"] = tray_info_idx;
|
doc["print"]["filament_id"] = tray_info_idx;
|
||||||
doc["print"]["nozzle_diameter"] = "0.4";
|
doc["print"]["nozzle_diameter"] = "0.4";
|
||||||
doc["print"]["cali_idx"] = setting_id.toInt();
|
doc["print"]["cali_idx"] = cali_idx.toInt();
|
||||||
|
doc["print"]["tray_id"] = trayId < 200 ? trayId : 254;
|
||||||
|
doc["print"]["ams_id"] = amsId < 200 ? amsId : 255;
|
||||||
|
|
||||||
// Serialize the JSON
|
// Serialize the JSON
|
||||||
String output;
|
String output;
|
||||||
serializeJson(doc, output);
|
serializeJson(doc, output);
|
||||||
|
|
||||||
if (sendMqttMessage(output)) {
|
if (sendMqttMessage(output)) {
|
||||||
Serial.println("Setting ID successfully set");
|
Serial.println("Extrusion calibration successfully set");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Failed to set setting ID");
|
Serial.println("Failed to set extrusion calibration");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.clear();
|
doc.clear();
|
||||||
|
yield();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
if (setting_id != "") {
|
||||||
|
yield();
|
||||||
|
doc["print"]["sequence_id"] = 0;
|
||||||
|
doc["print"]["command"] = "ams_filament_setting";
|
||||||
|
doc["print"]["nozzle_temp_min"] = minTemp;
|
||||||
|
doc["print"]["nozzle_temp_max"] = maxTemp;
|
||||||
|
doc["print"]["setting_id"] = setting_id;
|
||||||
|
doc["print"]["tray_color"] = color.length() == 8 ? color : color+"FF";
|
||||||
|
doc["print"]["ams_id"] = amsId < 200 ? amsId : 255;
|
||||||
|
doc["print"]["tray_id"] = trayId < 200 ? trayId : 254;
|
||||||
|
doc["print"]["tray_info_idx"] = tray_info_idx;
|
||||||
|
doc["print"]["tray_type"] = type;
|
||||||
|
|
||||||
|
// Serialize the JSON
|
||||||
|
String output;
|
||||||
|
serializeJson(doc, output);
|
||||||
|
|
||||||
|
if (sendMqttMessage(output)) {
|
||||||
|
Serial.println("Filament Setting successfully set");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println("Failed to set Filament setting");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.clear();
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -306,7 +306,8 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
JsonObject trayObj = trayArray[j];
|
JsonObject trayObj = trayArray[j];
|
||||||
if (trayObj["tray_info_idx"].as<String>() != ams_data[storedIndex].trays[j].tray_info_idx ||
|
if (trayObj["tray_info_idx"].as<String>() != ams_data[storedIndex].trays[j].tray_info_idx ||
|
||||||
trayObj["tray_type"].as<String>() != ams_data[storedIndex].trays[j].tray_type ||
|
trayObj["tray_type"].as<String>() != ams_data[storedIndex].trays[j].tray_type ||
|
||||||
trayObj["tray_color"].as<String>() != ams_data[storedIndex].trays[j].tray_color) {
|
trayObj["tray_color"].as<String>() != ams_data[storedIndex].trays[j].tray_color ||
|
||||||
|
trayObj["cali_idx"].as<String>() != ams_data[storedIndex].trays[j].cali_idx) {
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -323,7 +324,8 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
foundExternal = true;
|
foundExternal = true;
|
||||||
if (vtTray["tray_info_idx"].as<String>() != ams_data[i].trays[0].tray_info_idx ||
|
if (vtTray["tray_info_idx"].as<String>() != ams_data[i].trays[0].tray_info_idx ||
|
||||||
vtTray["tray_type"].as<String>() != ams_data[i].trays[0].tray_type ||
|
vtTray["tray_type"].as<String>() != ams_data[i].trays[0].tray_type ||
|
||||||
vtTray["tray_color"].as<String>() != ams_data[i].trays[0].tray_color) {
|
vtTray["tray_color"].as<String>() != ams_data[i].trays[0].tray_color ||
|
||||||
|
vtTray["cali_idx"].as<String>() != ams_data[i].trays[0].cali_idx) {
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -353,7 +355,8 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
ams_data[i].trays[j].tray_color = trayObj["tray_color"].as<String>();
|
ams_data[i].trays[j].tray_color = trayObj["tray_color"].as<String>();
|
||||||
ams_data[i].trays[j].nozzle_temp_min = trayObj["nozzle_temp_min"].as<int>();
|
ams_data[i].trays[j].nozzle_temp_min = trayObj["nozzle_temp_min"].as<int>();
|
||||||
ams_data[i].trays[j].nozzle_temp_max = trayObj["nozzle_temp_max"].as<int>();
|
ams_data[i].trays[j].nozzle_temp_max = trayObj["nozzle_temp_max"].as<int>();
|
||||||
ams_data[i].trays[j].setting_id = trayObj["cali_idx"].as<String>();
|
ams_data[i].trays[j].setting_id = trayObj["setting_id"].as<String>();
|
||||||
|
ams_data[i].trays[j].cali_idx = trayObj["cali_idx"].as<String>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Serial.println("----------------");
|
//Serial.println("----------------");
|
||||||
@ -391,7 +394,8 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
ams_data[extIdx].trays[0].tray_color = vtTray["tray_color"].as<String>();
|
ams_data[extIdx].trays[0].tray_color = vtTray["tray_color"].as<String>();
|
||||||
ams_data[extIdx].trays[0].nozzle_temp_min = vtTray["nozzle_temp_min"].as<int>();
|
ams_data[extIdx].trays[0].nozzle_temp_min = vtTray["nozzle_temp_min"].as<int>();
|
||||||
ams_data[extIdx].trays[0].nozzle_temp_max = vtTray["nozzle_temp_max"].as<int>();
|
ams_data[extIdx].trays[0].nozzle_temp_max = vtTray["nozzle_temp_max"].as<int>();
|
||||||
ams_data[extIdx].trays[0].setting_id = vtTray["cali_idx"].as<String>();
|
ams_data[extIdx].trays[0].setting_id = vtTray["setting_id"].as<String>();
|
||||||
|
ams_data[extIdx].trays[0].cali_idx = vtTray["cali_idx"].as<String>();
|
||||||
ams_count++; // Erhöhe ams_count für die externe Spule
|
ams_count++; // Erhöhe ams_count für die externe Spule
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,13 +422,61 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
trayObj["tray_color"] = ams_data[i].trays[j].tray_color;
|
trayObj["tray_color"] = ams_data[i].trays[j].tray_color;
|
||||||
trayObj["nozzle_temp_min"] = ams_data[i].trays[j].nozzle_temp_min;
|
trayObj["nozzle_temp_min"] = ams_data[i].trays[j].nozzle_temp_min;
|
||||||
trayObj["nozzle_temp_max"] = ams_data[i].trays[j].nozzle_temp_max;
|
trayObj["nozzle_temp_max"] = ams_data[i].trays[j].nozzle_temp_max;
|
||||||
trayObj["cali_idx"] = ams_data[i].trays[j].setting_id;
|
trayObj["setting_id"] = ams_data[i].trays[j].setting_id;
|
||||||
|
trayObj["cali_idx"] = ams_data[i].trays[j].cali_idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serializeJson(wsArray, amsJsonData);
|
serializeJson(wsArray, amsJsonData);
|
||||||
sendAmsData(nullptr);
|
sendAmsData(nullptr);
|
||||||
}
|
}
|
||||||
|
// Neue Bedingung für ams_filament_setting
|
||||||
|
else if (doc["print"]["command"] == "ams_filament_setting") {
|
||||||
|
int amsId = doc["print"]["ams_id"].as<int>();
|
||||||
|
int trayId = doc["print"]["tray_id"].as<int>();
|
||||||
|
String settingId = doc["print"]["setting_id"].as<String>();
|
||||||
|
|
||||||
|
// Finde das entsprechende AMS und Tray
|
||||||
|
for (int i = 0; i < ams_count; i++) {
|
||||||
|
if (ams_data[i].ams_id == amsId) {
|
||||||
|
// Update setting_id im entsprechenden Tray
|
||||||
|
ams_data[i].trays[trayId].setting_id = settingId;
|
||||||
|
|
||||||
|
// Erstelle neues JSON für WebSocket-Clients
|
||||||
|
JsonDocument wsDoc;
|
||||||
|
JsonArray wsArray = wsDoc.to<JsonArray>();
|
||||||
|
|
||||||
|
for (int j = 0; j < ams_count; j++) {
|
||||||
|
JsonObject amsObj = wsArray.createNestedObject();
|
||||||
|
amsObj["ams_id"] = ams_data[j].ams_id;
|
||||||
|
|
||||||
|
JsonArray trays = amsObj.createNestedArray("tray");
|
||||||
|
int maxTrays = (ams_data[j].ams_id == 255) ? 1 : 4;
|
||||||
|
|
||||||
|
for (int k = 0; k < maxTrays; k++) {
|
||||||
|
JsonObject trayObj = trays.createNestedObject();
|
||||||
|
trayObj["id"] = ams_data[j].trays[k].id;
|
||||||
|
trayObj["tray_info_idx"] = ams_data[j].trays[k].tray_info_idx;
|
||||||
|
trayObj["tray_type"] = ams_data[j].trays[k].tray_type;
|
||||||
|
trayObj["tray_sub_brands"] = ams_data[j].trays[k].tray_sub_brands;
|
||||||
|
trayObj["tray_color"] = ams_data[j].trays[k].tray_color;
|
||||||
|
trayObj["nozzle_temp_min"] = ams_data[j].trays[k].nozzle_temp_min;
|
||||||
|
trayObj["nozzle_temp_max"] = ams_data[j].trays[k].nozzle_temp_max;
|
||||||
|
trayObj["setting_id"] = ams_data[j].trays[k].setting_id;
|
||||||
|
trayObj["cali_idx"] = ams_data[j].trays[k].cali_idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aktualisiere das globale amsJsonData
|
||||||
|
amsJsonData = "";
|
||||||
|
serializeJson(wsArray, amsJsonData);
|
||||||
|
|
||||||
|
// Sende an WebSocket Clients
|
||||||
|
sendAmsData(nullptr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reconnect() {
|
void reconnect() {
|
||||||
|
@ -13,6 +13,7 @@ struct TrayData {
|
|||||||
int nozzle_temp_min;
|
int nozzle_temp_min;
|
||||||
int nozzle_temp_max;
|
int nozzle_temp_max;
|
||||||
String setting_id;
|
String setting_id;
|
||||||
|
String cali_idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_AMS 17 // 16 normale AMS + 1 externe Spule
|
#define MAX_AMS 17 // 16 normale AMS + 1 externe Spule
|
||||||
|
Loading…
x
Reference in New Issue
Block a user