Browse Source

More Anycubic + Trigorilla mappings, ExtUI (#18903)

Marco Burato 3 years ago
parent
commit
6bcfb58cd4
No account linked to committer's email address

+ 10
- 6
Marlin/Configuration.h View File

@@ -2137,6 +2137,16 @@
2137 2137
 //#define TOUCH_UI_FTDI_EVE
2138 2138
 
2139 2139
 //
2140
+// Touch-screen LCD for Anycubic printers
2141
+//
2142
+//#define ANYCUBIC_LCD_I3MEGA
2143
+//#define ANYCUBIC_LCD_CHIRON
2144
+#if EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
2145
+  #define ANYCUBIC_LCD_SERIAL_PORT 3
2146
+  //#define ANYCUBIC_LCD_DEBUG
2147
+#endif
2148
+
2149
+//
2140 2150
 // Third-party or vendor-customized controller interfaces.
2141 2151
 // Sources should be installed in 'src/lcd/extensible_ui'.
2142 2152
 //
@@ -2188,12 +2198,6 @@
2188 2198
 //#define TFT_LVGL_UI_FSMC  // Robin nano v1.2 uses FSMC
2189 2199
 //#define TFT_LVGL_UI_SPI   // Robin nano v2.0 uses SPI
2190 2200
 
2191
-//
2192
-// Anycubic Mega TFT (AI3M)
2193
-//
2194
-//#define ANYCUBIC_TFT_MODEL
2195
-//#define ANYCUBIC_TFT_DEBUG
2196
-
2197 2201
 //=============================================================================
2198 2202
 //============================  Other Controllers  ============================
2199 2203
 //=============================================================================

+ 11
- 0
Marlin/src/HAL/AVR/HAL.h View File

@@ -120,6 +120,17 @@ typedef int8_t pin_t;
120 120
   #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.get_tx_buffer_free
121 121
 #endif
122 122
 
123
+#ifdef ANYCUBIC_LCD_SERIAL_PORT
124
+  #if !WITHIN(ANYCUBIC_LCD_SERIAL_PORT, -1, 3)
125
+    #error "ANYCUBIC_LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
126
+  #elif ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT
127
+    #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
128
+  #elif defined(SERIAL_PORT_2) && ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT_2
129
+    #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
130
+  #endif
131
+  #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
132
+#endif
133
+
123 134
 // ------------------------
124 135
 // Public functions
125 136
 // ------------------------

+ 18
- 0
Marlin/src/HAL/AVR/MarlinSerial.cpp View File

@@ -792,6 +792,24 @@
792 792
 
793 793
 #endif
794 794
 
795
+#ifdef ANYCUBIC_LCD_SERIAL_PORT
796
+
797
+  ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_RX_vect)) {
798
+    MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>>::store_rxd_char();
799
+  }
800
+
801
+  ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_UDRE_vect)) {
802
+    MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>>::_tx_udr_empty_irq();
803
+  }
804
+
805
+  // Preinstantiate
806
+  template class MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>>;
807
+
808
+  // Instantiate
809
+  MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>> anycubicLcdSerial;
810
+
811
+#endif
812
+
795 813
 // For AT90USB targets use the UART for BT interfacing
796 814
 #if defined(USBCON) && ENABLED(BLUETOOTH)
797 815
   HardwareSerial bluetoothSerial;

+ 17
- 0
Marlin/src/HAL/AVR/MarlinSerial.h View File

@@ -312,6 +312,23 @@
312 312
   extern MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>> internalDgusSerial;
313 313
 #endif
314 314
 
315
+#ifdef ANYCUBIC_LCD_SERIAL_PORT
316
+  template <uint8_t serial>
317
+  struct AnycubicLcdSerialCfg {
318
+    static constexpr int PORT               = serial;
319
+    static constexpr unsigned int RX_SIZE   = 64;
320
+    static constexpr unsigned int TX_SIZE   = 128;
321
+    static constexpr bool XONOFF            = false;
322
+    static constexpr bool EMERGENCYPARSER   = false;
323
+    static constexpr bool DROPPED_RX        = false;
324
+    static constexpr bool RX_OVERRUNS       = false;
325
+    static constexpr bool RX_FRAMING_ERRORS = false;
326
+    static constexpr bool MAX_RX_QUEUED     = false;
327
+  };
328
+
329
+  extern MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>> anycubicLcdSerial;
330
+#endif
331
+
315 332
 // Use the UART for Bluetooth in AT90USB configurations
316 333
 #if defined(USBCON) && ENABLED(BLUETOOTH)
317 334
   extern HardwareSerial bluetoothSerial;

+ 1
- 1
Marlin/src/inc/Conditionals_LCD.h View File

@@ -411,7 +411,7 @@
411 411
 #endif
412 412
 
413 413
 // Extensible UI serial touch screens. (See src/lcd/extui)
414
-#if ANY(HAS_DGUS_LCD, MALYAN_LCD, TOUCH_UI_FTDI_EVE)
414
+#if ANY(HAS_DGUS_LCD, MALYAN_LCD, TOUCH_UI_FTDI_EVE, ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
415 415
   #define IS_EXTUI
416 416
   #define EXTENSIBLE_UI
417 417
 #endif

+ 5
- 1
Marlin/src/inc/SanityCheck.h View File

@@ -515,6 +515,8 @@
515 515
   #error "DIGIPOT_I2C is now DIGIPOT_MCP4451 (or DIGIPOT_MCP4018). Please update Configuration_adv.h."
516 516
 #elif defined(TOUCH_BUTTONS)
517 517
   #error "TOUCH_BUTTONS is now TOUCH_SCREEN. Please update your Configuration.h."
518
+#elif defined(ANYCUBIC_TFT_MODEL)
519
+  #error "ANYCUBIC_TFT_MODEL is now ANYCUBIC_LCD_I3MEGA. Please update your Configuration.h."
518 520
 #endif
519 521
 
520 522
 #ifdef FIL_RUNOUT_INVERTING
@@ -2237,7 +2239,9 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
2237 2239
   + ENABLED(TFT_320x240_SPI) \
2238 2240
   + ENABLED(FSMC_GRAPHICAL_TFT) \
2239 2241
   + ENABLED(TFT_LVGL_UI_FSMC) \
2240
-  + ENABLED(TFT_LVGL_UI_SPI)
2242
+  + ENABLED(TFT_LVGL_UI_SPI) \
2243
+  + ENABLED(ANYCUBIC_LCD_I3MEGA) \
2244
+  + ENABLED(ANYCUBIC_LCD_CHIRON)
2241 2245
   #error "Please select no more than one LCD controller option."
2242 2246
 #endif
2243 2247
 

+ 0
- 290
Marlin/src/lcd/extui/lib/anycubic/anycubic_serial.cpp View File

