Skip to content

Commit

Permalink
feat: add ESP-IDF support (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
sairon authored Aug 2, 2024
1 parent 15729c0 commit db5f576
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 41 deletions.
9 changes: 5 additions & 4 deletions components/nspanel_lovelace/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from esphome import automation
import esphome.config_validation as cv
import esphome.codegen as cg

from esphome.components import mqtt, uart
from esphome.const import (
CONF_ID,
CONF_TRIGGER_ID,
)
from esphome.core import CORE

AUTO_LOAD = ["text_sensor"]
CODEOWNERS = ["@sairon"]
Expand Down Expand Up @@ -60,7 +60,6 @@ def validate_config(config):
)
.extend(uart.UART_DEVICE_SCHEMA)
.extend(cv.COMPONENT_SCHEMA),
cv.only_with_arduino,
validate_config
)

Expand All @@ -82,6 +81,8 @@ async def to_code(config):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [(cg.std_string, "x")], conf)

cg.add_library("WiFiClientSecure", None)
cg.add_library("HTTPClient", None)
if CORE.is_esp32 and CORE.using_arduino:
cg.add_library("WiFiClientSecure", None)
cg.add_library("HTTPClient", None)

cg.add_define("USE_NSPANEL_LOVELACE")
5 changes: 5 additions & 0 deletions components/nspanel_lovelace/nspanel_lovelace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ void NSPanelLovelace::exit_reparse_mode() {

void NSPanelLovelace::set_baud_rate_(int baud_rate) {
// hopefully on NSPanel it should always be an ESP32ArduinoUARTComponent instance
#ifdef USE_ARDUINO
auto *uart = reinterpret_cast<uart::ESP32ArduinoUARTComponent *>(this->parent_);
#endif
#ifdef USE_ESP_IDF
auto *uart = reinterpret_cast<uart::IDFUARTComponent *>(this->parent_);
#endif
uart->set_baud_rate(baud_rate);
uart->setup();
}
Expand Down
23 changes: 16 additions & 7 deletions components/nspanel_lovelace/nspanel_lovelace.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

#include "esphome/components/mqtt/mqtt_client.h"
#include "esphome/components/uart/uart.h"
#include "esphome/components/uart/uart_component_esp32_arduino.h"
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include "esphome/core/defines.h"

#ifdef USE_ARDUINO
#include "esphome/components/uart/uart_component_esp32_arduino.h"
#include <HTTPClient.h>
#endif
#ifdef USE_ESP_IDF
#include "esphome/components/uart/uart_component_esp_idf.h"
#include <esp_http_client.h>
#endif

#ifdef USE_TIME
#include "esphome/components/time/real_time_clock.h"
Expand Down Expand Up @@ -49,11 +55,6 @@ class NSPanelLovelace : public Component, public uart::UARTDevice {

void exit_reparse_mode();

/**
* Set the tft file URL. https seems problamtic with arduino..
*/
void set_tft_url(const std::string &tft_url) { this->tft_url_ = tft_url; }

/**
* Upload the tft file and softreset the Nextion
*/
Expand Down Expand Up @@ -83,7 +84,6 @@ class NSPanelLovelace : public Component, public uart::UARTDevice {
bool is_updating_ = false;
bool reparse_mode_ = false;

std::string tft_url_;
uint8_t *transfer_buffer_{nullptr};
size_t transfer_buffer_size_;
bool upload_first_chunk_sent_ = false;
Expand All @@ -97,7 +97,16 @@ class NSPanelLovelace : public Component, public uart::UARTDevice {
*/
int content_length_ = 0;
int tft_size_ = 0;

#ifdef USE_ARDUINO
void init_upload(HTTPClient *http, const std::string &url);

int upload_by_chunks_(HTTPClient *http, const std::string &url, int range_start);
#elif defined(USE_ESP_IDF)
void init_upload(const std::string &url);

int upload_by_chunks_(const std::string &url, int range_start);
#endif

void upload_end_();
};
Expand Down
Loading

0 comments on commit db5f576

Please sign in to comment.