My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ota.cpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #ifdef ARDUINO_ARCH_ESP32
  21. #include "../../inc/MarlinConfigPre.h"
  22. #if BOTH(WIFISUPPORT, OTASUPPORT)
  23. #include <WiFi.h>
  24. #include <ESPmDNS.h>
  25. #include <WiFiUdp.h>
  26. #include <ArduinoOTA.h>
  27. #include <driver/timer.h>
  28. void OTA_init() {
  29. ArduinoOTA
  30. .onStart([]() {
  31. timer_pause(TIMER_GROUP_0, TIMER_0);
  32. timer_pause(TIMER_GROUP_0, TIMER_1);
  33. // U_FLASH or U_SPIFFS
  34. String type = (ArduinoOTA.getCommand() == U_FLASH) ? "sketch" : "filesystem";
  35. // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
  36. Serial.println("Start updating " + type);
  37. })
  38. .onEnd([]() {
  39. Serial.println("\nEnd");
  40. })
  41. .onProgress([](unsigned int progress, unsigned int total) {
  42. Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  43. })
  44. .onError([](ota_error_t error) {
  45. Serial.printf("Error[%u]: ", error);
  46. char *str;
  47. switch (error) {
  48. case OTA_AUTH_ERROR: str = "Auth Failed"; break;
  49. case OTA_BEGIN_ERROR: str = "Begin Failed"; break;
  50. case OTA_CONNECT_ERROR: str = "Connect Failed"; break;
  51. case OTA_RECEIVE_ERROR: str = "Receive Failed"; break;
  52. case OTA_END_ERROR: str = "End Failed"; break;
  53. }
  54. Serial.println(str);
  55. });
  56. ArduinoOTA.begin();
  57. }
  58. void OTA_handle() {
  59. ArduinoOTA.handle();
  60. }
  61. #endif // WIFISUPPORT && OTASUPPORT
  62. #endif // ARDUINO_ARCH_ESP32