@@ -1,290 +0,0 @@
1
-/*
2
-  anycubic_serial.cpp  --- Support for Anycubic i3 Mega TFT serial connection
3
-  Created by Christian Hopp on 09.12.17.
4
-
5
-  Original file:
6
-  HardwareSerial.cpp - Hardware serial library for Wiring
7
-  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.
8
-
9
-  This library is free software; you can redistribute it and/or
10
-  modify it under the terms of the GNU Lesser General Public
11
-  License as published by the Free Software Foundation; either
12
-  version 2.1 of the License, or (at your option) any later version.
13
-
14
-  This library is distributed in the hope that it will be useful,
15
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
-  Lesser General Public License for more details.
18
-
19
-  You should have received a copy of the GNU Lesser General Public
20
-  License along with this library; if not, write to the Free Software
21
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
-
23
-  Modified 23 November 2006 by David A. Mellis
24
-  Modified 28 September 2010 by Mark Sproul
25
-  Modified 14 August 2012 by Alarus
26
-*/
27
-
28
-#include "../../../../inc/MarlinConfig.h"
29
-
30
-#if ENABLED(ANYCUBIC_TFT_MODEL)
31
-
32
-#include <Arduino.h>
33
-
34
-// This next line disables the entire anycubic_serial.cpp,
35
-// to support AtTiny series and other chips without a UART
36
-#ifdef UBRR3H
37
-
38
-#include "anycubic_serial.h"
39
-
40
-#include <stdlib.h>
41
-#include <stdio.h>
42
-#include <string.h>
43
-#include <inttypes.h>
44
-#include "wiring_private.h"
45
-
46
-// Define constants and variables for buffering incoming serial data.  We're
47
-// using a ring buffer (I think), in which head is the index of the location
48
-// to which to write the next incoming character and tail is the index of the
49
-// location from which to read.
50
-#if (RAMEND < 1000)
51
-  #define SERIAL_BUFFER_SIZE 64
52
-#else
53
-  #define SERIAL_BUFFER_SIZE 128
54
-#endif
55
-
56
-struct ring_buffer {
57
-  unsigned char buffer[SERIAL_BUFFER_SIZE];
58
-  volatile unsigned int head;
59
-  volatile unsigned int tail;
60
-};
61
-
62
-ring_buffer rx_buffer_ajg  =  { { 0 }, 0, 0 };
63
-ring_buffer tx_buffer_ajg  =  { { 0 }, 0, 0 };
64
-
65
-inline void store_char(unsigned char c, ring_buffer *buffer) {
66
-  int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE;
67
-
68
-  // if we should be storing the received character into the location
69
-  // just before the tail (meaning that the head would advance to the
70
-  // current location of the tail), we're about to overflow the buffer
71
-  // and so we don't write the character or advance the head.
72
-  if (i != buffer->tail) {
73
-    buffer->buffer[buffer->head] = c;
74
-    buffer->head = i;
75
-  }
76
-}
77
-
78
-#if defined(USART3_RX_vect) && defined(UDR3)
79
-  void serialEvent3() __attribute__((weak));
80
-  void serialEvent3() {}
81
-  #define serialEvent3_implemented
82
-  ISR(USART3_RX_vect) {
83
-    if (bit_is_clear(UCSR3A, UPE3)) {
84
-      unsigned char c = UDR3;
85
-      store_char(c, &rx_buffer_ajg);
86
-    }
87
-    else {
88
-      unsigned char c = UDR3;
89
-    }
90
-  }
91
-#endif
92
-
93
-#ifdef USART3_UDRE_vect
94
-
95
-  ISR(USART3_UDRE_vect) {
96
-    if (tx_buffer_ajg.head == tx_buffer_ajg.tail) {
97
-  	// Buffer empty, so disable interrupts
98
-      cbi(UCSR3B, UDRIE3);
99
-    }
100
-    else {
101
-      // There is more data in the output buffer. Send the next byte
102
-      unsigned char c = tx_buffer_ajg.buffer[tx_buffer_ajg.tail];
103
-      tx_buffer_ajg.tail = (tx_buffer_ajg.tail + 1) % SERIAL_BUFFER_SIZE;
104
-
105
-      UDR3 = c;
106
-    }
107
-  }
108
-
109
-#endif
110
-
111
-// Constructors ////////////////////////////////////////////////////////////////
112
-
113
-AnycubicSerialClass::AnycubicSerialClass(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
114
-  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
115
-  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
116
-  volatile uint8_t *ucsrc, volatile uint8_t *udr,
117
-  uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x
118
-) {
119
-  _rx_buffer = rx_buffer;
120
-  _tx_buffer = tx_buffer;
121
-  _ubrrh = ubrrh;
122
-  _ubrrl = ubrrl;
123
-  _ucsra = ucsra;
124
-  _ucsrb = ucsrb;
125
-  _ucsrc = ucsrc;
126
-  _udr = udr;
127
-  _rxen = rxen;
128
-  _txen = txen;
129
-  _rxcie = rxcie;
130
-  _udrie = udrie;
131
-  _u2x = u2x;
132
-}
133
-
134
-// Public Methods //////////////////////////////////////////////////////////////
135
-
136
-void AnycubicSerialClass::begin(unsigned long baud) {
137
-  uint16_t baud_setting;
138
-  bool use_u2x = true;
139
-
140
-  #if F_CPU == 16000000UL
141
-    // hardcoded exception for compatibility with the bootloader shipped
142
-    // with the Duemilanove and previous boards and the firmware on the 8U2
143
-    // on the Uno and Mega 2560.
144
-    if (baud == 57600) use_u2x = false;
145
-  #endif
146
-
147
-try_again:
148
-
149
-  if (use_u2x) {
150
-    *_ucsra = 1 << _u2x;
151
-    baud_setting = (F_CPU / 4 / baud - 1) / 2;
152
-  } else {
153
-    *_ucsra = 0;
154
-    baud_setting = (F_CPU / 8 / baud - 1) / 2;
155
-  }
156
-
157
-  if ((baud_setting > 4095) && use_u2x) {
158
-    use_u2x = false;
159
-    goto try_again;
160
-  }
161
-
162
-  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
163
-  *_ubrrh = baud_setting >> 8;
164
-  *_ubrrl = baud_setting;
165
-
166
-  transmitting = false;
167
-
168
-  sbi(*_ucsrb, _rxen);
169
-  sbi(*_ucsrb, _txen);
170
-  sbi(*_ucsrb, _rxcie);
171
-  cbi(*_ucsrb, _udrie);
172
-}
173
-
174
-void AnycubicSerialClass::begin(unsigned long baud, byte config) {
175
-  uint16_t baud_setting;
176
-  uint8_t current_config;
177
-  bool use_u2x = true;
178
-
179
-  #if F_CPU == 16000000UL
180
-    // hardcoded exception for compatibility with the bootloader shipped
181
-    // with the Duemilanove and previous boards and the firmware on the 8U2
182
-    // on the Uno and Mega 2560.
183
-    if (baud == 57600) use_u2x = false;
184
-  #endif
185
-
186
-try_again:
187
-
188
-  if (use_u2x) {
189
-    *_ucsra = 1 << _u2x;
190
-    baud_setting = (F_CPU / 4 / baud - 1) / 2;
191
-  }
192
-  else {
193
-    *_ucsra = 0;
194
-    baud_setting = (F_CPU / 8 / baud - 1) / 2;
195
-  }
196
-
197
-  if ((baud_setting > 4095) && use_u2x) {
198
-    use_u2x = false;
199
-    goto try_again;
200
-  }
201
-
202
-  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
203
-  *_ubrrh = baud_setting >> 8;
204
-  *_ubrrl = baud_setting;
205
-
206
-  //set the data bits, parity, and stop bits
207
-  #ifdef __AVR_ATmega8__
208
-    config |= 0x80; // select UCSRC register (shared with UBRRH)
209
-  #endif
210
-  *_ucsrc = config;
211
-
212
-  sbi(*_ucsrb, _rxen);
213
-  sbi(*_ucsrb, _txen);
214
-  sbi(*_ucsrb, _rxcie);
215
-  cbi(*_ucsrb, _udrie);
216
-}
217
-
218
-void AnycubicSerialClass::end() {
219
-  // wait for transmission of outgoing data
220
-  while (_tx_buffer->head != _tx_buffer->tail)
221
-    ;
222
-
223
-  cbi(*_ucsrb, _rxen);
224
-  cbi(*_ucsrb, _txen);
225
-  cbi(*_ucsrb, _rxcie);
226
-  cbi(*_ucsrb, _udrie);
227
-
228
-  // clear any received data
229
-  _rx_buffer->head = _rx_buffer->tail;
230
-}
231
-
232
-int AnycubicSerialClass::available(void) {
233
-  return (int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % SERIAL_BUFFER_SIZE;
234
-}
235
-
236
-int AnycubicSerialClass::peek(void) {
237
-  if (_rx_buffer->head == _rx_buffer->tail) {
238
-    return -1;
239
-  } else {
240
-    return _rx_buffer->buffer[_rx_buffer->tail];
241
-  }
242
-}
243
-
244
-int AnycubicSerialClass::read(void) {
245
-  // if the head isn't ahead of the tail, we don't have any characters
246
-  if (_rx_buffer->head == _rx_buffer->tail) {
247
-    return -1;
248
-  } else {
249
-    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
250
-    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE;
251
-    return c;
252
-  }
253
-}
254
-
255
-void AnycubicSerialClass::flush() {
256
-  // UDR is kept full while the buffer is not empty, so TXC triggers when EMPTY && SENT
257
-  while (transmitting && ! (*_ucsra & _BV(TXC0)));
258
-  transmitting = false;
259
-}
260
-
261
-size_t AnycubicSerialClass::write(uint8_t c) {
262
-  int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE;
263
-
264
-  // If the output buffer is full, there's nothing for it other than to
265
-  // wait for the interrupt handler to empty it a bit
266
-  // ???: return 0 here instead?
267
-  while (i == _tx_buffer->tail)
268
-    ;
269
-
270
-  _tx_buffer->buffer[_tx_buffer->head] = c;
271
-  _tx_buffer->head = i;
272
-
273
-  sbi(*_ucsrb, _udrie);
274
-  // clear the TXC bit -- "can be cleared by writing a one to its bit location"
275
-  transmitting = true;
276
-  sbi(*_ucsra, TXC0);
277
-
278
-  return 1;
279
-}
280
-
281
-AnycubicSerialClass::operator bool() {
282
-	return true;
283
-}
284
-
285
-// Preinstantiate Objects //////////////////////////////////////////////////////
286
-
287
-AnycubicSerialClass AnycubicSerial(&rx_buffer_ajg, &tx_buffer_ajg, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3);
288
-
289
-#endif // UBRR3H
290
-#endif // ANYCUBIC_TFT_MODEL

+ 0
- 145
Marlin/src/lcd/extui/lib/anycubic/anycubic_serial.h View File

@@ -1,145 +0,0 @@
1
-/*
2
-  anycubic_serial.h  --- Support for Anycubic i3 Mega TFT serial connection
3
-  Created by Christian Hopp on 09.12.17.
4
-
5
-  Original file:
6
-
7
-  HardwareSerial.h - Hardware serial library for Wiring
8
-  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.
9
-
10
-  This library is free software; you can redistribute it and/or
11
-  modify it under the terms of the GNU Lesser General Public
12
-  License as published by the Free Software Foundation; either
13
-  version 2.1 of the License, or (at your option) any later version.
14
-
15
-  This library is distributed in the hope that it will be useful,
16
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
-  Lesser General Public License for more details.
19
-
20
-  You should have received a copy of the GNU Lesser General Public
21
-  License along with this library; if not, write to the Free Software
22
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23
-
24
-  Modified 28 September 2010 by Mark Sproul
25
-  Modified 14 August 2012 by Alarus
26
-*/
27
-#pragma once
28
-
29
-#include <inttypes.h>
30
-#include <avr/pgmspace.h>
31
-
32
-#include "Stream.h"
33
-
34
-#define FORCE_INLINE __attribute__((always_inline)) inline
35
-
36
-struct ring_buffer;
37
-
38
-class AnycubicSerialClass : public Stream {
39
-  private:
40
-    ring_buffer *_rx_buffer;
41
-    ring_buffer *_tx_buffer;
42
-    volatile uint8_t *_ubrrh;
43
-    volatile uint8_t *_ubrrl;
44
-    volatile uint8_t *_ucsra;
45
-    volatile uint8_t *_ucsrb;
46
-    volatile uint8_t *_ucsrc;
47
-    volatile uint8_t *_udr;
48
-    uint8_t _rxen;
49
-    uint8_t _txen;
50
-    uint8_t _rxcie;
51
-    uint8_t _udrie;
52
-    uint8_t _u2x;
53
-    bool transmitting;
54
-  public:
55
-    AnycubicSerialClass(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
56
-      volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
57
-      volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
58
-      volatile uint8_t *ucsrc, volatile uint8_t *udr,
59
-      uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x
60
-    );
61
-    void begin(unsigned long);
62
-    void begin(unsigned long, uint8_t);
63
-    void end();
64
-    virtual int available(void);
65
-    virtual int peek(void);
66
-    virtual int read(void);
67
-    virtual void flush(void);
68
-    virtual size_t write(uint8_t);
69
-    inline size_t write(unsigned long n) { return write((uint8_t)n); }
70
-    inline size_t write(long n) { return write((uint8_t)n); }
71
-    inline size_t write(unsigned int n) { return write((uint8_t)n); }
72
-    inline size_t write(int n) { return write((uint8_t)n); }
73
-    using Print::write; // pull in write(str) and write(buf, size) from Print
74
-    operator bool();
75
-};
76
-
77
-// Define config for Serial.begin(baud, config);
78
-#define SERIAL_5N1 0x00
79
-#define SERIAL_6N1 0x02
80
-#define SERIAL_7N1 0x04
81
-#define SERIAL_8N1 0x06
82
-#define SERIAL_5N2 0x08
83
-#define SERIAL_6N2 0x0A
84
-#define SERIAL_7N2 0x0C
85
-#define SERIAL_8N2 0x0E
86
-#define SERIAL_5E1 0x20
87
-#define SERIAL_6E1 0x22
88
-#define SERIAL_7E1 0x24
89
-#define SERIAL_8E1 0x26
90
-#define SERIAL_5E2 0x28
91
-#define SERIAL_6E2 0x2A
92
-#define SERIAL_7E2 0x2C
93
-#define SERIAL_8E2 0x2E
94
-#define SERIAL_5O1 0x30
95
-#define SERIAL_6O1 0x32
96
-#define SERIAL_7O1 0x34
97
-#define SERIAL_8O1 0x36
98
-#define SERIAL_5O2 0x38
99
-#define SERIAL_6O2 0x3A
100
-#define SERIAL_7O2 0x3C
101
-#define SERIAL_8O2 0x3E
102
-
103
-extern void serialEventRun(void) __attribute__((weak));
104
-
105
-#define ANYCUBIC_SERIAL_PROTOCOL(x) (AnycubicSerial.print(x))
106
-#define ANYCUBIC_SERIAL_PROTOCOL_F(x,y) (AnycubicSerial.print(x, y))
107
-#define ANYCUBIC_SERIAL_PROTOCOLPGM(x) (AnycubicSerialprintPGM(PSTR(x)))
108
-#define ANYCUBIC_SERIAL_(x) (AnycubicSerial.print(x), AnycubicSerial.write('\n'))
109
-#define ANYCUBIC_SERIAL_PROTOCOLLN(x) (AnycubicSerial.print(x), AnycubicSerial.write('\r'), AnycubicSerial.write('\n'))
110
-#define ANYCUBIC_SERIAL_PROTOCOLLNPGM(x) (AnycubicSerialprintPGM(PSTR(x)), AnycubicSerial.write('\r'), AnycubicSerial.write('\n'))
111
-
112
-#define ANYCUBIC_SERIAL_START() (AnycubicSerial.write('\r'), AnycubicSerial.write('\n'))
113
-#define ANYCUBIC_SERIAL_CMD_SEND(x) (AnycubicSerialprintPGM(PSTR(x)), AnycubicSerial.write('\r'), AnycubicSerial.write('\n'))
114
-#define ANYCUBIC_SERIAL_ENTER() (AnycubicSerial.write('\r'), AnycubicSerial.write('\n'))
115
-#define ANYCUBIC_SERIAL_SPACE() (AnycubicSerial.write(' '))
116
-
117
-const char newErr[] PROGMEM = "ERR ";
118
-const char newSucc[] PROGMEM = "OK";
119
-
120
-#define ANYCUBIC_SERIAL_ERROR_START (AnycubicSerialprintPGM(newErr))
121
-#define ANYCUBIC_SERIAL_ERROR(x) ANYCUBIC_SERIAL_PROTOCOL(x)
122
-#define ANYCUBIC_SERIAL_ERRORPGM(x) ANYCUBIC_SERIAL_PROTOCOLPGM(x)
123
-#define ANYCUBIC_SERIAL_ERRORLN(x) ANYCUBIC_SERIAL_PROTOCOLLN(x)
124
-#define ANYCUBIC_SERIAL_ERRORLNPGM(x) ANYCUBIC_SERIAL_PROTOCOLLNPGM(x)
125
-
126
-//##define ANYCUBIC_SERIAL_ECHO_START (AnycubicSerialprintPGM(newSucc))
127
-#define ANYCUBIC_SERIAL_ECHOLN(x) ANYCUBIC_SERIAL_PROTOCOLLN(x)
128
-#define ANYCUBIC_SERIAL_SUCC_START (AnycubicSerialprintPGM(newSucc))
129
-#define ANYCUBIC_SERIAL_ECHOPAIR(name,value) (serial_echopair_P(PSTR(name),(value)))
130
-#define ANYCUBIC_SERIAL_ECHOPGM(x) ANYCUBIC_SERIAL_PROTOCOLPGM(x)
131
-#define ANYCUBIC_SERIAL_ECHO(x) ANYCUBIC_SERIAL_PROTOCOL(x)
132
-
133
-#ifdef UBRR3H
134
-
135
-  extern AnycubicSerialClass AnycubicSerial;
136
-
137
-  FORCE_INLINE void AnycubicSerialprintPGM(const char *str) {
138
-    char ch = pgm_read_byte(str);
139
-    while (ch) {
140
-      AnycubicSerial.write(ch);
141
-      ch = pgm_read_byte(++str);
142
-    }
143
-  }
144
-
145
-#endif

Marlin/src/lcd/extui/lib/anycubic/anycubic_tft.cpp → Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp View File

@@ -1,5 +1,5 @@
1 1
 /**
2
- * anycubic_tft.cpp  --- Support for Anycubic i3 Mega TFT
2
+ * anycubic_i3mega_lcd.cpp  --- Support for Anycubic i3 Mega TFT
3 3
  * Created by Christian Hopp on 09.12.17.
4 4
  * Improved by David Ramiro
5 5
  * Converted to ext_iu by John BouAntoun 21 June 2020
@@ -21,15 +21,29 @@
21 21
 
22 22
 #include "../../../../inc/MarlinConfigPre.h"
23 23
 
24
-#if ENABLED(ANYCUBIC_TFT_MODEL)
24
+#if ENABLED(ANYCUBIC_LCD_I3MEGA)
25 25
 
26
-#include "anycubic_tft.h"
27
-#include "anycubic_serial.h"
26
+#include "anycubic_i3mega_lcd.h"
28 27
 
29 28
 #include "../../../../inc/MarlinConfig.h"
30 29
 #include "../../ui_api.h"
31 30
 #include "../../../../MarlinCore.h" // for quickstop_stepper and disable_steppers
32 31
 
32
+// command sending macro's with debugging capability
33
+#define SEND_PGM(x)                                 send_P(PSTR(x))
34
+#define SENDLINE_PGM(x)                             sendLine_P(PSTR(x))
35
+#define SEND_PGM_VAL(x,y)                           (send_P(PSTR(x)), sendLine(itostr3(y)))
36
+#define SEND(x)                                     send(x)
37
+#define SENDLINE(x)                                 sendLine(x)
38
+#if ENABLED(ANYCUBIC_LCD_DEBUG)
39
+  #define SENDLINE_DBG_PGM(x,y)                     (sendLine_P(PSTR(x)), SERIAL_ECHOLNPGM(y))
40
+  #define SENDLINE_DBG_PGM_VAL(x,y,z)               (sendLine_P(PSTR(x)), SERIAL_ECHOPGM(y), SERIAL_ECHOLN(z))
41
+#else
42
+  #define SENDLINE_DBG_PGM(x,y)                     sendLine_P(PSTR(x))
43
+  #define SENDLINE_DBG_PGM_VAL(x,y,z)               sendLine_P(PSTR(x))
44
+#endif
45
+
46
+
33 47
 AnycubicTFTClass AnycubicTFT;
34 48
 
35 49
 char _conv[8];
@@ -43,6 +57,30 @@ char *itostr2(const uint8_t &x) {
43 57
   return _conv;
44 58
 }
45 59
 
60
+static void sendNewLine(void) {
61
+  ANYCUBIC_LCD_SERIAL.write('\r');
62
+  ANYCUBIC_LCD_SERIAL.write('\n');
63
+}
64
+
65
+static void send(const char *str) {
66
+  ANYCUBIC_LCD_SERIAL.print(str);
67
+}
68
+
69
+static void sendLine(const char *str) {
70
+  send(str);
71
+  sendNewLine();
72
+}
73
+
74
+static void send_P(PGM_P str) {
75
+  while (const char c = pgm_read_byte(str++))
76
+    ANYCUBIC_LCD_SERIAL.write(c);
77
+}
78
+
79
+static void sendLine_P(PGM_P str) {
80
+  send_P(str);
81
+  sendNewLine();
82
+}
83
+
46 84
 #ifndef ULTRA_LCD
47 85
   #define DIGIT(n) ('0' + (n))
48 86
   #define DIGIMOD(n, f) DIGIT((n) / (f) % 10)
@@ -74,8 +112,8 @@ char *itostr2(const uint8_t &x) {
74 112
 AnycubicTFTClass::AnycubicTFTClass() {}
75 113
 
76 114
 void AnycubicTFTClass::OnSetup() {
77
-  AnycubicSerial.begin(115200);
78
-  ANYCUBIC_SENDCOMMAND_DBG_PGM("J17", "TFT Serial Debug: Main board reset... J17"); // J17 Main board reset
115
+  ANYCUBIC_LCD_SERIAL.begin(115200);
116
+  SENDLINE_DBG_PGM("J17", "TFT Serial Debug: Main board reset... J17"); // J17 Main board reset
79 117
   ExtUI::delay_ms(10);
80 118
 
81 119
   // initialise the state of the key pins running on the tft
@@ -92,7 +130,7 @@ void AnycubicTFTClass::OnSetup() {
92 130
   mediaPauseState = AMPAUSESTATE_NOT_PAUSED;
93 131
 
94 132
   // DoSDCardStateCheck();
95
-  ANYCUBIC_SENDCOMMAND_DBG_PGM("J12", "TFT Serial Debug: Ready... J12"); // J12 Ready
133
+  SENDLINE_DBG_PGM("J12", "TFT Serial Debug: Ready... J12"); // J12 Ready
96 134
   ExtUI::delay_ms(10);
97 135
 
98 136
   DoFilamentRunoutCheck();
@@ -101,7 +139,7 @@ void AnycubicTFTClass::OnSetup() {
101 139
   #if ENABLED(STARTUP_CHIME)
102 140
     ExtUI::injectCommands_P(PSTR("M300 P250 S554\nM300 P250 S554\nM300 P250 S740\nM300 P250 S554\nM300 P250 S740\nM300 P250 S554\nM300 P500 S831"));
103 141
   #endif
104
-  #if ENABLED(ANYCUBIC_TFT_DEBUG)
142
+  #if ENABLED(ANYCUBIC_LCD_DEBUG)
105 143
     SERIAL_ECHOLNPGM("TFT Serial Debug: Finished startup");
106 144
   #endif
107 145
 }
@@ -112,7 +150,7 @@ void AnycubicTFTClass::OnCommandScan() {
112 150
   if (ELAPSED(ms, nextStopCheck)) {
113 151
     nextStopCheck = ms + 1000UL;
114 152
     if (mediaPrintingState == AMPRINTSTATE_STOP_REQUESTED && IsNozzleHomed()) {
115
-      #if ENABLED(ANYCUBIC_TFT_DEBUG)
153
+      #if ENABLED(ANYCUBIC_LCD_DEBUG)
116 154
         SERIAL_ECHOLNPGM("TFT Serial Debug: Finished stopping print, releasing motors ...");
117 155
       #endif
118 156
       mediaPrintingState = AMPRINTSTATE_NOT_PRINTING;
@@ -120,7 +158,7 @@ void AnycubicTFTClass::OnCommandScan() {
120 158
       ExtUI::injectCommands_P(PSTR("M84\nM27")); // disable stepper motors and force report of SD status
121 159
       ExtUI::delay_ms(200);
122 160
       // tell printer to release resources of print to indicate it is done
123
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J14", "TFT Serial Debug: SD Print Stopped... J14");
161
+      SENDLINE_DBG_PGM("J14", "TFT Serial Debug: SD Print Stopped... J14");
124 162
     }
125 163
   }
126 164
 
@@ -134,11 +172,11 @@ void AnycubicTFTClass::OnCommandScan() {
134 172
 }
135 173
 
136 174
 void AnycubicTFTClass::OnKillTFT() {
137
-  ANYCUBIC_SENDCOMMAND_DBG_PGM("J11", "TFT Serial Debug: Kill command... J11");
175
+  SENDLINE_DBG_PGM("J11", "TFT Serial Debug: Kill command... J11");
138 176
 }
139 177
 
140 178
 void AnycubicTFTClass::OnSDCardStateChange(bool isInserted) {
141
-  #if ENABLED(ANYCUBIC_TFT_DEBUG)
179
+  #if ENABLED(ANYCUBIC_LCD_DEBUG)
142 180
     SERIAL_ECHOPGM("TFT Serial Debug: OnSDCardStateChange event triggered...");
143 181
     SERIAL_ECHO(itostr2(isInserted));
144 182
     SERIAL_EOL();
@@ -147,21 +185,21 @@ void AnycubicTFTClass::OnSDCardStateChange(bool isInserted) {
147 185
 }
148 186
 
149 187
 void AnycubicTFTClass::OnSDCardError() {
150
-  #if ENABLED(ANYCUBIC_TFT_DEBUG)
188
+  #if ENABLED(ANYCUBIC_LCD_DEBUG)
151 189
     SERIAL_ECHOLNPGM("TFT Serial Debug: OnSDCardError event triggered...");
152 190
   #endif
153
-  ANYCUBIC_SENDCOMMAND_DBG_PGM("J21", "TFT Serial Debug: On SD Card Error ... J21");
191
+  SENDLINE_DBG_PGM("J21", "TFT Serial Debug: On SD Card Error ... J21");
154 192
 }
155 193
 
156 194
 void AnycubicTFTClass::OnFilamentRunout() {
157
-  #if ENABLED(ANYCUBIC_TFT_DEBUG)
195
+  #if ENABLED(ANYCUBIC_LCD_DEBUG)
158 196
     SERIAL_ECHOLNPGM("TFT Serial Debug: FilamentRunout triggered...");
159 197
   #endif
160 198
   DoFilamentRunoutCheck();
161 199
 }
162 200
 
163 201
 void AnycubicTFTClass::OnUserConfirmRequired(const char * const msg) {
164
-  #if ENABLED(ANYCUBIC_TFT_DEBUG)
202
+  #if ENABLED(ANYCUBIC_LCD_DEBUG)
165 203
     SERIAL_ECHOPGM("TFT Serial Debug: OnUserConfirmRequired triggered... ");
166 204
     SERIAL_ECHOLN(msg);
167 205
   #endif
@@ -181,36 +219,36 @@ void AnycubicTFTClass::OnUserConfirmRequired(const char * const msg) {
181 219
       mediaPrintingState = AMPRINTSTATE_PAUSED;
182 220
       mediaPauseState    = AMPAUSESTATE_PARKED;
183 221
       // enable continue button
184
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD print paused done... J18");
222
+      SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD print paused done... J18");
185 223
     }
186 224
     else if (strcmp_P(msg, PSTR("Load Filament")) == 0) {
187 225
       mediaPrintingState = AMPRINTSTATE_PAUSED;
188 226
       mediaPauseState    = AMPAUSESTATE_FILAMENT_OUT;
189 227
       // enable continue button
190
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J18", "TFT Serial Debug: UserConfirm Filament is out... J18");
191
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J23", "TFT Serial Debug: UserConfirm Blocking filament prompt... J23");
228
+      SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm Filament is out... J18");
229
+      SENDLINE_DBG_PGM("J23", "TFT Serial Debug: UserConfirm Blocking filament prompt... J23");
192 230
     }
193 231
     else if (strcmp_P(msg, PSTR("Filament Purging...")) == 0) {
194 232
       mediaPrintingState = AMPRINTSTATE_PAUSED;
195 233
       mediaPauseState    = AMPAUSESTATE_PARKING;
196 234
       // TODO: JBA I don't think J05 just disables the continue button, i think it injects a rogue M25. So taking this out
197 235
       // disable continue button
198
-      // ANYCUBIC_SENDCOMMAND_DBG_PGM("J05", "TFT Serial Debug: UserConfirm SD Filament Purging... J05"); // J05 printing pause
236
+      // SENDLINE_DBG_PGM("J05", "TFT Serial Debug: UserConfirm SD Filament Purging... J05"); // J05 printing pause
199 237
 
200 238
       // enable continue button
201
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J18", "TFT Serial Debug: UserConfirm Filament is purging... J18");
239
+      SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm Filament is purging... J18");
202 240
     }
203 241
     else if (strcmp_P(msg, PSTR("HeaterTimeout")) == 0) {
204 242
       mediaPrintingState = AMPRINTSTATE_PAUSED;
205 243
       mediaPauseState    = AMPAUSESTATE_HEATER_TIMEOUT;
206 244
       // enable continue button
207
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD Heater timeout... J18");
245
+      SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD Heater timeout... J18");
208 246
     }
209 247
     else if (strcmp_P(msg, PSTR("Reheat finished.")) == 0) {
210 248
       mediaPrintingState = AMPRINTSTATE_PAUSED;
211 249
       mediaPauseState    = AMPAUSESTATE_REHEAT_FINISHED;
212 250
       // enable continue button
213
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD Reheat done... J18");
251
+      SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD Reheat done... J18");
214 252
     }
215 253
   #endif
216 254
 }
@@ -360,7 +398,7 @@ void AnycubicTFTClass::HandleSpecialMenu() {
360 398
           default:
361 399
             break;
362 400
     }
363
-    #if ENABLED(ANYCUBIC_TFT_DEBUG)
401
+    #if ENABLED(ANYCUBIC_LCD_DEBUG)
364 402
   }
365 403
   else {
366 404
     SERIAL_ECHOPGM("TFT Serial Debug: Attempted to HandleSpecialMenu on non-special menu... ");
@@ -375,14 +413,13 @@ void AnycubicTFTClass::RenderCurrentFileList() {
375 413
     SelectedDirectory[0] = 0;
376 414
     SelectedFile[0] = 0;
377 415
 
378
-    ANYCUBIC_SERIAL_PROTOCOLPGM("FN "); // Filelist start
379
-    ANYCUBIC_SERIAL_ENTER();
416
+    SENDLINE_PGM("FN "); // Filelist start
380 417
 
381 418
     if (!ExtUI::isMediaInserted() && !SpecialMenu) {
382
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to render Current File List... J02");
419
+      SENDLINE_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to render Current File List... J02");
383 420
 
384
-      ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Special_Menu>");
385
-      ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Special_Menu>");
421
+      SENDLINE_PGM("<Special_Menu>");
422
+      SENDLINE_PGM("<Special_Menu>");
386 423
     }
387 424
     else {
388 425
       if (CodeSeen('S'))
@@ -393,8 +430,7 @@ void AnycubicTFTClass::RenderCurrentFileList() {
393 430
       else
394 431
         RenderCurrentFolder(selectedNumber);
395 432
     }
396
-    ANYCUBIC_SERIAL_PROTOCOLPGM("END"); // Filelist stop
397
-    ANYCUBIC_SERIAL_ENTER();
433
+    SENDLINE_PGM("END"); // Filelist stop
398 434
   #endif // SDSUPPORT
399 435
 }
400 436
 
@@ -402,58 +438,58 @@ void AnycubicTFTClass::RenderSpecialMenu(uint16_t selectedNumber) {
402 438
   switch (selectedNumber) {
403 439
     #if ENABLED(PROBE_MANUALLY)
404 440
       case 0: // First Page
405
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<01ZUp0.1>");
406
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Z Up 0.1>");
407
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<02ZUp0.02>");
408
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Z Up 0.02>");
409
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<03ZDn0.02>");
410
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Z Down 0.02>");
411
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<04ZDn0.1>");
412
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Z Down 0.1>");
441
+        SENDLINE_PGM("<01ZUp0.1>");
442
+        SENDLINE_PGM("<Z Up 0.1>");
443
+        SENDLINE_PGM("<02ZUp0.02>");
444
+        SENDLINE_PGM("<Z Up 0.02>");
445
+        SENDLINE_PGM("<03ZDn0.02>");
446
+        SENDLINE_PGM("<Z Down 0.02>");
447
+        SENDLINE_PGM("<04ZDn0.1>");
448
+        SENDLINE_PGM("<Z Down 0.1>");
413 449
         break;
414 450
 
415 451
       case 4: // Second Page
416
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<05PrehtBed>");
417
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Preheat bed>");
418
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<06SMeshLvl>");
419
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Start Mesh Leveling>");
420
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<07MeshNPnt>");
421
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Next Mesh Point>");
422
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<08HtEndPID>");
423
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Auto Tune Hotend PID>");
452
+        SENDLINE_PGM("<05PrehtBed>");
453
+        SENDLINE_PGM("<Preheat bed>");
454
+        SENDLINE_PGM("<06SMeshLvl>");
455
+        SENDLINE_PGM("<Start Mesh Leveling>");
456
+        SENDLINE_PGM("<07MeshNPnt>");
457
+        SENDLINE_PGM("<Next Mesh Point>");
458
+        SENDLINE_PGM("<08HtEndPID>");
459
+        SENDLINE_PGM("<Auto Tune Hotend PID>");
424 460
         break;
425 461
 
426 462
       case 8: // Third Page
427
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<09HtBedPID>");
428
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Auto Tune Hotbed PID>");
429
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<10FWDeflts>");
430
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Load FW Defaults>");
431
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<11SvEEPROM>");
432
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Save EEPROM>");
433
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Exit>");
434
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Exit>");
463
+        SENDLINE_PGM("<09HtBedPID>");
464
+        SENDLINE_PGM("<Auto Tune Hotbed PID>");
465
+        SENDLINE_PGM("<10FWDeflts>");
466
+        SENDLINE_PGM("<Load FW Defaults>");
467
+        SENDLINE_PGM("<11SvEEPROM>");
468
+        SENDLINE_PGM("<Save EEPROM>");
469
+        SENDLINE_PGM("<Exit>");
470
+        SENDLINE_PGM("<Exit>");
435 471
         break;
436 472
     #else
437 473
       case 0: // First Page
438
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<01PrehtBed>");
439
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Preheat bed>");
440
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<02ABL>");
441
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Auto Bed Leveling>");
442
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<03HtEndPID>");
443
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Auto Tune Hotend PID>");
444
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<04HtBedPID>");
445
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Auto Tune Hotbed PID>");
474
+        SENDLINE_PGM("<01PrehtBed>");
475
+        SENDLINE_PGM("<Preheat bed>");
476
+        SENDLINE_PGM("<02ABL>");
477
+        SENDLINE_PGM("<Auto Bed Leveling>");
478
+        SENDLINE_PGM("<03HtEndPID>");
479
+        SENDLINE_PGM("<Auto Tune Hotend PID>");
480
+        SENDLINE_PGM("<04HtBedPID>");
481
+        SENDLINE_PGM("<Auto Tune Hotbed PID>");
446 482
         break;
447 483
 
448 484
       case 4: // Second Page
449
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<05FWDeflts>");
450
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Load FW Defaults>");
451
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<06SvEEPROM>");
452
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Save EEPROM>");
453
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<07SendM108>");
454
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Send User Confirmation>");
455
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Exit>");
456
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Exit>");
485
+        SENDLINE_PGM("<05FWDeflts>");
486
+        SENDLINE_PGM("<Load FW Defaults>");
487
+        SENDLINE_PGM("<06SvEEPROM>");
488
+        SENDLINE_PGM("<Save EEPROM>");
489
+        SENDLINE_PGM("<07SendM108>");
490
+        SENDLINE_PGM("<Send User Confirmation>");
491
+        SENDLINE_PGM("<Exit>");
492
+        SENDLINE_PGM("<Exit>");
457 493
         break;
458 494
 
459 495
         #endif // PROBE_MANUALLY
@@ -477,30 +513,30 @@ void AnycubicTFTClass::RenderCurrentFolder(uint16_t selectedNumber) {
477 513
   for (cnt = selectedNumber; cnt <= max_files; cnt++) {
478 514
     if (cnt == 0) { // Special Entry
479 515
       if (currentFileList.isAtRootDir()) {
480
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<specialmnu>");
481
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("<Special Menu>");
516
+        SENDLINE_PGM("<specialmnu>");
517
+        SENDLINE_PGM("<Special Menu>");
482 518
       }
483 519
       else {
484
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("/..");
485
-        ANYCUBIC_SERIAL_PROTOCOLLNPGM("/..");
520
+        SENDLINE_PGM("/..");
521
+        SENDLINE_PGM("/..");
486 522
       }
487 523
     }
488 524
     else {
489 525
       currentFileList.seek(cnt - 1, false);
490 526
 
491
-      #if ENABLED(ANYCUBIC_TFT_DEBUG)
527
+      #if ENABLED(ANYCUBIC_LCD_DEBUG)
492 528
         SERIAL_ECHOLN(currentFileList.filename());
493 529
       #endif
494 530
       if (currentFileList.isDir()) {
495
-        ANYCUBIC_SERIAL_PROTOCOLPGM("/");
496
-        ANYCUBIC_SERIAL_PROTOCOLLN(currentFileList.shortFilename());
497
-        ANYCUBIC_SERIAL_PROTOCOLPGM("/");
498
-        ANYCUBIC_SERIAL_PROTOCOLLN(currentFileList.longFilename());
531
+        SEND_PGM("/");
532
+        SENDLINE(currentFileList.shortFilename());
533
+        SEND_PGM("/");
534
+        SENDLINE(currentFileList.longFilename());
499 535
 
500 536
       }
501 537
       else {
502
-        ANYCUBIC_SERIAL_PROTOCOLLN(currentFileList.shortFilename());
503
-        ANYCUBIC_SERIAL_PROTOCOLLN(currentFileList.longFilename());
538
+        SENDLINE(currentFileList.shortFilename());
539
+        SENDLINE(currentFileList.longFilename());
504 540
       }
505 541
     }
506 542
   }
@@ -509,7 +545,7 @@ void AnycubicTFTClass::RenderCurrentFolder(uint16_t selectedNumber) {
509 545
 void AnycubicTFTClass::OnPrintTimerStarted() {
510 546
   #if ENABLED(SDSUPPORT)
511 547
     if (mediaPrintingState == AMPRINTSTATE_PRINTING)
512
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J04", "TFT Serial Debug: Starting SD Print... J04"); // J04 Starting Print
548
+      SENDLINE_DBG_PGM("J04", "TFT Serial Debug: Starting SD Print... J04"); // J04 Starting Print
513 549
 
514 550
   #endif
515 551
 }
@@ -528,7 +564,7 @@ void AnycubicTFTClass::OnPrintTimerStopped() {
528 564
     if (mediaPrintingState == AMPRINTSTATE_PRINTING) {
529 565
       mediaPrintingState = AMPRINTSTATE_NOT_PRINTING;
530 566
       mediaPauseState    = AMPAUSESTATE_NOT_PAUSED;
531
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J14", "TFT Serial Debug: SD Print Completed... J14");
567
+      SENDLINE_DBG_PGM("J14", "TFT Serial Debug: SD Print Completed... J14");
532 568
     }
533 569
     // otherwise it was stopped by the printer so don't send print completed signal to TFT
534 570
   #endif
@@ -536,8 +572,8 @@ void AnycubicTFTClass::OnPrintTimerStopped() {
536 572
 
537 573
 void AnycubicTFTClass::GetCommandFromTFT() {
538 574
   char *starpos = NULL;
539
-  while (AnycubicSerial.available() > 0  && TFTbuflen < TFTBUFSIZE) {
540
-    serial3_char = AnycubicSerial.read();
575
+  while (ANYCUBIC_LCD_SERIAL.available() > 0  && TFTbuflen < TFTBUFSIZE) {
576
+    serial3_char = ANYCUBIC_LCD_SERIAL.read();
541 577
     if (serial3_char == '\n' ||
542 578
         serial3_char == '\r' ||
543 579
         serial3_char == ':'  ||
@@ -553,7 +589,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
553 589
         TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'A');
554 590
         a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL))));
555 591
 
556
-        #if ENABLED(ANYCUBIC_TFT_DEBUG)
592
+        #if ENABLED(ANYCUBIC_LCD_DEBUG)
557 593
           if ((a_command > 7) && (a_command != 20)) { // No debugging of status polls, please!
558 594
             SERIAL_ECHOPGM("TFT Serial Command: ");
559 595
             SERIAL_ECHOLN(TFTcmdbuffer[TFTbufindw]);
@@ -563,25 +599,25 @@ void AnycubicTFTClass::GetCommandFromTFT() {
563 599
         switch (a_command) {
564 600
           case 0: { // A0 GET HOTEND TEMP
565 601
             float hotendActualTemp = ExtUI::getActualTemp_celsius((ExtUI::extruder_t) (ExtUI::extruder_t) ExtUI::E0);
566
-            ANYCUBIC_SENDCOMMANDPGM_VAL("A0V ", int(hotendActualTemp + 0.5));
602
+            SEND_PGM_VAL("A0V ", int(hotendActualTemp + 0.5));
567 603
           }
568 604
           break;
569 605
 
570 606
           case 1: { // A1  GET HOTEND TARGET TEMP
571 607
             float hotendTargetTemp = ExtUI::getTargetTemp_celsius((ExtUI::extruder_t) (ExtUI::extruder_t) ExtUI::E0);
572
-            ANYCUBIC_SENDCOMMANDPGM_VAL("A1V ", int(hotendTargetTemp + 0.5));
608
+            SEND_PGM_VAL("A1V ", int(hotendTargetTemp + 0.5));
573 609
           }
574 610
           break;
575 611
 
576 612
           case 2: { // A2 GET HOTBED TEMP
577 613
             float heatedBedActualTemp = ExtUI::getActualTemp_celsius((ExtUI::heater_t) ExtUI::BED);
578
-            ANYCUBIC_SENDCOMMANDPGM_VAL("A2V ", int(heatedBedActualTemp + 0.5));
614
+            SEND_PGM_VAL("A2V ", int(heatedBedActualTemp + 0.5));
579 615
           }
580 616
           break;
581 617
 
582 618
           case 3: { // A3 GET HOTBED TARGET TEMP
583 619
             float heatedBedTargetTemp = ExtUI::getTargetTemp_celsius((ExtUI::heater_t) ExtUI::BED);
584
-            ANYCUBIC_SENDCOMMANDPGM_VAL("A3V ", int(heatedBedTargetTemp + 0.5));
620
+            SEND_PGM_VAL("A3V ", int(heatedBedTargetTemp + 0.5));
585 621
           }
586 622
           break;
587 623
 
@@ -589,7 +625,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
589 625
           {
590 626
             float fanPercent = ExtUI::getActualFan_percent(ExtUI::FAN0);
591 627
             fanPercent = constrain(fanPercent, 0, 100);
592
-            ANYCUBIC_SENDCOMMANDPGM_VAL("A4V ", int(fanPercent));
628
+            SEND_PGM_VAL("A4V ", int(fanPercent));
593 629
           }
594 630
           break;
595 631
 
@@ -598,58 +634,46 @@ void AnycubicTFTClass::GetCommandFromTFT() {
598 634
             float xPostition = ExtUI::getAxisPosition_mm(ExtUI::X);
599 635
             float yPostition = ExtUI::getAxisPosition_mm(ExtUI::Y);
600 636
             float zPostition = ExtUI::getAxisPosition_mm(ExtUI::Z);
601
-            ANYCUBIC_SERIAL_PROTOCOLPGM("A5V");
602
-            ANYCUBIC_SERIAL_SPACE();
603
-            ANYCUBIC_SERIAL_PROTOCOLPGM("X: ");
604
-            ANYCUBIC_SERIAL_PROTOCOL(xPostition);
605
-            ANYCUBIC_SERIAL_SPACE();
606
-            ANYCUBIC_SERIAL_PROTOCOLPGM("Y: ");
607
-            ANYCUBIC_SERIAL_PROTOCOL(yPostition);
608
-            ANYCUBIC_SERIAL_SPACE();
609
-            ANYCUBIC_SERIAL_PROTOCOLPGM("Z: ");
610
-            ANYCUBIC_SERIAL_PROTOCOL(zPostition);
611
-            ANYCUBIC_SERIAL_SPACE();
612
-            ANYCUBIC_SERIAL_ENTER();
637
+            SEND_PGM("A5V X: ");
638
+            ANYCUBIC_LCD_SERIAL.print(xPostition);
639
+            SEND_PGM(" Y: ");
640
+            ANYCUBIC_LCD_SERIAL.print(yPostition);
641
+            SEND_PGM(" Z: ");
642
+            ANYCUBIC_LCD_SERIAL.print(zPostition);
643
+            SENDLINE_PGM("");
613 644
           }
614 645
           break;
615 646
 
616 647
           case 6: // A6 GET SD CARD PRINTING STATUS
617 648
             #if ENABLED(SDSUPPORT)
618 649
               if (ExtUI::isPrintingFromMedia()) {
619
-                ANYCUBIC_SERIAL_PROTOCOLPGM("A6V ");
650
+                SEND_PGM("A6V ");
620 651
                 if (ExtUI::isMediaInserted()) {
621
-                  ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(ExtUI::getProgress_percent())));
622
-                  ANYCUBIC_SERIAL_ENTER();
652
+                  SENDLINE(itostr3(int(ExtUI::getProgress_percent())));
623 653
                 }
624 654
                 else {
625
-                  ANYCUBIC_SENDCOMMAND_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to return printing status... J02");
655
+                  SENDLINE_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to return printing status... J02");
626 656
                 }
627 657
               }
628 658
               else {
629
-                ANYCUBIC_SERIAL_PROTOCOLPGM("A6V ---");
630
-                ANYCUBIC_SERIAL_ENTER();
659
+                SENDLINE_PGM("A6V ---");
631 660
               }
632 661
             #endif
633 662
             break;
634 663
 
635 664
           case 7: { // A7 GET PRINTING TIME
636 665
             uint32_t elapsedSeconds = ExtUI::getProgress_seconds_elapsed();
637
-            ANYCUBIC_SERIAL_PROTOCOLPGM("A7V ");
666
+            SEND_PGM("A7V ");
638 667
             if (elapsedSeconds != 0) {  // print time
639 668
               uint32_t elapsedMinutes = elapsedSeconds / 60;
640
-              ANYCUBIC_SERIAL_PROTOCOL(itostr2(elapsedMinutes / 60));
641
-              ANYCUBIC_SERIAL_SPACE();
642
-              ANYCUBIC_SERIAL_PROTOCOLPGM("H");
643
-              ANYCUBIC_SERIAL_SPACE();
644
-              ANYCUBIC_SERIAL_PROTOCOL(itostr2(elapsedMinutes % 60));
645
-              ANYCUBIC_SERIAL_SPACE();
646
-              ANYCUBIC_SERIAL_PROTOCOLPGM("M");
669
+              SEND(itostr2(elapsedMinutes / 60));
670
+              SEND_PGM(" H ");
671
+              SEND(itostr2(elapsedMinutes % 60));
672
+              SENDLINE_PGM(" M");
647 673
             }
648 674
             else {
649
-              ANYCUBIC_SERIAL_SPACE();
650
-              ANYCUBIC_SERIAL_PROTOCOLPGM("999:999");
675
+              SENDLINE_PGM(" 999:999");
651 676
             }
652
-            ANYCUBIC_SERIAL_ENTER();
653 677
           }
654 678
           break;
655 679
 
@@ -693,15 +717,15 @@ void AnycubicTFTClass::GetCommandFromTFT() {
693 717
                 if (TFTstrchr_pointer[4] == '/') {
694 718
                   strcpy(SelectedDirectory, TFTstrchr_pointer + 5);
695 719
                   SelectedFile[0] = 0;
696
-                  ANYCUBIC_SENDCOMMAND_DBG_PGM("J21", "TFT Serial Debug: Clear file selection... J21 "); // J21 Not File Selected
697
-                  ANYCUBIC_SERIAL_ENTER();
720
+                  SENDLINE_DBG_PGM("J21", "TFT Serial Debug: Clear file selection... J21 "); // J21 Not File Selected
721
+                  SENDLINE_PGM("");
698 722
                 }
699 723
                 else if (TFTstrchr_pointer[4] == '<') {
700 724
                   strcpy(SelectedDirectory, TFTstrchr_pointer + 4);
701 725
                   SpecialMenu = true;
702 726
                   SelectedFile[0] = 0;
703
-                  ANYCUBIC_SENDCOMMAND_DBG_PGM("J21", "TFT Serial Debug: Clear file selection... J21 "); // J21 Not File Selected
704
-                  ANYCUBIC_SERIAL_ENTER();
727
+                  SENDLINE_DBG_PGM("J21", "TFT Serial Debug: Clear file selection... J21 "); // J21 Not File Selected
728
+                  SENDLINE_PGM("");
705 729
                 }
706 730
                 else {
707 731
                   SelectedDirectory[0] = 0;
@@ -710,7 +734,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
710 734
                     *(starpos - 1) = '\0';
711 735
 
712 736
                   strcpy(SelectedFile, TFTstrchr_pointer + 4);
713
-                  ANYCUBIC_SENDCOMMAND_DBG_PGM_VAL("J20", "TFT Serial Debug: File Selected... J20 ", SelectedFile); // J20 File Selected
737
+                  SENDLINE_DBG_PGM_VAL("J20", "TFT Serial Debug: File Selected... J20 ", SelectedFile); // J20 File Selected
714 738
                 }
715 739
               }
716 740
             #endif
@@ -766,7 +790,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
766 790
             }
767 791
             ExtUI::setTargetFan_percent(fanPercent, ExtUI::FAN0);
768 792
 
769
-            ANYCUBIC_SERIAL_ENTER();
793
+            SENDLINE_PGM("");
770 794
           }
771 795
           break;
772 796
 
@@ -776,7 +800,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
776 800
               disable_all_steppers();
777 801
             }
778 802
 
779
-            ANYCUBIC_SERIAL_ENTER();
803
+            SENDLINE_PGM("");
780 804
             break;
781 805
 
782 806
           case 20: { // A20 read printing speed
@@ -785,7 +809,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
785 809
             if (CodeSeen('S'))
786 810
               feedrate_percentage = constrain(CodeValue(), 40, 999);
787 811
             else
788
-              ANYCUBIC_SENDCOMMANDPGM_VAL("A20V ", feedrate_percentage);
812
+              SEND_PGM_VAL("A20V ", feedrate_percentage);
789 813
           }
790 814
             break;
791 815
 
@@ -855,14 +879,14 @@ void AnycubicTFTClass::GetCommandFromTFT() {
855 879
 
856 880
               if (strlen(commandStr) > 0) {
857 881
                 sprintf_P(fullCommandStr, PSTR("G91\n%s\nG90"), commandStr);
858
-                #if ENABLED(ANYCUBIC_TFT_DEBUG)
882
+                #if ENABLED(ANYCUBIC_LCD_DEBUG)
859 883
                   SERIAL_ECHOPGM("TFT Serial Debug: A22 Move final request with gcode... ");
860 884
                   SERIAL_ECHOLN(fullCommandStr);
861 885
                 #endif
862 886
                 ExtUI::injectCommands(fullCommandStr);
863 887
               }
864 888
             }
865
-            ANYCUBIC_SERIAL_ENTER();
889
+            SENDLINE_PGM("");
866 890
             break;
867 891
 
868 892
           case 23: // A23 preheat pla
@@ -872,8 +896,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
872 896
 
873 897
               ExtUI::setTargetTemp_celsius(PREHEAT_1_TEMP_BED, (ExtUI::heater_t) ExtUI::BED);
874 898
               ExtUI::setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, (ExtUI::extruder_t) ExtUI::E0);
875
-              ANYCUBIC_SERIAL_SUCC_START;
876
-              ANYCUBIC_SERIAL_ENTER();
899
+              SENDLINE_PGM("OK");
877 900
             }
878 901
             break;
879 902
 
@@ -884,8 +907,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
884 907
 
885 908
               ExtUI::setTargetTemp_celsius(PREHEAT_2_TEMP_BED, (ExtUI::heater_t) ExtUI::BED);
886 909
               ExtUI::setTargetTemp_celsius(PREHEAT_2_TEMP_HOTEND, (ExtUI::extruder_t) ExtUI::E0);
887
-              ANYCUBIC_SERIAL_SUCC_START;
888
-              ANYCUBIC_SERIAL_ENTER();
910
+              SENDLINE_PGM("OK");
889 911
             }
890 912
             break;
891 913
 
@@ -894,7 +916,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
894 916
               ExtUI::setTargetTemp_celsius(0, (ExtUI::heater_t) ExtUI::BED);
895 917
               ExtUI::setTargetTemp_celsius(0, (ExtUI::extruder_t) ExtUI::E0);
896 918
 
897
-              ANYCUBIC_SENDCOMMAND_DBG_PGM("J12", "TFT Serial Debug: Cooling down... J12"); // J12 cool down
919
+              SENDLINE_DBG_PGM("J12", "TFT Serial Debug: Cooling down... J12"); // J12 cool down
898 920
             }
899 921
             break;
900 922
 
@@ -915,7 +937,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
915 937
                 }
916 938
               }
917 939
               else {
918
-                ANYCUBIC_SENDCOMMAND_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to refresh SD A26... J02");
940
+                SENDLINE_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to refresh SD A26... J02");
919 941
               }
920 942
 
921 943
               SelectedDirectory[0] = 0;
@@ -931,13 +953,12 @@ void AnycubicTFTClass::GetCommandFromTFT() {
931 953
               NOOP;
932 954
             else if (CodeSeen('C'))
933 955
               NOOP;
934
-            ANYCUBIC_SERIAL_ENTER();
956
+            SENDLINE_PGM("");
935 957
             break;
936 958
 
937 959
           case 33: // A33 get version info
938
-            ANYCUBIC_SERIAL_PROTOCOLPGM("J33 ");
939
-            ANYCUBIC_SERIAL_PROTOCOLPGM(DETAILED_BUILD_VERSION);
940
-            ANYCUBIC_SERIAL_ENTER();
960
+            SEND_PGM("J33 ");
961
+            SENDLINE_PGM(DETAILED_BUILD_VERSION);
941 962
             break;
942 963
 
943 964
           default:
@@ -959,9 +980,9 @@ void AnycubicTFTClass::DoSDCardStateCheck() {
959 980
   #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
960 981
     bool isInserted = ExtUI::isMediaInserted();
961 982
     if (isInserted)
962
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J00", "TFT Serial Debug: SD card state changed... isInserted");
983
+      SENDLINE_DBG_PGM("J00", "TFT Serial Debug: SD card state changed... isInserted");
963 984
     else
964
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J01", "TFT Serial Debug: SD card state changed... !isInserted");
985
+      SENDLINE_DBG_PGM("J01", "TFT Serial Debug: SD card state changed... !isInserted");
965 986
 
966 987
   #endif
967 988
 }
@@ -976,10 +997,10 @@ void AnycubicTFTClass::DoFilamentRunoutCheck() {
976 997
         ExtUI::injectCommands_P(PSTR("\nM300 P200 S1567\nM300 P200 S1174\nM300 P200 S1567\nM300 P200 S1174\nM300 P2000 S1567"));
977 998
 
978 999
         // tell the user that the filament has run out and wait
979
-        ANYCUBIC_SENDCOMMAND_DBG_PGM("J23", "TFT Serial Debug: Blocking filament prompt... J23");
1000
+        SENDLINE_DBG_PGM("J23", "TFT Serial Debug: Blocking filament prompt... J23");
980 1001
       }
981 1002
       else {
982
-        ANYCUBIC_SENDCOMMAND_DBG_PGM("J15", "TFT Serial Debug: Non blocking filament runout... J15");
1003
+        SENDLINE_DBG_PGM("J15", "TFT Serial Debug: Non blocking filament runout... J15");
983 1004
       }
984 1005
     }
985 1006
   #endif // FILAMENT_RUNOUT_SENSOR
@@ -988,7 +1009,7 @@ void AnycubicTFTClass::DoFilamentRunoutCheck() {
988 1009
 void AnycubicTFTClass::StartPrint() {
989 1010
   #if ENABLED(SDSUPPORT)
990 1011
     if (!ExtUI::isPrinting() && strlen(SelectedFile) > 0) {
991
-      #if ENABLED(ANYCUBIC_TFT_DEBUG)
1012
+      #if ENABLED(ANYCUBIC_LCD_DEBUG)
992 1013
         SERIAL_ECHOPGM("TFT Serial Debug: About to print file ... ");
993 1014
         SERIAL_ECHO(ExtUI::isPrinting());
994 1015
         SERIAL_ECHOPGM(" ");
@@ -1006,7 +1027,7 @@ void AnycubicTFTClass::PausePrint() {
1006 1027
     if (ExtUI::isPrintingFromMedia() && mediaPrintingState != AMPRINTSTATE_STOP_REQUESTED && mediaPauseState == AMPAUSESTATE_NOT_PAUSED) {
1007 1028
       mediaPrintingState = AMPRINTSTATE_PAUSE_REQUESTED;
1008 1029
       mediaPauseState    = AMPAUSESTATE_NOT_PAUSED; // need the userconfirm method to update pause state
1009
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J05", "TFT Serial Debug: SD print pause started... J05"); // J05 printing pause
1030
+      SENDLINE_DBG_PGM("J05", "TFT Serial Debug: SD print pause started... J05"); // J05 printing pause
1010 1031
 
1011 1032
       // for some reason pausing the print doesn't retract the extruder so force a manual one here
1012 1033
       ExtUI::injectCommands_P(PSTR("G91\nG1 E-2 F1800\nG90"));
@@ -1019,7 +1040,7 @@ void AnycubicTFTClass::ResumePrint() {
1019 1040
   #if ENABLED(SDSUPPORT)
1020 1041
     #if ENABLED(FILAMENT_RUNOUT_SENSOR)
1021 1042
       if (READ(FIL_RUNOUT_PIN)) {
1022
-        #if ENABLED(ANYCUBIC_TFT_DEBUG)
1043
+        #if ENABLED(ANYCUBIC_LCD_DEBUG)
1023 1044
           SERIAL_ECHOLNPGM("TFT Serial Debug: Resume Print with filament sensor still tripped... ");
1024 1045
         #endif
1025 1046
 
@@ -1027,7 +1048,7 @@ void AnycubicTFTClass::ResumePrint() {
1027 1048
         DoFilamentRunoutCheck();
1028 1049
 
1029 1050
         // re-enable the continue button
1030
-        ANYCUBIC_SENDCOMMAND_DBG_PGM("J18", "TFT Serial Debug: Resume Print with filament sensor still tripped... J18");
1051
+        SENDLINE_DBG_PGM("J18", "TFT Serial Debug: Resume Print with filament sensor still tripped... J18");
1031 1052
         return;
1032 1053
       }
1033 1054
     #endif
@@ -1036,7 +1057,7 @@ void AnycubicTFTClass::ResumePrint() {
1036 1057
       mediaPauseState = AMPAUSESTATE_REHEATING;
1037 1058
       // TODO: JBA I don't think J05 just disables the continue button, i think it injects a rogue M25. So taking this out
1038 1059
       // // disable the continue button
1039
-      // ANYCUBIC_SENDCOMMAND_DBG_PGM("J05", "TFT Serial Debug: Resume called with heater timeout... J05"); // J05 printing pause
1060
+      // SENDLINE_DBG_PGM("J05", "TFT Serial Debug: Resume called with heater timeout... J05"); // J05 printing pause
1040 1061
 
1041 1062
       // reheat the nozzle
1042 1063
       ExtUI::setUserConfirmed();
@@ -1045,7 +1066,7 @@ void AnycubicTFTClass::ResumePrint() {
1045 1066
       mediaPrintingState = AMPRINTSTATE_PRINTING;
1046 1067
       mediaPauseState    = AMPAUSESTATE_NOT_PAUSED;
1047 1068
 
1048
-      ANYCUBIC_SENDCOMMAND_DBG_PGM("J04", "TFT Serial Debug: SD print resumed... J04"); // J04 printing form sd card now
1069
+      SENDLINE_DBG_PGM("J04", "TFT Serial Debug: SD print resumed... J04"); // J04 printing form sd card now
1049 1070
       ExtUI::resumePrint();
1050 1071
     }
1051 1072
   #endif
@@ -1055,7 +1076,7 @@ void AnycubicTFTClass::StopPrint() {
1055 1076
   #if ENABLED(SDSUPPORT)
1056 1077
     mediaPrintingState = AMPRINTSTATE_STOP_REQUESTED;
1057 1078
     mediaPauseState    = AMPAUSESTATE_NOT_PAUSED;
1058
-    ANYCUBIC_SENDCOMMAND_DBG_PGM("J16", "TFT Serial Debug: SD print stop called... J16");
1079
+    SENDLINE_DBG_PGM("J16", "TFT Serial Debug: SD print stop called... J16");
1059 1080
 
1060 1081
     // for some reason stopping the print doesn't retract the extruder so force a manual one here
1061 1082
     ExtUI::injectCommands_P(PSTR("G91\nG1 E-2 F1800\nG90"));
@@ -1063,4 +1084,4 @@ void AnycubicTFTClass::StopPrint() {
1063 1084
   #endif
1064 1085
 }
1065 1086
 
1066
-#endif // ANYCUBIC_TFT_MODEL
1087
+#endif // ANYCUBIC_LCD_I3MEGA

Marlin/src/lcd/extui/lib/anycubic/anycubic_tft.h → Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.h View File

@@ -1,5 +1,5 @@
1 1
 /**
2
- * anycubic_tft.h  --- Support for Anycubic i3 Mega TFT
2
+ * anycubic_i3mega_lcd.h  --- Support for Anycubic i3 Mega TFT
3 3
  * Created by Christian Hopp on 09.12.17.
4 4
  * Improved by David Ramiro
5 5
  * Converted to ext_iu by John BouAntoun 21 June 2020
@@ -23,18 +23,6 @@
23 23
 #include "../../../../inc/MarlinConfigPre.h"
24 24
 #include "../../../../sd/SdFatConfig.h"   // for the FILENAME_LENGTH macro
25 25
 
26
-// command sending macro's with debugging capability
27
-#define ANYCUBIC_SENDCOMMANDPGM(x)                  ANYCUBIC_SERIAL_PROTOCOLLNPGM(x)
28
-#define ANYCUBIC_SENDCOMMANDPGM_VAL(x,y)            (ANYCUBIC_SERIAL_PROTOCOLPGM(x), ANYCUBIC_SERIAL_PROTOCOLLN(itostr3(y)))
29
-#define ANYCUBIC_SENDCOMMAND(x)                     ANYCUBIC_SERIAL_PROTOCOLLN(x)
30
-#if ENABLED(ANYCUBIC_TFT_DEBUG)
31
-  #define ANYCUBIC_SENDCOMMAND_DBG_PGM(x,y)         (ANYCUBIC_SERIAL_PROTOCOLLNPGM(x), SERIAL_ECHOLNPGM(y))
32
-  #define ANYCUBIC_SENDCOMMAND_DBG_PGM_VAL(x,y,z)   (ANYCUBIC_SERIAL_PROTOCOLLNPGM(x), SERIAL_ECHOPGM(y), SERIAL_ECHOLN(z))
33
-#else
34
-  #define ANYCUBIC_SENDCOMMAND_DBG_PGM(x,y)         (ANYCUBIC_SERIAL_PROTOCOLLNPGM(x))
35
-  #define ANYCUBIC_SENDCOMMAND_DBG_PGM_VAL(x,y,z)   (ANYCUBIC_SERIAL_PROTOCOLLNPGM(x))
36
-#endif
37
-
38 26
 char *itostr2(const uint8_t &x);
39 27
 #ifndef ULTRA_LCD
40 28
   char *itostr3(const int);

+ 4
- 4
Marlin/src/lcd/extui/ui_api.cpp View File

@@ -304,7 +304,7 @@ namespace ExtUI {
304 304
     return epos;
305 305
   }
306 306
 
307
-  void setAxisPosition_mm(const float position, const axis_t axis) {
307
+  void setAxisPosition_mm(const float position, const axis_t axis, const feedRate_t feedrate/*=0*/) {
308 308
     // Start with no limits to movement
309 309
     float min = current_position[axis] - 1000,
310 310
           max = current_position[axis] + 1000;
@@ -337,14 +337,14 @@ namespace ExtUI {
337 337
     #endif
338 338
 
339 339
     current_position[axis] = constrain(position, min, max);
340
-    line_to_current_position(manual_feedrate_mm_s[axis]);
340
+    line_to_current_position(feedrate ?: manual_feedrate_mm_s[axis]);
341 341
   }
342 342
 
343
-  void setAxisPosition_mm(const float position, const extruder_t extruder) {
343
+  void setAxisPosition_mm(const float position, const extruder_t extruder, const feedRate_t feedrate/*=0*/) {
344 344
     setActiveTool(extruder, true);
345 345
 
346 346
     current_position.e = position;
347
-    line_to_current_position(manual_feedrate_mm_s.e);
347
+    line_to_current_position(feedrate ?: manual_feedrate_mm_s.e);
348 348
   }
349 349
 
350 350
   void setActiveTool(const extruder_t extruder, bool no_move) {

+ 2
- 2
Marlin/src/lcd/extui/ui_api.h View File

@@ -164,8 +164,8 @@ namespace ExtUI {
164 164
   void setTargetTemp_celsius(const float, const heater_t);
165 165
   void setTargetTemp_celsius(const float, const extruder_t);
166 166
   void setTargetFan_percent(const float, const fan_t);
167
-  void setAxisPosition_mm(const float, const axis_t);
168
-  void setAxisPosition_mm(const float, const extruder_t);
167
+  void setAxisPosition_mm(const float, const axis_t, const feedRate_t=0);
168
+  void setAxisPosition_mm(const float, const extruder_t, const feedRate_t=0);
169 169
   void setAxisSteps_per_mm(const float, const axis_t);
170 170
   void setAxisSteps_per_mm(const float, const extruder_t);
171 171
   void setAxisMaxFeedrate_mm_s(const feedRate_t, const axis_t);

+ 536
- 0
Marlin/src/lcd/extui_anycubic_chiron_lcd.cpp View File

@@ -0,0 +1,536 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 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
+
23
+/**
24
+ * extui_anycubic_chiron_lcd.cpp
25
+ *
26
+ * Anycubic Chiron TFT support for Marlin
27
+ */
28
+
29
+#include "../inc/MarlinConfigPre.h"
30
+
31
+#if ENABLED(ANYCUBIC_LCD_CHIRON)
32
+
33
+#include "extui/ui_api.h"
34
+
35
+#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
36
+  #if GRID_MAX_POINTS_X != 5 || GRID_MAX_POINTS_Y != 5
37
+    #error ANYCUBIC CHIRON LCD requires a 5x5 bed leveling grid (GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y)
38
+  #endif
39
+#else
40
+  #error ANYCUBIC CHIRON LCD requires AUTO_BED_LEVELING_BILINEAR enabled
41
+#endif
42
+
43
+#if DISABLED(FILAMENT_RUNOUT_SENSOR)
44
+  #error ANYCUBIC CHIRON LCD requires FILAMENT_RUNOUT_SENSOR enabled
45
+#endif
46
+
47
+#if ENABLED(POWER_LOSS_RECOVERY)
48
+  #error ANYCUBIC CHIRON LCD does not currently support POWER_LOSS_RECOVERY
49
+#endif
50
+
51
+static bool is_auto_leveling = false;
52
+static bool is_printing_from_sd = false;
53
+static bool is_out_of_filament = false;
54
+
55
+static void sendNewLine(void) {
56
+  ANYCUBIC_LCD_SERIAL.write('\r');
57
+  ANYCUBIC_LCD_SERIAL.write('\n');
58
+}
59
+
60
+static void send(const char *str) {
61
+  ANYCUBIC_LCD_SERIAL.print(str);
62
+}
63
+
64
+static void sendLine(const char *str) {
65
+  send(str);
66
+  sendNewLine();
67
+}
68
+
69
+static void send_P(PGM_P str) {
70
+  while (const char c = pgm_read_byte(str++))
71
+    ANYCUBIC_LCD_SERIAL.write(c);
72
+}
73
+
74
+static void sendLine_P(PGM_P str) {
75
+  send_P(str);
76
+  sendNewLine();
77
+}
78
+
79
+static void sendValue_P(PGM_P prefix, int value) {
80
+  send_P(prefix);
81
+  ANYCUBIC_LCD_SERIAL.print(value);
82
+}
83
+
84
+static void sendValue_P(PGM_P prefix, float value) {
85
+  send_P(prefix);
86
+  ANYCUBIC_LCD_SERIAL.print(value);
87
+}
88
+
89
+static void sendValueLine_P(PGM_P prefix, int value) {
90
+  send_P(prefix);
91
+  ANYCUBIC_LCD_SERIAL.print(value);
92
+  sendNewLine();
93
+}
94
+
95
+static void sendValueLine_P(PGM_P prefix, float value) {
96
+  send_P(prefix);
97
+  ANYCUBIC_LCD_SERIAL.print(value);
98
+  sendNewLine();
99
+}
100
+
101
+static int parseIntArgument(const char *buffer, char letterId) {
102
+  char *p = strchr(buffer, letterId);
103
+  if (!p)
104
+    return -1;
105
+  return atoi(p+1);
106
+}
107
+
108
+static float parseFloatArgument(const char *buffer, char letterId) {
109
+  char *p = strchr(buffer, letterId);
110
+  if (!p)
111
+    return NAN;
112
+  return strtof(p+1, nullptr);
113
+}
114
+
115
+static int mmToHundredths(float x) {
116
+  // Round
117
+  if (x >= 0)
118
+    x += 0.005f;
119
+  else
120
+    x -= 0.005f;
121
+  return (int)(x * 100.0f);
122
+}
123
+
124
+static float hundredthsToMm(int x) {
125
+  return x / 100.0f;
126
+}
127
+
128
+#define SEND_PGM(str)                           send_P(PSTR(str))
129
+#define SENDLINE_PGM(str)                       sendLine_P(PSTR(str))
130
+#define SENDVALUE_PGM(prefix, value)            sendValue_P(PSTR(prefix), value)
131
+#define SENDVALUELINE_PGM(prefix, value)        sendValueLine_P(PSTR(prefix), value)
132
+
133
+namespace ExtUI {
134
+
135
+  static void moveAxis(float delta, feedRate_t feedrate, axis_t axis) {
136
+    float pos = getAxisPosition_mm(axis);
137
+    pos += delta;
138
+    setAxisPosition_mm(pos, axis, feedrate);
139
+  }
140
+
141
+  static void handleCmd(const char *rx) {
142
+    static FileList fileList;
143
+    static char selectedFileShortName[8+1+3+1];
144
+
145
+    if (rx[0] != 'A') {
146
+      SERIAL_ECHOPGM("Unexpected RX: ");
147
+      SERIAL_ECHOLN(rx);
148
+    
149
+      return;
150
+    }
151
+
152
+    const int cmd = atoi(&rx[1]);
153
+
154
+    // Uncomment for debugging RX
155
+    //if (cmd > 7 && cmd != 20) {
156
+    //  SERIAL_ECHOPGM("RX: ");
157
+    //  SERIAL_ECHOLN(rx);
158
+    //}
159
+
160
+    switch (cmd) {
161
+      case 0: // Get Hotend Actual Temperature
162
+        SENDVALUELINE_PGM("A0V ", (int)getActualTemp_celsius(E0));
163
+        break;
164
+      case 1: // Get Hotend Target Temperature
165
+        SENDVALUELINE_PGM("A1V ", (int)getTargetTemp_celsius(E0));
166
+        break;
167
+      case 2: // Get Bed Actual Temperature
168
+        SENDVALUELINE_PGM("A2V ", (int)getActualTemp_celsius(BED));
169
+        break;
170
+      case 3: // Get Bed Target Temperature
171
+        SENDVALUELINE_PGM("A3V ", (int)getTargetTemp_celsius(BED));
172
+        break;
173
+      case 4: // Get Fan Speed
174
+        SENDVALUELINE_PGM("A4V ", (int)getTargetFan_percent(FAN0));
175
+        break;
176
+      case 5: // Get Current Coordinates
177
+        SENDVALUE_PGM("A5V X: ", getAxisPosition_mm(X));
178
+        SENDVALUE_PGM(" Y: ", getAxisPosition_mm(Y));
179
+        SENDVALUE_PGM(" Z: ", getAxisPosition_mm(Z));
180
+        sendNewLine();
181
+        break;
182
+      case 6: // Get SD Card Print Status
183
+        if (isPrintingFromMedia())
184
+          SENDVALUELINE_PGM("A6V ", (int)getProgress_percent());
185
+        else
186
+          SENDLINE_PGM("A6V ---");
187
+        break;
188
+      case 7: // Get Printing Time
189
+        if (isPrinting()) {
190
+          const int totalMinutes = getProgress_seconds_elapsed() / 60;
191
+          SENDVALUE_PGM("A7V ", (int)(totalMinutes/60));
192
+          SENDVALUE_PGM(" H ", (int)(totalMinutes%60));
193
+          SENDLINE_PGM(" M");
194
+        } else {
195
+          SENDLINE_PGM("A7V 999:999");
196
+        }
197
+        break;
198
+      case 8: // Get SD Card File List
199
+        if (isMediaInserted()) {
200
+          const int startIndex = parseIntArgument(rx, 'S');
201
+          SENDLINE_PGM("FN ");
202
+          for (int i = 0, fileIndex = 0, numFiles = 0; i < (int)fileList.count() && numFiles < 4; i++) {
203
+            fileList.seek(i);
204
+            if (!fileList.isDir()) {
205
+              if (fileIndex >= startIndex) {
206
+                sendLine(fileList.shortFilename());
207
+                sendLine(fileList.longFilename());
208
+                numFiles++;
209
+              }
210
+              fileIndex++;
211
+            }
212
+          }
213
+          SENDLINE_PGM("END");
214
+        } else {
215
+          SENDLINE_PGM("J02");
216
+        }
217
+        break;
218
+      case 9: // Pause SD Card Print
219
+        if (isPrintingFromMedia()) {
220
+          pausePrint();
221
+          is_printing_from_sd = false;
222
+          SENDLINE_PGM("J05");
223
+        } else {
224
+          SENDLINE_PGM("J16"); // Print stopped
225
+        }
226
+        break;
227
+      case 10: // Resume SD Card Print
228
+        if (is_out_of_filament) {
229
+          is_out_of_filament = false;
230
+          // Filament change did eject the old filament automatically,
231
+          // now continue and load the new one
232
+          setUserConfirmed();
233
+          SENDLINE_PGM("J04"); // Printing from SD card
234
+        } else if (isPrintingFromMediaPaused()) {
235
+          resumePrint();
236
+          SENDLINE_PGM("J04"); // Printing from SD card
237
+        }
238
+        break;
239
+      case 11: // Stop SD Card Print
240
+        if (isPrintingFromMedia()) {
241
+          stopPrint();
242
+          is_printing_from_sd = false;
243
+          SENDLINE_PGM("J16"); // Print stopped
244
+        }
245
+        break;
246
+      //case 12: // Kill
247
+      //  break;
248
+      case 13: // Select File
249
+        if (!isPrinting()) {
250
+          // Store selected file name
251
+          char *p = strchr(rx, ' ');
252
+          if (p != nullptr && strlen(p+1) < sizeof(selectedFileShortName)) {
253
+            strcpy(selectedFileShortName, p+1);
254
+            SENDLINE_PGM("J20"); // Open succeeded
255
+          }
256
+          else
257
+            SENDLINE_PGM("J21"); // Open failed
258
+        }
259
+        break;
260
+      case 14: // Start Print
261
+        if (!isPrinting() && strcmp(selectedFileShortName, "") != 0) {
262
+          printFile(selectedFileShortName);
263
+          is_printing_from_sd = true;
264
+          SENDLINE_PGM("J04"); // Printing from SD card
265
+        }
266
+        break;
267
+      case 15: // Resume from power outage
268
+        // This is not supported, just report print as completed
269
+        SENDLINE_PGM("J16"); // Print stopped
270
+        break;
271
+      case 16: // Set Hotend Target Temperature
272
+        {
273
+          int temp = parseIntArgument(rx, 'S');
274
+          if (temp >= 0)
275
+            setTargetTemp_celsius(temp, E0);
276
+        }
277
+        break;
278
+      case 17: // Set Bed Target Temperature
279
+        {
280
+          int temp = parseIntArgument(rx, 'S');
281
+          if (temp >= 0)
282
+            setTargetTemp_celsius(temp, BED);
283
+        }
284
+        break;
285
+      case 18: // Set Fan Speed
286
+        {
287
+          int temp = parseIntArgument(rx, 'S');
288
+          if (temp >= 0)
289
+            setTargetFan_percent(temp, FAN0);
290
+        }
291
+        break;
292
+      case 19: // Disable Motors
293
+        injectCommands_P(PSTR("M84"));
294
+        break;
295
+      case 20: // Get/Set Printing Speed
296
+        {
297
+          int newPerc = parseIntArgument(rx, 'S');
298
+          if (newPerc >= 0)
299
+            setFeedrate_percent(newPerc);
300
+          else
301
+            SENDVALUELINE_PGM("A20V ", (int)getFeedrate_percent());
302
+        }
303
+        break;
304
+      case 21: // Home axes
305
+        if (!isPrinting()) {
306
+          const bool hasX = strchr(rx, 'X') != nullptr,
307
+                     hasY = strchr(rx, 'Y') != nullptr,
308
+                     hasZ = strchr(rx, 'Z') != nullptr,
309
+                     hasC = strchr(rx, 'C') != nullptr;
310
+          if (hasX || hasY || hasZ) {
311
+            if (hasX) injectCommands_P(PSTR("G28 X"));
312
+            if (hasY) injectCommands_P(PSTR("G28 Y"));
313
+            if (hasZ) injectCommands_P(PSTR("G28 Z"));
314
+          } else if (hasC) {
315
+            injectCommands_P(PSTR("G28"));
316
+          }
317
+        }
318
+        break;
319
+      case 22: // Move axes
320
+        if (!isPrinting()) {
321
+          const int feedrate = parseIntArgument(rx, 'F') / 60;
322
+          float delta;
323
+          if (!isnan(delta = parseFloatArgument(rx, 'X')))
324
+            moveAxis(delta, feedrate, X);
325
+          else if (!isnan(delta = parseFloatArgument(rx, 'Y')))
326
+            moveAxis(delta, feedrate, Y);
327
+          else if (!isnan(delta = parseFloatArgument(rx, 'Z')))
328
+            moveAxis(delta, feedrate, Z);
329
+        }
330
+        break;
331
+      case 23: // Preheat PLA
332
+        setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, E0);
333
+        setTargetTemp_celsius(PREHEAT_1_TEMP_BED, BED);
334
+        SENDLINE_PGM("OK");
335
+        break;
336
+      case 24: // Preheat ABS
337
+        setTargetTemp_celsius(PREHEAT_2_TEMP_HOTEND, E0);
338
+        setTargetTemp_celsius(PREHEAT_2_TEMP_BED, BED);
339
+        SENDLINE_PGM("OK");
340
+        break;
341
+      case 25: // Cool down
342
+        setTargetTemp_celsius(0, E0);
343
+        setTargetTemp_celsius(0, BED);
344
+        SENDLINE_PGM("J12");
345
+        break;
346
+      case 26: // Refresh SD Card
347
+        fileList.refresh();
348
+        break;
349
+      //case 27: // Adjust Servo Angles
350
+      //  break;
351
+      //case 28: // Filament Test
352
+      //  break;
353
+      case 29: // Get Bed Autolevel Grid
354
+        {
355
+          int x = parseIntArgument(rx, 'X'),
356
+              y = parseIntArgument(rx, 'Y');
357
+          if (x != -1 && y != -1) {
358
+            xy_uint8_t coord;
359
+            coord.set(x, y);
360
+            const int value = mmToHundredths(getMeshPoint(coord));
361
+            SENDVALUELINE_PGM("A29V ", value);
362
+          }
363
+        }
364
+        break;
365
+      case 30: // Autolevel
366
+        if (strchr(rx, 'S')) { // Autoleveling started by clicking "PROBE" and then "OK"
367
+          // Note:
368
+          //  We check for completion by monitoring the command queue.
369
+          //  Since it will become empty *while* processing the last injected command,
370
+          //  we enqueue an extra 10ms delay so we can the determine when all the others
371
+          //  have completed.
372
+          if (isMachineHomed())
373
+            injectCommands_P(PSTR("G29\nG4 P10"));
374
+          else
375
+            injectCommands_P(PSTR("G28\nG29\nG4 P10"));
376
+          is_auto_leveling = true;
377
+        } else { // Entering Autoleveling screen
378
+          if (isPrinting())
379
+            SENDLINE_PGM("J24"); // Disallow autoleveling
380
+          else
381
+            SENDLINE_PGM("J26"); // Allow autoleveling
382
+        }
383
+        break;
384
+      case 31: // Set Bed Autolevel Z offset
385
+        if (strchr(rx, 'G')) { // Get
386
+          SENDVALUELINE_PGM("A31V ", getZOffset_mm());
387
+        } else if (strchr(rx, 'S')) { // Set
388
+          float delta = parseFloatArgument(rx, 'S');
389
+          delta = constrain(delta, -1.0, 1.0);
390
+          setZOffset_mm(getZOffset_mm() + delta);
391
+
392
+          SENDVALUELINE_PGM("A31V ", getZOffset_mm());
393
+        } else if (strchr(rx, 'D')) { // Save
394
+          injectCommands_P(PSTR("M500"));
395
+        }
396
+        break;
397
+      //case 32: // ?
398
+      //  break;
399
+      case 33: // Get Version Info
400
+        SENDLINE_PGM("J33 " SHORT_BUILD_VERSION);
401
+        break;
402
+      case 34: // Set Bed Autolevel Grid
403
+        {
404
+          int x = parseIntArgument(rx, 'X'),
405
+              y = parseIntArgument(rx, 'Y'),
406
+              v = parseIntArgument(rx, 'V');
407
+          if (x != -1 && y != -1 && v != -1) { // Set new value
408
+            float value = hundredthsToMm(v);
409
+            value = constrain(value, -10, 10);
410
+
411
+            xy_uint8_t coord;
412
+            coord.set(x, y);
413
+            setMeshPoint(coord, value);
414
+          } else if (strchr(rx, 'S')) { // Save (apply new values)
415
+            injectCommands_P(PSTR("M500"));
416
+          } else if (strchr(rx, 'C')) { // Cancel (discard new values)
417
+            injectCommands_P(PSTR("M501"));
418
+          }
419
+        }
420
+        break;
421
+    }
422
+  }
423
+
424
+  #define RX_LEN_MAX 63
425
+  static void parseSerialRx() {
426
+    static char rxBuffer[RX_LEN_MAX+1];
427
+    static uint8_t rxLen = 0;
428
+
429
+    while (ANYCUBIC_LCD_SERIAL.available()) {
430
+      const char c = ANYCUBIC_LCD_SERIAL.read();
431
+      switch (c) {
432
+        case '\r': case '\n':
433
+          if (rxLen > 0 && rxLen <= RX_LEN_MAX) {
434
+            rxBuffer[rxLen] = '\0'; // Terminate string
435
+            handleCmd(rxBuffer);
436
+          }
437
+          rxLen = 0;
438
+          break;
439
+        default:
440
+          if (rxLen < RX_LEN_MAX)
441
+            rxBuffer[rxLen++] = c;
442
+          else {
443
+            rxLen = 0xFF; // Overrun
444
+            SERIAL_ECHOPGM("Warning: dropping long received line");
445
+          }
446
+          break;
447
+      }
448
+    }
449
+  }
450
+
451
+  static void detectPrintFromSdCompletion() {
452
+    // Note: printFile() queues some commands that actually start the print, so isPrintingFromMedia()
453
+    //       initially returns false
454
+    if (is_printing_from_sd && !commandsInQueue() && !isPrintingFromMedia()) {
455
+      is_printing_from_sd = false;
456
+      SENDLINE_PGM("J14"); // Print done
457
+    }
458
+  }
459
+
460
+  static void detectAutolevelingCompletion() {
461
+    if (is_auto_leveling && !commandsInQueue()) {
462
+      is_auto_leveling = false;
463
+      injectCommands_P(PSTR("M500"));
464
+      SENDLINE_PGM("J25"); // Autoleveling done
465
+    }
466
+  }
467
+
468
+  void onStartup() {
469
+    ANYCUBIC_LCD_SERIAL.begin(115200);
470
+    sendNewLine();
471
+    SENDLINE_PGM("J17"); // Reset
472
+    delay_ms(10);
473
+    SENDLINE_PGM("J12"); // Ready
474
+  }
475
+
476
+  void onIdle() {
477
+    parseSerialRx();
478
+    detectAutolevelingCompletion();
479
+    detectPrintFromSdCompletion();
480
+  }
481
+
482
+  void onPrinterKilled(PGM_P const error, PGM_P const component) { }
483
+
484
+  void onMediaInserted() {
485
+    SENDLINE_PGM("J00"); // SD Inserted
486
+  }
487
+
488
+  void onMediaError() { }
489
+
490
+  void onMediaRemoved() {
491
+    SENDLINE_PGM("J01"); // SD Removed
492
+  }
493
+  
494
+  void onPlayTone(const uint16_t frequency, const uint16_t duration) {
495
+    tone(BEEPER_PIN, frequency, duration);
496
+  }
497
+
498
+  void onPrintTimerStarted() { }
499
+
500
+  void onPrintTimerPaused() { }
501
+
502
+  void onPrintTimerStopped() { }
503
+
504
+  void onFilamentRunout(const extruder_t extruder) {
505
+    is_out_of_filament = true;
506
+    SENDLINE_PGM("J23"); // Filament runout
507
+    SENDLINE_PGM("J18"); // Print paused
508
+    // Note: printer will unload filament automatically
509
+  }
510
+
511
+  void onUserConfirmRequired(const char * const msg) { }
512
+
513
+  void onStatusChanged(const char * const msg) { }
514
+
515
+  void onFactoryReset() { }
516
+
517
+  void onStoreSettings(char *buff) { }
518
+
519
+  void onLoadSettings(const char *buff) { }
520
+
521
+  void onConfigurationStoreWritten(bool success) { }
522
+
523
+  void onConfigurationStoreRead(bool success) { }
524
+
525
+  void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) { }
526
+
527
+  #if ENABLED(POWER_LOSS_RECOVERY)
528
+    void onPowerLossResume() { }
529
+  #endif
530
+
531
+  #if HAS_PID_HEATING
532
+    void onPidTuning(const result_t rst) { }
533
+  #endif
534
+}
535
+
536
+#endif // ANYCUBIC_LCD_CHIRON

Marlin/src/lcd/extui_anycubic_tft.cpp → Marlin/src/lcd/extui_anycubic_i3mega_lcd.cpp View File

@@ -21,14 +21,14 @@
21 21
  */
22 22
 
23 23
 /**
24
- * extui_anycubic_tft.cpp
24
+ * extui_anycubic_i3mega_lcd.cpp
25 25
  */
26 26
 
27 27
 #include "../inc/MarlinConfigPre.h"
28 28
 
29
-#if BOTH(ANYCUBIC_TFT_MODEL, EXTENSIBLE_UI)
29
+#if ENABLED(ANYCUBIC_LCD_I3MEGA)
30 30
 
31
-#include "extui/lib/anycubic/anycubic_tft.h"
31
+#include "extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.h"
32 32
 #include "extui/ui_api.h"
33 33
 
34 34
 #include <Arduino.h>    // for the ::tone() call
@@ -101,4 +101,4 @@ namespace ExtUI {
101 101
   #endif
102 102
 }
103 103
 
104
-#endif // ANYCUBIC_TFT_MODEL && EXTENSIBLE_UI
104
+#endif // ANYCUBIC_LCD_I3MEGA

+ 53
- 47
Marlin/src/pins/ramps/pins_TRIGORILLA_14.h View File

@@ -27,49 +27,8 @@
27 27
 
28 28
 #define BOARD_INFO_NAME "Anycubic RAMPS 1.4"
29 29
 
30
-//
31
-// Servos
32
-//
33
-#if MB(TRIGORILLA_14_11)
34
-  #define SERVO0_PIN                           5
35
-  #define SERVO1_PIN                           4
36
-  #define SERVO2_PIN                          11
37
-  #define SERVO3_PIN                           6
38
-#endif
39
-
40
-//
41
-// Limit Switches
42
-//
43
-//#define ANYCUBIC_4_MAX_PRO_ENDSTOPS
44
-
45
-#define X_MIN_PIN                              3
46
-
47
-#if ENABLED(ANYCUBIC_4_MAX_PRO_ENDSTOPS)
48
-  #define X_MAX_PIN                           43
49
-#else
50
-  #define X_MAX_PIN                           43
51
-#endif
30
+// Board labeled pins:
52 31
 
53
-#if ENABLED(ANYCUBIC_4_MAX_PRO_ENDSTOPS)
54
-  #define Y_STOP_PIN                          19
55
-#else
56
-  #define Y_STOP_PIN                          42
57
-#endif
58
-
59
-#define Z_STOP_PIN                            18
60
-
61
-//
62
-// Z Probe (when not Z_MIN_PIN)
63
-//
64
-#define Z_MIN_PROBE_PIN                        2
65
-
66
-#ifndef FIL_RUNOUT_PIN
67
-  #define FIL_RUNOUT_PIN                      19
68
-#endif
69
-
70
-//
71
-// Heaters / Fans
72
-//
73 32
 #define TG_HEATER_BED_PIN                      8
74 33
 #define TG_HEATER_0_PIN                       10
75 34
 #define TG_HEATER_1_PIN                       45  // Anycubic Kossel: Unused
@@ -78,10 +37,15 @@
78 37
 #define TG_FAN1_PIN                            7  // Anycubic Kossel: Unused
79 38
 #define TG_FAN2_PIN                           44  // Anycubic Kossel: Hotend fan
80 39
 
81
-#define CONTROLLER_FAN_PIN           TG_FAN1_PIN
82
-
83
-#define BEEPER_PIN                            31
84
-#define SD_DETECT_PIN                         49
40
+//
41
+// Servos
42
+//
43
+#if MB(TRIGORILLA_14_11)
44
+  #define SERVO0_PIN                           5
45
+  #define SERVO1_PIN                           4
46
+  #define SERVO2_PIN                          11
47
+  #define SERVO3_PIN                           6
48
+#endif
85 49
 
86 50
 // Remap MOSFET pins to common usages:
87 51
 
@@ -100,7 +64,11 @@
100 64
 #elif TEMP_SENSOR_BED
101 65
   // EFB (Anycubic Kossel default)
102 66
   #define RAMPS_D9_PIN               TG_FAN0_PIN
103
-  #define RAMPS_D8_PIN         TG_HEATER_BED_PIN
67
+  #if ENABLED(ANYCUBIC_CHIRON)
68
+    #define RAMPS_D8_PIN         TG_HEATER_1_PIN  // Heated bed is connected to HEATER1 output
69
+  #else
70
+    #define RAMPS_D8_PIN       TG_HEATER_BED_PIN
71
+  #endif
104 72
 #else
105 73
   // EFF
106 74
   #define RAMPS_D9_PIN               TG_FAN1_PIN
@@ -116,6 +84,44 @@
116 84
   #define E0_AUTO_FAN_PIN            TG_FAN2_PIN  // Used in Anycubic Kossel example config
117 85
 #endif
118 86
 
87
+#if ENABLED(ANYCUBIC_I3MEGA)
88
+  #define CONTROLLER_FAN_PIN         TG_FAN1_PIN
89
+#endif
90
+
91
+//
92
+// AnyCubic standard pin mappings
93
+//
94
+//  On most printers, endstops are NOT all wired to the appropriate pins on the Trigorilla board.
95
+//  For instance, on a Chiron, Y axis goes to an aux connector.
96
+//  There are also other things that have been wired in creative ways.
97
+//  To enable PIN definitions for a specific printer model, #define the appropriate symbol after
98
+//  MOTHERBOARD in Configuration.h
99
+
100
+//
101
+// Limit Switches
102
+//
103
+//#define ANYCUBIC_4_MAX_PRO_ENDSTOPS
104
+
105
+#if ENABLED(ANYCUBIC_4_MAX_PRO_ENDSTOPS)
106
+  #define X_MAX_PIN                           43
107
+  #define Y_STOP_PIN                          19
108
+#elif EITHER(ANYCUBIC_CHIRON, ANYCUBIC_I3MEGA)
109
+  #define Y_STOP_PIN                          42
110
+  #define Z2_MIN_PIN                          43
111
+  #ifndef Z_MIN_PROBE_PIN
112
+    #define Z_MIN_PROBE_PIN                    2
113
+  #endif
114
+  #ifndef FIL_RUNOUT_PIN
115
+    #if ENABLED(ANYCUBIC_CHIRON)
116
+      #define FIL_RUNOUT_PIN                  33
117
+    #else
118
+      #define FIL_RUNOUT_PIN                  19
119
+    #endif
120
+  #endif
121
+  #define BEEPER_PIN                          31
122
+  #define SD_DETECT_PIN                       49
123
+#endif
124
+
119 125
 #include "pins_RAMPS.h"
120 126
 
121 127
 //

+ 1
- 1
platformio.ini View File

@@ -66,7 +66,7 @@ HAS_GRAPHICAL_TFT       = src_filter=+<src/lcd/tft>
66 66
 HAS_LCD_MENU            = src_filter=+<src/lcd/menu>
67 67
 HAS_DGUS_LCD            = src_filter=+<src/lcd/extui/lib/dgus>
68 68
 TOUCH_UI_FTDI_EVE       = src_filter=+<src/lcd/extui/lib/ftdi_eve_touch_ui>
69
-ANYCUBIC_TFT_MODEL      = src_filter=+<src/lcd/extui/lib/anycubic>
69
+ANYCUBIC_LCD_I3MEGA     = src_filter=+<src/lcd/extui/lib/anycubic_i3mega>
70 70
 USB_FLASH_DRIVE_SUPPORT = src_filter=+<src/sd/usb_flashdrive>
71 71
 AUTO_BED_LEVELING_(3POINT|(BI)?LINEAR) = src_filter=+<src/feature/bedlevel/abl> +<src/gcode/bedlevel/abl>
72 72
 MESH_BED_LEVELING       = src_filter=+<src/feature/bedlevel/mbl> +<src/gcode/bedlevel/mbl>

Loading…
Cancel
Save