feat: füge Unterstützung für Spoolman-Einstellungen hinzu und aktualisiere die Benutzeroberfläche
This commit is contained in:
parent
3d0411e3c1
commit
b87d43c64e
46
html/rfid.js
46
html/rfid.js
@ -150,6 +150,13 @@ function initWebSocket() {
|
|||||||
ramStatus.textContent = `${data.freeHeap}k`;
|
ramStatus.textContent = `${data.freeHeap}k`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (data.type === 'setSpoolmanSettings') {
|
||||||
|
if (data.payload == 'success') {
|
||||||
|
showNotification(`Spoolman Settings set successfully`, true);
|
||||||
|
} else {
|
||||||
|
showNotification(`Error setting Spoolman Settings`, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
@ -285,6 +292,14 @@ function displayAmsData(amsData) {
|
|||||||
<img src="spool_in.png" alt="Spool In" style="width: 48px; height: 48px; transform: rotate(180deg) scaleX(-1);">
|
<img src="spool_in.png" alt="Spool In" style="width: 48px; height: 48px; transform: rotate(180deg) scaleX(-1);">
|
||||||
</button>`;
|
</button>`;
|
||||||
|
|
||||||
|
const spoolmanButtonHtml = `
|
||||||
|
<button class="spool-button" onclick="handleSpoolmanSettings('${tray.tray_info_idx}', '${tray.setting_id}', '${tray.cali_idx}', '${tray.nozzle_temp_min}', '${tray.nozzle_temp_max}')"
|
||||||
|
style="position: absolute; bottom: 0px; right: 0px;
|
||||||
|
background: none; border: none; padding: 0;
|
||||||
|
cursor: pointer; display: none;">
|
||||||
|
<img src="set_spoolman.png" alt="Spool In" style="width: 38px; height: 38px;">
|
||||||
|
</button>`;
|
||||||
|
|
||||||
if (!hasAnyContent) {
|
if (!hasAnyContent) {
|
||||||
return `
|
return `
|
||||||
<div class="tray">
|
<div class="tray">
|
||||||
@ -348,6 +363,7 @@ function displayAmsData(amsData) {
|
|||||||
${trayDetails}
|
${trayDetails}
|
||||||
${tempHTML}
|
${tempHTML}
|
||||||
${(ams.ams_id === 255 && tray.tray_type !== '') ? outButtonHtml : ''}
|
${(ams.ams_id === 255 && tray.tray_type !== '') ? outButtonHtml : ''}
|
||||||
|
${(tray.setting_id != "" && tray.setting_id != "null") ? spoolmanButtonHtml : ''}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>`;
|
</div>`;
|
||||||
@ -373,6 +389,36 @@ function updateSpoolButtons(show) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSpoolmanSettings(tray_info_idx, setting_id, cali_idx, nozzle_temp_min, nozzle_temp_max) {
|
||||||
|
// Hole das ausgewählte Filament
|
||||||
|
const selectedText = document.getElementById("selected-filament").textContent;
|
||||||
|
|
||||||
|
// Finde die ausgewählte Spule in den Daten
|
||||||
|
const selectedSpool = spoolsData.find(spool =>
|
||||||
|
`${spool.id} | ${spool.filament.name} (${spool.filament.material})` === selectedText
|
||||||
|
);
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
type: 'setSpoolmanSettings',
|
||||||
|
payload: {
|
||||||
|
filament_id: selectedSpool.filament.id,
|
||||||
|
tray_info_idx: tray_info_idx,
|
||||||
|
setting_id: setting_id,
|
||||||
|
cali_idx: cali_idx,
|
||||||
|
temp_min: nozzle_temp_min,
|
||||||
|
temp_max: nozzle_temp_max
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
socket.send(JSON.stringify(payload));
|
||||||
|
showNotification(`Setting send to Spoolman`, true);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error while sending settings to Spoolman:", error);
|
||||||
|
showNotification("Error while sending!", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleSpoolOut() {
|
function handleSpoolOut() {
|
||||||
// Erstelle Payload
|
// Erstelle Payload
|
||||||
const payload = {
|
const payload = {
|
||||||
|
BIN
html/set_spoolman.png
Normal file
BIN
html/set_spoolman.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
@ -761,17 +761,19 @@ a:hover {
|
|||||||
right: 20px;
|
right: 20px;
|
||||||
padding: 15px 25px;
|
padding: 15px 25px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
color: white;
|
color: black;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
animation: slideIn 0.3s ease-out;
|
animation: slideIn 0.3s ease-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notification.success {
|
.notification.success {
|
||||||
background-color: #28a745;
|
background-color: #28a745;
|
||||||
|
color: black !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notification.error {
|
.notification.error {
|
||||||
background-color: #dc3545;
|
background-color: #dc3545;
|
||||||
|
color: white !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notification.fade-out {
|
.notification.fade-out {
|
||||||
@ -1013,6 +1015,7 @@ input[type="submit"]:disabled,
|
|||||||
color: #000;
|
color: #000;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
margin-left: 0.5rem;
|
margin-left: 0.5rem;
|
||||||
|
text-shadow: 0 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.progress-container {
|
.progress-container {
|
||||||
|
50
src/api.cpp
50
src/api.cpp
@ -122,9 +122,9 @@ void sendToApi(void *parameter) {
|
|||||||
if (httpType == "PATCH") httpCode = http.PATCH(updatePayload);
|
if (httpType == "PATCH") httpCode = http.PATCH(updatePayload);
|
||||||
|
|
||||||
if (httpCode == HTTP_CODE_OK) {
|
if (httpCode == HTTP_CODE_OK) {
|
||||||
Serial.println("Gewicht der Spule erfolgreich aktualisiert");
|
Serial.println("Spoolman erfolgreich aktualisiert");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Fehler beim Aktualisieren des Gewichts der Spule");
|
Serial.println("Fehler beim Senden an Spoolman!");
|
||||||
oledShowMessage("Spoolman update failed");
|
oledShowMessage("Spoolman update failed");
|
||||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
@ -223,6 +223,52 @@ uint8_t updateSpoolWeight(String spoolId, uint16_t weight) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool updateSpoolBambuData(String payload) {
|
||||||
|
JsonDocument doc;
|
||||||
|
DeserializationError error = deserializeJson(doc, payload);
|
||||||
|
if (error) {
|
||||||
|
Serial.print("Fehler beim JSON-Parsing: ");
|
||||||
|
Serial.println(error.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String spoolsUrl = spoolmanUrl + apiUrl + "/filament/" + doc["filament_id"].as<String>();
|
||||||
|
Serial.print("Update Spule mit URL: ");
|
||||||
|
Serial.println(spoolsUrl);
|
||||||
|
|
||||||
|
JsonDocument updateDoc;
|
||||||
|
updateDoc["extra"]["bambu_setting_id"] = "\"" + doc["setting_id"].as<String>() + "\"";
|
||||||
|
updateDoc["extra"]["bambu_cali_id"] = "\"" + doc["cali_idx"].as<String>() + "\"";
|
||||||
|
updateDoc["extra"]["bambu_idx"] = "\"" + doc["tray_info_idx"].as<String>() + "\"";
|
||||||
|
updateDoc["extra"]["nozzle_temperature"] = "[" + doc["temp_min"].as<String>() + "," + doc["temp_max"].as<String>() + "]";
|
||||||
|
|
||||||
|
String updatePayload;
|
||||||
|
serializeJson(updateDoc, updatePayload);
|
||||||
|
Serial.print("Update Payload: ");
|
||||||
|
Serial.println(updatePayload);
|
||||||
|
|
||||||
|
SendToApiParams* params = new SendToApiParams();
|
||||||
|
if (params == nullptr) {
|
||||||
|
Serial.println("Fehler: Kann Speicher für Task-Parameter nicht allokieren.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
params->httpType = "PATCH";
|
||||||
|
params->spoolsUrl = spoolsUrl;
|
||||||
|
params->updatePayload = updatePayload;
|
||||||
|
|
||||||
|
// Erstelle die Task
|
||||||
|
BaseType_t result = xTaskCreate(
|
||||||
|
sendToApi, // Task-Funktion
|
||||||
|
"SendToApiTask", // Task-Name
|
||||||
|
4096, // Stackgröße in Bytes
|
||||||
|
(void*)params, // Parameter
|
||||||
|
0, // Priorität
|
||||||
|
NULL // Task-Handle (nicht benötigt)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// #### Spoolman init
|
// #### Spoolman init
|
||||||
bool checkSpoolmanExtraFields() {
|
bool checkSpoolmanExtraFields() {
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
|
@ -18,5 +18,6 @@ JsonDocument fetchSingleSpoolInfo(int spoolId); // API-Funktion für die Webseit
|
|||||||
bool updateSpoolTagId(String uidString, const char* payload); // Neue Funktion zum Aktualisieren eines Spools
|
bool updateSpoolTagId(String uidString, const char* payload); // Neue Funktion zum Aktualisieren eines Spools
|
||||||
uint8_t updateSpoolWeight(String spoolId, uint16_t weight); // Neue Funktion zum Aktualisieren des Gewichts
|
uint8_t updateSpoolWeight(String spoolId, uint16_t weight); // Neue Funktion zum Aktualisieren des Gewichts
|
||||||
bool initSpoolman(); // Neue Funktion zum Initialisieren von Spoolman
|
bool initSpoolman(); // Neue Funktion zum Initialisieren von Spoolman
|
||||||
|
bool updateSpoolBambuData(String payload); // Neue Funktion zum Aktualisieren der Bambu-Daten
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -95,6 +95,15 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
|||||||
setBambuSpool(doc["payload"]);
|
setBambuSpool(doc["payload"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (doc["type"] == "setSpoolmanSettings") {
|
||||||
|
Serial.println(doc["payload"].as<String>());
|
||||||
|
if (updateSpoolBambuData(doc["payload"].as<String>())) {
|
||||||
|
ws.textAll("{\"type\":\"setSpoolmanSettings\",\"payload\":\"success\"}");
|
||||||
|
} else {
|
||||||
|
ws.textAll("{\"type\":\"setSpoolmanSettings\",\"payload\":\"error\"}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
Serial.println("Unbekannter WebSocket-Typ: " + doc["type"].as<String>());
|
Serial.println("Unbekannter WebSocket-Typ: " + doc["type"].as<String>());
|
||||||
}
|
}
|
||||||
@ -346,6 +355,15 @@ void setupWebserver(AsyncWebServer &server) {
|
|||||||
Serial.println("spool_in.png gesendet");
|
Serial.println("spool_in.png gesendet");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Route für set_spoolman.png
|
||||||
|
server.on("/set_spoolman.png", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
|
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/set_spoolman.png.gz", "image/png");
|
||||||
|
response->addHeader("Content-Encoding", "gzip");
|
||||||
|
response->addHeader("Cache-Control", CACHE_CONTROL);
|
||||||
|
request->send(response);
|
||||||
|
Serial.println("set_spoolman.png gesendet");
|
||||||
|
});
|
||||||
|
|
||||||
// Route für JavaScript Dateien
|
// Route für JavaScript Dateien
|
||||||
server.on("/spoolman.js", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/spoolman.js", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
Serial.println("Anfrage für /spoolman.js erhalten");
|
Serial.println("Anfrage für /spoolman.js erhalten");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user