Pārlūkot izejas kodu

Implement custom delay/millis for EXTENSIBLE_UI (#12188)

Marcio Teixeira 6 gadus atpakaļ
vecāks
revīzija
fc31da1114

+ 1
- 3
Marlin/src/Marlin.cpp Parādīt failu

@@ -617,9 +617,7 @@ void kill(PGM_P const lcd_msg/*=NULL*/) {
617 617
   SERIAL_ERROR_START();
618 618
   SERIAL_ERRORLNPGM(MSG_ERR_KILLED);
619 619
 
620
-  #if ENABLED(EXTENSIBLE_UI)
621
-    UI::onPrinterKilled(lcd_msg ? lcd_msg : PSTR(MSG_KILLED));
622
-  #elif ENABLED(ULTRA_LCD)
620
+  #if ENABLED(ULTRA_LCD) || ENABLED(EXTENSIBLE_UI)
623 621
     kill_screen(lcd_msg ? lcd_msg : PSTR(MSG_KILLED));
624 622
   #else
625 623
     UNUSED(lcd_msg);

+ 89
- 3
Marlin/src/lcd/extensible_ui/ui_api.cpp Parādīt failu

@@ -1,3 +1,25 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
1 23
 /**************
2 24
  * ui_api.cpp *
3 25
  **************/
@@ -29,6 +51,7 @@
29 51
 #include "../../module/probe.h"
30 52
 #include "../../module/temperature.h"
31 53
 #include "../../libs/duration_t.h"
54
+#include "../../HAL/shared/Delay.h"
32 55
 
33 56
 #if DO_SWITCH_EXTRUDER || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER)
34 57
   #include "../../module/tool_change.h"
@@ -64,14 +87,70 @@ inline float clamp(const float value, const float minimum, const float maximum)
64 87
   return MAX(MIN(value, maximum), minimum);
65 88
 }
66 89
 
90
+static bool printer_killed = false;
91
+
67 92
 namespace UI {
93
+  #ifdef __SAM3X8E__
94
+    /**
95
+     * Implement a special millis() to allow time measurement
96
+     * within an ISR (such as when the printer is killed).
97
+     *
98
+     * To keep proper time, must be called at least every 1s.
99
+     */
100
+    uint32_t safe_millis() {
101
+      // Not killed? Just call millis()
102
+      if (!printer_killed) return millis();
103
+
104
+      static uint32_t currTimeHI = 0; /* Current time */
105
+
106
+      // Machine was killed, reinit SysTick so we are able to compute time without ISRs
107
+      if (currTimeHI == 0) {
108
+        // Get the last time the Arduino time computed (from CMSIS) and convert it to SysTick
109
+        currTimeHI = (uint32_t)((GetTickCount() * (uint64_t)(F_CPU/8000)) >> 24);
110
+
111
+        // Reinit the SysTick timer to maximize its period
112
+        SysTick->LOAD  = SysTick_LOAD_RELOAD_Msk;                    // get the full range for the systick timer
113
+        SysTick->VAL   = 0;                                          // Load the SysTick Counter Value
114
+        SysTick->CTRL  = // MCLK/8 as source
115
+                         // No interrupts
116
+                         SysTick_CTRL_ENABLE_Msk;                    // Enable SysTick Timer
117
+     }
118
+
119
+      // Check if there was a timer overflow from the last read
120
+      if (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) {
121
+        // There was. This means (SysTick_LOAD_RELOAD_Msk * 1000 * 8)/F_CPU ms has elapsed
122
+        currTimeHI++;
123
+      }
124
+
125
+      // Calculate current time in milliseconds
126
+      uint32_t currTimeLO = SysTick_LOAD_RELOAD_Msk - SysTick->VAL; // (in MCLK/8)
127
+      uint64_t currTime = ((uint64_t)currTimeLO) | (((uint64_t)currTimeHI) << 24);
128
+
129
+      // The ms count is
130
+      return (uint32_t)(currTime / (F_CPU / 8000));
131
+    }
132
+
133
+  #else
134
+
135
+    // TODO: Implement for AVR
136
+    uint32_t safe_millis() { return millis(); }
137
+
138
+  #endif
139
+
140
+  void delay_us(unsigned long us) {
141
+    DELAY_US(us);
142
+  }
68 143
 
69 144
   void delay_ms(unsigned long ms) {
70
-    safe_delay(ms);
145
+    if (printer_killed)
146
+      DELAY_US(ms * 1000);
147
+    else
148
+      safe_delay(ms);
71 149
   }
72 150
 
73 151
   void yield() {
74
-    thermalManager.manage_heater();
152
+    if (!printer_killed)
153
+      thermalManager.manage_heater();
75 154
   }
76 155
 
77 156
   float getActualTemp_celsius(const uint8_t extruder) {
@@ -491,7 +570,7 @@ namespace UI {
491 570
   }
492 571
 
493 572
   const char* FileList::filename() {
494
-    return IFSD(card.longFilename && card.longFilename[0]) ? card.longFilename : card.filename, "");
573
+    return IFSD(card.longFilename && card.longFilename[0] ? card.longFilename : card.filename, "");
495 574
   }
496 575
 
497 576
   const char* FileList::shortFilename() {
@@ -603,4 +682,11 @@ void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
603 682
   UI::onStatusChanged(buff);
604 683
 }
605 684
 
685
+void kill_screen(PGM_P msg) {
686
+  if (!printer_killed) {
687
+    printer_killed = true;
688
+    UI::onPrinterKilled(msg);
689
+  }
690
+}
691
+
606 692
 #endif // EXTENSIBLE_UI

+ 25
- 0
Marlin/src/lcd/extensible_ui/ui_api.h Parādīt failu

@@ -1,3 +1,25 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
1 23
 /************
2 24
  * ui_api.h *
3 25
  ************/
@@ -127,6 +149,9 @@ namespace UI {
127 149
     #endif
128 150
   #endif
129 151
 
152
+  // This safe_millis is safe to use even when printer is killed (as long as called at least every 1 second)
153
+  uint32_t safe_millis();
154
+  void delay_us(unsigned long us);
130 155
   void delay_ms(unsigned long ms);
131 156
   void yield(); // Within lengthy loop, call this periodically
132 157
 

+ 1
- 0
Marlin/src/lcd/ultralcd.h Parādīt failu

@@ -30,6 +30,7 @@
30 30
   bool lcd_detected();
31 31
   void lcd_update();
32 32
   void lcd_setalertstatusPGM(PGM_P message);
33
+  void kill_screen(PGM_P lcd_msg);
33 34
 #else
34 35
   inline void lcd_init() {}
35 36
   inline bool lcd_detected() { return true; }

Notiek ielāde…
Atcelt
Saglabāt