ESPHomeMarlin2/marlin2.h

60 lines
1.8 KiB
C
Raw Normal View History

2024-12-27 10:47:42 +00:00
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/uart/uart.h"
2024-12-30 08:42:31 +00:00
#ifdef USE_SENSOR
#include "esphome/components/sensor/sensor.h"
#endif
#ifdef USE_TEXT_SENSOR
#include "esphome/components/text_sensor/text_sensor.h"
#endif
2024-12-27 10:47:42 +00:00
namespace esphome {
2024-12-30 09:39:19 +00:00
class Marlin2 : public PollingComponent, public uart::UARTDevice {
2024-12-27 10:47:42 +00:00
public:
2024-12-30 08:42:31 +00:00
Marlin2() = default;
2024-12-30 09:39:19 +00:00
2024-12-30 08:42:31 +00:00
#ifdef USE_SENSOR
void add_sensor(const std::string& sName, sensor::Sensor *sens);
sensor::Sensor* find_sensor(std::string key);
#endif
#ifdef USE_TEXT_SENSOR
void add_text_sensor(const std::string& sName, text_sensor::TextSensor *tSens);
text_sensor::TextSensor* find_text_sensor(std::string key);
#endif
2024-12-31 07:18:35 +00:00
void set_bed_setpoint();
void set_extruder_setpoint();
2024-12-30 08:42:31 +00:00
2024-12-27 11:21:33 +00:00
float get_setup_priority() const override { return setup_priority::LATE; }
2024-12-30 08:42:31 +00:00
void setup() override;
void update() override;
2024-12-27 21:23:54 +00:00
protected:
std::string MarlinOutput;
2024-12-27 20:41:13 +00:00
std::string MarlinTime;
std::string PrinterState;
2024-12-28 15:57:08 +00:00
float print_progress = 0;
2024-12-30 11:18:21 +00:00
double print_time_offset = 0;
2024-12-30 08:42:31 +00:00
#ifdef USE_SENSOR
std::vector<std::pair<std::string, sensor::Sensor *>> sensors;
#endif
#ifdef USE_TEXT_SENSOR
std::vector<std::pair<std::string, text_sensor::TextSensor *>> text_sensors;
#endif
void process_line();
2024-12-30 11:07:51 +00:00
void set_printer_state(std::string status);
2024-12-30 08:42:31 +00:00
int process_temp_msg(float* ext_temperature, float* ext_set_temperature, float* bed_temperature, float* bed_set_temperature);
float process_progress_msg();
int process_print_time_msg(double* current, double* remaining, float progress);
private:
unsigned long millisProgress=0;
2024-12-27 10:47:42 +00:00
};
} // namespace esphome