浏览代码

Implement custom delay/millis for EXTENSIBLE_UI (#12188)

Marcio Teixeira 6 年前
父节点
当前提交
fc31da1114
共有 4 个文件被更改,包括 116 次插入6 次删除
  1. 1
    3
      Marlin/src/Marlin.cpp
  2. 89
    3
      Marlin/src/lcd/extensible_ui/ui_api.cpp
  3. 25
    0
      Marlin/src/lcd/extensible_ui/ui_api.h
  4. 1
    0
      Marlin/src/lcd/ultralcd.h

+ 1
- 3
Marlin/src/Marlin.cpp 查看文件

617
   SERIAL_ERROR_START();
617
   SERIAL_ERROR_START();
618
   SERIAL_ERRORLNPGM(MSG_ERR_KILLED);
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
     kill_screen(lcd_msg ? lcd_msg : PSTR(MSG_KILLED));
621
     kill_screen(lcd_msg ? lcd_msg : PSTR(MSG_KILLED));
624
   #else
622
   #else
625
     UNUSED(lcd_msg);
623
     UNUSED(lcd_msg);

+ 89
- 3
Marlin/src/lcd/extensible_ui/ui_api.cpp 查看文件

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
  * ui_api.cpp *
24
  * ui_api.cpp *
3
  **************/
25
  **************/
29
 #include "../../module/probe.h"
51
 #include "../../module/probe.h"
30
 #include "../../module/temperature.h"
52
 #include "../../module/temperature.h"
31
 #include "../../libs/duration_t.h"
53
 #include "../../libs/duration_t.h"
54
+#include "../../HAL/shared/Delay.h"
32
 
55
 
33
 #if DO_SWITCH_EXTRUDER || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER)
56
 #if DO_SWITCH_EXTRUDER || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER)
34
   #include "../../module/tool_change.h"
57
   #include "../../module/tool_change.h"
64
   return MAX(MIN(value, maximum), minimum);
87
   return MAX(MIN(value, maximum), minimum);
65
 }
88
 }
66
 
89
 
90
+static bool printer_killed = false;
91
+
67
 namespace UI {
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
   void delay_ms(unsigned long ms) {
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
   void yield() {
151
   void yield() {
74
-    thermalManager.manage_heater();
152
+    if (!printer_killed)
153
+      thermalManager.manage_heater();
75
   }
154
   }
76
 
155
 
77
   float getActualTemp_celsius(const uint8_t extruder) {
156
   float getActualTemp_celsius(const uint8_t extruder) {
491
   }
570
   }
492
 
571
 
493
   const char* FileList::filename() {
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
   const char* FileList::shortFilename() {
576
   const char* FileList::shortFilename() {
603
   UI::onStatusChanged(buff);
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
 #endif // EXTENSIBLE_UI
692
 #endif // EXTENSIBLE_UI

+ 25
- 0
Marlin/src/lcd/extensible_ui/ui_api.h 查看文件

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
  * ui_api.h *
24
  * ui_api.h *
3
  ************/
25
  ************/
127
     #endif
149
     #endif
128
   #endif
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
   void delay_ms(unsigned long ms);
155
   void delay_ms(unsigned long ms);
131
   void yield(); // Within lengthy loop, call this periodically
156
   void yield(); // Within lengthy loop, call this periodically
132
 
157
 

+ 1
- 0
Marlin/src/lcd/ultralcd.h 查看文件

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

正在加载...
取消
保存