2017-10-08 18:38:10 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-02-12 22:06:53 +01:00
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-10-08 18:38:10 +02:00
|
|
|
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
|
|
|
|
#include "../../inc/MarlinConfigPre.h"
|
|
|
|
|
2019-03-13 06:48:08 +01:00
|
|
|
#if ENABLED(OTASUPPORT)
|
2017-10-08 18:38:10 +02:00
|
|
|
|
|
|
|
#include <WiFi.h>
|
|
|
|
#include <ESPmDNS.h>
|
|
|
|
#include <WiFiUdp.h>
|
|
|
|
#include <ArduinoOTA.h>
|
|
|
|
#include "driver/timer.h"
|
|
|
|
|
|
|
|
void OTA_init() {
|
|
|
|
ArduinoOTA
|
|
|
|
.onStart([]() {
|
|
|
|
timer_pause(TIMER_GROUP_0, TIMER_0);
|
|
|
|
timer_pause(TIMER_GROUP_0, TIMER_1);
|
|
|
|
|
|
|
|
// U_FLASH or U_SPIFFS
|
|
|
|
String type = (ArduinoOTA.getCommand() == U_FLASH) ? "sketch" : "filesystem";
|
|
|
|
|
|
|
|
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
|
|
|
|
Serial.println("Start updating " + type);
|
|
|
|
})
|
|
|
|
.onEnd([]() {
|
|
|
|
Serial.println("\nEnd");
|
|
|
|
})
|
|
|
|
.onProgress([](unsigned int progress, unsigned int total) {
|
|
|
|
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
|
|
|
})
|
|
|
|
.onError([](ota_error_t error) {
|
|
|
|
Serial.printf("Error[%u]: ", error);
|
|
|
|
char *str;
|
|
|
|
switch (error) {
|
|
|
|
case OTA_AUTH_ERROR: str = "Auth Failed"; break;
|
|
|
|
case OTA_BEGIN_ERROR: str = "Begin Failed"; break;
|
|
|
|
case OTA_CONNECT_ERROR: str = "Connect Failed"; break;
|
|
|
|
case OTA_RECEIVE_ERROR: str = "Receive Failed"; break;
|
|
|
|
case OTA_END_ERROR: str = "End Failed"; break;
|
|
|
|
}
|
|
|
|
Serial.println(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
ArduinoOTA.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OTA_handle() {
|
|
|
|
ArduinoOTA.handle();
|
|
|
|
}
|
|
|
|
|
2019-03-13 06:48:08 +01:00
|
|
|
#endif // OTASUPPORT
|
2017-10-08 18:38:10 +02:00
|
|
|
|
|
|
|
#endif // ARDUINO_ARCH_ESP32
|