Skip to content

Commit

Permalink
Fix bed temp set, start octoprint impl
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Nov 16, 2024
1 parent 1278105 commit 1b0ca80
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 61 deletions.
4 changes: 4 additions & 0 deletions CYD-Klipper/src/core/data_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "klipper/klipper_printer_integration.hpp"
#include "klipper-serial/serial_klipper_printer_integration.hpp"
#include "bambu/bambu_printer_integration.hpp"
#include "octoprint/octoprint_printer_integration.hpp"

SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore;
const long data_update_interval = 780;
Expand Down Expand Up @@ -126,6 +127,9 @@ void data_setup()
case PrinterType::PrinterTypeKlipperSerial:
available_printers[count++] = new SerialKlipperPrinter(i);
break;
case PrinterType::PrinterTypeOctoprint:
available_printers[count++] = new OctoPrinter(i);
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
#include <UrlEncode.h>
#include "../../ui/serial/serial_console.h"

enum HttpRequestType
{
HttpPost,
HttpGet
};

void clear_serial_buffer()
{
while (Serial.available())
Expand Down
157 changes: 157 additions & 0 deletions CYD-Klipper/src/core/octoprint/octoprint_printer_integration.cpp
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 CYD-Klipper/src/core/octoprint/octoprint_printer_integration.hpp
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);
3 changes: 3 additions & 0 deletions CYD-Klipper/src/core/octoprint/octoprint_printer_parsers.cpp
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>
6 changes: 6 additions & 0 deletions CYD-Klipper/src/core/printer_integration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ typedef struct {
unsigned char* png;
} Thumbnail;

enum HttpRequestType
{
HttpPost,
HttpGet
};

class BasePrinter
{
protected:
Expand Down
Loading

0 comments on commit 1b0ca80

Please sign in to comment.