From dd7540b8bb0ecf621e63ba58de3765343d956280 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Fri, 27 Dec 2024 12:21:33 +0100 Subject: [PATCH] Small progress Working COmpilation --- __init__.py | 0 marlin2.cpp | 53 ++++++++++++++++++++++++++--------------------------- marlin2.h | 21 ++++++++++----------- sensor.py | 6 ++---- 4 files changed, 38 insertions(+), 42 deletions(-) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/marlin2.cpp b/marlin2.cpp index 1753cde..a84a9f3 100644 --- a/marlin2.cpp +++ b/marlin2.cpp @@ -2,37 +2,36 @@ #include "esphome/core/log.h" namespace esphome { -namespace serial { -static const char *TAG = "serial.marlin2"; +static const char *TAG = "marlin2"; -void Marlin2::loop() { - // while (this->available()) { - // uint8_t c; - // this->read_byte(&c); - - // if (c == '\r') - // continue; - - // if (c == '\n') - // this->parse_values_(); - // else - // this->rx_message_.push_back(c); - // } +void Marlin2::setup() { + this->write_str("\r\n\r\nM155 S10\r\n"); + ESP_LOGV(TAG, "M155 S10"); } -// void Marlin2::parse_values_() { -// std::string s(this->rx_message_.begin(), this->rx_message_.end()); -// ESP_LOGV(TAG, s); -// } +void Marlin2::loop() { + while (this->available()) { + uint8_t c; + this->read_byte(&c); -// void Marlin2::dump_config() { -// ESP_LOGCONFIG("", "Serial CSV Reader"); -// for (auto sens : this->sensors_) { -// ESP_LOGCONFIG(TAG, "Index %d", sens.first); -// LOG_SENSOR(TAG, "", sens.second); -// } -// } + if (c == '\r') + continue; + + if (c == '\n') + this->parse_values_(); + else + this->rx_message_.push_back(c); + } +} + +void Marlin2::parse_values_() { + std::string s(this->rx_message_.begin(), this->rx_message_.end()); + ESP_LOGV(TAG, s); +} + +void Marlin2::dump_config() { + ESP_LOGCONFIG(TAG, "Serial CSV Reader"); +} -} // namespace serial } // namespace esphome \ No newline at end of file diff --git a/marlin2.h b/marlin2.h index 548e84f..258896d 100644 --- a/marlin2.h +++ b/marlin2.h @@ -5,23 +5,22 @@ #include "esphome/components/uart/uart.h" namespace esphome { -namespace serial { class Marlin2 : public Component, public uart::UARTDevice { public: - // float get_setup_priority() const override { return setup_priority::DATA; } + void setup() override; + float get_setup_priority() const override { return setup_priority::LATE; } void loop() override; - // void dump_config() override; + void dump_config() override; - // void add_sensor(int index, sensor::Sensor *sens) { - // this->sensors_.push_back(std::make_pair(index, sens)); - // } + void add_sensor(int index, sensor::Sensor *sens) { + this->sensors_.push_back(std::make_pair(index, sens)); + } - // protected: - // void parse_values_(); - // std::vector rx_message_; - // std::vector> sensors_; + protected: + void parse_values_(); + std::vector rx_message_; + std::vector> sensors_; }; -} // namespace serial } // namespace esphome \ No newline at end of file diff --git a/sensor.py b/sensor.py index 0174d9a..2482952 100644 --- a/sensor.py +++ b/sensor.py @@ -23,8 +23,7 @@ DEPENDENCIES = ['uart'] CONF_BED_TEMPERATURE = "bed_temperature" -marlin_ns = cg.esphome_ns.namespace('marlin2') -Marlin2 = marlin_ns.class_('Marlin2', cg.Component, sensor.Sensor, uart.UARTDevice) +Marlin2 = cg.esphome_ns.class_('Marlin2', cg.Component, sensor.Sensor, uart.UARTDevice) CONFIG_SCHEMA = uart.UART_DEVICE_SCHEMA.extend( { @@ -44,5 +43,4 @@ async def to_code(config): await uart.register_uart_device(var, config) if CONF_BED_TEMPERATURE in config: - sens = await sensor.new_sensor(config[CONF_BED_TEMPERATURE]) - cg.add(var.set_temperature_sensor(sens)) \ No newline at end of file + await sensor.new_sensor(config[CONF_BED_TEMPERATURE])