-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bed temp set, start octoprint impl
- Loading branch information
1 parent
1278105
commit 1b0ca80
Showing
9 changed files
with
293 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
CYD-Klipper/src/core/octoprint/octoprint_printer_integration.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
#include "octoprint_printer_integration.hpp" | ||
#include "../../conf/global_config.h" | ||
#include <HTTPClient.h> | ||
#include <UrlEncode.h> | ||
#include <ArduinoJson.h> | ||
#include <list> | ||
|
||
void configure_http_client(HTTPClient &client, String url_part, bool stream, int timeout, PrinterConfiguration* printer_config) | ||
{ | ||
client.useHTTP10(stream); | ||
|
||
if (timeout > 0){ | ||
client.setTimeout(timeout); | ||
client.setConnectTimeout(timeout); | ||
} | ||
|
||
client.begin("http://" + String(printer_config->klipper_host) + ":" + String(printer_config->klipper_port) + url_part); | ||
|
||
if (printer_config->auth_configured) { | ||
client.addHeader("X-Api-Key", printer_config->klipper_auth); | ||
} | ||
} | ||
|
||
bool OctoPrinter::make_request(const char* endpoint, HttpRequestType requestType, int timeout_ms, bool stream) | ||
{ | ||
HTTPClient client; | ||
|
||
if (timeout_ms <= 0) | ||
{ | ||
timeout_ms = 500; | ||
} | ||
|
||
configure_http_client(client, endpoint, stream, timeout_ms, printer_config); | ||
int result = client.GET(); | ||
return result >= 200 && result < 300; | ||
} | ||
|
||
bool OctoPrinter::make_request(JsonDocument& doc, const char* endpoint, HttpRequestType requestType, int timeout_ms, bool stream) | ||
{ | ||
HTTPClient client; | ||
|
||
if (timeout_ms <= 0) | ||
{ | ||
timeout_ms = 500; | ||
} | ||
|
||
configure_http_client(client, endpoint, stream, timeout_ms, printer_config); | ||
int result = client.GET(); | ||
|
||
if (result >= 200 && result < 300) | ||
{ | ||
auto result = deserializeJson(doc, client.getStream()); | ||
return result == DeserializationError::Ok; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool OctoPrinter::move_printer(const char* axis, float amount, bool relative) | ||
{ | ||
return false; | ||
} | ||
|
||
bool OctoPrinter::execute_feature(PrinterFeatures feature) | ||
{ | ||
return false; | ||
} | ||
|
||
bool OctoPrinter::connect() | ||
{ | ||
return false; | ||
} | ||
|
||
bool OctoPrinter::fetch() | ||
{ | ||
return false; | ||
} | ||
|
||
PrinterDataMinimal OctoPrinter::fetch_min() | ||
{ | ||
return {}; | ||
} | ||
|
||
void OctoPrinter::disconnect() | ||
{ | ||
|
||
} | ||
|
||
Macros OctoPrinter::get_macros() | ||
{ | ||
return {}; | ||
} | ||
|
||
int OctoPrinter::get_macros_count() | ||
{ | ||
return 0; | ||
} | ||
|
||
bool OctoPrinter::execute_macro(const char* macro) | ||
{ | ||
return false; | ||
} | ||
|
||
PowerDevices OctoPrinter::get_power_devices() | ||
{ | ||
return {}; | ||
} | ||
|
||
int OctoPrinter::get_power_devices_count() | ||
{ | ||
return 0; | ||
} | ||
|
||
bool OctoPrinter::set_power_device_state(const char* device_name, bool state) | ||
{ | ||
return false; | ||
} | ||
|
||
Files OctoPrinter::get_files() | ||
{ | ||
return {}; | ||
} | ||
|
||
bool OctoPrinter::start_file(const char* filename) | ||
{ | ||
return false; | ||
} | ||
|
||
Thumbnail OctoPrinter::get_32_32_png_image_thumbnail(const char* gcode_filename) | ||
{ | ||
return {}; | ||
} | ||
|
||
bool OctoPrinter::set_target_temperature(PrinterTemperatureDevice device, unsigned int temperature) | ||
{ | ||
return false; | ||
} | ||
|
||
OctoConnectionStatus connection_test_octoprint(PrinterConfiguration* config) | ||
{ | ||
HTTPClient client; | ||
configure_http_client(client, "/api/version", false, 1000, config); | ||
|
||
int http_code = client.GET(); | ||
if (http_code == 200) | ||
{ | ||
return OctoConnectionStatus::OctoConnectOk; | ||
} | ||
else if (http_code == 401 || http_code == 403) | ||
{ | ||
return OctoConnectionStatus::OctoConnectKeyFail; | ||
} | ||
else | ||
{ | ||
return OctoConnectionStatus::OctoConnectFail; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
CYD-Klipper/src/core/octoprint/octoprint_printer_integration.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "../printer_integration.hpp" | ||
#include <HTTPClient.h> | ||
#include <ArduinoJson.h> | ||
|
||
class OctoPrinter : public BasePrinter | ||
{ | ||
protected: | ||
bool make_request(const char* endpoint, HttpRequestType requestType = HttpRequestType::HttpGet, int timeout_ms = 1000, bool stream = true); | ||
bool make_request(JsonDocument& doc, const char* endpoint, HttpRequestType requestType = HttpRequestType::HttpGet, int timeout_ms = 1000, bool stream = true); | ||
|
||
public: | ||
OctoPrinter(int index) : BasePrinter(index) | ||
{ | ||
supported_features = PrinterFeatureHome | ||
| PrinterFeatureDisableSteppers | ||
| PrinterFeaturePause | ||
| PrinterFeatureResume | ||
| PrinterFeatureStop | ||
| PrinterFeatureExtrude | ||
| PrinterFeatureRetract | ||
| PrinterFeatureCooldown | ||
| PrinterFeatureRetryError; | ||
|
||
supported_temperature_devices = PrinterTemperatureDeviceBed | ||
| PrinterTemperatureDeviceNozzle1; | ||
|
||
printer_data.error_screen_features = PrinterFeatureRetryError; | ||
} | ||
|
||
bool move_printer(const char* axis, float amount, bool relative); | ||
bool execute_feature(PrinterFeatures feature); | ||
bool connect(); | ||
bool fetch(); | ||
PrinterDataMinimal fetch_min(); | ||
void disconnect(); | ||
|
||
Macros get_macros(); | ||
int get_macros_count(); | ||
bool execute_macro(const char* macro); | ||
|
||
PowerDevices get_power_devices(); | ||
int get_power_devices_count(); | ||
bool set_power_device_state(const char* device_name, bool state); | ||
|
||
Files get_files(); | ||
bool start_file(const char* filename); | ||
|
||
Thumbnail get_32_32_png_image_thumbnail(const char* gcode_filename); | ||
bool set_target_temperature(PrinterTemperatureDevice device, unsigned int temperature); | ||
}; | ||
|
||
enum OctoConnectionStatus { | ||
OctoConnectFail = 0, | ||
OctoConnectOk = 1, | ||
OctoConnectKeyFail = 2, | ||
}; | ||
|
||
OctoConnectionStatus connection_test_octoprint(PrinterConfiguration* config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include "../printer_integration.hpp" | ||
#include "octoprint_printer_integration.hpp" | ||
#include <ArduinoJson.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.