Simplify printer classes for code reuse and to prevent doubles
parent
13c04d65e8
commit
6d74b4ca0c
|
|
@ -1,6 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <base64.h>
|
||||||
|
#include "Debug.h"
|
||||||
|
|
||||||
class BasePrinterClient {
|
class BasePrinterClient {
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,135 @@
|
||||||
|
#include "BasePrinterClientImpl.h"
|
||||||
|
|
||||||
|
BasePrinterClientImpl::BasePrinterClientImpl(String printerType, GlobalDataController *globalDataController, DebugController *debugController) {
|
||||||
|
this->globalDataController = globalDataController;
|
||||||
|
this->debugController = debugController;
|
||||||
|
this->printerType = printerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset all PrinterData
|
||||||
|
void BasePrinterClientImpl::resetPrintData() {
|
||||||
|
this->printerData.averagePrintTime = "";
|
||||||
|
this->printerData.estimatedPrintTime = "";
|
||||||
|
this->printerData.fileName = "";
|
||||||
|
this->printerData.fileSize = "";
|
||||||
|
this->printerData.lastPrintTime = "";
|
||||||
|
this->printerData.progressCompletion = "";
|
||||||
|
this->printerData.progressFilepos = "";
|
||||||
|
this->printerData.progressPrintTime = "";
|
||||||
|
this->printerData.progressPrintTimeLeft = "";
|
||||||
|
this->printerData.state = "";
|
||||||
|
this->printerData.toolTemp = "";
|
||||||
|
this->printerData.toolTargetTemp = "";
|
||||||
|
this->printerData.filamentLength = "";
|
||||||
|
this->printerData.bedTemp = "";
|
||||||
|
this->printerData.bedTargetTemp = "";
|
||||||
|
this->printerData.isPrinting = false;
|
||||||
|
this->printerData.isPSUoff = false;
|
||||||
|
this->printerData.error = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getAveragePrintTime(){
|
||||||
|
return printerData.averagePrintTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getEstimatedPrintTime() {
|
||||||
|
return printerData.estimatedPrintTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getFileName() {
|
||||||
|
return printerData.fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getFileSize() {
|
||||||
|
return printerData.fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getLastPrintTime(){
|
||||||
|
return printerData.lastPrintTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getProgressCompletion() {
|
||||||
|
return String(printerData.progressCompletion.toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getProgressFilepos() {
|
||||||
|
return printerData.progressFilepos;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getProgressPrintTime() {
|
||||||
|
return printerData.progressPrintTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getProgressPrintTimeLeft() {
|
||||||
|
String rtnValue = printerData.progressPrintTimeLeft;
|
||||||
|
if (getProgressCompletion() == "100") {
|
||||||
|
rtnValue = "0"; // Print is done so this should be 0 this is a fix for Duet
|
||||||
|
}
|
||||||
|
return rtnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getState() {
|
||||||
|
return printerData.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean BasePrinterClientImpl::isPrinting() {
|
||||||
|
return printerData.isPrinting;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean BasePrinterClientImpl::isPSUoff() {
|
||||||
|
return printerData.isPSUoff;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean BasePrinterClientImpl::isOperational() {
|
||||||
|
boolean operational = false;
|
||||||
|
if (printerData.state == "I" || isPrinting()) {
|
||||||
|
operational = true;
|
||||||
|
}
|
||||||
|
return operational;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getTempBedActual() {
|
||||||
|
return printerData.bedTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getTempBedTarget() {
|
||||||
|
return printerData.bedTargetTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getTempToolActual() {
|
||||||
|
return printerData.toolTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getTempToolTarget() {
|
||||||
|
return printerData.toolTargetTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getFilamentLength() {
|
||||||
|
return printerData.filamentLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getError() {
|
||||||
|
return printerData.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getValueRounded(String value) {
|
||||||
|
float f = value.toFloat();
|
||||||
|
int rounded = (int)(f+0.5f);
|
||||||
|
return String(rounded);
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getPrinterType() {
|
||||||
|
return this->printerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BasePrinterClientImpl::getPrinterPort() {
|
||||||
|
return this->globalDataController->getPrinterPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
String BasePrinterClientImpl::getPrinterName() {
|
||||||
|
return printerData.printerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BasePrinterClientImpl::setPrinterName(String printer) {
|
||||||
|
printerData.printerName = printer;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
#pragma once
|
||||||
|
#include "BasePrinterClient.h"
|
||||||
|
#include "../Global/GlobalDataController.h"
|
||||||
|
|
||||||
|
class BasePrinterClientImpl : public BasePrinterClient {
|
||||||
|
protected:
|
||||||
|
GlobalDataController *globalDataController;
|
||||||
|
DebugController *debugController;
|
||||||
|
String printerType = "Octoprint";
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
String averagePrintTime;
|
||||||
|
String estimatedPrintTime;
|
||||||
|
String fileName;
|
||||||
|
String fileSize;
|
||||||
|
String lastPrintTime;
|
||||||
|
String progressCompletion;
|
||||||
|
String progressFilepos;
|
||||||
|
String progressPrintTime;
|
||||||
|
String progressPrintTimeLeft;
|
||||||
|
String state;
|
||||||
|
String toolTemp;
|
||||||
|
String toolTargetTemp;
|
||||||
|
String filamentLength;
|
||||||
|
String bedTemp;
|
||||||
|
String bedTargetTemp;
|
||||||
|
boolean isPrinting;
|
||||||
|
boolean isPSUoff;
|
||||||
|
String error;
|
||||||
|
String printerName;
|
||||||
|
} PrinterStruct;
|
||||||
|
|
||||||
|
PrinterStruct printerData;
|
||||||
|
|
||||||
|
public:
|
||||||
|
BasePrinterClientImpl(String printerType, GlobalDataController *globalDataController, DebugController *debugController);
|
||||||
|
|
||||||
|
void getPrinterJobResults() {};
|
||||||
|
void getPrinterPsuState() {};
|
||||||
|
void updatePrintClient() {};
|
||||||
|
|
||||||
|
void resetPrintData();
|
||||||
|
String getAveragePrintTime();
|
||||||
|
String getEstimatedPrintTime();
|
||||||
|
String getFileName();
|
||||||
|
String getFileSize();
|
||||||
|
String getLastPrintTime();
|
||||||
|
String getProgressCompletion();
|
||||||
|
String getProgressFilepos();
|
||||||
|
String getProgressPrintTime();
|
||||||
|
String getProgressPrintTimeLeft();
|
||||||
|
String getState();
|
||||||
|
boolean isPrinting();
|
||||||
|
boolean isOperational();
|
||||||
|
boolean isPSUoff();
|
||||||
|
String getTempBedActual();
|
||||||
|
String getTempBedTarget();
|
||||||
|
String getTempToolActual();
|
||||||
|
String getTempToolTarget();
|
||||||
|
String getFilamentLength();
|
||||||
|
String getValueRounded(String value);
|
||||||
|
String getError();
|
||||||
|
String getPrinterType();
|
||||||
|
int getPrinterPort();
|
||||||
|
String getPrinterName();
|
||||||
|
void setPrinterName(String printer);
|
||||||
|
};
|
||||||
|
|
@ -3,16 +3,13 @@
|
||||||
|
|
||||||
#include "DuetClient.h"
|
#include "DuetClient.h"
|
||||||
|
|
||||||
DuetClient::DuetClient(GlobalDataController *globalDataController, DebugController *debugController) {
|
DuetClient::DuetClient(GlobalDataController *globalDataController, DebugController *debugController)
|
||||||
this->globalDataController = globalDataController;
|
: BasePrinterClientImpl("Duet", globalDataController, debugController) {
|
||||||
this->debugController = debugController;
|
|
||||||
this->updatePrintClient();
|
this->updatePrintClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DuetClient::updatePrintClient() {
|
void DuetClient::updatePrintClient() {
|
||||||
this->globalDataController->getPrinterHostName().toCharArray(this->myServer, 100);
|
|
||||||
myApiKey = this->globalDataController->getPrinterApiKey();
|
myApiKey = this->globalDataController->getPrinterApiKey();
|
||||||
myPort = this->globalDataController->getPrinterPort();
|
|
||||||
encodedAuth = "";
|
encodedAuth = "";
|
||||||
if (this->globalDataController->getPrinterAuthUser() != "") {
|
if (this->globalDataController->getPrinterAuthUser() != "") {
|
||||||
String userpass = this->globalDataController->getPrinterAuthUser() + ":" + this->globalDataController->getPrinterAuthPass();
|
String userpass = this->globalDataController->getPrinterAuthUser() + ":" + this->globalDataController->getPrinterAuthPass();
|
||||||
|
|
@ -25,7 +22,7 @@ void DuetClient::updatePrintClient() {
|
||||||
boolean DuetClient::validate() {
|
boolean DuetClient::validate() {
|
||||||
boolean rtnValue = false;
|
boolean rtnValue = false;
|
||||||
printerData.error = "";
|
printerData.error = "";
|
||||||
if (String(myServer) == "") {
|
if (this->globalDataController->getPrinterServer() == "") {
|
||||||
printerData.error += "Server address is required; ";
|
printerData.error += "Server address is required; ";
|
||||||
}
|
}
|
||||||
if (myApiKey == "") {
|
if (myApiKey == "") {
|
||||||
|
|
@ -44,9 +41,9 @@ WiFiClient DuetClient::getSubmitRequest(String apiGetData) {
|
||||||
this->debugController->printLn("Getting Duet Data via GET");
|
this->debugController->printLn("Getting Duet Data via GET");
|
||||||
this->debugController->printLn(apiGetData);
|
this->debugController->printLn(apiGetData);
|
||||||
result = "";
|
result = "";
|
||||||
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
|
if (printClient.connect(this->globalDataController->getPrinterServer(), this->globalDataController->getPrinterPort())) { //starts client connection, checks for connection
|
||||||
printClient.println(apiGetData);
|
printClient.println(apiGetData);
|
||||||
printClient.println("Host: " + String(myServer) + ":" + String(myPort));
|
printClient.println("Host: " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort()));
|
||||||
printClient.println("X-Api-Key: " + myApiKey);
|
printClient.println("X-Api-Key: " + myApiKey);
|
||||||
if (encodedAuth != "") {
|
if (encodedAuth != "") {
|
||||||
printClient.print("Authorization: ");
|
printClient.print("Authorization: ");
|
||||||
|
|
@ -55,18 +52,18 @@ WiFiClient DuetClient::getSubmitRequest(String apiGetData) {
|
||||||
printClient.println("User-Agent: ArduinoWiFi/1.1");
|
printClient.println("User-Agent: ArduinoWiFi/1.1");
|
||||||
printClient.println("Connection: close");
|
printClient.println("Connection: close");
|
||||||
if (printClient.println() == 0) {
|
if (printClient.println() == 0) {
|
||||||
this->debugController->printLn("Connection to " + String(myServer) + ":" + String(myPort) + " failed.");
|
this->debugController->printLn("Connection to " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort()) + " failed.");
|
||||||
this->debugController->printLn("");
|
this->debugController->printLn("");
|
||||||
resetPrintData();
|
resetPrintData();
|
||||||
printerData.error = "Connection to " + String(myServer) + ":" + String(myPort) + " failed.";
|
printerData.error = "Connection to " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort()) + " failed.";
|
||||||
return printClient;
|
return printClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->debugController->printLn("Connection to Duet failed: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
|
this->debugController->printLn("Connection to Duet failed: " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort())); //error message if no client connect
|
||||||
this->debugController->printLn("");
|
this->debugController->printLn("");
|
||||||
resetPrintData();
|
resetPrintData();
|
||||||
printerData.error = "Connection to Duet failed: " + String(myServer) + ":" + String(myPort);
|
printerData.error = "Connection to Duet failed: " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort());
|
||||||
return printClient;
|
return printClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,7 +82,7 @@ WiFiClient DuetClient::getSubmitRequest(String apiGetData) {
|
||||||
char endOfHeaders[] = "\r\n\r\n";
|
char endOfHeaders[] = "\r\n\r\n";
|
||||||
if (!printClient.find(endOfHeaders)) {
|
if (!printClient.find(endOfHeaders)) {
|
||||||
this->debugController->printLn("Invalid response");
|
this->debugController->printLn("Invalid response");
|
||||||
printerData.error = "Invalid response from " + String(myServer) + ":" + String(myPort);
|
printerData.error = "Invalid response from " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort());
|
||||||
printerData.state = "";
|
printerData.state = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,9 +96,9 @@ WiFiClient DuetClient::getPostRequest(String apiPostData, String apiPostBody) {
|
||||||
this->debugController->printLn("Getting Duet Data via POST");
|
this->debugController->printLn("Getting Duet Data via POST");
|
||||||
this->debugController->printLn(apiPostData + " | " + apiPostBody);
|
this->debugController->printLn(apiPostData + " | " + apiPostBody);
|
||||||
result = "";
|
result = "";
|
||||||
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
|
if (printClient.connect(this->globalDataController->getPrinterServer(), this->globalDataController->getPrinterPort())) { //starts client connection, checks for connection
|
||||||
printClient.println(apiPostData);
|
printClient.println(apiPostData);
|
||||||
printClient.println("Host: " + String(myServer) + ":" + String(myPort));
|
printClient.println("Host: " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort()));
|
||||||
printClient.println("Connection: close");
|
printClient.println("Connection: close");
|
||||||
printClient.println("X-Api-Key: " + myApiKey);
|
printClient.println("X-Api-Key: " + myApiKey);
|
||||||
if (encodedAuth != "") {
|
if (encodedAuth != "") {
|
||||||
|
|
@ -115,18 +112,18 @@ WiFiClient DuetClient::getPostRequest(String apiPostData, String apiPostBody) {
|
||||||
printClient.println();
|
printClient.println();
|
||||||
printClient.println(apiPostBody);
|
printClient.println(apiPostBody);
|
||||||
if (printClient.println() == 0) {
|
if (printClient.println() == 0) {
|
||||||
this->debugController->printLn("Connection to " + String(myServer) + ":" + String(myPort) + " failed.");
|
this->debugController->printLn("Connection to " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort()) + " failed.");
|
||||||
this->debugController->printLn("");
|
this->debugController->printLn("");
|
||||||
resetPrintData();
|
resetPrintData();
|
||||||
printerData.error = "Connection to " + String(myServer) + ":" + String(myPort) + " failed.";
|
printerData.error = "Connection to " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort()) + " failed.";
|
||||||
return printClient;
|
return printClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->debugController->printLn("Connection to Duet failed: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
|
this->debugController->printLn("Connection to Duet failed: " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort())); //error message if no client connect
|
||||||
this->debugController->printLn("");
|
this->debugController->printLn("");
|
||||||
resetPrintData();
|
resetPrintData();
|
||||||
printerData.error = "Connection to Duet failed: " + String(myServer) + ":" + String(myPort);
|
printerData.error = "Connection to Duet failed: " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort());
|
||||||
return printClient;
|
return printClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +142,7 @@ WiFiClient DuetClient::getPostRequest(String apiPostData, String apiPostBody) {
|
||||||
char endOfHeaders[] = "\r\n\r\n";
|
char endOfHeaders[] = "\r\n\r\n";
|
||||||
if (!printClient.find(endOfHeaders)) {
|
if (!printClient.find(endOfHeaders)) {
|
||||||
this->debugController->printLn("Invalid response");
|
this->debugController->printLn("Invalid response");
|
||||||
printerData.error = "Invalid response from " + String(myServer) + ":" + String(myPort);
|
printerData.error = "Invalid response from " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort());
|
||||||
printerData.state = "";
|
printerData.state = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,8 +165,8 @@ void DuetClient::getPrinterJobResults() {
|
||||||
// Parse JSON object
|
// Parse JSON object
|
||||||
DeserializationError error = deserializeJson(jsonBuffer, printClient);
|
DeserializationError error = deserializeJson(jsonBuffer, printClient);
|
||||||
if (error) {
|
if (error) {
|
||||||
this->debugController->printLn("Duet Data Parsing failed: " + String(myServer) + ":" + String(myPort));
|
this->debugController->printLn("Duet Data Parsing failed: " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort()));
|
||||||
printerData.error = "Duet Data Parsing failed: " + String(myServer) + ":" + String(myPort);
|
printerData.error = "Duet Data Parsing failed: " + this->globalDataController->getPrinterServer() + ":" + String(this->globalDataController->getPrinterPort());
|
||||||
printerData.state = "";
|
printerData.state = "";
|
||||||
printerData.isPrinting = false;
|
printerData.isPrinting = false;
|
||||||
printerData.toolTemp = "";
|
printerData.toolTemp = "";
|
||||||
|
|
@ -202,7 +199,7 @@ let total_time = pstats.print_duration / vsd.progress;
|
||||||
let eta = total_time - pstats.print_duration; */
|
let eta = total_time - pstats.print_duration; */
|
||||||
|
|
||||||
|
|
||||||
if (isOperational()) {
|
if (BasePrinterClientImpl::isOperational()) {
|
||||||
this->debugController->printLn("Status: " + printerData.state);
|
this->debugController->printLn("Status: " + printerData.state);
|
||||||
} else {
|
} else {
|
||||||
this->debugController->printLn("Printer Not Operational");
|
this->debugController->printLn("Printer Not Operational");
|
||||||
|
|
@ -240,14 +237,14 @@ let eta = total_time - pstats.print_duration; */
|
||||||
printerData.bedTargetTemp = (int)jsonBuffer["result"]["status"]["heater_bed"]["target"];
|
printerData.bedTargetTemp = (int)jsonBuffer["result"]["status"]["heater_bed"]["target"];
|
||||||
printerData.fileSize = (long)jsonBuffer["result"]["size"];
|
printerData.fileSize = (long)jsonBuffer["result"]["size"];
|
||||||
|
|
||||||
if (isPrinting()) {
|
if (BasePrinterClientImpl::isPrinting()) {
|
||||||
this->debugController->printLn("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)");
|
this->debugController->printLn("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DuetClient::getPrinterPsuState() {
|
void DuetClient::getPrinterPsuState() {
|
||||||
//**** get the PSU state (if enabled and printer operational)
|
//**** get the PSU state (if enabled and printer operational)
|
||||||
if (pollPsu && isOperational()) {
|
if (pollPsu && BasePrinterClientImpl::isOperational()) {
|
||||||
if (!validate()) {
|
if (!validate()) {
|
||||||
printerData.isPSUoff = false; // we do not know PSU state, so assume on.
|
printerData.isPSUoff = false; // we do not know PSU state, so assume on.
|
||||||
return;
|
return;
|
||||||
|
|
@ -280,131 +277,3 @@ void DuetClient::getPrinterPsuState() {
|
||||||
printerData.isPSUoff = false; // we are not checking PSU state, so assume on
|
printerData.isPSUoff = false; // we are not checking PSU state, so assume on
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset all PrinterData
|
|
||||||
void DuetClient::resetPrintData() {
|
|
||||||
printerData.averagePrintTime = "";
|
|
||||||
printerData.estimatedPrintTime = "";
|
|
||||||
printerData.fileName = "";
|
|
||||||
printerData.fileSize = "";
|
|
||||||
printerData.lastPrintTime = "";
|
|
||||||
printerData.progressCompletion = "";
|
|
||||||
printerData.progressFilepos = "";
|
|
||||||
printerData.progressPrintTime = "";
|
|
||||||
printerData.progressPrintTimeLeft = "";
|
|
||||||
printerData.state = "";
|
|
||||||
printerData.toolTemp = "";
|
|
||||||
printerData.toolTargetTemp = "";
|
|
||||||
printerData.filamentLength = "";
|
|
||||||
printerData.bedTemp = "";
|
|
||||||
printerData.bedTargetTemp = "";
|
|
||||||
printerData.isPrinting = false;
|
|
||||||
printerData.isPSUoff = false;
|
|
||||||
printerData.error = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getAveragePrintTime(){
|
|
||||||
return printerData.averagePrintTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getEstimatedPrintTime() {
|
|
||||||
return printerData.estimatedPrintTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getFileName() {
|
|
||||||
return printerData.fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getFileSize() {
|
|
||||||
return printerData.fileSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getLastPrintTime(){
|
|
||||||
return printerData.lastPrintTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getProgressCompletion() {
|
|
||||||
return String(printerData.progressCompletion.toInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getProgressFilepos() {
|
|
||||||
return printerData.progressFilepos;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getProgressPrintTime() {
|
|
||||||
return printerData.progressPrintTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getProgressPrintTimeLeft() {
|
|
||||||
String rtnValue = printerData.progressPrintTimeLeft;
|
|
||||||
if (getProgressCompletion() == "100") {
|
|
||||||
rtnValue = "0"; // Print is done so this should be 0 this is a fix for Duet
|
|
||||||
}
|
|
||||||
return rtnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getState() {
|
|
||||||
return printerData.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean DuetClient::isPrinting() {
|
|
||||||
return printerData.isPrinting;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean DuetClient::isPSUoff() {
|
|
||||||
return printerData.isPSUoff;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean DuetClient::isOperational() {
|
|
||||||
boolean operational = false;
|
|
||||||
if (printerData.state == "I" || isPrinting()) {
|
|
||||||
operational = true;
|
|
||||||
}
|
|
||||||
return operational;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getTempBedActual() {
|
|
||||||
return printerData.bedTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getTempBedTarget() {
|
|
||||||
return printerData.bedTargetTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getTempToolActual() {
|
|
||||||
return printerData.toolTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getTempToolTarget() {
|
|
||||||
return printerData.toolTargetTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getFilamentLength() {
|
|
||||||
return printerData.filamentLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getError() {
|
|
||||||
return printerData.error;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getValueRounded(String value) {
|
|
||||||
float f = value.toFloat();
|
|
||||||
int rounded = (int)(f+0.5f);
|
|
||||||
return String(rounded);
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getPrinterType() {
|
|
||||||
return printerType;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DuetClient::getPrinterPort() {
|
|
||||||
return myPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DuetClient::getPrinterName() {
|
|
||||||
return printerData.printerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DuetClient::setPrinterName(String printer) {
|
|
||||||
printerData.printerName = printer;
|
|
||||||
}
|
|
||||||
|
|
@ -3,79 +3,24 @@
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <base64.h>
|
#include <base64.h>
|
||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
#include "BasePrinterClient.h"
|
#include "BasePrinterClientImpl.h"
|
||||||
#include "../Global/GlobalDataController.h"
|
|
||||||
|
|
||||||
class DuetClient : public BasePrinterClient {
|
class DuetClient : public BasePrinterClientImpl {
|
||||||
private:
|
private:
|
||||||
char myServer[100];
|
|
||||||
int myPort = 80;
|
|
||||||
String myApiKey = "";
|
String myApiKey = "";
|
||||||
String encodedAuth = "";
|
String encodedAuth = "";
|
||||||
boolean pollPsu;
|
boolean pollPsu;
|
||||||
const String printerType = "Duet";
|
|
||||||
|
|
||||||
void resetPrintData();
|
|
||||||
boolean validate();
|
boolean validate();
|
||||||
WiFiClient getSubmitRequest(String apiGetData);
|
WiFiClient getSubmitRequest(String apiGetData);
|
||||||
WiFiClient getPostRequest(String apiPostData, String apiPostBody);
|
WiFiClient getPostRequest(String apiPostData, String apiPostBody);
|
||||||
|
|
||||||
String result;
|
String result;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
String averagePrintTime;
|
|
||||||
String estimatedPrintTime;
|
|
||||||
String fileName;
|
|
||||||
String fileSize;
|
|
||||||
String lastPrintTime;
|
|
||||||
String progressCompletion;
|
|
||||||
String progressFilepos;
|
|
||||||
String progressPrintTime;
|
|
||||||
String progressPrintTimeLeft;
|
|
||||||
String state;
|
|
||||||
String toolTemp;
|
|
||||||
String toolTargetTemp;
|
|
||||||
String filamentLength;
|
|
||||||
String bedTemp;
|
|
||||||
String bedTargetTemp;
|
|
||||||
boolean isPrinting;
|
|
||||||
boolean isPSUoff;
|
|
||||||
String error;
|
|
||||||
String printerName;
|
|
||||||
} PrinterStruct;
|
|
||||||
|
|
||||||
PrinterStruct printerData;
|
|
||||||
GlobalDataController *globalDataController;
|
|
||||||
DebugController *debugController;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DuetClient(GlobalDataController *globalDataController, DebugController *debugController);
|
DuetClient(GlobalDataController *globalDataController, DebugController *debugController);
|
||||||
void getPrinterJobResults();
|
|
||||||
void getPrinterPsuState();
|
|
||||||
void updatePrintClient();
|
|
||||||
|
|
||||||
String getAveragePrintTime();
|
void getPrinterJobResults() override;
|
||||||
String getEstimatedPrintTime();
|
void getPrinterPsuState() override;
|
||||||
String getFileName();
|
void updatePrintClient() override;
|
||||||
String getFileSize();
|
|
||||||
String getLastPrintTime();
|
|
||||||
String getProgressCompletion();
|
|
||||||
String getProgressFilepos();
|
|
||||||
String getProgressPrintTime();
|
|
||||||
String getProgressPrintTimeLeft();
|
|
||||||
String getState();
|
|
||||||
boolean isPrinting();
|
|
||||||
boolean isOperational();
|
|
||||||
boolean isPSUoff();
|
|
||||||
String getTempBedActual();
|
|
||||||
String getTempBedTarget();
|
|
||||||
String getTempToolActual();
|
|
||||||
String getTempToolTarget();
|
|
||||||
String getFilamentLength();
|
|
||||||
String getValueRounded(String value);
|
|
||||||
String getError();
|
|
||||||
String getPrinterType();
|
|
||||||
int getPrinterPort();
|
|
||||||
String getPrinterName();
|
|
||||||
void setPrinterName(String printer);
|
|
||||||
};
|
};
|
||||||
|
|
@ -3,16 +3,12 @@
|
||||||
|
|
||||||
#include "KlipperClient.h"
|
#include "KlipperClient.h"
|
||||||
|
|
||||||
KlipperClient::KlipperClient(GlobalDataController *globalDataController, DebugController *debugController) {
|
KlipperClient::KlipperClient(GlobalDataController *globalDataController, DebugController *debugController)
|
||||||
this->globalDataController = globalDataController;
|
: BasePrinterClientImpl("Klipper", globalDataController, debugController) {
|
||||||
this->debugController = debugController;
|
|
||||||
this->updatePrintClient();
|
this->updatePrintClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KlipperClient::updatePrintClient() {
|
void KlipperClient::updatePrintClient() {
|
||||||
this->globalDataController->getPrinterHostName().toCharArray(this->myServer, 100);
|
|
||||||
this->globalDataController->getPrinterServer().toCharArray(this->myServerIp, 30);
|
|
||||||
this->myPort = this->globalDataController->getPrinterPort();
|
|
||||||
encodedAuth = "";
|
encodedAuth = "";
|
||||||
if (this->globalDataController->getPrinterAuthUser() != "") {
|
if (this->globalDataController->getPrinterAuthUser() != "") {
|
||||||
String userpass = this->globalDataController->getPrinterAuthUser() + ":" + this->globalDataController->getPrinterAuthPass();
|
String userpass = this->globalDataController->getPrinterAuthUser() + ":" + this->globalDataController->getPrinterAuthPass();
|
||||||
|
|
@ -25,7 +21,7 @@ void KlipperClient::updatePrintClient() {
|
||||||
boolean KlipperClient::validate() {
|
boolean KlipperClient::validate() {
|
||||||
boolean rtnValue = false;
|
boolean rtnValue = false;
|
||||||
printerData.error = "";
|
printerData.error = "";
|
||||||
if ((String(this->myServer) == "") && (String(this->myServerIp) == "")) {
|
if ((this->globalDataController->getPrinterServer() == "") && (this->globalDataController->getPrinterHostName() == "")) {
|
||||||
printerData.error += "Server address or host name is required; ";
|
printerData.error += "Server address or host name is required; ";
|
||||||
}
|
}
|
||||||
if (printerData.error == "") {
|
if (printerData.error == "") {
|
||||||
|
|
@ -37,17 +33,17 @@ boolean KlipperClient::validate() {
|
||||||
WiFiClient KlipperClient::getSubmitRequest(String apiGetData) {
|
WiFiClient KlipperClient::getSubmitRequest(String apiGetData) {
|
||||||
WiFiClient printClient;
|
WiFiClient printClient;
|
||||||
printClient.setTimeout(5000);
|
printClient.setTimeout(5000);
|
||||||
const char *targetServer = this->myServerIp;
|
String targetServer = this->globalDataController->getPrinterServer();
|
||||||
if (String(this->myServerIp) == "") {
|
if (this->globalDataController->getPrinterServer() == "") {
|
||||||
targetServer = this->myServer;
|
targetServer = this->globalDataController->getPrinterHostName();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->debugController->printLn("Getting Klipper Data via GET");
|
this->debugController->printLn("Getting Klipper Data via GET");
|
||||||
this->debugController->printLn(apiGetData);
|
this->debugController->printLn(apiGetData);
|
||||||
result = "";
|
result = "";
|
||||||
if (printClient.connect(targetServer, myPort)) { //starts client connection, checks for connection
|
if (printClient.connect(targetServer, this->globalDataController->getPrinterPort())) { //starts client connection, checks for connection
|
||||||
printClient.println(apiGetData);
|
printClient.println(apiGetData);
|
||||||
printClient.println("Host: " + String(targetServer) + ":" + String(myPort));
|
printClient.println("Host: " + String(targetServer) + ":" + this->globalDataController->getPrinterPort());
|
||||||
if (encodedAuth != "") {
|
if (encodedAuth != "") {
|
||||||
printClient.print("Authorization: ");
|
printClient.print("Authorization: ");
|
||||||
printClient.println("Basic " + encodedAuth);
|
printClient.println("Basic " + encodedAuth);
|
||||||
|
|
@ -55,18 +51,18 @@ WiFiClient KlipperClient::getSubmitRequest(String apiGetData) {
|
||||||
printClient.println("User-Agent: ArduinoWiFi/1.1");
|
printClient.println("User-Agent: ArduinoWiFi/1.1");
|
||||||
printClient.println("Connection: close");
|
printClient.println("Connection: close");
|
||||||
if (printClient.println() == 0) {
|
if (printClient.println() == 0) {
|
||||||
this->debugController->printLn("Connection to " + String(targetServer) + ":" + String(myPort) + " failed.");
|
this->debugController->printLn("Connection to " + targetServer + ":" + String(this->globalDataController->getPrinterPort()) + " failed.");
|
||||||
this->debugController->printLn("");
|
this->debugController->printLn("");
|
||||||
resetPrintData();
|
resetPrintData();
|
||||||
printerData.error = "Connection to " + String(targetServer) + ":" + String(myPort) + " failed.";
|
printerData.error = "Connection to " + targetServer + ":" + String(this->globalDataController->getPrinterPort()) + " failed.";
|
||||||
return printClient;
|
return printClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->debugController->printLn("Connection to Klipper failed: " + String(targetServer) + ":" + String(myPort)); //error message if no client connect
|
this->debugController->printLn("Connection to Klipper failed: " + targetServer + ":" + String(this->globalDataController->getPrinterPort())); //error message if no client connect
|
||||||
this->debugController->printLn("");
|
this->debugController->printLn("");
|
||||||
resetPrintData();
|
resetPrintData();
|
||||||
printerData.error = "Connection to Klipper failed: " + String(targetServer) + ":" + String(myPort);
|
printerData.error = "Connection to Klipper failed: " + targetServer + ":" + String(this->globalDataController->getPrinterPort());
|
||||||
return printClient;
|
return printClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,7 +81,7 @@ WiFiClient KlipperClient::getSubmitRequest(String apiGetData) {
|
||||||
char endOfHeaders[] = "\r\n\r\n";
|
char endOfHeaders[] = "\r\n\r\n";
|
||||||
if (!printClient.find(endOfHeaders)) {
|
if (!printClient.find(endOfHeaders)) {
|
||||||
this->debugController->printLn("Invalid response");
|
this->debugController->printLn("Invalid response");
|
||||||
printerData.error = "Invalid response from " + String(targetServer) + ":" + String(myPort);
|
printerData.error = "Invalid response from " + targetServer + ":" + String(this->globalDataController->getPrinterPort());
|
||||||
printerData.state = "";
|
printerData.state = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,17 +91,17 @@ WiFiClient KlipperClient::getSubmitRequest(String apiGetData) {
|
||||||
WiFiClient KlipperClient::getPostRequest(String apiPostData, String apiPostBody) {
|
WiFiClient KlipperClient::getPostRequest(String apiPostData, String apiPostBody) {
|
||||||
WiFiClient printClient;
|
WiFiClient printClient;
|
||||||
printClient.setTimeout(5000);
|
printClient.setTimeout(5000);
|
||||||
const char *targetServer = this->myServerIp;
|
String targetServer = this->globalDataController->getPrinterServer();
|
||||||
if (String(this->myServerIp) == "") {
|
if (this->globalDataController->getPrinterServer() == "") {
|
||||||
targetServer = this->myServer;
|
targetServer = this->globalDataController->getPrinterHostName();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->debugController->printLn("Getting Klipper Data via POST");
|
this->debugController->printLn("Getting Klipper Data via POST");
|
||||||
this->debugController->printLn(apiPostData + " | " + apiPostBody);
|
this->debugController->printLn(apiPostData + " | " + apiPostBody);
|
||||||
result = "";
|
result = "";
|
||||||
if (printClient.connect(targetServer, myPort)) { //starts client connection, checks for connection
|
if (printClient.connect(targetServer, this->globalDataController->getPrinterPort())) { //starts client connection, checks for connection
|
||||||
printClient.println(apiPostData);
|
printClient.println(apiPostData);
|
||||||
printClient.println("Host: " + String(targetServer) + ":" + String(myPort));
|
printClient.println("Host: " + targetServer + ":" + String(this->globalDataController->getPrinterPort()));
|
||||||
printClient.println("Connection: close");
|
printClient.println("Connection: close");
|
||||||
if (encodedAuth != "") {
|
if (encodedAuth != "") {
|
||||||
printClient.print("Authorization: ");
|
printClient.print("Authorization: ");
|
||||||
|
|
@ -118,18 +114,18 @@ WiFiClient KlipperClient::getPostRequest(String apiPostData, String apiPostBody)
|
||||||
printClient.println();
|
printClient.println();
|
||||||
printClient.println(apiPostBody);
|
printClient.println(apiPostBody);
|
||||||
if (printClient.println() == 0) {
|
if (printClient.println() == 0) {
|
||||||
this->debugController->printLn("Connection to " + String(targetServer) + ":" + String(myPort) + " failed.");
|
this->debugController->printLn("Connection to " + targetServer + ":" + String(this->globalDataController->getPrinterPort()) + " failed.");
|
||||||
this->debugController->printLn("");
|
this->debugController->printLn("");
|
||||||
resetPrintData();
|
resetPrintData();
|
||||||
printerData.error = "Connection to " + String(targetServer) + ":" + String(myPort) + " failed.";
|
printerData.error = "Connection to " + targetServer + ":" + String(this->globalDataController->getPrinterPort()) + " failed.";
|
||||||
return printClient;
|
return printClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->debugController->printLn("Connection to Klipper failed: " + String(targetServer) + ":" + String(myPort)); //error message if no client connect
|
this->debugController->printLn("Connection to Klipper failed: " + targetServer + ":" + String(this->globalDataController->getPrinterPort())); //error message if no client connect
|
||||||
this->debugController->printLn("");
|
this->debugController->printLn("");
|
||||||
resetPrintData();
|
resetPrintData();
|
||||||
printerData.error = "Connection to Klipper failed: " + String(targetServer) + ":" + String(myPort);
|
printerData.error = "Connection to Klipper failed: " + targetServer + ":" + String(this->globalDataController->getPrinterPort());
|
||||||
return printClient;
|
return printClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,7 +144,7 @@ WiFiClient KlipperClient::getPostRequest(String apiPostData, String apiPostBody)
|
||||||
char endOfHeaders[] = "\r\n\r\n";
|
char endOfHeaders[] = "\r\n\r\n";
|
||||||
if (!printClient.find(endOfHeaders)) {
|
if (!printClient.find(endOfHeaders)) {
|
||||||
this->debugController->printLn("Invalid response");
|
this->debugController->printLn("Invalid response");
|
||||||
printerData.error = "Invalid response from " + String(targetServer) + ":" + String(myPort);
|
printerData.error = "Invalid response from " + targetServer + ":" + String(this->globalDataController->getPrinterPort());
|
||||||
printerData.state = "";
|
printerData.state = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,9 +155,9 @@ void KlipperClient::getPrinterJobResults() {
|
||||||
if (!validate()) {
|
if (!validate()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const char *targetServer = this->myServerIp;
|
String targetServer = this->globalDataController->getPrinterServer();
|
||||||
if (String(this->myServerIp) == "") {
|
if (this->globalDataController->getPrinterServer() == "") {
|
||||||
targetServer = this->myServer;
|
targetServer = this->globalDataController->getPrinterHostName();
|
||||||
}
|
}
|
||||||
|
|
||||||
//**** get the Printer Job status
|
//**** get the Printer Job status
|
||||||
|
|
@ -176,8 +172,8 @@ void KlipperClient::getPrinterJobResults() {
|
||||||
// Parse JSON object
|
// Parse JSON object
|
||||||
DeserializationError error = deserializeJson(jsonBuffer, printClient);
|
DeserializationError error = deserializeJson(jsonBuffer, printClient);
|
||||||
if (error) {
|
if (error) {
|
||||||
this->debugController->printLn("Klipper Data Parsing failed: " + String(targetServer) + ":" + String(myPort));
|
this->debugController->printLn("Klipper Data Parsing failed: " + targetServer + ":" + String(this->globalDataController->getPrinterPort()));
|
||||||
printerData.error = "Klipper Data Parsing failed: " + String(targetServer) + ":" + String(myPort);
|
printerData.error = "Klipper Data Parsing failed: " + targetServer + ":" + String(this->globalDataController->getPrinterPort());
|
||||||
printerData.state = "";
|
printerData.state = "";
|
||||||
printerData.isPrinting = false;
|
printerData.isPrinting = false;
|
||||||
printerData.toolTemp = "";
|
printerData.toolTemp = "";
|
||||||
|
|
@ -185,7 +181,6 @@ void KlipperClient::getPrinterJobResults() {
|
||||||
printerData.bedTemp = "";
|
printerData.bedTemp = "";
|
||||||
printerData.bedTargetTemp = (const char*)jsonBuffer["result"]["status"]["heater_bed"]["target"];
|
printerData.bedTargetTemp = (const char*)jsonBuffer["result"]["status"]["heater_bed"]["target"];
|
||||||
return;
|
return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printerData.averagePrintTime = (int)jsonBuffer["result"]["status"]["toolhead"]["averagePrintTime"];
|
printerData.averagePrintTime = (int)jsonBuffer["result"]["status"]["toolhead"]["averagePrintTime"];
|
||||||
|
|
@ -210,7 +205,7 @@ let total_time = pstats.print_duration / vsd.progress;
|
||||||
let eta = total_time - pstats.print_duration; */
|
let eta = total_time - pstats.print_duration; */
|
||||||
|
|
||||||
|
|
||||||
if (isOperational()) {
|
if (BasePrinterClientImpl::isOperational()) {
|
||||||
this->debugController->printLn("Status: " + printerData.state);
|
this->debugController->printLn("Status: " + printerData.state);
|
||||||
} else {
|
} else {
|
||||||
this->debugController->printLn("Printer Not Operational");
|
this->debugController->printLn("Printer Not Operational");
|
||||||
|
|
@ -248,14 +243,14 @@ let eta = total_time - pstats.print_duration; */
|
||||||
printerData.bedTargetTemp = (int)jsonBuffer["result"]["status"]["heater_bed"]["target"];
|
printerData.bedTargetTemp = (int)jsonBuffer["result"]["status"]["heater_bed"]["target"];
|
||||||
printerData.fileSize = (long)jsonBuffer2["result"]["size"];
|
printerData.fileSize = (long)jsonBuffer2["result"]["size"];
|
||||||
|
|
||||||
if (isPrinting()) {
|
if (BasePrinterClientImpl::isOperational()) {
|
||||||
this->debugController->printLn("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)");
|
this->debugController->printLn("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KlipperClient::getPrinterPsuState() {
|
void KlipperClient::getPrinterPsuState() {
|
||||||
//**** get the PSU state (if enabled and printer operational)
|
//**** get the PSU state (if enabled and printer operational)
|
||||||
if (pollPsu && isOperational()) {
|
if (pollPsu && BasePrinterClientImpl::isOperational()) {
|
||||||
if (!validate()) {
|
if (!validate()) {
|
||||||
printerData.isPSUoff = false; // we do not know PSU state, so assume on.
|
printerData.isPSUoff = false; // we do not know PSU state, so assume on.
|
||||||
return;
|
return;
|
||||||
|
|
@ -288,131 +283,3 @@ void KlipperClient::getPrinterPsuState() {
|
||||||
printerData.isPSUoff = false; // we are not checking PSU state, so assume on
|
printerData.isPSUoff = false; // we are not checking PSU state, so assume on
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset all PrinterData
|
|
||||||
void KlipperClient::resetPrintData() {
|
|
||||||
printerData.averagePrintTime = "";
|
|
||||||
printerData.estimatedPrintTime = "";
|
|
||||||
printerData.fileName = "";
|
|
||||||
printerData.fileSize = "";
|
|
||||||
printerData.lastPrintTime = "";
|
|
||||||
printerData.progressCompletion = "";
|
|
||||||
printerData.progressFilepos = "";
|
|
||||||
printerData.progressPrintTime = "";
|
|
||||||
printerData.progressPrintTimeLeft = "";
|
|
||||||
printerData.state = "";
|
|
||||||
printerData.toolTemp = "";
|
|
||||||
printerData.toolTargetTemp = "";
|
|
||||||
printerData.filamentLength = "";
|
|
||||||
printerData.bedTemp = "";
|
|
||||||
printerData.bedTargetTemp = "";
|
|
||||||
printerData.isPrinting = false;
|
|
||||||
printerData.isPSUoff = false;
|
|
||||||
printerData.error = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getAveragePrintTime(){
|
|
||||||
return printerData.averagePrintTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getEstimatedPrintTime() {
|
|
||||||
return printerData.estimatedPrintTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getFileName() {
|
|
||||||
return printerData.fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getFileSize() {
|
|
||||||
return printerData.fileSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getLastPrintTime(){
|
|
||||||
return printerData.lastPrintTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getProgressCompletion() {
|
|
||||||
return String(printerData.progressCompletion.toInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getProgressFilepos() {
|
|
||||||
return printerData.progressFilepos;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getProgressPrintTime() {
|
|
||||||
return printerData.progressPrintTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getProgressPrintTimeLeft() {
|
|
||||||
String rtnValue = printerData.progressPrintTimeLeft;
|
|
||||||
if (getProgressCompletion() == "100") {
|
|
||||||
rtnValue = "0"; // Print is done so this should be 0 this is a fix for Klipper
|
|
||||||
}
|
|
||||||
return rtnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getState() {
|
|
||||||
return printerData.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean KlipperClient::isPrinting() {
|
|
||||||
return printerData.isPrinting;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean KlipperClient::isPSUoff() {
|
|
||||||
return printerData.isPSUoff;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean KlipperClient::isOperational() {
|
|
||||||
boolean operational = false;
|
|
||||||
if (printerData.state == "standby" || isPrinting()) {
|
|
||||||
operational = true;
|
|
||||||
}
|
|
||||||
return operational;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getTempBedActual() {
|
|
||||||
return printerData.bedTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getTempBedTarget() {
|
|
||||||
return printerData.bedTargetTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getTempToolActual() {
|
|
||||||
return printerData.toolTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getTempToolTarget() {
|
|
||||||
return printerData.toolTargetTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getFilamentLength() {
|
|
||||||
return printerData.filamentLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getError() {
|
|
||||||
return printerData.error;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getValueRounded(String value) {
|
|
||||||
float f = value.toFloat();
|
|
||||||
int rounded = (int)(f+0.5f);
|
|
||||||
return String(rounded);
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getPrinterType() {
|
|
||||||
return printerType;
|
|
||||||
}
|
|
||||||
|
|
||||||
int KlipperClient::getPrinterPort() {
|
|
||||||
return myPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
String KlipperClient::getPrinterName() {
|
|
||||||
return printerData.printerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void KlipperClient::setPrinterName(String printer) {
|
|
||||||
printerData.printerName = printer;
|
|
||||||
}
|
|
||||||
|
|
@ -3,79 +3,24 @@
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <base64.h>
|
#include <base64.h>
|
||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
#include "BasePrinterClient.h"
|
#include "BasePrinterClientImpl.h"
|
||||||
#include "../Global/GlobalDataController.h"
|
#include "../Global/GlobalDataController.h"
|
||||||
|
|
||||||
class KlipperClient : public BasePrinterClient {
|
class KlipperClient : public BasePrinterClientImpl {
|
||||||
private:
|
private:
|
||||||
char myServer[100];
|
|
||||||
char myServerIp[30];
|
|
||||||
int myPort = 7125;
|
|
||||||
String encodedAuth = "";
|
String encodedAuth = "";
|
||||||
boolean pollPsu;
|
boolean pollPsu;
|
||||||
const String printerType = "Klipper";
|
|
||||||
|
|
||||||
void resetPrintData();
|
|
||||||
boolean validate();
|
boolean validate();
|
||||||
WiFiClient getSubmitRequest(String apiGetData);
|
WiFiClient getSubmitRequest(String apiGetData);
|
||||||
WiFiClient getPostRequest(String apiPostData, String apiPostBody);
|
WiFiClient getPostRequest(String apiPostData, String apiPostBody);
|
||||||
|
|
||||||
String result;
|
String result;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
String averagePrintTime;
|
|
||||||
String estimatedPrintTime;
|
|
||||||
String fileName;
|
|
||||||
String fileSize;
|
|
||||||
String lastPrintTime;
|
|
||||||
String progressCompletion;
|
|
||||||
String progressFilepos;
|
|
||||||
String progressPrintTime;
|
|
||||||
String progressPrintTimeLeft;
|
|
||||||
String state;
|
|
||||||
String toolTemp;
|
|
||||||
String toolTargetTemp;
|
|
||||||
String filamentLength;
|
|
||||||
String bedTemp;
|
|
||||||
String bedTargetTemp;
|
|
||||||
boolean isPrinting;
|
|
||||||
boolean isPSUoff;
|
|
||||||
String error;
|
|
||||||
String printerName;
|
|
||||||
} PrinterStruct;
|
|
||||||
|
|
||||||
PrinterStruct printerData;
|
|
||||||
GlobalDataController *globalDataController;
|
|
||||||
DebugController *debugController;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KlipperClient(GlobalDataController *globalDataController, DebugController *debugController);
|
KlipperClient(GlobalDataController *globalDataController, DebugController *debugController);
|
||||||
void getPrinterJobResults();
|
|
||||||
void getPrinterPsuState();
|
|
||||||
void updatePrintClient();
|
|
||||||
|
|
||||||
String getAveragePrintTime();
|
void getPrinterJobResults() override;
|
||||||
String getEstimatedPrintTime();
|
void getPrinterPsuState() override;
|
||||||
String getFileName();
|
void updatePrintClient() override;
|
||||||
String getFileSize();
|
|
||||||
String getLastPrintTime();
|
|
||||||
String getProgressCompletion();
|
|
||||||
String getProgressFilepos();
|
|
||||||
String getProgressPrintTime();
|
|
||||||
String getProgressPrintTimeLeft();
|
|
||||||
String getState();
|
|
||||||
boolean isPrinting();
|
|
||||||
boolean isOperational();
|
|
||||||
boolean isPSUoff();
|
|
||||||
String getTempBedActual();
|
|
||||||
String getTempBedTarget();
|
|
||||||
String getTempToolActual();
|
|
||||||
String getTempToolTarget();
|
|
||||||
String getFilamentLength();
|
|
||||||
String getValueRounded(String value);
|
|
||||||
String getError();
|
|
||||||
String getPrinterType();
|
|
||||||
int getPrinterPort();
|
|
||||||
String getPrinterName();
|
|
||||||
void setPrinterName(String printer);
|
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue