mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
Move make_ota_backend into the OTA backend
This commit is contained in:
@@ -24,26 +24,6 @@ static constexpr u_int16_t OTA_BLOCK_SIZE = 8192;
|
|||||||
|
|
||||||
OTAESPHomeComponent *global_ota_component = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
OTAESPHomeComponent *global_ota_component = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
|
||||||
std::unique_ptr<ota::OTABackend> make_ota_backend() {
|
|
||||||
#ifdef USE_ARDUINO
|
|
||||||
#ifdef USE_ESP8266
|
|
||||||
return make_unique<ota::ArduinoESP8266OTABackend>();
|
|
||||||
#endif // USE_ESP8266
|
|
||||||
#ifdef USE_ESP32
|
|
||||||
return make_unique<ota::ArduinoESP32OTABackend>();
|
|
||||||
#endif // USE_ESP32
|
|
||||||
#endif // USE_ARDUINO
|
|
||||||
#ifdef USE_ESP_IDF
|
|
||||||
return make_unique<ota::IDFOTABackend>();
|
|
||||||
#endif // USE_ESP_IDF
|
|
||||||
#ifdef USE_RP2040
|
|
||||||
return make_unique<ota::ArduinoRP2040OTABackend>();
|
|
||||||
#endif // USE_RP2040
|
|
||||||
#ifdef USE_LIBRETINY
|
|
||||||
return make_unique<ota::ArduinoLibreTinyOTABackend>();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
OTAESPHomeComponent::OTAESPHomeComponent() { global_ota_component = this; }
|
OTAESPHomeComponent::OTAESPHomeComponent() { global_ota_component = this; }
|
||||||
|
|
||||||
void OTAESPHomeComponent::setup() {
|
void OTAESPHomeComponent::setup() {
|
||||||
@@ -172,7 +152,7 @@ void OTAESPHomeComponent::handle_() {
|
|||||||
buf[1] = USE_OTA_VERSION;
|
buf[1] = USE_OTA_VERSION;
|
||||||
this->writeall_(buf, 2);
|
this->writeall_(buf, 2);
|
||||||
|
|
||||||
backend = make_ota_backend();
|
backend = ota::make_ota_backend();
|
||||||
|
|
||||||
// Read features - 1 byte
|
// Read features - 1 byte
|
||||||
if (!this->readall_(buf, 1)) {
|
if (!this->readall_(buf, 1)) {
|
||||||
|
|||||||
@@ -44,5 +44,7 @@ class OTABackend {
|
|||||||
virtual bool supports_compression() = 0;
|
virtual bool supports_compression() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<ota::OTABackend> make_ota_backend();
|
||||||
|
|
||||||
} // namespace ota
|
} // namespace ota
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ota {
|
namespace ota {
|
||||||
|
|
||||||
|
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoESP32OTABackend>(); }
|
||||||
|
|
||||||
OTAResponseTypes ArduinoESP32OTABackend::begin(size_t image_size) {
|
OTAResponseTypes ArduinoESP32OTABackend::begin(size_t image_size) {
|
||||||
bool ret = Update.begin(image_size, U_FLASH);
|
bool ret = Update.begin(image_size, U_FLASH);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ota {
|
namespace ota {
|
||||||
|
|
||||||
|
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoESP8266OTABackend>(); }
|
||||||
|
|
||||||
OTAResponseTypes ArduinoESP8266OTABackend::begin(size_t image_size) {
|
OTAResponseTypes ArduinoESP8266OTABackend::begin(size_t image_size) {
|
||||||
bool ret = Update.begin(image_size, U_FLASH);
|
bool ret = Update.begin(image_size, U_FLASH);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ota {
|
namespace ota {
|
||||||
|
|
||||||
|
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoLibreTinyOTABackend>(); }
|
||||||
|
|
||||||
OTAResponseTypes ArduinoLibreTinyOTABackend::begin(size_t image_size) {
|
OTAResponseTypes ArduinoLibreTinyOTABackend::begin(size_t image_size) {
|
||||||
bool ret = Update.begin(image_size, U_FLASH);
|
bool ret = Update.begin(image_size, U_FLASH);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ota {
|
namespace ota {
|
||||||
|
|
||||||
|
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoRP2040OTABackend>(); }
|
||||||
|
|
||||||
OTAResponseTypes ArduinoRP2040OTABackend::begin(size_t image_size) {
|
OTAResponseTypes ArduinoRP2040OTABackend::begin(size_t image_size) {
|
||||||
bool ret = Update.begin(image_size, U_FLASH);
|
bool ret = Update.begin(image_size, U_FLASH);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ota {
|
namespace ota {
|
||||||
|
|
||||||
|
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::IDFOTABackend>(); }
|
||||||
|
|
||||||
OTAResponseTypes IDFOTABackend::begin(size_t image_size) {
|
OTAResponseTypes IDFOTABackend::begin(size_t image_size) {
|
||||||
this->partition_ = esp_ota_get_next_update_partition(nullptr);
|
this->partition_ = esp_ota_get_next_update_partition(nullptr);
|
||||||
if (this->partition_ == nullptr) {
|
if (this->partition_ == nullptr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user