ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
recovery_service.cpp
Go to the documentation of this file.
1 /*
2  recovery.cpp - recovery functions class
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library 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 GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #include "../../include/esp3d_config.h"
22 #ifdef RECOVERY_FEATURE
23 #include "recovery_service.h"
24 #include "../../core/settings_esp3d.h"
25 #include "../../core/esp3doutput.h"
27 
28 #ifdef PIN_RESET_FEATURE
29 #include "../../core/esp3d.h"
30 volatile bool interruptswitch =false;
31 #ifdef ARDUINO_ARCH_ESP32
32 portMUX_TYPE espmux = portMUX_INITIALIZER_UNLOCKED;
33 #endif //ARDUINO_ARCH_ESP32
34 
35 #ifdef ARDUINO_ARCH_ESP8266
36 void handlePinResetInterrupt()
37 {
38 #endif //ARDUINO_ARCH_ESP8266
39 #ifdef ARDUINO_ARCH_ESP32
40  void IRAM_ATTR handlePinResetInterrupt() {
41  portENTER_CRITICAL_ISR(&espmux);
42 #endif //ARDUINO_ARCH_ESP32
43  interruptswitch = true;
44 #ifdef ARDUINO_ARCH_ESP32
45  portEXIT_CRITICAL_ISR(&espmux);
46 #endif //ARDUINO_ARCH_ESP32
47  }
48 #endif //PIN_RESET_FEATURE
49 
51  _started = false;
52  }
54  end();
55  }
56 
57  bool RecoveryService::begin() {
58  bool res = true;
59  end();
60 #ifdef PIN_RESET_FEATURE
61  pinMode(ESP3D_RESET_PIN, INPUT_PULLUP);
62  attachInterrupt(digitalPinToInterrupt(ESP3D_RESET_PIN), handlePinResetInterrupt, FALLING);
63 #endif //PIN_RESET_FEATURE
64  if (!res) {
65  end();
66  }
67  _started = res;
68  return _started;
69  }
70 
71 
72  void RecoveryService::end() {
73  if(!_started) {
74  return;
75  }
76 #ifdef PIN_RESET_FEATURE
77  detachInterrupt(digitalPinToInterrupt(ESP3D_RESET_PIN));
78 #endif //PIN_RESET_FEATURE
79  _started = false;
80  }
81 
82 
84  return _started;
85  }
86 
88  if (_started) {
89 #ifdef PIN_RESET_FEATURE
90  if (interruptswitch) {
91  static uint32_t lastreset = 0;
92  interruptswitch = false;
93  if ((millis() - lastreset) > 1000) {
94  lastreset = millis();
96  output.printMSG("Reset requested");
97  Esp3D::reset();
98  }
99  }
100 #endif //PIN_RESET_FEATURE
101  }
102  }
103 
104 #endif //RECOVERY_FEATURE
RecoveryService
Definition: recovery_service.h:26
RecoveryService::handle
void handle()
RecoveryService::begin
bool begin()
Esp3D::reset
static bool reset()
Definition: esp3d.cpp:154
RecoveryService::~RecoveryService
~RecoveryService()
RecoveryService::started
bool started()
recovery_service.h
recovery_service
RecoveryService recovery_service
ESP_ALL_CLIENTS
#define ESP_ALL_CLIENTS
Definition: esp3doutput.h:30
RecoveryService::end
void end()
RecoveryService::RecoveryService
RecoveryService()
ESP3DOutput
Definition: esp3doutput.h:48