Skip to content

Commit db5f576

Browse files
authored
feat: add ESP-IDF support (#33)
1 parent 15729c0 commit db5f576

File tree

4 files changed

+224
-41
lines changed

4 files changed

+224
-41
lines changed

components/nspanel_lovelace/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from esphome import automation
22
import esphome.config_validation as cv
33
import esphome.codegen as cg
4-
54
from esphome.components import mqtt, uart
65
from esphome.const import (
76
CONF_ID,
87
CONF_TRIGGER_ID,
98
)
9+
from esphome.core import CORE
1010

1111
AUTO_LOAD = ["text_sensor"]
1212
CODEOWNERS = ["@sairon"]
@@ -60,7 +60,6 @@ def validate_config(config):
6060
)
6161
.extend(uart.UART_DEVICE_SCHEMA)
6262
.extend(cv.COMPONENT_SCHEMA),
63-
cv.only_with_arduino,
6463
validate_config
6564
)
6665

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

85-
cg.add_library("WiFiClientSecure", None)
86-
cg.add_library("HTTPClient", None)
84+
if CORE.is_esp32 and CORE.using_arduino:
85+
cg.add_library("WiFiClientSecure", None)
86+
cg.add_library("HTTPClient", None)
87+
8788
cg.add_define("USE_NSPANEL_LOVELACE")

components/nspanel_lovelace/nspanel_lovelace.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@ void NSPanelLovelace::exit_reparse_mode() {
219219

220220
void NSPanelLovelace::set_baud_rate_(int baud_rate) {
221221
// hopefully on NSPanel it should always be an ESP32ArduinoUARTComponent instance
222+
#ifdef USE_ARDUINO
222223
auto *uart = reinterpret_cast<uart::ESP32ArduinoUARTComponent *>(this->parent_);
224+
#endif
225+
#ifdef USE_ESP_IDF
226+
auto *uart = reinterpret_cast<uart::IDFUARTComponent *>(this->parent_);
227+
#endif
223228
uart->set_baud_rate(baud_rate);
224229
uart->setup();
225230
}

components/nspanel_lovelace/nspanel_lovelace.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44

55
#include "esphome/components/mqtt/mqtt_client.h"
66
#include "esphome/components/uart/uart.h"
7-
#include "esphome/components/uart/uart_component_esp32_arduino.h"
87
#include "esphome/core/automation.h"
98
#include "esphome/core/component.h"
109
#include "esphome/core/defines.h"
1110

11+
#ifdef USE_ARDUINO
12+
#include "esphome/components/uart/uart_component_esp32_arduino.h"
1213
#include <HTTPClient.h>
14+
#endif
15+
#ifdef USE_ESP_IDF
16+
#include "esphome/components/uart/uart_component_esp_idf.h"
17+
#include <esp_http_client.h>
18+
#endif
1319

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

5056
void exit_reparse_mode();
5157

52-
/**
53-
* Set the tft file URL. https seems problamtic with arduino..
54-
*/
55-
void set_tft_url(const std::string &tft_url) { this->tft_url_ = tft_url; }
56-
5758
/**
5859
* Upload the tft file and softreset the Nextion
5960
*/
@@ -83,7 +84,6 @@ class NSPanelLovelace : public Component, public uart::UARTDevice {
8384
bool is_updating_ = false;
8485
bool reparse_mode_ = false;
8586

86-
std::string tft_url_;
8787
uint8_t *transfer_buffer_{nullptr};
8888
size_t transfer_buffer_size_;
8989
bool upload_first_chunk_sent_ = false;
@@ -97,7 +97,16 @@ class NSPanelLovelace : public Component, public uart::UARTDevice {
9797
*/
9898
int content_length_ = 0;
9999
int tft_size_ = 0;
100+
101+
#ifdef USE_ARDUINO
102+
void init_upload(HTTPClient *http, const std::string &url);
103+
100104
int upload_by_chunks_(HTTPClient *http, const std::string &url, int range_start);
105+
#elif defined(USE_ESP_IDF)
106+
void init_upload(const std::string &url);
107+
108+
int upload_by_chunks_(const std::string &url, int range_start);
109+
#endif
101110

102111
void upload_end_();
103112
};

0 commit comments

Comments
 (0)