瀏覽代碼

Multi-host support

Thomas Moore 7 年之前
父節點
當前提交
f7efac57b7
共有 41 個檔案被更改,包括 1190 行新增745 行删除
  1. 9
    0
      Marlin/Configuration.h
  2. 1
    2
      Marlin/src/HAL/HAL_AVR/HAL_AVR.cpp
  3. 18
    0
      Marlin/src/HAL/HAL_AVR/HAL_AVR.h
  4. 2
    2
      Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h
  5. 2
    2
      Marlin/src/HAL/HAL_AVR/pinsDebug_AVR_8_bit.h
  6. 8
    8
      Marlin/src/HAL/HAL_DUE/EepromEmulation_Due.cpp
  7. 13
    2
      Marlin/src/HAL/HAL_DUE/HAL_Due.h
  8. 6
    6
      Marlin/src/HAL/HAL_LPC1768/HAL.cpp
  9. 31
    6
      Marlin/src/HAL/HAL_LPC1768/HAL.h
  10. 1
    1
      Marlin/src/HAL/HAL_LPC1768/arduino.cpp
  11. 7
    8
      Marlin/src/HAL/HAL_LPC1768/main.cpp
  12. 49
    106
      Marlin/src/HAL/HAL_LPC1768/serial.h
  13. 30
    5
      Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.h
  14. 7
    5
      Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.h
  15. 16
    3
      Marlin/src/Marlin.cpp
  16. 26
    14
      Marlin/src/core/serial.cpp
  17. 155
    23
      Marlin/src/core/serial.h
  18. 6
    3
      Marlin/src/feature/bedlevel/abl/abl.cpp
  19. 21
    10
      Marlin/src/feature/bedlevel/ubl/ubl.cpp
  20. 10
    2
      Marlin/src/feature/bedlevel/ubl/ubl.h
  21. 2
    2
      Marlin/src/feature/tmc_util.cpp
  22. 24
    4
      Marlin/src/gcode/eeprom/M500-M504.cpp
  23. 20
    20
      Marlin/src/gcode/feature/trinamic/M122.cpp
  24. 12
    1
      Marlin/src/gcode/host/M115.cpp
  25. 11
    4
      Marlin/src/gcode/parser.cpp
  26. 162
    110
      Marlin/src/gcode/queue.cpp
  27. 7
    0
      Marlin/src/gcode/queue.h
  28. 27
    5
      Marlin/src/gcode/sdcard/M20-M30_M32-M34_M928.cpp
  29. 9
    2
      Marlin/src/gcode/stats/M31.cpp
  30. 17
    5
      Marlin/src/gcode/temperature/M105.cpp
  31. 0
    6
      Marlin/src/inc/Conditionals_LCD.h
  32. 293
    243
      Marlin/src/module/configuration_store.cpp
  33. 37
    7
      Marlin/src/module/configuration_store.h
  34. 2
    2
      Marlin/src/module/stepper.h
  35. 35
    19
      Marlin/src/module/temperature.cpp
  36. 5
    1
      Marlin/src/module/temperature.h
  37. 19
    20
      Marlin/src/sd/SdBaseFile.cpp
  38. 13
    45
      Marlin/src/sd/SdFatUtil.cpp
  39. 0
    8
      Marlin/src/sd/SdFatUtil.h
  40. 57
    29
      Marlin/src/sd/cardreader.cpp
  41. 20
    4
      Marlin/src/sd/cardreader.h

+ 9
- 0
Marlin/Configuration.h 查看文件

103
 #define SERIAL_PORT 0
103
 #define SERIAL_PORT 0
104
 
104
 
105
 /**
105
 /**
106
+ * Select a secondary serial port on the board to use for communication with the host.
107
+ * This allows the connection of wireless adapters (for instance) to non-default port pins.
108
+ * Serial port -1 is the USB emulated serial port, if avaialble.
109
+ *
110
+ * :[-1, 0, 1, 2, 3, 4, 5, 6, 7]
111
+ */
112
+#define SERIAL_PORT_2 -1
113
+
114
+/**
106
  * This setting determines the communication speed of the printer.
115
  * This setting determines the communication speed of the printer.
107
  *
116
  *
108
  * 250000 works in most cases, but you might try a lower speed if
117
  * 250000 works in most cases, but you might try a lower speed if

+ 1
- 2
Marlin/src/HAL/HAL_AVR/HAL_AVR.cpp 查看文件

33
 // Includes
33
 // Includes
34
 // --------------------------------------------------------------------------
34
 // --------------------------------------------------------------------------
35
 
35
 
36
-#include "../HAL.h"
37
-#include "../../core/macros.h"
36
+#include "../../inc/MarlinConfig.h"
38
 
37
 
39
 // --------------------------------------------------------------------------
38
 // --------------------------------------------------------------------------
40
 // Externals
39
 // Externals

+ 18
- 0
Marlin/src/HAL/HAL_AVR/HAL_AVR.h 查看文件

47
 #include "watchdog_AVR.h"
47
 #include "watchdog_AVR.h"
48
 #include "math_AVR.h"
48
 #include "math_AVR.h"
49
 
49
 
50
+#ifdef USBCON
51
+  #include "HardwareSerial.h"
52
+#else
53
+  #include "MarlinSerial.h"
54
+#endif
55
+
50
 // --------------------------------------------------------------------------
56
 // --------------------------------------------------------------------------
51
 // Defines
57
 // Defines
52
 // --------------------------------------------------------------------------
58
 // --------------------------------------------------------------------------
79
 
85
 
80
 //extern uint8_t MCUSR;
86
 //extern uint8_t MCUSR;
81
 
87
 
88
+#define NUM_SERIAL 1
89
+
90
+#ifdef USBCON
91
+  #if ENABLED(BLUETOOTH)
92
+    #define MYSERIAL0 bluetoothSerial
93
+  #else
94
+    #define MYSERIAL0 Serial
95
+  #endif
96
+#else
97
+  #define MYSERIAL0 customizedSerial
98
+#endif
99
+
82
 // --------------------------------------------------------------------------
100
 // --------------------------------------------------------------------------
83
 // Public functions
101
 // Public functions
84
 // --------------------------------------------------------------------------
102
 // --------------------------------------------------------------------------

+ 2
- 2
Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h 查看文件

483
       for (uint8_t y = 0; y < 28; y++) {                   // always print pin name
483
       for (uint8_t y = 0; y < 28; y++) {                   // always print pin name
484
         temp_char = pgm_read_byte(name_mem_pointer + y);
484
         temp_char = pgm_read_byte(name_mem_pointer + y);
485
         if (temp_char != 0)
485
         if (temp_char != 0)
486
-          MYSERIAL.write(temp_char);
486
+          SERIAL_CHAR(temp_char);
487
         else {
487
         else {
488
-          for (uint8_t i = 0; i < 28 - y; i++) MYSERIAL.write(' ');
488
+          for (uint8_t i = 0; i < 28 - y; i++) SERIAL_CHAR(' ');
489
           break;
489
           break;
490
         }
490
         }
491
       }
491
       }

+ 2
- 2
Marlin/src/HAL/HAL_AVR/pinsDebug_AVR_8_bit.h 查看文件

66
   for (uint8_t y = 0; y < MAX_NAME_LENGTH; y++) {
66
   for (uint8_t y = 0; y < MAX_NAME_LENGTH; y++) {
67
     char temp_char = pgm_read_byte(name_mem_pointer + y);
67
     char temp_char = pgm_read_byte(name_mem_pointer + y);
68
     if (temp_char != 0)
68
     if (temp_char != 0)
69
-      MYSERIAL.write(temp_char);
69
+      SERIAL_CHAR(temp_char);
70
     else {
70
     else {
71
-      for (uint8_t i = 0; i < MAX_NAME_LENGTH - y; i++) MYSERIAL.write(' ');
71
+      for (uint8_t i = 0; i < MAX_NAME_LENGTH - y; i++) SERIAL_CHAR(' ');
72
       break;
72
       break;
73
     }
73
     }
74
   }
74
   }

+ 8
- 8
Marlin/src/HAL/HAL_DUE/EepromEmulation_Due.cpp 查看文件

121
     char buffer[80];
121
     char buffer[80];
122
 
122
 
123
     sprintf(buffer, "Page: %d (0x%04x)\n", page, page);
123
     sprintf(buffer, "Page: %d (0x%04x)\n", page, page);
124
-    MYSERIAL.print(buffer);
124
+    SERIAL_PROTOCOL(buffer);
125
 
125
 
126
     char* p = &buffer[0];
126
     char* p = &buffer[0];
127
     for (int i = 0; i< PageSize; ++i) {
127
     for (int i = 0; i< PageSize; ++i) {
133
       if ((i & 15) == 15) {
133
       if ((i & 15) == 15) {
134
         *p++ = '\n';
134
         *p++ = '\n';
135
         *p = 0;
135
         *p = 0;
136
-        MYSERIAL.print(buffer);
136
+        SERIAL_PROTOCOL(buffer);
137
         p = &buffer[0];
137
         p = &buffer[0];
138
       }
138
       }
139
     }
139
     }
182
     SERIAL_ECHOLNPAIR("EEPROM PageWrite   ",page);
182
     SERIAL_ECHOLNPAIR("EEPROM PageWrite   ",page);
183
     SERIAL_ECHOLNPAIR(" in FLASH address ",(uint32_t)addrflash);
183
     SERIAL_ECHOLNPAIR(" in FLASH address ",(uint32_t)addrflash);
184
     SERIAL_ECHOLNPAIR(" base address     ",(uint32_t)getFlashStorage(0));
184
     SERIAL_ECHOLNPAIR(" base address     ",(uint32_t)getFlashStorage(0));
185
-    MYSERIAL.flush();
185
+    SERIAL_FLUSH();
186
   #endif
186
   #endif
187
 
187
 
188
   // Get the page relative to the start of the EFC controller, and the EFC controller to use
188
   // Get the page relative to the start of the EFC controller, and the EFC controller to use
313
     SERIAL_ECHOLNPAIR("EEPROM PageErase  ",page);
313
     SERIAL_ECHOLNPAIR("EEPROM PageErase  ",page);
314
     SERIAL_ECHOLNPAIR(" in FLASH address ",(uint32_t)addrflash);
314
     SERIAL_ECHOLNPAIR(" in FLASH address ",(uint32_t)addrflash);
315
     SERIAL_ECHOLNPAIR(" base address     ",(uint32_t)getFlashStorage(0));
315
     SERIAL_ECHOLNPAIR(" base address     ",(uint32_t)getFlashStorage(0));
316
-    MYSERIAL.flush();
316
+    SERIAL_FLUSH();
317
   #endif
317
   #endif
318
 
318
 
319
   // Get the page relative to the start of the EFC controller, and the EFC controller to use
319
   // Get the page relative to the start of the EFC controller, and the EFC controller to use
943
   #ifdef EE_EMU_DEBUG
943
   #ifdef EE_EMU_DEBUG
944
     SERIAL_ECHO_START();
944
     SERIAL_ECHO_START();
945
     SERIAL_ECHOLNPAIR("EEPROM Current Group: ",curGroup);
945
     SERIAL_ECHOLNPAIR("EEPROM Current Group: ",curGroup);
946
-    MYSERIAL.flush();
946
+    SERIAL_FLUSH();
947
   #endif
947
   #endif
948
 
948
 
949
   // Now, validate that all the other group pages are empty
949
   // Now, validate that all the other group pages are empty
957
           SERIAL_ECHO_START();
957
           SERIAL_ECHO_START();
958
           SERIAL_ECHOPAIR("EEPROM Page ",page);
958
           SERIAL_ECHOPAIR("EEPROM Page ",page);
959
           SERIAL_ECHOLNPAIR(" not clean on group ",grp);
959
           SERIAL_ECHOLNPAIR(" not clean on group ",grp);
960
-          MYSERIAL.flush();
960
+          SERIAL_FLUSH();
961
         #endif
961
         #endif
962
         ee_PageErase(grp * PagesPerGroup + page);
962
         ee_PageErase(grp * PagesPerGroup + page);
963
       }
963
       }
978
   #ifdef EE_EMU_DEBUG
978
   #ifdef EE_EMU_DEBUG
979
     SERIAL_ECHO_START();
979
     SERIAL_ECHO_START();
980
     SERIAL_ECHOLNPAIR("EEPROM Active page: ",curPage);
980
     SERIAL_ECHOLNPAIR("EEPROM Active page: ",curPage);
981
-    MYSERIAL.flush();
981
+    SERIAL_FLUSH();
982
   #endif
982
   #endif
983
 
983
 
984
   // Make sure the pages following the first clean one are also clean
984
   // Make sure the pages following the first clean one are also clean
988
         SERIAL_ECHO_START();
988
         SERIAL_ECHO_START();
989
         SERIAL_ECHOPAIR("EEPROM Page ",page);
989
         SERIAL_ECHOPAIR("EEPROM Page ",page);
990
         SERIAL_ECHOLNPAIR(" not clean on active group ",curGroup);
990
         SERIAL_ECHOLNPAIR(" not clean on active group ",curGroup);
991
-        MYSERIAL.flush();
991
+        SERIAL_FLUSH();
992
         ee_Dump(curGroup * PagesPerGroup + page, getFlashStorage(curGroup * PagesPerGroup + page));
992
         ee_Dump(curGroup * PagesPerGroup + page, getFlashStorage(curGroup * PagesPerGroup + page));
993
       #endif
993
       #endif
994
       ee_PageErase(curGroup * PagesPerGroup + page);
994
       ee_PageErase(curGroup * PagesPerGroup + page);

+ 13
- 2
Marlin/src/HAL/HAL_DUE/HAL_Due.h 查看文件

40
 //
40
 //
41
 // Defines
41
 // Defines
42
 //
42
 //
43
-#if SERIAL_PORT >= -1 && SERIAL_PORT <= 4
44
-  #define MYSERIAL customizedSerial
43
+#define NUM_SERIAL 1
44
+
45
+//#undef SERIAL_PORT
46
+//#define SERIAL_PORT -1
47
+
48
+#if SERIAL_PORT == -1
49
+  #define MYSERIAL0 SerialUSB
50
+#else
51
+  #define MYSERIAL0 customizedSerial
45
 #endif
52
 #endif
46
 
53
 
47
 // We need the previous define before the include, or compilation bombs...
54
 // We need the previous define before the include, or compilation bombs...
147
 void HAL_enable_AdcFreerun(void);
154
 void HAL_enable_AdcFreerun(void);
148
 //void HAL_disable_AdcFreerun(uint8_t chan);
155
 //void HAL_disable_AdcFreerun(uint8_t chan);
149
 
156
 
157
+/**
158
+ * Pin Map
159
+ */
160
+
150
 #define GET_PIN_MAP_PIN(index) index
161
 #define GET_PIN_MAP_PIN(index) index
151
 #define GET_PIN_MAP_INDEX(pin) pin
162
 #define GET_PIN_MAP_INDEX(pin) pin
152
 #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
163
 #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

+ 6
- 6
Marlin/src/HAL/HAL_LPC1768/HAL.cpp 查看文件

29
 
29
 
30
 HalSerial usb_serial;
30
 HalSerial usb_serial;
31
 
31
 
32
-//u8glib required fucntions
32
+// U8glib required functions
33
 extern "C" void u8g_xMicroDelay(uint16_t val) {
33
 extern "C" void u8g_xMicroDelay(uint16_t val) {
34
   delayMicroseconds(val);
34
   delayMicroseconds(val);
35
 }
35
 }
85
   pin_t pin = analogInputToDigitalPin(ch);
85
   pin_t pin = analogInputToDigitalPin(ch);
86
 
86
 
87
   if (pin == -1) {
87
   if (pin == -1) {
88
-    MYSERIAL.printf("%sINVALID ANALOG PORT:%d\n", errormagic, ch);
88
+    SERIAL_PRINTF("%sINVALID ANALOG PORT:%d\n", errormagic, ch);
89
     kill(MSG_KILLED);
89
     kill(MSG_KILLED);
90
   }
90
   }
91
 
91
 
97
                               pin_port == 1                        ? 3 : 10;
97
                               pin_port == 1                        ? 3 : 10;
98
 
98
 
99
   switch (pin_sel_register) {
99
   switch (pin_sel_register) {
100
-    case 1 :
100
+    case 1:
101
       LPC_PINCON->PINSEL1 &= ~(0x3 << pinsel_start_bit);
101
       LPC_PINCON->PINSEL1 &= ~(0x3 << pinsel_start_bit);
102
       LPC_PINCON->PINSEL1 |=  (0x1 << pinsel_start_bit);
102
       LPC_PINCON->PINSEL1 |=  (0x1 << pinsel_start_bit);
103
       break;
103
       break;
104
-    case 3 :
104
+    case 3:
105
       LPC_PINCON->PINSEL3 &= ~(0x3 << pinsel_start_bit);
105
       LPC_PINCON->PINSEL3 &= ~(0x3 << pinsel_start_bit);
106
       LPC_PINCON->PINSEL3 |=  (0x3 << pinsel_start_bit);
106
       LPC_PINCON->PINSEL3 |=  (0x3 << pinsel_start_bit);
107
       break;
107
       break;
108
-    case 0 :
108
+    case 0:
109
       LPC_PINCON->PINSEL0 &= ~(0x3 << pinsel_start_bit);
109
       LPC_PINCON->PINSEL0 &= ~(0x3 << pinsel_start_bit);
110
       LPC_PINCON->PINSEL0 |=  (0x2 << pinsel_start_bit);
110
       LPC_PINCON->PINSEL0 |=  (0x2 << pinsel_start_bit);
111
       break;
111
       break;
115
 uint8_t active_adc = 0;
115
 uint8_t active_adc = 0;
116
 void HAL_adc_start_conversion(const uint8_t ch) {
116
 void HAL_adc_start_conversion(const uint8_t ch) {
117
   if (analogInputToDigitalPin(ch) == -1) {
117
   if (analogInputToDigitalPin(ch) == -1) {
118
-    MYSERIAL.printf("HAL: HAL_adc_start_conversion: invalid channel %d\n", ch);
118
+    SERIAL_PRINTF("HAL: HAL_adc_start_conversion: invalid channel %d\n", ch);
119
     return;
119
     return;
120
   }
120
   }
121
 
121
 

+ 31
- 6
Marlin/src/HAL/HAL_LPC1768/HAL.h 查看文件

69
 #define ST7920_DELAY_2 DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP
69
 #define ST7920_DELAY_2 DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP
70
 #define ST7920_DELAY_3 DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP
70
 #define ST7920_DELAY_3 DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP;DELAY_5_NOP
71
 
71
 
72
-//Serial override
73
 extern HalSerial usb_serial;
72
 extern HalSerial usb_serial;
74
 
73
 
74
+#if !WITHIN(SERIAL_PORT, -1, 3)
75
+  #error "SERIAL_PORT must be from -1 to 3"
76
+#endif
77
+
75
 #if SERIAL_PORT == -1
78
 #if SERIAL_PORT == -1
76
-  #define MYSERIAL usb_serial
79
+  #define MYSERIAL0 usb_serial
77
 #elif SERIAL_PORT == 0
80
 #elif SERIAL_PORT == 0
78
-  #define MYSERIAL Serial
81
+  #define MYSERIAL0 Serial
79
 #elif SERIAL_PORT == 1
82
 #elif SERIAL_PORT == 1
80
-  #define MYSERIAL Serial1
83
+  #define MYSERIAL0 Serial1
81
 #elif SERIAL_PORT == 2
84
 #elif SERIAL_PORT == 2
82
-  #define MYSERIAL Serial2
85
+  #define MYSERIAL0 Serial2
83
 #elif SERIAL_PORT == 3
86
 #elif SERIAL_PORT == 3
84
-  #define MYSERIAL Serial3
87
+  #define MYSERIAL0 Serial3
88
+#endif
89
+
90
+#ifdef SERIAL_PORT_2
91
+  #if !WITHIN(SERIAL_PORT_2, -1, 3)
92
+    #error "SERIAL_PORT_2 must be from -1 to 3"
93
+  #elif SERIAL_PORT_2 == SERIAL_PORT
94
+    #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
95
+  #endif
96
+  #define NUM_SERIAL 2
97
+  #if SERIAL_PORT_2 == -1
98
+    #define MYSERIAL1 usb_serial
99
+  #elif SERIAL_PORT_2 == 0
100
+    #define MYSERIAL1 Serial
101
+  #elif SERIAL_PORT_2 == 1
102
+    #define MYSERIAL1 Serial1
103
+  #elif SERIAL_PORT_2 == 2
104
+    #define MYSERIAL1 Serial2
105
+  #elif SERIAL_PORT_2 == 3
106
+    #define MYSERIAL1 Serial3
107
+  #endif
108
+#else
109
+  #define NUM_SERIAL 1
85
 #endif
110
 #endif
86
 
111
 
87
 #define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq();
112
 #define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq();

+ 1
- 1
Marlin/src/HAL/HAL_LPC1768/arduino.cpp 查看文件

139
     if (LPC1768_PWM_attach_pin(pin, 1, LPC_PWM1->MR0, 0xFF))
139
     if (LPC1768_PWM_attach_pin(pin, 1, LPC_PWM1->MR0, 0xFF))
140
       LPC1768_PWM_write(pin, map(value, 0, 255, 1, LPC_PWM1->MR0));  // map 1-254 onto PWM range
140
       LPC1768_PWM_write(pin, map(value, 0, 255, 1, LPC_PWM1->MR0));  // map 1-254 onto PWM range
141
     else {                                                                 // out of PWM channels
141
     else {                                                                 // out of PWM channels
142
-      if (!out_of_PWM_slots) MYSERIAL.printf(".\nWARNING - OUT OF PWM CHANNELS\n.\n");  //only warn once
142
+      if (!out_of_PWM_slots) SERIAL_ECHOPGM(".\nWARNING - OUT OF PWM CHANNELS\n.\n");  //only warn once
143
       out_of_PWM_slots = true;
143
       out_of_PWM_slots = true;
144
       digitalWrite(pin, value);  // treat as a digital pin if out of channels
144
       digitalWrite(pin, value);  // treat as a digital pin if out of channels
145
     }
145
     }

+ 7
- 8
Marlin/src/HAL/HAL_LPC1768/main.cpp 查看文件

88
     #endif
88
     #endif
89
   }
89
   }
90
 
90
 
91
-  // Only initialize the debug framework if using the USB emulated serial port
92
-  if ((HalSerial*) &MYSERIAL == &usb_serial)
93
-    debug_frmwrk_init();
94
-
95
-  MYSERIAL.begin(BAUDRATE);
96
-  MYSERIAL.printf("\n\nLPC1768 (%dMhz) UART0 Initialised\n", SystemCoreClock / 1000000);
97
-  #if TX_BUFFER_SIZE > 0
98
-    MYSERIAL.flushTX();
91
+  #if NUM_SERIAL > 0
92
+    MYSERIAL0.begin(BAUDRATE);
93
+    #if NUM_SERIAL > 1
94
+      MYSERIAL1.begin(BAUDRATE);
95
+    #endif
96
+    SERIAL_PRINTF("\n\nLPC1768 (%dMhz) UART0 Initialised\n", SystemCoreClock / 1000000);
97
+    SERIAL_FLUSHTX();
99
   #endif
98
   #endif
100
 
99
 
101
   HAL_timer_init();
100
   HAL_timer_init();

+ 49
- 106
Marlin/src/HAL/HAL_LPC1768/serial.h 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-#ifndef HAL_SERIAL_H_
24
-#define HAL_SERIAL_H_
23
+#ifndef _HAL_SERIAL_H_
24
+#define _HAL_SERIAL_H_
25
 
25
 
26
 #include <stdarg.h>
26
 #include <stdarg.h>
27
 #include <stdio.h>
27
 #include <stdio.h>
30
 #include <debug_frmwrk.h>
30
 #include <debug_frmwrk.h>
31
 }
31
 }
32
 
32
 
33
-/*
33
+/**
34
  * Generic RingBuffer
34
  * Generic RingBuffer
35
  * T type of the buffer array
35
  * T type of the buffer array
36
  * S size of the buffer (must be power of 2)
36
  * S size of the buffer (must be power of 2)
39
  */
39
  */
40
 template <typename T, uint32_t S> class RingBuffer {
40
 template <typename T, uint32_t S> class RingBuffer {
41
 public:
41
 public:
42
-  RingBuffer() {
43
-    index_read = 0;
44
-    index_write = 0;
45
-  }
42
+  RingBuffer() { index_read = index_write = 0; }
43
+  uint32_t available() volatile { return buffer_mask & (index_write - index_read); }
44
+  uint32_t free() volatile      { return buffer_size - available(); }
45
+  bool empty() volatile         { return (buffer_mask & index_read) == (buffer_mask & index_write); }
46
+  bool full() volatile          { return index_read == buffer_mask & (index_write + 1); }
47
+  void clear() volatile         { index_read = index_write = 0; }
46
   bool peek(T *value) volatile {
48
   bool peek(T *value) volatile {
47
-    if(value == 0 || available() == 0)
49
+    if (value == 0 || available() == 0)
48
       return false;
50
       return false;
49
     *value = buffer[buffer_mask & index_read];
51
     *value = buffer[buffer_mask & index_read];
50
     return true;
52
     return true;
51
   }
53
   }
52
-  uint32_t available() volatile {
53
-    return buffer_mask & (index_write - index_read);
54
-  }
55
-  uint32_t free() volatile {
56
-    return buffer_size - available();
57
-  }
58
-  T read() volatile {
59
-    if((buffer_mask & index_read) == (buffer_mask & index_write)) return T(-1);
54
+  int read() volatile {
55
+    if ((buffer_mask & index_read) == (buffer_mask & index_write)) return -1;
60
     T val = buffer[buffer_mask & index_read];
56
     T val = buffer[buffer_mask & index_read];
61
     ++index_read;
57
     ++index_read;
62
     return val;
58
     return val;
63
   }
59
   }
64
-  bool write( T value) volatile {
60
+  bool write(T value) volatile {
65
     uint32_t next_head = buffer_mask & (index_write + 1);
61
     uint32_t next_head = buffer_mask & (index_write + 1);
66
-    if(next_head != index_read) {
62
+    if (next_head != index_read) {
67
       buffer[buffer_mask & index_write] = value;
63
       buffer[buffer_mask & index_write] = value;
68
       index_write = next_head;
64
       index_write = next_head;
69
       return true;
65
       return true;
70
     }
66
     }
71
     return false;
67
     return false;
72
   }
68
   }
73
-  bool empty() volatile {
74
-    return (buffer_mask & index_read) == (buffer_mask & index_write);
75
-  }
76
-  bool full() volatile {
77
-    return index_read == buffer_mask & (index_write + 1);
78
-  }
79
-  void clear() volatile {
80
-    index_read = index_write = 0;
81
-  }
82
 
69
 
83
 private:
70
 private:
84
   static const uint32_t buffer_size = S;
71
   static const uint32_t buffer_size = S;
90
 
77
 
91
 class HalSerial {
78
 class HalSerial {
92
 public:
79
 public:
93
-  HalSerial() {
94
-    host_connected = false;
95
-  }
80
+  HalSerial() { host_connected = false; }
96
 
81
 
97
   void begin(int32_t baud) {
82
   void begin(int32_t baud) {
98
   }
83
   }
99
 
84
 
100
-  char read() {
101
-    return (char)receive_buffer.read();
85
+  int peek() {
86
+    uint8_t value;
87
+    return receive_buffer.peek(&value) ? value : -1;
102
   }
88
   }
103
 
89
 
104
-  void write(char c) {
105
-    _DBC(c); //Duplicate output over uart0
106
-    if(host_connected) transmit_buffer.write((uint8_t)c);
107
-  }
90
+  int read() { return receive_buffer.read(); }
108
 
91
 
109
-  operator bool() {
110
-    return host_connected;
111
-  }
92
+  size_t write(char c) { return host_connected ? transmit_buffer.write((uint8_t)c) : 0; }
93
+
94
+  operator bool() { return host_connected; }
112
 
95
 
113
   uint16_t available() {
96
   uint16_t available() {
114
     return (uint16_t)receive_buffer.available();
97
     return (uint16_t)receive_buffer.available();
115
   }
98
   }
116
 
99
 
117
-  void flush() {
118
-    receive_buffer.clear();
119
-  }
100
+  void flush() { receive_buffer.clear(); }
120
 
101
 
121
   uint8_t availableForWrite(void){
102
   uint8_t availableForWrite(void){
122
     return transmit_buffer.free() > 255 ? 255 : (uint8_t)transmit_buffer.free();
103
     return transmit_buffer.free() > 255 ? 255 : (uint8_t)transmit_buffer.free();
123
   }
104
   }
124
 
105
 
125
   void flushTX(void){
106
   void flushTX(void){
126
-    if(host_connected) {
127
-      while(transmit_buffer.available());
128
-    }
107
+    if (host_connected)
108
+      while (transmit_buffer.available()) { /* nada */ }
129
   }
109
   }
130
 
110
 
131
   void printf(const char *format, ...) {
111
   void printf(const char *format, ...) {
135
     int length = vsnprintf((char *) buffer, 256, (char const *) format, vArgs);
115
     int length = vsnprintf((char *) buffer, 256, (char const *) format, vArgs);
136
     va_end(vArgs);
116
     va_end(vArgs);
137
     if (length > 0 && length < 256) {
117
     if (length > 0 && length < 256) {
138
-      _DBG(buffer); //Duplicate output over uart0
139
       if (host_connected) {
118
       if (host_connected) {
140
         for (int i = 0; i < length;) {
119
         for (int i = 0; i < length;) {
141
           if (transmit_buffer.write(buffer[i])) {
120
           if (transmit_buffer.write(buffer[i])) {
152
   #define BIN 2
131
   #define BIN 2
153
   #define BYTE 0
132
   #define BYTE 0
154
 
133
 
155
-
156
   void print_bin(uint32_t value, uint8_t num_digits) {
134
   void print_bin(uint32_t value, uint8_t num_digits) {
157
     uint32_t mask = 1 << (num_digits -1);
135
     uint32_t mask = 1 << (num_digits -1);
158
     for (uint8_t i = 0; i < num_digits; i++) {
136
     for (uint8_t i = 0; i < num_digits; i++) {
159
-      if (!(i % 4) && i)    printf(" ");
160
-      if (!(i % 16)  && i)  printf(" ");
161
-      if (value & mask)     printf("1");
162
-      else                  printf("0");
137
+      if (!(i % 4) && i)    write(' ');
138
+      if (!(i % 16)  && i)  write(' ');
139
+      if (value & mask)     write('1');
140
+      else                  write('0');
163
       value <<= 1;
141
       value <<= 1;
164
     }
142
     }
165
   }
143
   }
166
 
144
 
167
-  void print(const char value[]) {
168
-    printf("%s" , value);
169
-  }
145
+  void print(const char value[]) { printf("%s" , value); }
170
   void print(char value, int nbase = BYTE) {
146
   void print(char value, int nbase = BYTE) {
171
-    if (nbase == BIN) print_bin(value,8);
147
+    if (nbase == BIN) print_bin(value, 8);
172
     else if (nbase == OCT) printf("%3o", value);
148
     else if (nbase == OCT) printf("%3o", value);
173
     else if (nbase == HEX) printf("%2X", value);
149
     else if (nbase == HEX) printf("%2X", value);
174
     else if (nbase == DEC ) printf("%d", value);
150
     else if (nbase == DEC ) printf("%d", value);
175
     else printf("%c" , value);
151
     else printf("%c" , value);
176
   }
152
   }
177
   void print(unsigned char value, int nbase = BYTE) {
153
   void print(unsigned char value, int nbase = BYTE) {
178
-    if (nbase == BIN) print_bin(value,8);
154
+    if (nbase == BIN) print_bin(value, 8);
179
     else if (nbase == OCT) printf("%3o", value);
155
     else if (nbase == OCT) printf("%3o", value);
180
     else if (nbase == HEX) printf("%2X", value);
156
     else if (nbase == HEX) printf("%2X", value);
181
     else printf("%u" , value);
157
     else printf("%u" , value);
182
   }
158
   }
183
   void print(int value, int nbase = BYTE) {
159
   void print(int value, int nbase = BYTE) {
184
-    if (nbase == BIN) print_bin(value,16);
160
+    if (nbase == BIN) print_bin(value, 16);
185
     else if (nbase == OCT) printf("%6o", value);
161
     else if (nbase == OCT) printf("%6o", value);
186
     else if (nbase == HEX) printf("%4X", value);
162
     else if (nbase == HEX) printf("%4X", value);
187
     else printf("%d", value);
163
     else printf("%d", value);
188
   }
164
   }
189
   void print(unsigned int value, int nbase = BYTE) {
165
   void print(unsigned int value, int nbase = BYTE) {
190
-    if (nbase == BIN) print_bin(value,16);
166
+    if (nbase == BIN) print_bin(value, 16);
191
     else if (nbase == OCT) printf("%6o", value);
167
     else if (nbase == OCT) printf("%6o", value);
192
     else if (nbase == HEX) printf("%4X", value);
168
     else if (nbase == HEX) printf("%4X", value);
193
     else printf("%u" , value);
169
     else printf("%u" , value);
194
   }
170
   }
195
   void print(long value, int nbase = BYTE) {
171
   void print(long value, int nbase = BYTE) {
196
-    if (nbase == BIN) print_bin(value,32);
172
+    if (nbase == BIN) print_bin(value, 32);
197
     else if (nbase == OCT) printf("%11o", value);
173
     else if (nbase == OCT) printf("%11o", value);
198
     else if (nbase == HEX) printf("%8X", value);
174
     else if (nbase == HEX) printf("%8X", value);
199
     else printf("%ld" , value);
175
     else printf("%ld" , value);
200
   }
176
   }
201
   void print(unsigned long value, int nbase = BYTE) {
177
   void print(unsigned long value, int nbase = BYTE) {
202
-    if (nbase == BIN) print_bin(value,32);
178
+    if (nbase == BIN) print_bin(value, 32);
203
     else if (nbase == OCT) printf("%11o", value);
179
     else if (nbase == OCT) printf("%11o", value);
204
     else if (nbase == HEX) printf("%8X", value);
180
     else if (nbase == HEX) printf("%8X", value);
205
     else printf("%lu" , value);
181
     else printf("%lu" , value);
206
   }
182
   }
207
-  void print(float value, int round = 6) {
208
-    printf("%f" , value);
209
-  }
210
-  void print(double value, int round = 6) {
211
-    printf("%f" , value );
212
-  }
183
+  void print(float value, int round = 6)  { printf("%f" , value); }
184
+  void print(double value, int round = 6) { printf("%f" , value); }
213
 
185
 
214
-
215
-
216
-  void println(const char value[]) {
217
-    printf("%s\n" , value);
218
-  }
219
-  void println(char value, int nbase = BYTE) {
220
-    print(value, nbase);
221
-    println();
222
-  }
223
-  void println(unsigned char value, int nbase = BYTE) {
224
-    print(value, nbase);
225
-    println();
226
-  }
227
-  void println(int value, int nbase = BYTE) {
228
-    print(value, nbase);
229
-    println();
230
-  }
231
-  void println(unsigned int value, int nbase = BYTE) {
232
-    print(value, nbase);
233
-    println();
234
-  }
235
-  void println(long value, int nbase = BYTE) {
236
-    print(value, nbase);
237
-    println();
238
-  }
239
-  void println(unsigned long value, int nbase = BYTE) {
240
-    print(value, nbase);
241
-    println();
242
-  }
243
-  void println(float value, int round = 6) {
244
-    printf("%f\n" , value );
245
-  }
246
-  void println(double value, int round = 6) {
247
-    printf("%f\n" , value );
248
-  }
249
-  void println(void) {
250
-    print('\n');
251
-  }
186
+  void println(const char value[]) { printf("%s\n" , value); }
187
+  void println(char value, int nbase = BYTE) { print(value, nbase); println(); }
188
+  void println(unsigned char value, int nbase = BYTE) { print(value, nbase); println(); }
189
+  void println(int value, int nbase = BYTE) { print(value, nbase); println(); }
190
+  void println(unsigned int value, int nbase = BYTE) { print(value, nbase); println(); }
191
+  void println(long value, int nbase = BYTE) { print(value, nbase); println(); }
192
+  void println(unsigned long value, int nbase = BYTE) { print(value, nbase); println(); }
193
+  void println(float value, int round = 6) { printf("%f\n" , value); }
194
+  void println(double value, int round = 6) { printf("%f\n" , value); }
195
+  void println(void) { print('\n'); }
252
 
196
 
253
   volatile RingBuffer<uint8_t, 128> receive_buffer;
197
   volatile RingBuffer<uint8_t, 128> receive_buffer;
254
   volatile RingBuffer<uint8_t, 128> transmit_buffer;
198
   volatile RingBuffer<uint8_t, 128> transmit_buffer;
255
   volatile bool host_connected;
199
   volatile bool host_connected;
256
 };
200
 };
257
 
201
 
258
-
259
-#endif /* MARLIN_SRC_HAL_HAL_SERIAL_H_ */
202
+#endif // _HAL_SERIAL_H_

+ 30
- 5
Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.h 查看文件

65
 // Defines
65
 // Defines
66
 // --------------------------------------------------------------------------
66
 // --------------------------------------------------------------------------
67
 
67
 
68
+#if !WITHIN(SERIAL_PORT, -1, 3)
69
+  #error "SERIAL_PORT must be from -1 to 3"
70
+#endif
68
 #if SERIAL_PORT == -1
71
 #if SERIAL_PORT == -1
69
-  #define MYSERIAL SerialUSB
72
+  #define MYSERIAL0 SerialUSB
70
 #elif SERIAL_PORT == 0
73
 #elif SERIAL_PORT == 0
71
-  #define MYSERIAL Serial
74
+  #define MYSERIAL0 Serial
72
 #elif SERIAL_PORT == 1
75
 #elif SERIAL_PORT == 1
73
-  #define MYSERIAL Serial1
76
+  #define MYSERIAL0 Serial1
74
 #elif SERIAL_PORT == 2
77
 #elif SERIAL_PORT == 2
75
-  #define MYSERIAL Serial2
78
+  #define MYSERIAL0 Serial2
76
 #elif SERIAL_PORT == 3
79
 #elif SERIAL_PORT == 3
77
-  #define MYSERIAL Serial3
80
+  #define MYSERIAL0 Serial3
81
+#endif
82
+
83
+#ifdef SERIAL_PORT_2
84
+  #if !WITHIN(SERIAL_PORT_2, -1, 3)
85
+    #error "SERIAL_PORT_2 must be from -1 to 3"
86
+  #elif SERIAL_PORT_2 == SERIAL_PORT
87
+    #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
88
+  #endif
89
+  #define NUM_SERIAL 2
90
+  #if SERIAL_PORT_2 == -1
91
+    #define MYSERIAL1 SerialUSB
92
+  #elif SERIAL_PORT_2 == 0
93
+    #define MYSERIAL1 Serial
94
+  #elif SERIAL_PORT_2 == 1
95
+    #define MYSERIAL1 Serial1
96
+  #elif SERIAL_PORT_2 == 2
97
+    #define MYSERIAL1 Serial2
98
+  #elif SERIAL_PORT_2 == 3
99
+    #define MYSERIAL1 Serial3
100
+  #endif
101
+#else
102
+  #define NUM_SERIAL 1
78
 #endif
103
 #endif
79
 
104
 
80
 /**
105
 /**

+ 7
- 5
Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.h 查看文件

57
 #define IS_TEENSY35 defined(__MK64FX512__)
57
 #define IS_TEENSY35 defined(__MK64FX512__)
58
 #define IS_TEENSY36 defined(__MK66FX1M0__)
58
 #define IS_TEENSY36 defined(__MK66FX1M0__)
59
 
59
 
60
+#define NUM_SERIAL 1
61
+
60
 #if SERIAL_PORT == -1
62
 #if SERIAL_PORT == -1
61
-  #define MYSERIAL SerialUSB
63
+  #define MYSERIAL0 SerialUSB
62
 #elif SERIAL_PORT == 0
64
 #elif SERIAL_PORT == 0
63
-  #define MYSERIAL Serial
65
+  #define MYSERIAL0 Serial
64
 #elif SERIAL_PORT == 1
66
 #elif SERIAL_PORT == 1
65
-  #define MYSERIAL Serial1
67
+  #define MYSERIAL0 Serial1
66
 #elif SERIAL_PORT == 2
68
 #elif SERIAL_PORT == 2
67
-  #define MYSERIAL Serial2
69
+  #define MYSERIAL0 Serial2
68
 #elif SERIAL_PORT == 3
70
 #elif SERIAL_PORT == 3
69
-  #define MYSERIAL Serial3
71
+  #define MYSERIAL0 Serial3
70
 #endif
72
 #endif
71
 
73
 
72
 #define HAL_SERVO_LIB libServo
74
 #define HAL_SERVO_LIB libServo

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

669
     disableStepperDrivers();
669
     disableStepperDrivers();
670
   #endif
670
   #endif
671
 
671
 
672
-  MYSERIAL.begin(BAUDRATE);
673
-  uint32_t serial_connect_timeout = millis() + 1000;
674
-  while(!MYSERIAL && PENDING(millis(), serial_connect_timeout));
672
+  #if NUM_SERIAL > 0
673
+    MYSERIAL0.begin(BAUDRATE);
674
+    #if NUM_SERIAL > 1
675
+      MYSERIAL1.begin(BAUDRATE);
676
+    #endif
677
+  #endif
678
+
679
+  #if NUM_SERIAL > 0
680
+    uint32_t serial_connect_timeout = millis() + 1000UL;
681
+    while(!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
682
+    #if NUM_SERIAL > 1
683
+      serial_connect_timeout = millis() + 1000UL;
684
+      while(!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
685
+    #endif
686
+  #endif
687
+
675
   SERIAL_PROTOCOLLNPGM("start");
688
   SERIAL_PROTOCOLLNPGM("start");
676
   SERIAL_ECHO_START();
689
   SERIAL_ECHO_START();
677
 
690
 

+ 26
- 14
Marlin/src/core/serial.cpp 查看文件

27
 const char errormagic[] PROGMEM = "Error:";
27
 const char errormagic[] PROGMEM = "Error:";
28
 const char echomagic[] PROGMEM = "echo:";
28
 const char echomagic[] PROGMEM = "echo:";
29
 
29
 
30
+#if NUM_SERIAL > 1
31
+  void serialprintPGM_P(const int8_t p, const char * str) {
32
+    while (char ch = pgm_read_byte(str++)) SERIAL_CHAR_P(p, ch);
33
+  }
34
+
35
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, const char *v)   { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
36
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, char v)          { serialprintPGM_P(p, s_P); SERIAL_CHAR_P(p, v); }
37
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, int v)           { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
38
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, long v)          { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
39
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, float v)         { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
40
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, double v)        { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
41
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, unsigned int v)  { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
42
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, unsigned long v) { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
43
+
44
+  void serial_spaces_P(const int8_t p, uint8_t count) { count *= (PROPORTIONAL_FONT_RATIO); while (count--) SERIAL_CHAR_P(p, ' '); }
45
+#endif
30
 
46
 
31
 void serialprintPGM(const char * str) {
47
 void serialprintPGM(const char * str) {
32
-  #ifdef TARGET_LPC1768
33
-    MYSERIAL.print(str);
34
-  #else
35
-    while (char ch = pgm_read_byte(str++)) MYSERIAL.write(ch);
36
-  #endif
48
+  while (char ch = pgm_read_byte(str++)) SERIAL_CHAR(ch);
37
 }
49
 }
38
 
50
 
39
-void serial_echopair_P(const char* s_P, const char *v)   { serialprintPGM(s_P); SERIAL_ECHO(v); }
40
-void serial_echopair_P(const char* s_P, char v)          { serialprintPGM(s_P); SERIAL_CHAR(v); }
41
-void serial_echopair_P(const char* s_P, int v)           { serialprintPGM(s_P); SERIAL_ECHO(v); }
42
-void serial_echopair_P(const char* s_P, long v)          { serialprintPGM(s_P); SERIAL_ECHO(v); }
43
-void serial_echopair_P(const char* s_P, float v)         { serialprintPGM(s_P); SERIAL_ECHO(v); }
44
-void serial_echopair_P(const char* s_P, double v)        { serialprintPGM(s_P); SERIAL_ECHO(v); }
45
-void serial_echopair_P(const char* s_P, unsigned int v)  { serialprintPGM(s_P); SERIAL_ECHO(v); }
46
-void serial_echopair_P(const char* s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
51
+void serial_echopair_PGM(const char* s_P, const char *v)   { serialprintPGM(s_P); SERIAL_ECHO(v); }
52
+void serial_echopair_PGM(const char* s_P, char v)          { serialprintPGM(s_P); SERIAL_CHAR(v); }
53
+void serial_echopair_PGM(const char* s_P, int v)           { serialprintPGM(s_P); SERIAL_ECHO(v); }
54
+void serial_echopair_PGM(const char* s_P, long v)          { serialprintPGM(s_P); SERIAL_ECHO(v); }
55
+void serial_echopair_PGM(const char* s_P, float v)         { serialprintPGM(s_P); SERIAL_ECHO(v); }
56
+void serial_echopair_PGM(const char* s_P, double v)        { serialprintPGM(s_P); SERIAL_ECHO(v); }
57
+void serial_echopair_PGM(const char* s_P, unsigned int v)  { serialprintPGM(s_P); SERIAL_ECHO(v); }
58
+void serial_echopair_PGM(const char* s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
47
 
59
 
48
-void serial_spaces(uint8_t count) { count *= (PROPORTIONAL_FONT_RATIO); while (count--) MYSERIAL.write(' '); }
60
+void serial_spaces(uint8_t count) { count *= (PROPORTIONAL_FONT_RATIO); while (count--) SERIAL_CHAR(' '); }
49
 
61
 
50
 #if ENABLED(DEBUG_LEVELING_FEATURE)
62
 #if ENABLED(DEBUG_LEVELING_FEATURE)
51
 
63
 

+ 155
- 23
Marlin/src/core/serial.h 查看文件

75
     #include "../HAL/HAL_AVR/MarlinSerial.h"
75
     #include "../HAL/HAL_AVR/MarlinSerial.h"
76
     #define MYSERIAL customizedSerial
76
     #define MYSERIAL customizedSerial
77
   #endif
77
   #endif
78
-#endif
79
-
80
-#ifdef ARDUINO_ARCH_SAM
78
+#elif defined(ARDUINO_ARCH_SAM)
81
   // To pull the Serial port definitions and overrides
79
   // To pull the Serial port definitions and overrides
82
   #include "../HAL/HAL_DUE/MarlinSerial_Due.h"
80
   #include "../HAL/HAL_DUE/MarlinSerial_Due.h"
83
 #endif
81
 #endif
88
 extern const char echomagic[] PROGMEM;
86
 extern const char echomagic[] PROGMEM;
89
 extern const char errormagic[] PROGMEM;
87
 extern const char errormagic[] PROGMEM;
90
 
88
 
91
-#define SERIAL_CHAR(x) ((void)MYSERIAL.write(x))
89
+#if TX_BUFFER_SIZE < 1
90
+  #define SERIAL_FLUSHTX_P(p)
91
+  #define SERIAL_FLUSHTX()
92
+#endif
93
+
94
+#if NUM_SERIAL > 1
95
+  #define SERIAL_CHAR_P(p,x)          (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.write(x) : MYSERIAL1.write(x)) : SERIAL_CHAR(x))
96
+  #define SERIAL_PROTOCOL_P(p,x)      (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.print(x) : MYSERIAL1.print(x)) : SERIAL_PROTOCOL(x))
97
+  #define SERIAL_PROTOCOL_F_P(p,x,y)  (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.print(x,y) : MYSERIAL1.print(x,y)) : SERIAL_PROTOCOL_F(x,y))
98
+  #define SERIAL_PROTOCOLLN_P(p,x)    (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.println(x) : MYSERIAL1.println(x)) : SERIAL_PROTOCOLLN(x))
99
+  #define SERIAL_PRINT_P(p,x,b)       (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.print(x,b) : MYSERIAL1.print(x,b)) : SERIAL_PRINT(x,b))
100
+  #define SERIAL_PRINTLN_P(p,x,b)     (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.println(x,b) : MYSERIAL1.println(x,b)) : SERIAL_PRINTLN(x,b))
101
+  #define SERIAL_PRINTF_P(p,args...)  (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.printf(args) : MYSERIAL1.printf(args)) : SERIAL_PRINTF(args))
102
+
103
+  #define SERIAL_CHAR(x)              (MYSERIAL0.write(x), MYSERIAL1.write(x))
104
+  #define SERIAL_PROTOCOL(x)          (MYSERIAL0.print(x), MYSERIAL1.print(x))
105
+  #define SERIAL_PROTOCOL_F(x,y)      (MYSERIAL0.print(x,y), MYSERIAL1.print(x,y))
106
+  #define SERIAL_PROTOCOLLN(x)        (MYSERIAL0.println(x), MYSERIAL1.println(x))
107
+  #define SERIAL_PRINT(x,b)           (MYSERIAL0.print(x,b), MYSERIAL1.print(x,b))
108
+  #define SERIAL_PRINTLN(x,b)         (MYSERIAL0.println(x,b), MYSERIAL1.println(x,b))
109
+  #define SERIAL_PRINTF(args...)      (MYSERIAL0.printf(args), MYSERIAL1.printf(args))
110
+
111
+  #define SERIAL_FLUSH_P(p)           (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.flush() : MYSERIAL1.flush()) : SERIAL_FLUSH())
112
+  #define SERIAL_FLUSH()              (MYSERIAL0.flush(), MYSERIAL1.flush())
113
+  #if TX_BUFFER_SIZE > 0
114
+    #define SERIAL_FLUSHTX_P(p)       (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.flushTX() : MYSERIAL1.flushTX()) : SERIAL_FLUSHTX())
115
+    #define SERIAL_FLUSHTX()          (MYSERIAL0.flushTX(), MYSERIAL1.flushTX())
116
+  #endif
117
+
118
+  #define SERIAL_EOL_P(p) SERIAL_CHAR_P(p,'\n')
119
+  
120
+  #define SERIAL_PROTOCOLCHAR_P(p,x)              SERIAL_CHAR_P(p,x)
121
+  #define SERIAL_PROTOCOLPGM_P(p,x)               (serialprintPGM_P(p,PSTR(x)))
122
+  #define SERIAL_PROTOCOLLNPGM_P(p,x)             (serialprintPGM_P(p,PSTR(x "\n")))
123
+  #define SERIAL_PROTOCOLPAIR_P(p, pre, value)    (serial_echopair_PGM_P(p,PSTR(pre),(value)))
124
+  #define SERIAL_PROTOCOLLNPAIR_P(p, pre, value)  do { SERIAL_PROTOCOLPAIR_P(p, pre, value); SERIAL_EOL_P(p); } while(0)
125
+  
126
+  #define SERIAL_ECHO_START_P(p)             (serialprintPGM_P(p,echomagic))
127
+  #define SERIAL_ECHO_P(p,x)                 SERIAL_PROTOCOL_P(p,x)
128
+  #define SERIAL_ECHOPGM_P(p,x)              SERIAL_PROTOCOLPGM_P(p,x)
129
+  #define SERIAL_ECHOLN_P(p,x)               SERIAL_PROTOCOLLN_P(p,x)
130
+  #define SERIAL_ECHOLNPGM_P(p,x)            SERIAL_PROTOCOLLNPGM_P(p,x)
131
+  #define SERIAL_ECHOPAIR_P(p,pre,value)     SERIAL_PROTOCOLPAIR_P(p, pre, value)
132
+  #define SERIAL_ECHOLNPAIR_P(p,pre, value)  SERIAL_PROTOCOLLNPAIR_P(p, pre, value)
133
+  #define SERIAL_ECHO_F_P(p,x,y)             SERIAL_PROTOCOL_F_P(p,x,y)
134
+  
135
+  #define SERIAL_ERROR_START_P(p)            (serialprintPGM_P(p,errormagic))
136
+  #define SERIAL_ERROR_P(p,x)                SERIAL_PROTOCOL_P(p,x)
137
+  #define SERIAL_ERRORPGM_P(p,x)             SERIAL_PROTOCOLPGM_P(p,x)
138
+  #define SERIAL_ERRORLN_P(p,x)              SERIAL_PROTOCOLLN_P(p,x)
139
+  #define SERIAL_ERRORLNPGM_P(p,x)           SERIAL_PROTOCOLLNPGM_P(p,x)
140
+  
141
+  // These macros compensate for float imprecision
142
+  #define SERIAL_PROTOCOLPAIR_F_P(p, pre, value)    SERIAL_PROTOCOLPAIR_P(p, pre, FIXFLOAT(value))
143
+  #define SERIAL_PROTOCOLLNPAIR_F_P(p, pre, value)  SERIAL_PROTOCOLLNPAIR_P(p, pre, FIXFLOAT(value))
144
+  #define SERIAL_ECHOPAIR_F_P(p,pre,value)          SERIAL_ECHOPAIR_P(p, pre, FIXFLOAT(value))
145
+  #define SERIAL_ECHOLNPAIR_F_P(p,pre, value)       SERIAL_ECHOLNPAIR_P(p, pre, FIXFLOAT(value))
146
+
147
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, const char *v);
148
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, char v);
149
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, int v);
150
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, long v);
151
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, float v);
152
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, double v);
153
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, unsigned int v);
154
+  void serial_echopair_PGM_P(const int8_t p, const char* s_P, unsigned long v);
155
+  FORCE_INLINE void serial_echopair_PGM_P(const int8_t p, const char* s_P, uint8_t v) { serial_echopair_PGM_P(p, s_P, (int)v); }
156
+  FORCE_INLINE void serial_echopair_PGM_P(const int8_t p, const char* s_P, bool v) { serial_echopair_PGM_P(p, s_P, (int)v); }
157
+  FORCE_INLINE void serial_echopair_PGM_P(const int8_t p, const char* s_P, void *v) { serial_echopair_PGM_P(p, s_P, (unsigned long)v); }
158
+
159
+  void serial_spaces_P(const int8_t p, uint8_t count);
160
+  #define SERIAL_ECHO_SP_P(p,C)     serial_spaces_P(p,C)
161
+  #define SERIAL_ERROR_SP_P(p,C)    serial_spaces_P(p,C)
162
+  #define SERIAL_PROTOCOL_SP_P(p,C) serial_spaces_P(p,C)
163
+
164
+  void serialprintPGM_P(const int8_t p, const char* str);
165
+#else
166
+  #define SERIAL_CHAR_P(p,x)          SERIAL_CHAR(x)
167
+  #define SERIAL_PROTOCOL_P(p,x)      SERIAL_PROTOCOL(x)
168
+  #define SERIAL_PROTOCOL_F_P(p,x,y)  SERIAL_PROTOCOL_F(x,y)
169
+  #define SERIAL_PROTOCOLLN_P(p,x)    SERIAL_PROTOCOLLN(x)
170
+  #define SERIAL_PRINT_P(p,x,b)       SERIAL_PRINT(x,b)
171
+  #define SERIAL_PRINTLN_P(p,x,b)     SERIAL_PRINTLN(x,b) 
172
+  #define SERIAL_PRINTF_P(p,args...)  SERIAL_PRINTF(args)
173
+
174
+  #define SERIAL_CHAR(x)              MYSERIAL0.write(x)
175
+  #define SERIAL_PROTOCOL(x)          MYSERIAL0.print(x)
176
+  #define SERIAL_PROTOCOL_F(x,y)      MYSERIAL0.print(x,y)
177
+  #define SERIAL_PROTOCOLLN(x)        MYSERIAL0.println(x)
178
+  #define SERIAL_PRINT(x,b)           MYSERIAL0.print(x,b)
179
+  #define SERIAL_PRINTLN(x,b)         MYSERIAL0.println(x,b)
180
+  #define SERIAL_PRINTF(args...)      MYSERIAL0.printf(args)
181
+
182
+  #define SERIAL_FLUSH_P(p)           SERIAL_FLUSH()
183
+  #define SERIAL_FLUSH()              MYSERIAL0.flush()
184
+  #if TX_BUFFER_SIZE > 0
185
+    #define SERIAL_FLUSHTX_P(p)       SERIAL_FLUSHTX()
186
+    #define SERIAL_FLUSHTX()          MYSERIAL0.flushTX()
187
+  #endif
188
+
189
+  #define SERIAL_EOL_P(p) SERIAL_EOL()
190
+  
191
+  #define SERIAL_PROTOCOLCHAR_P(p,x)              SERIAL_PROTOCOLCHAR(x)
192
+  #define SERIAL_PROTOCOLPGM_P(p,x)               SERIAL_PROTOCOLPGM(x)
193
+  #define SERIAL_PROTOCOLLNPGM_P(p,x)             SERIAL_PROTOCOLLNPGM(x)
194
+  #define SERIAL_PROTOCOLPAIR_P(p, pre, value)    SERIAL_PROTOCOLPAIR(pre, value)
195
+  #define SERIAL_PROTOCOLLNPAIR_P(p, pre, value)  SERIAL_PROTOCOLLNPAIR(pre, value)
196
+  
197
+  #define SERIAL_ECHO_START_P(p)             SERIAL_ECHO_START()
198
+  #define SERIAL_ECHO_P(p,x)                 SERIAL_ECHO(x)
199
+  #define SERIAL_ECHOPGM_P(p,x)              SERIAL_ECHOPGM(x)
200
+  #define SERIAL_ECHOLN_P(p,x)               SERIAL_ECHOLN(x)
201
+  #define SERIAL_ECHOLNPGM_P(p,x)            SERIAL_ECHOLNPGM(x)
202
+  #define SERIAL_ECHOPAIR_P(p,pre,value)     SERIAL_ECHOPAIR(pre, value)
203
+  #define SERIAL_ECHOLNPAIR_P(p,pre, value)  SERIAL_ECHOLNPAIR(pre, value)
204
+  #define SERIAL_ECHO_F_P(p,x,y)             SERIAL_ECHO_F(x,y)
205
+  
206
+  #define SERIAL_ERROR_START_P(p)            SERIAL_ERROR_START()
207
+  #define SERIAL_ERROR_P(p,x)                SERIAL_ERROR(x)
208
+  #define SERIAL_ERRORPGM_P(p,x)             SERIAL_ERRORPGM(x)
209
+  #define SERIAL_ERRORLN_P(p,x)              SERIAL_ERRORLN(x)
210
+  #define SERIAL_ERRORLNPGM_P(p,x)           SERIAL_ERRORLNPGM(x)
211
+  
212
+  // These macros compensate for float imprecision
213
+  #define SERIAL_PROTOCOLPAIR_F_P(p, pre, value)    SERIAL_PROTOCOLPAIR_F(pre, value)
214
+  #define SERIAL_PROTOCOLLNPAIR_F_P(p, pre, value)  SERIAL_PROTOCOLLNPAIR_F(pre, value)
215
+  #define SERIAL_ECHOPAIR_F_P(p,pre,value)          SERIAL_ECHOPAIR_F(pre, value)
216
+  #define SERIAL_ECHOLNPAIR_F_P(p,pre, value)       SERIAL_ECHOLNPAIR_F(pre, value)
217
+
218
+  #define serial_echopair_PGM_P(p,s_P,v)            serial_echopair_PGM(s_P, v)
219
+
220
+  #define serial_spaces_P(p,c)      serial_spaces(c)
221
+  #define SERIAL_ECHO_SP_P(p,C)     SERIAL_ECHO_SP(C)
222
+  #define SERIAL_ERROR_SP_P(p,C)    SERIAL_ERROR_SP(C)
223
+  #define SERIAL_PROTOCOL_SP_P(p,C) SERIAL_PROTOCOL_SP(C)
224
+
225
+  #define serialprintPGM_P(p,s)     serialprintPGM(s)
226
+#endif
227
+
92
 #define SERIAL_EOL() SERIAL_CHAR('\n')
228
 #define SERIAL_EOL() SERIAL_CHAR('\n')
93
 
229
 
94
 #define SERIAL_PROTOCOLCHAR(x)              SERIAL_CHAR(x)
230
 #define SERIAL_PROTOCOLCHAR(x)              SERIAL_CHAR(x)
95
-#define SERIAL_PROTOCOL(x)                  (MYSERIAL.print(x))
96
-#define SERIAL_PROTOCOL_F(x,y)              (MYSERIAL.print(x,y))
97
 #define SERIAL_PROTOCOLPGM(x)               (serialprintPGM(PSTR(x)))
231
 #define SERIAL_PROTOCOLPGM(x)               (serialprintPGM(PSTR(x)))
98
-#define SERIAL_PROTOCOLLN(x)                do{ MYSERIAL.print(x); SERIAL_EOL(); }while(0)
99
 #define SERIAL_PROTOCOLLNPGM(x)             (serialprintPGM(PSTR(x "\n")))
232
 #define SERIAL_PROTOCOLLNPGM(x)             (serialprintPGM(PSTR(x "\n")))
100
-#define SERIAL_PROTOCOLPAIR(pre, value)     (serial_echopair_P(PSTR(pre),(value)))
101
-#define SERIAL_PROTOCOLLNPAIR(pre, value)   do{ SERIAL_PROTOCOLPAIR(pre, value); SERIAL_EOL(); }while(0)
233
+#define SERIAL_PROTOCOLPAIR(pre, value)     (serial_echopair_PGM(PSTR(pre), value))
234
+#define SERIAL_PROTOCOLLNPAIR(pre, value)   do { SERIAL_PROTOCOLPAIR(pre, value); SERIAL_EOL(); } while(0)
102
 
235
 
103
 #define SERIAL_ECHO_START()            (serialprintPGM(echomagic))
236
 #define SERIAL_ECHO_START()            (serialprintPGM(echomagic))
104
 #define SERIAL_ECHO(x)                 SERIAL_PROTOCOL(x)
237
 #define SERIAL_ECHO(x)                 SERIAL_PROTOCOL(x)
107
 #define SERIAL_ECHOLNPGM(x)            SERIAL_PROTOCOLLNPGM(x)
240
 #define SERIAL_ECHOLNPGM(x)            SERIAL_PROTOCOLLNPGM(x)
108
 #define SERIAL_ECHOPAIR(pre,value)     SERIAL_PROTOCOLPAIR(pre, value)
241
 #define SERIAL_ECHOPAIR(pre,value)     SERIAL_PROTOCOLPAIR(pre, value)
109
 #define SERIAL_ECHOLNPAIR(pre, value)  SERIAL_PROTOCOLLNPAIR(pre, value)
242
 #define SERIAL_ECHOLNPAIR(pre, value)  SERIAL_PROTOCOLLNPAIR(pre, value)
110
-#define SERIAL_ECHO_F(x,y)             SERIAL_PROTOCOL_F(x,y)
243
+#define SERIAL_ECHO_F(x,y)             SERIAL_PROTOCOL_F(x, y)
111
 
244
 
112
 #define SERIAL_ERROR_START()           (serialprintPGM(errormagic))
245
 #define SERIAL_ERROR_START()           (serialprintPGM(errormagic))
113
 #define SERIAL_ERROR(x)                SERIAL_PROTOCOL(x)
246
 #define SERIAL_ERROR(x)                SERIAL_PROTOCOL(x)
121
 #define SERIAL_ECHOPAIR_F(pre,value)        SERIAL_ECHOPAIR(pre, FIXFLOAT(value))
254
 #define SERIAL_ECHOPAIR_F(pre,value)        SERIAL_ECHOPAIR(pre, FIXFLOAT(value))
122
 #define SERIAL_ECHOLNPAIR_F(pre, value)     SERIAL_ECHOLNPAIR(pre, FIXFLOAT(value))
255
 #define SERIAL_ECHOLNPAIR_F(pre, value)     SERIAL_ECHOLNPAIR(pre, FIXFLOAT(value))
123
 
256
 
124
-void serial_echopair_P(const char* s_P, const char *v);
125
-void serial_echopair_P(const char* s_P, char v);
126
-void serial_echopair_P(const char* s_P, int v);
127
-void serial_echopair_P(const char* s_P, long v);
128
-void serial_echopair_P(const char* s_P, float v);
129
-void serial_echopair_P(const char* s_P, double v);
130
-void serial_echopair_P(const char* s_P, unsigned int v);
131
-void serial_echopair_P(const char* s_P, unsigned long v);
132
-FORCE_INLINE void serial_echopair_P(const char* s_P, uint8_t v) { serial_echopair_P(s_P, (int)v); }
133
-FORCE_INLINE void serial_echopair_P(const char* s_P, bool v) { serial_echopair_P(s_P, (int)v); }
134
-FORCE_INLINE void serial_echopair_P(const char* s_P, void *v) { serial_echopair_P(s_P, (unsigned long)v); }
257
+void serial_echopair_PGM(const char* s_P, const char *v);
258
+void serial_echopair_PGM(const char* s_P, char v);
259
+void serial_echopair_PGM(const char* s_P, int v);
260
+void serial_echopair_PGM(const char* s_P, long v);
261
+void serial_echopair_PGM(const char* s_P, float v);
262
+void serial_echopair_PGM(const char* s_P, double v);
263
+void serial_echopair_PGM(const char* s_P, unsigned int v);
264
+void serial_echopair_PGM(const char* s_P, unsigned long v);
265
+FORCE_INLINE void serial_echopair_PGM(const char* s_P, uint8_t v) { serial_echopair_PGM(s_P, (int)v); }
266
+FORCE_INLINE void serial_echopair_PGM(const char* s_P, bool v) { serial_echopair_PGM(s_P, (int)v); }
267
+FORCE_INLINE void serial_echopair_PGM(const char* s_P, void *v) { serial_echopair_PGM(s_P, (unsigned long)v); }
135
 
268
 
136
 void serial_spaces(uint8_t count);
269
 void serial_spaces(uint8_t count);
137
 #define SERIAL_ECHO_SP(C)     serial_spaces(C)
270
 #define SERIAL_ECHO_SP(C)     serial_spaces(C)
149
   #if HAS_ABL
282
   #if HAS_ABL
150
     void print_xyz(const char* prefix, const char* suffix, const vector_3 &xyz);
283
     void print_xyz(const char* prefix, const char* suffix, const vector_3 &xyz);
151
   #endif
284
   #endif
152
-  #define DEBUG_POS(SUFFIX,VAR) do { \
153
-    print_xyz(PSTR("  " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n"), VAR); }while(0)
285
+  #define DEBUG_POS(SUFFIX,VAR) do { print_xyz(PSTR("  " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n"), VAR); } while(0)
154
 #endif
286
 #endif
155
 
287
 
156
 #endif // __SERIAL_H__
288
 #endif // __SERIAL_H__

+ 6
- 3
Marlin/src/feature/bedlevel/abl/abl.cpp 查看文件

64
         c1 = z_values[x1][y1], c2 = z_values[x2][y2];
64
         c1 = z_values[x1][y1], c2 = z_values[x2][y2];
65
 
65
 
66
   // Treat far unprobed points as zero, near as equal to far
66
   // Treat far unprobed points as zero, near as equal to far
67
-  if (isnan(a2)) a2 = 0.0; if (isnan(a1)) a1 = a2;
68
-  if (isnan(b2)) b2 = 0.0; if (isnan(b1)) b1 = b2;
69
-  if (isnan(c2)) c2 = 0.0; if (isnan(c1)) c1 = c2;
67
+  if (isnan(a2)) a2 = 0.0;
68
+  if (isnan(a1)) a1 = a2;
69
+  if (isnan(b2)) b2 = 0.0;
70
+  if (isnan(b1)) b1 = b2;
71
+  if (isnan(c2)) c2 = 0.0;
72
+  if (isnan(c1)) c1 = c2;
70
 
73
 
71
   const float a = 2 * a1 - a2, b = 2 * b1 - b2, c = 2 * c1 - c2;
74
   const float a = 2 * a1 - a2, b = 2 * b1 - b2, c = 2 * c1 - c2;
72
 
75
 

+ 21
- 10
Marlin/src/feature/bedlevel/ubl/ubl.cpp 查看文件

36
 
36
 
37
   uint8_t ubl_cnt = 0;
37
   uint8_t ubl_cnt = 0;
38
 
38
 
39
-  void unified_bed_leveling::echo_name() { SERIAL_PROTOCOLPGM("Unified Bed Leveling"); }
39
+  void unified_bed_leveling::echo_name(
40
+    #if NUM_SERIAL > 1
41
+      const int8_t port/*= -1*/
42
+    #endif
43
+  ) {
44
+    SERIAL_PROTOCOLPGM_P(port, "Unified Bed Leveling");
45
+  }
40
 
46
 
41
-  void unified_bed_leveling::report_state() {
42
-    echo_name();
43
-    SERIAL_PROTOCOLPGM(" System v" UBL_VERSION " ");
44
-    if (!planner.leveling_active) SERIAL_PROTOCOLPGM("in");
45
-    SERIAL_PROTOCOLLNPGM("active.");
47
+  void unified_bed_leveling::report_state(
48
+    #if NUM_SERIAL > 1
49
+      const int8_t port/*= -1*/
50
+    #endif
51
+  ) {
52
+    echo_name(
53
+      #if NUM_SERIAL > 1
54
+        port
55
+      #endif
56
+    );
57
+    SERIAL_PROTOCOLPGM_P(port, " System v" UBL_VERSION " ");
58
+    if (!planner.leveling_active) SERIAL_PROTOCOLPGM_P(port, "in");
59
+    SERIAL_PROTOCOLLNPGM_P(port, "active.");
46
     safe_delay(50);
60
     safe_delay(50);
47
   }
61
   }
48
 
62
 
198
         }
212
         }
199
         idle();
213
         idle();
200
         if (map_type == 1 && i < GRID_MAX_POINTS_X - 1) SERIAL_CHAR(',');
214
         if (map_type == 1 && i < GRID_MAX_POINTS_X - 1) SERIAL_CHAR(',');
201
-
202
-        #if TX_BUFFER_SIZE > 0
203
-          MYSERIAL.flushTX();
204
-        #endif
215
+        SERIAL_FLUSHTX();
205
         safe_delay(15);
216
         safe_delay(15);
206
         if (map_type == 0) {
217
         if (map_type == 0) {
207
           SERIAL_CHAR(is_current ? ']' : ' ');
218
           SERIAL_CHAR(is_current ? ']' : ' ');

+ 10
- 2
Marlin/src/feature/bedlevel/ubl/ubl.h 查看文件

104
 
104
 
105
   public:
105
   public:
106
 
106
 
107
-    static void echo_name();
108
-    static void report_state();
107
+    static void echo_name(
108
+      #if NUM_SERIAL > 1
109
+        const int8_t port = -1
110
+      #endif
111
+    );
112
+    static void report_state(
113
+      #if NUM_SERIAL > 1
114
+        const int8_t port = -1
115
+      #endif
116
+    );
109
     static void save_ubl_active_state_and_disable();
117
     static void save_ubl_active_state_and_disable();
110
     static void restore_ubl_active_state_and_leave();
118
     static void restore_ubl_active_state_and_leave();
111
     static void display_map(const int);
119
     static void display_map(const int);

+ 2
- 2
Marlin/src/feature/tmc_util.cpp 查看文件

146
       const uint32_t pwm_scale = get_pwm_scale(st);
146
       const uint32_t pwm_scale = get_pwm_scale(st);
147
       SERIAL_ECHO(axisID);
147
       SERIAL_ECHO(axisID);
148
       SERIAL_ECHOPAIR(":", pwm_scale);
148
       SERIAL_ECHOPAIR(":", pwm_scale);
149
-      SERIAL_ECHO(" |0b"); MYSERIAL.print(get_status_response(st), BIN);
149
+      SERIAL_ECHO(" |0b"); SERIAL_PRINT(get_status_response(st), BIN);
150
       SERIAL_ECHO("| ");
150
       SERIAL_ECHO("| ");
151
       if (data.is_error) SERIAL_ECHO('E');
151
       if (data.is_error) SERIAL_ECHO('E');
152
       else if (data.is_ot) SERIAL_ECHO('O');
152
       else if (data.is_ot) SERIAL_ECHO('O');
153
       else if (data.is_otpw) SERIAL_ECHO('W');
153
       else if (data.is_otpw) SERIAL_ECHO('W');
154
-      else if (otpw_cnt>0) MYSERIAL.print(otpw_cnt, DEC);
154
+      else if (otpw_cnt>0) SERIAL_PRINT(otpw_cnt, DEC);
155
       else if (st.flag_otpw) SERIAL_ECHO('F');
155
       else if (st.flag_otpw) SERIAL_ECHO('F');
156
       SERIAL_ECHO("\t");
156
       SERIAL_ECHO("\t");
157
     }
157
     }

+ 24
- 4
Marlin/src/gcode/eeprom/M500-M504.cpp 查看文件

24
 #include "../../module/configuration_store.h"
24
 #include "../../module/configuration_store.h"
25
 #include "../../inc/MarlinConfig.h"
25
 #include "../../inc/MarlinConfig.h"
26
 
26
 
27
+#if NUM_SERIAL > 1
28
+  #include "../../gcode/queue.h"
29
+#endif
30
+
27
 /**
31
 /**
28
  * M500: Store settings in EEPROM
32
  * M500: Store settings in EEPROM
29
  */
33
  */
30
 void GcodeSuite::M500() {
34
 void GcodeSuite::M500() {
31
-  (void)settings.save();
35
+  (void)settings.save(
36
+    #if ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
37
+      command_queue_port[cmd_queue_index_r]
38
+    #endif
39
+  );
32
 }
40
 }
33
 
41
 
34
 /**
42
 /**
35
  * M501: Read settings from EEPROM
43
  * M501: Read settings from EEPROM
36
  */
44
  */
37
 void GcodeSuite::M501() {
45
 void GcodeSuite::M501() {
38
-  (void)settings.load();
46
+  (void)settings.load(
47
+    #if ENABLED(EEPROM_SETTINGS) && ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
48
+      command_queue_port[cmd_queue_index_r]
49
+    #endif
50
+  );
39
 }
51
 }
40
 
52
 
41
 /**
53
 /**
42
  * M502: Revert to default settings
54
  * M502: Revert to default settings
43
  */
55
  */
44
 void GcodeSuite::M502() {
56
 void GcodeSuite::M502() {
45
-  (void)settings.reset();
57
+  (void)settings.reset(
58
+    #if ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
59
+      command_queue_port[cmd_queue_index_r]
60
+    #endif
61
+  );
46
 }
62
 }
47
 
63
 
48
 #if DISABLED(DISABLE_M503)
64
 #if DISABLED(DISABLE_M503)
51
    * M503: print settings currently in memory
67
    * M503: print settings currently in memory
52
    */
68
    */
53
   void GcodeSuite::M503() {
69
   void GcodeSuite::M503() {
54
-    (void)settings.report(parser.seen('S') && !parser.value_bool());
70
+    (void)settings.report(parser.seen('S') && !parser.value_bool()
71
+      #if NUM_SERIAL > 1
72
+        , command_queue_port[cmd_queue_index_r]
73
+      #endif
74
+    );
55
   }
75
   }
56
 
76
 
57
 #endif // !DISABLE_M503
77
 #endif // !DISABLE_M503

+ 20
- 20
Marlin/src/gcode/feature/trinamic/M122.cpp 查看文件

79
   SERIAL_ECHO(name);
79
   SERIAL_ECHO(name);
80
   SERIAL_ECHOPGM(" = 0x");
80
   SERIAL_ECHOPGM(" = 0x");
81
   for(int B=24; B>=8; B-=8){
81
   for(int B=24; B>=8; B-=8){
82
-    MYSERIAL.print((drv_status>>(B+4))&0xF, HEX);
83
-    MYSERIAL.print((drv_status>>B)&0xF, HEX);
84
-    MYSERIAL.print(':');
82
+    SERIAL_PRINT((drv_status>>(B+4))&0xF, HEX);
83
+    SERIAL_PRINT((drv_status>>B)&0xF, HEX);
84
+    SERIAL_CHAR(':');
85
   }
85
   }
86
-  MYSERIAL.print((drv_status>>4)&0xF, HEX);
87
-  MYSERIAL.print((drv_status)&0xF, HEX);
86
+  SERIAL_PRINT((drv_status>>4)&0xF, HEX);
87
+  SERIAL_PRINT((drv_status)&0xF, HEX);
88
   SERIAL_EOL();
88
   SERIAL_EOL();
89
 }
89
 }
90
 
90
 
91
 #if ENABLED(HAVE_TMC2130)
91
 #if ENABLED(HAVE_TMC2130)
92
   static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
92
   static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
93
     switch(i) {
93
     switch(i) {
94
-      case TMC_PWM_SCALE: MYSERIAL.print(st.PWM_SCALE(), DEC); break;
94
+      case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
95
       case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break;
95
       case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break;
96
-      case TMC_SGT: MYSERIAL.print(st.sgt(), DEC); break;
96
+      case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
97
       case TMC_STEALTHCHOP: serialprintPGM(st.stealthChop() ? PSTR("true") : PSTR("false")); break;
97
       case TMC_STEALTHCHOP: serialprintPGM(st.stealthChop() ? PSTR("true") : PSTR("false")); break;
98
       default: break;
98
       default: break;
99
     }
99
     }
101
   static void tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) {
101
   static void tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) {
102
     switch(i) {
102
     switch(i) {
103
       case TMC_STALLGUARD: if (st.stallguard()) SERIAL_ECHOPGM("X"); break;
103
       case TMC_STALLGUARD: if (st.stallguard()) SERIAL_ECHOPGM("X"); break;
104
-      case TMC_SG_RESULT:  MYSERIAL.print(st.sg_result(), DEC);      break;
104
+      case TMC_SG_RESULT:  SERIAL_PRINT(st.sg_result(), DEC);      break;
105
       case TMC_FSACTIVE:   if (st.fsactive())   SERIAL_ECHOPGM("X"); break;
105
       case TMC_FSACTIVE:   if (st.fsactive())   SERIAL_ECHOPGM("X"); break;
106
       default: break;
106
       default: break;
107
     }
107
     }
113
       case TMC_TSTEP: {
113
       case TMC_TSTEP: {
114
           uint32_t data = 0;
114
           uint32_t data = 0;
115
           st.TSTEP(&data);
115
           st.TSTEP(&data);
116
-          MYSERIAL.print(data);
116
+          SERIAL_PROTOCOL(data);
117
           break;
117
           break;
118
         }
118
         }
119
-      case TMC_PWM_SCALE: MYSERIAL.print(st.pwm_scale_sum(), DEC); break;
119
+      case TMC_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
120
       case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break;
120
       case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break;
121
       case TMC_S2VSA: if (st.s2vsa()) SERIAL_ECHOPGM("X"); break;
121
       case TMC_S2VSA: if (st.s2vsa()) SERIAL_ECHOPGM("X"); break;
122
       case TMC_S2VSB: if (st.s2vsb()) SERIAL_ECHOPGM("X"); break;
122
       case TMC_S2VSB: if (st.s2vsb()) SERIAL_ECHOPGM("X"); break;
140
     case TMC_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
140
     case TMC_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
141
     case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break;
141
     case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break;
142
     case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break;
142
     case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break;
143
-    case TMC_RMS_CURRENT: MYSERIAL.print(st.rms_current()); break;
144
-    case TMC_MAX_CURRENT: MYSERIAL.print((float)st.rms_current()*1.41, 0); break;
143
+    case TMC_RMS_CURRENT: SERIAL_PROTOCOL(st.rms_current()); break;
144
+    case TMC_MAX_CURRENT: SERIAL_PRINT((float)st.rms_current()*1.41, 0); break;
145
     case TMC_IRUN:
145
     case TMC_IRUN:
146
-      MYSERIAL.print(st.irun(), DEC);
146
+      SERIAL_PRINT(st.irun(), DEC);
147
       SERIAL_ECHOPGM("/31");
147
       SERIAL_ECHOPGM("/31");
148
       break;
148
       break;
149
     case TMC_IHOLD:
149
     case TMC_IHOLD:
150
-      MYSERIAL.print(st.ihold(), DEC);
150
+      SERIAL_PRINT(st.ihold(), DEC);
151
       SERIAL_ECHOPGM("/31");
151
       SERIAL_ECHOPGM("/31");
152
       break;
152
       break;
153
     case TMC_CS_ACTUAL:
153
     case TMC_CS_ACTUAL:
154
-      MYSERIAL.print(st.cs_actual(), DEC);
154
+      SERIAL_PRINT(st.cs_actual(), DEC);
155
       SERIAL_ECHOPGM("/31");
155
       SERIAL_ECHOPGM("/31");
156
       break;
156
       break;
157
 
157
 
170
       break;
170
       break;
171
     case TMC_OTPW: serialprintPGM(st.otpw() ? PSTR("true") : PSTR("false")); break;
171
     case TMC_OTPW: serialprintPGM(st.otpw() ? PSTR("true") : PSTR("false")); break;
172
     case TMC_OTPW_TRIGGERED: serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false")); break;
172
     case TMC_OTPW_TRIGGERED: serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false")); break;
173
-    case TMC_TOFF: MYSERIAL.print(st.toff(), DEC); break;
174
-    case TMC_TBL: MYSERIAL.print(st.blank_time(), DEC); break;
175
-    case TMC_HEND: MYSERIAL.print(st.hysterisis_end(), DEC); break;
176
-    case TMC_HSTRT: MYSERIAL.print(st.hysterisis_start(), DEC); break;
173
+    case TMC_TOFF: SERIAL_PRINT(st.toff(), DEC); break;
174
+    case TMC_TBL: SERIAL_PRINT(st.blank_time(), DEC); break;
175
+    case TMC_HEND: SERIAL_PRINT(st.hysterisis_end(), DEC); break;
176
+    case TMC_HSTRT: SERIAL_PRINT(st.hysterisis_start(), DEC); break;
177
     default: tmc_status(st, i); break;
177
     default: tmc_status(st, i); break;
178
   }
178
   }
179
 }
179
 }
189
     case TMC_S2GA:          if (st.s2ga())         SERIAL_ECHOPGM("X"); break;
189
     case TMC_S2GA:          if (st.s2ga())         SERIAL_ECHOPGM("X"); break;
190
     case TMC_DRV_OTPW:      if (st.otpw())         SERIAL_ECHOPGM("X"); break;
190
     case TMC_DRV_OTPW:      if (st.otpw())         SERIAL_ECHOPGM("X"); break;
191
     case TMC_OT:            if (st.ot())           SERIAL_ECHOPGM("X"); break;
191
     case TMC_OT:            if (st.ot())           SERIAL_ECHOPGM("X"); break;
192
-    case TMC_DRV_CS_ACTUAL: MYSERIAL.print(st.cs_actual(), DEC);        break;
192
+    case TMC_DRV_CS_ACTUAL: SERIAL_PRINT(st.cs_actual(), DEC);        break;
193
     case TMC_DRV_STATUS_HEX:drv_status_print_hex(extended_axis_codes[axis], st.DRV_STATUS()); break;
193
     case TMC_DRV_STATUS_HEX:drv_status_print_hex(extended_axis_codes[axis], st.DRV_STATUS()); break;
194
     default: tmc_parse_drv_status(st, i); break;
194
     default: tmc_parse_drv_status(st, i); break;
195
   }
195
   }

+ 12
- 1
Marlin/src/gcode/host/M115.cpp 查看文件

23
 #include "../gcode.h"
23
 #include "../gcode.h"
24
 #include "../../inc/MarlinConfig.h"
24
 #include "../../inc/MarlinConfig.h"
25
 
25
 
26
+#if NUM_SERIAL > 1
27
+  #include "../../gcode/queue.h"
28
+#endif
29
+
26
 #if ENABLED(EXTENDED_CAPABILITIES_REPORT)
30
 #if ENABLED(EXTENDED_CAPABILITIES_REPORT)
27
   static void cap_line(const char * const name, bool ena=false) {
31
   static void cap_line(const char * const name, bool ena=false) {
28
     SERIAL_PROTOCOLPGM("Cap:");
32
     SERIAL_PROTOCOLPGM("Cap:");
36
  * M115: Capabilities string
40
  * M115: Capabilities string
37
  */
41
  */
38
 void GcodeSuite::M115() {
42
 void GcodeSuite::M115() {
39
-  SERIAL_PROTOCOLLNPGM(MSG_M115_REPORT);
43
+  #if NUM_SERIAL > 1
44
+    const int8_t port = command_queue_port[cmd_queue_index_r];
45
+    #define CAPLINE(STR,...) cap_line(PSTR(STR), port, __VA_ARGS__)
46
+  #else
47
+    #define CAPLINE(STR,...) cap_line(PSTR(STR), __VA_ARGS__)
48
+  #endif
49
+
50
+  SERIAL_PROTOCOLLNPGM_P(port, MSG_M115_REPORT);
40
 
51
 
41
   #if ENABLED(EXTENDED_CAPABILITIES_REPORT)
52
   #if ENABLED(EXTENDED_CAPABILITIES_REPORT)
42
 
53
 

+ 11
- 4
Marlin/src/gcode/parser.cpp 查看文件

32
   #include "../libs/hex_print_routines.h"
32
   #include "../libs/hex_print_routines.h"
33
 #endif
33
 #endif
34
 
34
 
35
+#if NUM_SERIAL > 1
36
+  #include "queue.h"
37
+#endif
38
+
35
 // Must be declared for allocation and to satisfy the linker
39
 // Must be declared for allocation and to satisfy the linker
36
 // Zero values need no initialization.
40
 // Zero values need no initialization.
37
 
41
 
265
 #endif // CNC_COORDINATE_SYSTEMS
269
 #endif // CNC_COORDINATE_SYSTEMS
266
 
270
 
267
 void GCodeParser::unknown_command_error() {
271
 void GCodeParser::unknown_command_error() {
268
-  SERIAL_ECHO_START();
269
-  SERIAL_ECHOPAIR(MSG_UNKNOWN_COMMAND, command_ptr);
270
-  SERIAL_CHAR('"');
271
-  SERIAL_EOL();
272
+  #if NUM_SERIAL > 1
273
+    const int16_t port = command_queue_port[cmd_queue_index_r];
274
+  #endif
275
+  SERIAL_ECHO_START_P(port);
276
+  SERIAL_ECHOPAIR_P(port, MSG_UNKNOWN_COMMAND, command_ptr);
277
+  SERIAL_CHAR_P(port, '"');
278
+  SERIAL_EOL_P(port);
272
 }
279
 }
273
 
280
 
274
 #if ENABLED(DEBUG_GCODE_PARSER)
281
 #if ENABLED(DEBUG_GCODE_PARSER)

+ 162
- 110
Marlin/src/gcode/queue.cpp 查看文件

58
 
58
 
59
 char command_queue[BUFSIZE][MAX_CMD_SIZE];
59
 char command_queue[BUFSIZE][MAX_CMD_SIZE];
60
 
60
 
61
+/*
62
+ * The port that the command was received on
63
+ */
64
+#if NUM_SERIAL > 1
65
+  int16_t command_queue_port[BUFSIZE];
66
+#endif
67
+
61
 /**
68
 /**
62
  * Serial command injection
69
  * Serial command injection
63
  */
70
  */
64
 
71
 
65
 // Number of characters read in the current line of serial input
72
 // Number of characters read in the current line of serial input
66
-static int serial_count = 0;
73
+static int serial_count[NUM_SERIAL] = { 0 };
67
 
74
 
68
 bool send_ok[BUFSIZE];
75
 bool send_ok[BUFSIZE];
69
 
76
 
90
 /**
97
 /**
91
  * Once a new command is in the ring buffer, call this to commit it
98
  * Once a new command is in the ring buffer, call this to commit it
92
  */
99
  */
93
-inline void _commit_command(bool say_ok) {
100
+inline void _commit_command(bool say_ok
101
+  #if NUM_SERIAL > 1
102
+    , int16_t port = -1
103
+  #endif
104
+) {
94
   send_ok[cmd_queue_index_w] = say_ok;
105
   send_ok[cmd_queue_index_w] = say_ok;
106
+  #if NUM_SERIAL > 1
107
+    command_queue_port[cmd_queue_index_w] = port;
108
+  #endif
95
   if (++cmd_queue_index_w >= BUFSIZE) cmd_queue_index_w = 0;
109
   if (++cmd_queue_index_w >= BUFSIZE) cmd_queue_index_w = 0;
96
   commands_in_queue++;
110
   commands_in_queue++;
97
 }
111
 }
101
  * Return true if the command was successfully added.
115
  * Return true if the command was successfully added.
102
  * Return false for a full buffer, or if the 'command' is a comment.
116
  * Return false for a full buffer, or if the 'command' is a comment.
103
  */
117
  */
104
-inline bool _enqueuecommand(const char* cmd, bool say_ok/*=false*/) {
118
+inline bool _enqueuecommand(const char* cmd, bool say_ok
119
+  #if NUM_SERIAL > 1
120
+    , int16_t port = -1
121
+  #endif
122
+) {
105
   if (*cmd == ';' || commands_in_queue >= BUFSIZE) return false;
123
   if (*cmd == ';' || commands_in_queue >= BUFSIZE) return false;
106
   strcpy(command_queue[cmd_queue_index_w], cmd);
124
   strcpy(command_queue[cmd_queue_index_w], cmd);
107
-  _commit_command(say_ok);
125
+  _commit_command(say_ok
126
+    #if NUM_SERIAL > 1
127
+      , port
128
+    #endif
129
+  );
108
   return true;
130
   return true;
109
 }
131
 }
110
 
132
 
178
  *   B<int>  Block queue space remaining
200
  *   B<int>  Block queue space remaining
179
  */
201
  */
180
 void ok_to_send() {
202
 void ok_to_send() {
203
+  #if NUM_SERIAL > 1
204
+    const int16_t port = command_queue_port[cmd_queue_index_r];
205
+    if (port < 0) return;
206
+  #endif
181
   gcode.refresh_cmd_timeout();
207
   gcode.refresh_cmd_timeout();
182
   if (!send_ok[cmd_queue_index_r]) return;
208
   if (!send_ok[cmd_queue_index_r]) return;
183
-  SERIAL_PROTOCOLPGM(MSG_OK);
209
+  SERIAL_PROTOCOLPGM_P(port, MSG_OK);
184
   #if ENABLED(ADVANCED_OK)
210
   #if ENABLED(ADVANCED_OK)
185
     char* p = command_queue[cmd_queue_index_r];
211
     char* p = command_queue[cmd_queue_index_r];
186
     if (*p == 'N') {
212
     if (*p == 'N') {
187
-      SERIAL_PROTOCOL(' ');
188
-      SERIAL_ECHO(*p++);
213
+      SERIAL_PROTOCOL_P(port, ' ');
214
+      SERIAL_ECHO_P(port, *p++);
189
       while (NUMERIC_SIGNED(*p))
215
       while (NUMERIC_SIGNED(*p))
190
-        SERIAL_ECHO(*p++);
216
+        SERIAL_ECHO_P(port, *p++);
191
     }
217
     }
192
-    SERIAL_PROTOCOLPGM(" P"); SERIAL_PROTOCOL(int(BLOCK_BUFFER_SIZE - planner.movesplanned() - 1));
193
-    SERIAL_PROTOCOLPGM(" B"); SERIAL_PROTOCOL(BUFSIZE - commands_in_queue);
218
+    SERIAL_PROTOCOLPGM_P(port, " P"); SERIAL_PROTOCOL_P(port, int(BLOCK_BUFFER_SIZE - planner.movesplanned() - 1));
219
+    SERIAL_PROTOCOLPGM_P(port, " B"); SERIAL_PROTOCOL_P(port, BUFSIZE - commands_in_queue);
194
   #endif
220
   #endif
195
-  SERIAL_EOL();
221
+  SERIAL_EOL_P(port);
196
 }
222
 }
197
 
223
 
198
 /**
224
 /**
200
  * indicate that a command needs to be re-sent.
226
  * indicate that a command needs to be re-sent.
201
  */
227
  */
202
 void flush_and_request_resend() {
228
 void flush_and_request_resend() {
203
-  //char command_queue[cmd_queue_index_r][100]="Resend:";
204
-  MYSERIAL.flush();
205
-  SERIAL_PROTOCOLPGM(MSG_RESEND);
206
-  SERIAL_PROTOCOLLN(gcode_LastN + 1);
207
-  ok_to_send();
229
+  #if NUM_SERIAL > 1
230
+    const int16_t port = command_queue_port[cmd_queue_index_r];
231
+    if (port < 0) return;
232
+  #endif
233
+  SERIAL_FLUSH_P(port);
234
+  SERIAL_PROTOCOLPGM_P(port, MSG_RESEND);
235
+  SERIAL_PROTOCOLLN_P(port, gcode_LastN + 1);
208
 }
236
 }
209
 
237
 
210
-void gcode_line_error(const char* err, bool doFlush = true) {
211
-  SERIAL_ERROR_START();
212
-  serialprintPGM(err);
213
-  SERIAL_ERRORLN(gcode_LastN);
214
-  //Serial.println(gcode_N);
215
-  if (doFlush) flush_and_request_resend();
216
-  serial_count = 0;
238
+void gcode_line_error(const char* err, uint8_t port) {
239
+  SERIAL_ERROR_START_P(port);
240
+  serialprintPGM_P(port, err);
241
+  SERIAL_ERRORLN_P(port, gcode_LastN);
242
+  flush_and_request_resend();
243
+  serial_count[port] = 0;
244
+}
245
+
246
+static bool serial_data_available() {
247
+  return (MYSERIAL0.available() ? true :
248
+    #if NUM_SERIAL > 1
249
+      MYSERIAL1.available() ? true :
250
+    #endif
251
+    false);
252
+}
253
+
254
+static int read_serial(const int index) {
255
+  switch (index) {
256
+    case 0: return MYSERIAL0.read();
257
+    #if NUM_SERIAL > 1 
258
+      case 1: return MYSERIAL1.read();
259
+    #endif
260
+    default: return -1;
261
+  }
217
 }
262
 }
218
 
263
 
219
 /**
264
 /**
222
  * left on the serial port.
267
  * left on the serial port.
223
  */
268
  */
224
 inline void get_serial_commands() {
269
 inline void get_serial_commands() {
225
-  static char serial_line_buffer[MAX_CMD_SIZE];
226
-  static bool serial_comment_mode = false;
270
+  static char serial_line_buffer[NUM_SERIAL][MAX_CMD_SIZE];
271
+  static bool serial_comment_mode[NUM_SERIAL] = { false };
227
 
272
 
228
   // If the command buffer is empty for too long,
273
   // If the command buffer is empty for too long,
229
   // send "wait" to indicate Marlin is still waiting.
274
   // send "wait" to indicate Marlin is still waiting.
230
   #if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
275
   #if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
231
     static millis_t last_command_time = 0;
276
     static millis_t last_command_time = 0;
232
     const millis_t ms = millis();
277
     const millis_t ms = millis();
233
-    if (commands_in_queue == 0 && !MYSERIAL.available() && ELAPSED(ms, last_command_time + NO_TIMEOUTS)) {
278
+    if (commands_in_queue == 0 && !serial_data_available() && ELAPSED(ms, last_command_time + NO_TIMEOUTS)) {
234
       SERIAL_ECHOLNPGM(MSG_WAIT);
279
       SERIAL_ECHOLNPGM(MSG_WAIT);
235
       last_command_time = ms;
280
       last_command_time = ms;
236
     }
281
     }
239
   /**
284
   /**
240
    * Loop while serial characters are incoming and the queue is not full
285
    * Loop while serial characters are incoming and the queue is not full
241
    */
286
    */
242
-  int c;
243
-  while (commands_in_queue < BUFSIZE && (c = MYSERIAL.read()) >= 0) {
244
-    char serial_char = c;
287
+  while (commands_in_queue < BUFSIZE && serial_data_available()) {
288
+    for (uint8_t i = 0; i < NUM_SERIAL; ++i) {
289
+      int c;
290
+      if ((c = read_serial(i)) < 0) continue;
245
 
291
 
246
-    /**
247
-     * If the character ends the line
248
-     */
249
-    if (serial_char == '\n' || serial_char == '\r') {
292
+      char serial_char = c;
250
 
293
 
251
-      serial_comment_mode = false;                      // end of line == end of comment
294
+      /**
295
+       * If the character ends the line
296
+       */
297
+      if (serial_char == '\n' || serial_char == '\r') {
252
 
298
 
253
-      if (!serial_count) continue;                      // Skip empty lines
299
+        serial_comment_mode[i] = false;                   // end of line == end of comment
254
 
300
 
255
-      serial_line_buffer[serial_count] = 0;             // Terminate string
256
-      serial_count = 0;                                 // Reset buffer
301
+        if (!serial_count[i]) continue;                   // Skip empty lines
257
 
302
 
258
-      char* command = serial_line_buffer;
303
+        serial_line_buffer[i][serial_count[i]] = 0;       // Terminate string
304
+        serial_count[i] = 0;                              // Reset buffer
259
 
305
 
260
-      while (*command == ' ') command++;                // Skip leading spaces
261
-      char *npos = (*command == 'N') ? command : NULL;  // Require the N parameter to start the line
306
+        char* command = serial_line_buffer[i];
262
 
307
 
263
-      if (npos) {
308
+        while (*command == ' ') command++;                // Skip leading spaces
309
+        char *npos = (*command == 'N') ? command : NULL;  // Require the N parameter to start the line
264
 
310
 
265
-        bool M110 = strstr_P(command, PSTR("M110")) != NULL;
311
+        if (npos) {
266
 
312
 
267
-        if (M110) {
268
-          char* n2pos = strchr(command + 4, 'N');
269
-          if (n2pos) npos = n2pos;
270
-        }
313
+          bool M110 = strstr_P(command, PSTR("M110")) != NULL;
271
 
314
 
272
-        gcode_N = strtol(npos + 1, NULL, 10);
315
+          if (M110) {
316
+            char* n2pos = strchr(command + 4, 'N');
317
+            if (n2pos) npos = n2pos;
318
+          }
273
 
319
 
274
-        if (gcode_N != gcode_LastN + 1 && !M110) {
275
-          gcode_line_error(PSTR(MSG_ERR_LINE_NO));
276
-          return;
277
-        }
320
+          gcode_N = strtol(npos + 1, NULL, 10);
278
 
321
 
279
-        char *apos = strrchr(command, '*');
280
-        if (apos) {
281
-          uint8_t checksum = 0, count = uint8_t(apos - command);
282
-          while (count) checksum ^= command[--count];
283
-          if (strtol(apos + 1, NULL, 10) != checksum) {
284
-            gcode_line_error(PSTR(MSG_ERR_CHECKSUM_MISMATCH));
322
+          if (gcode_N != gcode_LastN + 1 && !M110) {
323
+            gcode_line_error(PSTR(MSG_ERR_LINE_NO), i);
285
             return;
324
             return;
286
           }
325
           }
287
-        }
288
-        else {
289
-          gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM));
290
-          return;
291
-        }
292
-
293
-        gcode_LastN = gcode_N;
294
-      }
295
 
326
 
296
-      // Movement commands alert when stopped
297
-      if (IsStopped()) {
298
-        char* gpos = strchr(command, 'G');
299
-        if (gpos) {
300
-          const int codenum = strtol(gpos + 1, NULL, 10);
301
-          switch (codenum) {
302
-            case 0:
303
-            case 1:
304
-            case 2:
305
-            case 3:
306
-              SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
307
-              LCD_MESSAGEPGM(MSG_STOPPED);
308
-              break;
327
+          char *apos = strrchr(command, '*');
328
+          if (apos) {
329
+            uint8_t checksum = 0, count = uint8_t(apos - command);
330
+            while (count) checksum ^= command[--count];
331
+            if (strtol(apos + 1, NULL, 10) != checksum) {
332
+              gcode_line_error(PSTR(MSG_ERR_CHECKSUM_MISMATCH), i);
333
+              return;
334
+            }
335
+          }
336
+          else {
337
+            gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM), i);
338
+            return;
309
           }
339
           }
310
-        }
311
-      }
312
 
340
 
313
-      #if DISABLED(EMERGENCY_PARSER)
314
-        // If command was e-stop process now
315
-        if (strcmp(command, "M108") == 0) {
316
-          wait_for_heatup = false;
317
-          #if ENABLED(ULTIPANEL)
318
-            wait_for_user = false;
319
-          #endif
341
+          gcode_LastN = gcode_N;
320
         }
342
         }
321
-        if (strcmp(command, "M112") == 0) kill(PSTR(MSG_KILLED));
322
-        if (strcmp(command, "M410") == 0) { quickstop_stepper(); }
323
-      #endif
324
-
325
-      #if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
326
-        last_command_time = ms;
327
-      #endif
328
 
343
 
329
-      // Add the command to the queue
330
-      _enqueuecommand(serial_line_buffer, true);
331
-    }
332
-    else if (serial_count >= MAX_CMD_SIZE - 1) {
333
-      // Keep fetching, but ignore normal characters beyond the max length
334
-      // The command will be injected when EOL is reached
335
-    }
336
-    else if (serial_char == '\\') {  // Handle escapes
337
-      // if we have one more character, copy it over
338
-      if ((c = MYSERIAL.read()) >= 0 && !serial_comment_mode)
339
-        serial_line_buffer[serial_count++] = serial_char;
340
-    }
341
-    else { // it's not a newline, carriage return or escape char
342
-      if (serial_char == ';') serial_comment_mode = true;
343
-      if (!serial_comment_mode) serial_line_buffer[serial_count++] = serial_char;
344
-    }
344
+        // Movement commands alert when stopped
345
+        if (IsStopped()) {
346
+          char* gpos = strchr(command, 'G');
347
+          if (gpos) {
348
+            const int codenum = strtol(gpos + 1, NULL, 10);
349
+            switch (codenum) {
350
+              case 0:
351
+              case 1:
352
+              case 2:
353
+              case 3:
354
+                SERIAL_ERRORLNPGM_P(i, MSG_ERR_STOPPED);
355
+                LCD_MESSAGEPGM(MSG_STOPPED);
356
+                break;
357
+            }
358
+          }
359
+        }
345
 
360
 
361
+        #if DISABLED(EMERGENCY_PARSER)
362
+          // If command was e-stop process now
363
+          if (strcmp(command, "M108") == 0) {
364
+            wait_for_heatup = false;
365
+            #if ENABLED(ULTIPANEL)
366
+              wait_for_user = false;
367
+            #endif
368
+          }
369
+          if (strcmp(command, "M112") == 0) kill(PSTR(MSG_KILLED));
370
+          if (strcmp(command, "M410") == 0) { quickstop_stepper(); }
371
+        #endif
372
+
373
+        #if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
374
+          last_command_time = ms;
375
+        #endif
376
+
377
+        // Add the command to the queue
378
+        _enqueuecommand(serial_line_buffer[i], true
379
+          #if NUM_SERIAL > 1
380
+            , i
381
+          #endif
382
+        );
383
+      }
384
+      else if (serial_count[i] >= MAX_CMD_SIZE - 1) {
385
+        // Keep fetching, but ignore normal characters beyond the max length
386
+        // The command will be injected when EOL is reached
387
+      }
388
+      else if (serial_char == '\\') {  // Handle escapes
389
+        // if we have one more character, copy it over
390
+        if ((c = read_serial(i)) >= 0 && !serial_comment_mode[i])
391
+          serial_line_buffer[i][serial_count[i]++] = serial_char;
392
+      }
393
+      else { // it's not a newline, carriage return or escape char
394
+        if (serial_char == ';') serial_comment_mode[i] = true;
395
+        if (!serial_comment_mode[i]) serial_line_buffer[i][serial_count[i]++] = serial_char;
396
+      }
397
+    } // for NUM_SERIAL
346
   } // queue has space, serial has data
398
   } // queue has space, serial has data
347
 }
399
 }
348
 
400
 

+ 7
- 0
Marlin/src/gcode/queue.h 查看文件

51
 
51
 
52
 extern char command_queue[BUFSIZE][MAX_CMD_SIZE];
52
 extern char command_queue[BUFSIZE][MAX_CMD_SIZE];
53
 
53
 
54
+/*
55
+ * The port that the command was received on
56
+ */
57
+#if NUM_SERIAL > 1
58
+  extern int16_t command_queue_port[BUFSIZE];
59
+#endif
60
+
54
 /**
61
 /**
55
  * Initialization of queue for setup()
62
  * Initialization of queue for setup()
56
  */
63
  */

+ 27
- 5
Marlin/src/gcode/sdcard/M20-M30_M32-M34_M928.cpp 查看文件

34
   #include "../queue.h"
34
   #include "../queue.h"
35
 #endif
35
 #endif
36
 
36
 
37
+#if NUM_SERIAL > 1
38
+  #include "../../gcode/queue.h"
39
+#endif
40
+
37
 /**
41
 /**
38
  * M20: List SD card to serial output
42
  * M20: List SD card to serial output
39
  */
43
  */
40
 void GcodeSuite::M20() {
44
 void GcodeSuite::M20() {
41
-  SERIAL_PROTOCOLLNPGM(MSG_BEGIN_FILE_LIST);
42
-  card.ls();
43
-  SERIAL_PROTOCOLLNPGM(MSG_END_FILE_LIST);
45
+  #if NUM_SERIAL > 1
46
+    const int16_t port = command_queue_port[cmd_queue_index_r];
47
+  #endif
48
+
49
+  SERIAL_PROTOCOLLNPGM_P(port, MSG_BEGIN_FILE_LIST);
50
+  card.ls(
51
+    #if NUM_SERIAL > 1
52
+      port
53
+    #endif
54
+  );
55
+  SERIAL_PROTOCOLLNPGM_P(port, MSG_END_FILE_LIST);
44
 }
56
 }
45
 
57
 
46
 /**
58
 /**
97
 /**
109
 /**
98
  * M27: Get SD Card status
110
  * M27: Get SD Card status
99
  */
111
  */
100
-void GcodeSuite::M27() { card.getStatus(); }
112
+void GcodeSuite::M27() { 
113
+  card.getStatus(
114
+    #if NUM_SERIAL > 1
115
+      command_queue_port[cmd_queue_index_r]
116
+    #endif
117
+  );
118
+}
101
 
119
 
102
 /**
120
 /**
103
  * M28: Start SD Write
121
  * M28: Start SD Write
164
    *   /Miscellaneous/Armchair/Armchair.gcode
182
    *   /Miscellaneous/Armchair/Armchair.gcode
165
    */
183
    */
166
   void GcodeSuite::M33() {
184
   void GcodeSuite::M33() {
167
-    card.printLongPath(parser.string_arg);
185
+    card.printLongPath(parser.string_arg
186
+      #if NUM_SERIAL > 1
187
+        , command_queue_port[cmd_queue_index_r]
188
+      #endif
189
+    );
168
   }
190
   }
169
 
191
 
170
 #endif // LONG_FILENAME_HOST_SUPPORT
192
 #endif // LONG_FILENAME_HOST_SUPPORT

+ 9
- 2
Marlin/src/gcode/stats/M31.cpp 查看文件

26
 #include "../../libs/duration_t.h"
26
 #include "../../libs/duration_t.h"
27
 #include "../../lcd/ultralcd.h"
27
 #include "../../lcd/ultralcd.h"
28
 
28
 
29
+#if NUM_SERIAL > 1
30
+  #include "../../gcode/queue.h"
31
+#endif
32
+
29
 /**
33
 /**
30
  * M31: Get the time since the start of SD Print (or last M109)
34
  * M31: Get the time since the start of SD Print (or last M109)
31
  */
35
  */
32
 void GcodeSuite::M31() {
36
 void GcodeSuite::M31() {
37
+  #if NUM_SERIAL > 1
38
+    const int16_t port = command_queue_port[cmd_queue_index_r];
39
+  #endif
33
   char buffer[21];
40
   char buffer[21];
34
   duration_t elapsed = print_job_timer.duration();
41
   duration_t elapsed = print_job_timer.duration();
35
   elapsed.toString(buffer);
42
   elapsed.toString(buffer);
36
   lcd_setstatus(buffer);
43
   lcd_setstatus(buffer);
37
 
44
 
38
-  SERIAL_ECHO_START();
39
-  SERIAL_ECHOLNPAIR("Print time: ", buffer);
45
+  SERIAL_ECHO_START_P(port);
46
+  SERIAL_ECHOLNPAIR_P(port, "Print time: ", buffer);
40
 }
47
 }

+ 17
- 5
Marlin/src/gcode/temperature/M105.cpp 查看文件

23
 #include "../gcode.h"
23
 #include "../gcode.h"
24
 #include "../../module/temperature.h"
24
 #include "../../module/temperature.h"
25
 
25
 
26
+#if NUM_SERIAL > 1
27
+  #include "../../gcode/queue.h"
28
+#endif
29
+
26
 /**
30
 /**
27
  * M105: Read hot end and bed temperature
31
  * M105: Read hot end and bed temperature
28
  */
32
  */
29
 void GcodeSuite::M105() {
33
 void GcodeSuite::M105() {
30
   if (get_target_extruder_from_command()) return;
34
   if (get_target_extruder_from_command()) return;
31
 
35
 
36
+  #if NUM_SERIAL > 1
37
+    const int16_t port = command_queue_port[cmd_queue_index_r];
38
+  #endif
39
+
32
   #if HAS_TEMP_HOTEND || HAS_TEMP_BED
40
   #if HAS_TEMP_HOTEND || HAS_TEMP_BED
33
-    SERIAL_PROTOCOLPGM(MSG_OK);
34
-    thermalManager.print_heaterstates();
41
+    SERIAL_PROTOCOLPGM_P(port, MSG_OK);
42
+    thermalManager.print_heaterstates(
43
+      #if NUM_SERIAL > 1
44
+        port
45
+      #endif
46
+    );
35
   #else // !HAS_TEMP_HOTEND && !HAS_TEMP_BED
47
   #else // !HAS_TEMP_HOTEND && !HAS_TEMP_BED
36
-    SERIAL_ERROR_START();
37
-    SERIAL_ERRORLNPGM(MSG_ERR_NO_THERMISTORS);
48
+    SERIAL_ERROR_START_P(port);
49
+    SERIAL_ERRORLNPGM_P(port, MSG_ERR_NO_THERMISTORS);
38
   #endif
50
   #endif
39
 
51
 
40
-  SERIAL_EOL();
52
+  SERIAL_EOL_P(port);
41
 }
53
 }

+ 0
- 6
Marlin/src/inc/Conditionals_LCD.h 查看文件

494
 #define HAS_RESUME_CONTINUE (ENABLED(NEWPANEL) || ENABLED(EMERGENCY_PARSER))
494
 #define HAS_RESUME_CONTINUE (ENABLED(NEWPANEL) || ENABLED(EMERGENCY_PARSER))
495
 #define HAS_COLOR_LEDS (ENABLED(BLINKM) || ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(PCA9632) || ENABLED(NEOPIXEL_LED))
495
 #define HAS_COLOR_LEDS (ENABLED(BLINKM) || ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(PCA9632) || ENABLED(NEOPIXEL_LED))
496
 
496
 
497
-// For Re-ARM boards, always use the USB Emulated Serial Port unless RE_ARM_FORCE_SERIAL_PORT is defined
498
-#if !defined(RE_ARM_FORCE_SERIAL_PORT) && (MB(RAMPS_14_RE_ARM_EFB) || MB(RAMPS_14_RE_ARM_EEB) || MB(RAMPS_14_RE_ARM_EFF) || MB(RAMPS_14_RE_ARM_EEF) || MB(RAMPS_14_RE_ARM_SF))
499
-  #undef SERIAL_PORT
500
-  #define SERIAL_PORT -1
501
-#endif
502
-
503
 #endif // CONDITIONALS_LCD_H
497
 #endif // CONDITIONALS_LCD_H

+ 293
- 243
Marlin/src/module/configuration_store.cpp
文件差異過大導致無法顯示
查看文件


+ 37
- 7
Marlin/src/module/configuration_store.h 查看文件

25
 
25
 
26
 #include "../inc/MarlinConfig.h"
26
 #include "../inc/MarlinConfig.h"
27
 
27
 
28
+#define ADD_PORT_ARG ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
29
+
28
 class MarlinSettings {
30
 class MarlinSettings {
29
   public:
31
   public:
30
     MarlinSettings() { }
32
     MarlinSettings() { }
31
 
33
 
32
     static uint16_t datasize();
34
     static uint16_t datasize();
33
 
35
 
34
-    static void reset();
35
-    static bool save();   // Return 'true' if data was saved
36
+    static void reset(
37
+      #if ADD_PORT_ARG
38
+        const int8_t port=-1
39
+      #endif
40
+    );
41
+    static bool save(
42
+      #if ADD_PORT_ARG
43
+        const int8_t port=-1
44
+      #endif
45
+    );   // Return 'true' if data was saved
36
 
46
 
37
     FORCE_INLINE static bool init_eeprom() {
47
     FORCE_INLINE static bool init_eeprom() {
38
       bool success = true;
48
       bool success = true;
47
     }
57
     }
48
 
58
 
49
     #if ENABLED(EEPROM_SETTINGS)
59
     #if ENABLED(EEPROM_SETTINGS)
50
-      static bool load();     // Return 'true' if data was loaded ok
51
-      static bool validate(); // Return 'true' if EEPROM data is ok
60
+      static bool load(
61
+        #if ADD_PORT_ARG
62
+          const int8_t port=-1
63
+        #endif
64
+      );     // Return 'true' if data was loaded ok
65
+      static bool validate(
66
+        #if ADD_PORT_ARG
67
+          const int8_t port=-1
68
+        #endif
69
+      ); // Return 'true' if EEPROM data is ok
52
 
70
 
53
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
71
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
54
                                          // That can store is enabled
72
                                          // That can store is enabled
67
     #endif
85
     #endif
68
 
86
 
69
     #if DISABLED(DISABLE_M503)
87
     #if DISABLED(DISABLE_M503)
70
-      static void report(const bool forReplay=false);
88
+      static void report(const bool forReplay=false
89
+        #if ADD_PORT_ARG
90
+          , const int8_t port=-1
91
+        #endif
92
+      );
71
     #else
93
     #else
72
       FORCE_INLINE
94
       FORCE_INLINE
73
       static void report(const bool forReplay=false) { UNUSED(forReplay); }
95
       static void report(const bool forReplay=false) { UNUSED(forReplay); }
87
 
109
 
88
       #endif
110
       #endif
89
 
111
 
90
-      static bool _load();
91
-      static bool size_error(const uint16_t size);
112
+      static bool _load(
113
+        #if ADD_PORT_ARG
114
+          const int8_t port=-1
115
+        #endif
116
+      );
117
+      static bool size_error(const uint16_t size
118
+        #if ADD_PORT_ARG
119
+          const int8_t port=-1
120
+        #endif
121
+      );
92
     #endif
122
     #endif
93
 };
123
 };
94
 
124
 

+ 2
- 2
Marlin/src/module/stepper.h 查看文件

337
         }
337
         }
338
         if (timer < 100) { // (20kHz - this should never happen)
338
         if (timer < 100) { // (20kHz - this should never happen)
339
           timer = 100;
339
           timer = 100;
340
-          MYSERIAL.print(MSG_STEPPER_TOO_HIGH);
341
-          MYSERIAL.println(step_rate);
340
+          SERIAL_ECHOPGM(MSG_STEPPER_TOO_HIGH);
341
+          SERIAL_ECHOLN(step_rate);
342
         }
342
         }
343
       #endif
343
       #endif
344
 
344
 

+ 35
- 19
Marlin/src/module/temperature.cpp 查看文件

2121
 
2121
 
2122
   #include "../gcode/gcode.h"
2122
   #include "../gcode/gcode.h"
2123
 
2123
 
2124
-  void print_heater_state(const float &c, const float &t,
2124
+  static void print_heater_state(const float &c, const float &t
2125
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
2125
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
2126
-      const float r,
2126
+      , const float r
2127
     #endif
2127
     #endif
2128
-    const int8_t e=-2
2128
+    #if NUM_SERIAL > 1
2129
+      , const int8_t port=-1
2130
+    #endif
2131
+    , const int8_t e=-2
2129
   ) {
2132
   ) {
2130
     #if !(HAS_TEMP_BED && HAS_TEMP_HOTEND) && HOTENDS <= 1
2133
     #if !(HAS_TEMP_BED && HAS_TEMP_HOTEND) && HOTENDS <= 1
2131
       UNUSED(e);
2134
       UNUSED(e);
2132
     #endif
2135
     #endif
2133
 
2136
 
2134
-    SERIAL_PROTOCOLCHAR(' ');
2135
-    SERIAL_PROTOCOLCHAR(
2137
+    SERIAL_PROTOCOLCHAR_P(port, ' ');
2138
+    SERIAL_PROTOCOLCHAR_P(port,
2136
       #if HAS_TEMP_BED && HAS_TEMP_HOTEND
2139
       #if HAS_TEMP_BED && HAS_TEMP_HOTEND
2137
         e == -1 ? 'B' : 'T'
2140
         e == -1 ? 'B' : 'T'
2138
       #elif HAS_TEMP_HOTEND
2141
       #elif HAS_TEMP_HOTEND
2142
       #endif
2145
       #endif
2143
     );
2146
     );
2144
     #if HOTENDS > 1
2147
     #if HOTENDS > 1
2145
-      if (e >= 0) SERIAL_PROTOCOLCHAR('0' + e);
2148
+      if (e >= 0) SERIAL_PROTOCOLCHAR_P(port, '0' + e);
2146
     #endif
2149
     #endif
2147
-    SERIAL_PROTOCOLCHAR(':');
2148
-    SERIAL_PROTOCOL(c);
2149
-    SERIAL_PROTOCOLPAIR(" /" , t);
2150
+    SERIAL_PROTOCOLCHAR_P(port, ':');
2151
+    SERIAL_PROTOCOL_P(port, c);
2152
+    SERIAL_PROTOCOLPAIR_P(port, " /" , t);
2150
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
2153
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
2151
-      SERIAL_PROTOCOLPAIR(" (", r / OVERSAMPLENR);
2152
-      SERIAL_PROTOCOLCHAR(')');
2154
+      SERIAL_PROTOCOLPAIR_P(port, " (", r / OVERSAMPLENR);
2155
+      SERIAL_PROTOCOLCHAR_P(port, ')');
2153
     #endif
2156
     #endif
2154
   }
2157
   }
2155
 
2158
 
2156
-  void Temperature::print_heaterstates() {
2159
+  void Temperature::print_heaterstates(
2160
+    #if NUM_SERIAL > 1
2161
+      const int8_t port
2162
+    #endif
2163
+  ) {
2157
     #if HAS_TEMP_HOTEND
2164
     #if HAS_TEMP_HOTEND
2158
       print_heater_state(degHotend(gcode.target_extruder), degTargetHotend(gcode.target_extruder)
2165
       print_heater_state(degHotend(gcode.target_extruder), degTargetHotend(gcode.target_extruder)
2159
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
2166
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
2160
           , rawHotendTemp(gcode.target_extruder)
2167
           , rawHotendTemp(gcode.target_extruder)
2161
         #endif
2168
         #endif
2169
+        #if NUM_SERIAL > 1
2170
+          , port
2171
+        #endif
2162
       );
2172
       );
2163
     #endif
2173
     #endif
2164
     #if HAS_TEMP_BED
2174
     #if HAS_TEMP_BED
2166
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
2176
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
2167
           , rawBedTemp()
2177
           , rawBedTemp()
2168
         #endif
2178
         #endif
2179
+        #if NUM_SERIAL > 1
2180
+          , port
2181
+        #endif
2169
         , -1 // BED
2182
         , -1 // BED
2170
       );
2183
       );
2171
     #endif
2184
     #endif
2174
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
2187
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
2175
           , rawHotendTemp(e)
2188
           , rawHotendTemp(e)
2176
         #endif
2189
         #endif
2190
+        #if NUM_SERIAL > 1
2191
+          , port
2192
+        #endif
2177
         , e
2193
         , e
2178
       );
2194
       );
2179
     #endif
2195
     #endif
2180
-    SERIAL_PROTOCOLPGM(" @:");
2181
-    SERIAL_PROTOCOL(getHeaterPower(gcode.target_extruder));
2196
+    SERIAL_PROTOCOLPGM_P(port, " @:");
2197
+    SERIAL_PROTOCOL_P(port, getHeaterPower(gcode.target_extruder));
2182
     #if HAS_TEMP_BED
2198
     #if HAS_TEMP_BED
2183
-      SERIAL_PROTOCOLPGM(" B@:");
2184
-      SERIAL_PROTOCOL(getHeaterPower(-1));
2199
+      SERIAL_PROTOCOLPGM_P(port, " B@:");
2200
+      SERIAL_PROTOCOL_P(port, getHeaterPower(-1));
2185
     #endif
2201
     #endif
2186
     #if HOTENDS > 1
2202
     #if HOTENDS > 1
2187
       HOTEND_LOOP() {
2203
       HOTEND_LOOP() {
2188
-        SERIAL_PROTOCOLPAIR(" @", e);
2189
-        SERIAL_PROTOCOLCHAR(':');
2190
-        SERIAL_PROTOCOL(getHeaterPower(e));
2204
+        SERIAL_PROTOCOLPAIR_P(port, " @", e);
2205
+        SERIAL_PROTOCOLCHAR_P(port, ':');
2206
+        SERIAL_PROTOCOL_P(port, getHeaterPower(e));
2191
       }
2207
       }
2192
     #endif
2208
     #endif
2193
   }
2209
   }

+ 5
- 1
Marlin/src/module/temperature.h 查看文件

547
     #endif // HEATER_IDLE_HANDLER
547
     #endif // HEATER_IDLE_HANDLER
548
 
548
 
549
     #if HAS_TEMP_HOTEND || HAS_TEMP_BED
549
     #if HAS_TEMP_HOTEND || HAS_TEMP_BED
550
-      static void print_heaterstates();
550
+      static void print_heaterstates(
551
+        #if NUM_SERIAL > 1
552
+          const int8_t port = -1
553
+        #endif
554
+      );
551
       #if ENABLED(AUTO_REPORT_TEMPERATURES)
555
       #if ENABLED(AUTO_REPORT_TEMPERATURES)
552
         static uint8_t auto_report_temp_interval;
556
         static uint8_t auto_report_temp_interval;
553
         static millis_t next_temp_report_ms;
557
         static millis_t next_temp_report_ms;

+ 19
- 20
Marlin/src/sd/SdBaseFile.cpp 查看文件

339
         && DIR_IS_FILE_OR_SUBDIR(&dir)) break;
339
         && DIR_IS_FILE_OR_SUBDIR(&dir)) break;
340
   }
340
   }
341
   // indent for dir level
341
   // indent for dir level
342
-  for (uint8_t i = 0; i < indent; i++) MYSERIAL.write(' ');
342
+  for (uint8_t i = 0; i < indent; i++) SERIAL_CHAR(' ');
343
 
343
 
344
   // print name
344
   // print name
345
   for (uint8_t i = 0; i < 11; i++) {
345
   for (uint8_t i = 0; i < 11; i++) {
346
     if (dir.name[i] == ' ')continue;
346
     if (dir.name[i] == ' ')continue;
347
     if (i == 8) {
347
     if (i == 8) {
348
-      MYSERIAL.write('.');
348
+      SERIAL_CHAR('.');
349
       w++;
349
       w++;
350
     }
350
     }
351
-    MYSERIAL.write(dir.name[i]);
351
+    SERIAL_CHAR(dir.name[i]);
352
     w++;
352
     w++;
353
   }
353
   }
354
   if (DIR_IS_SUBDIR(&dir)) {
354
   if (DIR_IS_SUBDIR(&dir)) {
355
-    MYSERIAL.write('/');
355
+    SERIAL_CHAR('/');
356
     w++;
356
     w++;
357
   }
357
   }
358
   if (flags & (LS_DATE | LS_SIZE)) {
358
   if (flags & (LS_DATE | LS_SIZE)) {
359
-    while (w++ < 14) MYSERIAL.write(' ');
359
+    while (w++ < 14) SERIAL_CHAR(' ');
360
   }
360
   }
361
   // print modify date/time if requested
361
   // print modify date/time if requested
362
   if (flags & LS_DATE) {
362
   if (flags & LS_DATE) {
363
-    MYSERIAL.write(' ');
363
+    SERIAL_CHAR(' ');
364
     printFatDate(dir.lastWriteDate);
364
     printFatDate(dir.lastWriteDate);
365
-    MYSERIAL.write(' ');
365
+    SERIAL_CHAR(' ');
366
     printFatTime(dir.lastWriteTime);
366
     printFatTime(dir.lastWriteTime);
367
   }
367
   }
368
   // print size if requested
368
   // print size if requested
369
   if (!DIR_IS_SUBDIR(&dir) && (flags & LS_SIZE)) {
369
   if (!DIR_IS_SUBDIR(&dir) && (flags & LS_SIZE)) {
370
-    MYSERIAL.write(' ');
371
-    MYSERIAL.print(dir.fileSize);
370
+    SERIAL_CHAR(' ');
371
+    SERIAL_ECHO(dir.fileSize);
372
   }
372
   }
373
-  MYSERIAL.println();
373
+  SERIAL_EOL();
374
   return DIR_IS_FILE(&dir) ? 1 : 2;
374
   return DIR_IS_FILE(&dir) ? 1 : 2;
375
 }
375
 }
376
 
376
 
902
   return c;
902
   return c;
903
 }
903
 }
904
 
904
 
905
-
906
 // print uint8_t with width 2
905
 // print uint8_t with width 2
907
-static void print2u(uint8_t v) {
908
-  if (v < 10) MYSERIAL.write('0');
909
-  MYSERIAL.print(v, DEC);
906
+static void print2u(const uint8_t v) {
907
+  if (v < 10) SERIAL_CHAR('0');
908
+  SERIAL_ECHO_F(v, DEC);
910
 }
909
 }
911
 
910
 
912
 /**
911
 /**
927
  * \param[in] fatDate The date field from a directory entry.
926
  * \param[in] fatDate The date field from a directory entry.
928
  */
927
  */
929
 void SdBaseFile::printFatDate(uint16_t fatDate) {
928
 void SdBaseFile::printFatDate(uint16_t fatDate) {
930
-  MYSERIAL.print(FAT_YEAR(fatDate));
931
-  MYSERIAL.write('-');
929
+  SERIAL_ECHO(FAT_YEAR(fatDate));
930
+  SERIAL_CHAR('-');
932
   print2u(FAT_MONTH(fatDate));
931
   print2u(FAT_MONTH(fatDate));
933
-  MYSERIAL.write('-');
932
+  SERIAL_CHAR('-');
934
   print2u(FAT_DAY(fatDate));
933
   print2u(FAT_DAY(fatDate));
935
 }
934
 }
936
 
935
 
945
  */
944
  */
946
 void SdBaseFile::printFatTime(uint16_t fatTime) {
945
 void SdBaseFile::printFatTime(uint16_t fatTime) {
947
   print2u(FAT_HOUR(fatTime));
946
   print2u(FAT_HOUR(fatTime));
948
-  MYSERIAL.write(':');
947
+  SERIAL_CHAR(':');
949
   print2u(FAT_MINUTE(fatTime));
948
   print2u(FAT_MINUTE(fatTime));
950
-  MYSERIAL.write(':');
949
+  SERIAL_CHAR(':');
951
   print2u(FAT_SECOND(fatTime));
950
   print2u(FAT_SECOND(fatTime));
952
 }
951
 }
953
 
952
 
959
 bool SdBaseFile::printName() {
958
 bool SdBaseFile::printName() {
960
   char name[FILENAME_LENGTH];
959
   char name[FILENAME_LENGTH];
961
   if (!getFilename(name)) return false;
960
   if (!getFilename(name)) return false;
962
-  MYSERIAL.print(name);
961
+  SERIAL_ECHO(name);
963
   return true;
962
   return true;
964
 }
963
 }
965
 
964
 

+ 13
- 45
Marlin/src/sd/SdFatUtil.cpp 查看文件

38
  * \return The number of free bytes.
38
  * \return The number of free bytes.
39
  */
39
  */
40
 #ifdef __arm__
40
 #ifdef __arm__
41
-extern "C" char* sbrk(int incr);
42
-int SdFatUtil::FreeRam() {
43
-  char top;
44
-  return &top - reinterpret_cast<char*>(sbrk(0));
45
-}
46
-#else  // __arm__
47
-extern char* __brkval;
48
-extern char __bss_end;
49
-/**
50
- * Amount of free RAM
51
- * \return The number of free bytes.
52
- */
53
-int SdFatUtil::FreeRam() {
54
-  char top;
55
-  return __brkval ? &top - __brkval : &top - &__bss_end;
56
-}
57
-#endif  // __arm
58
 
41
 
59
-/**
60
- * %Print a string in flash memory.
61
- *
62
- * \param[in] pr Print object for output.
63
- * \param[in] str Pointer to string stored in flash memory.
64
- */
65
-void SdFatUtil::print_P(PGM_P str) {
66
-  for (uint8_t c; (c = pgm_read_byte(str)); str++) MYSERIAL.write(c);
67
-}
42
+  extern "C" char* sbrk(int incr);
43
+  int SdFatUtil::FreeRam() {
44
+    char top;
45
+    return &top - reinterpret_cast<char*>(sbrk(0));
46
+  }
68
 
47
 
69
-/**
70
- * %Print a string in flash memory followed by a CR/LF.
71
- *
72
- * \param[in] pr Print object for output.
73
- * \param[in] str Pointer to string stored in flash memory.
74
- */
75
-void SdFatUtil::println_P(PGM_P str) { print_P(str); MYSERIAL.println(); }
48
+#else
76
 
49
 
77
-/**
78
- * %Print a string in flash memory to Serial.
79
- *
80
- * \param[in] str Pointer to string stored in flash memory.
81
- */
82
-void SdFatUtil::SerialPrint_P(PGM_P str) { print_P(str); }
50
+  extern char* __brkval;
51
+  extern char __bss_end;
52
+  int SdFatUtil::FreeRam() {
53
+    char top;
54
+    return __brkval ? &top - __brkval : &top - &__bss_end;
55
+  }
83
 
56
 
84
-/**
85
- * %Print a string in flash memory to Serial followed by a CR/LF.
86
- *
87
- * \param[in] str Pointer to string stored in flash memory.
88
- */
89
-void SdFatUtil::SerialPrintln_P(PGM_P str) { println_P(str); }
57
+#endif
90
 
58
 
91
 #endif // SDSUPPORT
59
 #endif // SDSUPPORT

+ 0
- 8
Marlin/src/sd/SdFatUtil.h 查看文件

35
  * \file
35
  * \file
36
  * \brief Useful utility functions.
36
  * \brief Useful utility functions.
37
  */
37
  */
38
-/** Store and print a string in flash memory.*/
39
-#define PgmPrint(x) SerialPrint_P(PSTR(x))
40
-/** Store and print a string in flash memory followed by a CR/LF.*/
41
-#define PgmPrintln(x) SerialPrintln_P(PSTR(x))
42
 
38
 
43
 namespace SdFatUtil {
39
 namespace SdFatUtil {
44
   int FreeRam();
40
   int FreeRam();
45
-  void print_P(PGM_P str);
46
-  void println_P(PGM_P str);
47
-  void SerialPrint_P(PGM_P str);
48
-  void SerialPrintln_P(PGM_P str);
49
 }
41
 }
50
 
42
 
51
 using namespace SdFatUtil;  // NOLINT
43
 using namespace SdFatUtil;  // NOLINT

+ 57
- 29
Marlin/src/sd/cardreader.cpp 查看文件

85
 
85
 
86
 uint16_t nrFile_index;
86
 uint16_t nrFile_index;
87
 
87
 
88
-void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
88
+void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/
89
+  #if NUM_SERIAL > 1
90
+    , const int8_t port/*= -1*/
91
+  #endif
92
+) {
89
   dir_t p;
93
   dir_t p;
90
   uint8_t cnt = 0;
94
   uint8_t cnt = 0;
91
 
95
 
118
       SdFile dir;
122
       SdFile dir;
119
       if (!dir.open(parent, lfilename, O_READ)) {
123
       if (!dir.open(parent, lfilename, O_READ)) {
120
         if (lsAction == LS_SerialPrint) {
124
         if (lsAction == LS_SerialPrint) {
121
-          SERIAL_ECHO_START();
122
-          SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
123
-          SERIAL_ECHOLN(lfilename);
125
+          SERIAL_ECHO_START_P(port);
126
+          SERIAL_ECHOPGM_P(port, MSG_SD_CANT_OPEN_SUBDIR);
127
+          SERIAL_ECHOLN_P(port, lfilename);
124
         }
128
         }
125
       }
129
       }
126
-      lsDive(path, dir);
130
+      lsDive(path, dir
131
+        #if NUM_SERIAL > 1
132
+          , NULL, port
133
+        #endif
134
+      );
127
       // close() is done automatically by destructor of SdFile
135
       // close() is done automatically by destructor of SdFile
128
     }
136
     }
129
     else {
137
     else {
145
 
153
 
146
         case LS_SerialPrint:
154
         case LS_SerialPrint:
147
           createFilename(filename, p);
155
           createFilename(filename, p);
148
-          SERIAL_PROTOCOL(prepend);
149
-          SERIAL_PROTOCOL(filename);
150
-          SERIAL_PROTOCOLCHAR(' ');
151
-          SERIAL_PROTOCOLLN(p.fileSize);
156
+          SERIAL_PROTOCOL_P(port, prepend);
157
+          SERIAL_PROTOCOL_P(port, filename);
158
+          SERIAL_PROTOCOLCHAR_P(port, ' ');
159
+          SERIAL_PROTOCOLLN_P(port, p.fileSize);
152
           break;
160
           break;
153
 
161
 
154
         case LS_GetFilename:
162
         case LS_GetFilename:
165
   } // while readDir
173
   } // while readDir
166
 }
174
 }
167
 
175
 
168
-void CardReader::ls() {
176
+void CardReader::ls(
177
+  #if NUM_SERIAL > 1
178
+    const int8_t port
179
+  #endif
180
+) {
169
   lsAction = LS_SerialPrint;
181
   lsAction = LS_SerialPrint;
170
   root.rewind();
182
   root.rewind();
171
-  lsDive("", root);
183
+  lsDive("", root  
184
+    #if NUM_SERIAL > 1
185
+      , NULL, port
186
+    #endif
187
+  );
172
 }
188
 }
173
 
189
 
174
 #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
190
 #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
176
   /**
192
   /**
177
    * Get a long pretty path based on a DOS 8.3 path
193
    * Get a long pretty path based on a DOS 8.3 path
178
    */
194
    */
179
-  void CardReader::printLongPath(char *path) {
195
+  void CardReader::printLongPath(char *path
196
+    #if NUM_SERIAL > 1
197
+      , const int8_t port/*= -1*/
198
+    #endif
199
+  ) {
180
     lsAction = LS_GetFilename;
200
     lsAction = LS_GetFilename;
181
 
201
 
182
     int i, pathLen = strlen(path);
202
     int i, pathLen = strlen(path);
183
 
203
 
184
-    // SERIAL_ECHOPGM("Full Path: "); SERIAL_ECHOLN(path);
204
+    // SERIAL_ECHOPGM_P(port, "Full Path: "); SERIAL_ECHOLN_P(port, path);
185
 
205
 
186
     // Zero out slashes to make segments
206
     // Zero out slashes to make segments
187
     for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0';
207
     for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0';
199
       // Go to the next segment
219
       // Go to the next segment
200
       while (path[++i]) { }
220
       while (path[++i]) { }
201
 
221
 
202
-      // SERIAL_ECHOPGM("Looking for segment: "); SERIAL_ECHOLN(segment);
222
+      // SERIAL_ECHOPGM_P(port, "Looking for segment: "); SERIAL_ECHOLN_P(port, segment);
203
 
223
 
204
       // Find the item, setting the long filename
224
       // Find the item, setting the long filename
205
       diveDir.rewind();
225
       diveDir.rewind();
206
-      lsDive("", diveDir, segment);
226
+      lsDive("", diveDir, segment
227
+        #if NUM_SERIAL > 1
228
+          , port
229
+        #endif
230
+      );
207
 
231
 
208
       // Print /LongNamePart to serial output
232
       // Print /LongNamePart to serial output
209
-      SERIAL_PROTOCOLCHAR('/');
210
-      SERIAL_PROTOCOL(longFilename[0] ? longFilename : "???");
233
+      SERIAL_PROTOCOLCHAR_P(port, '/');
234
+      SERIAL_PROTOCOL_P(port, longFilename[0] ? longFilename : "???");
211
 
235
 
212
       // If the filename was printed then that's it
236
       // If the filename was printed then that's it
213
       if (!filenameIsDir) break;
237
       if (!filenameIsDir) break;
214
 
238
 
215
-      // SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment);
239
+      // SERIAL_ECHOPGM_P(port, "Opening dir: "); SERIAL_ECHOLN_P(port, segment);
216
 
240
 
217
       // Open the sub-item as the new dive parent
241
       // Open the sub-item as the new dive parent
218
       SdFile dir;
242
       SdFile dir;
219
       if (!dir.open(diveDir, segment, O_READ)) {
243
       if (!dir.open(diveDir, segment, O_READ)) {
220
-        SERIAL_EOL();
221
-        SERIAL_ECHO_START();
222
-        SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
223
-        SERIAL_ECHO(segment);
244
+        SERIAL_EOL_P(port);
245
+        SERIAL_ECHO_START_P(port);
246
+        SERIAL_ECHOPGM_P(port, MSG_SD_CANT_OPEN_SUBDIR);
247
+        SERIAL_ECHO_P(port, segment);
224
         break;
248
         break;
225
       }
249
       }
226
 
250
 
229
 
253
 
230
     } // while i<pathLen
254
     } // while i<pathLen
231
 
255
 
232
-    SERIAL_EOL();
256
+    SERIAL_EOL_P(port);
233
   }
257
   }
234
 
258
 
235
 #endif // LONG_FILENAME_HOST_SUPPORT
259
 #endif // LONG_FILENAME_HOST_SUPPORT
500
   }
524
   }
501
 }
525
 }
502
 
526
 
503
-void CardReader::getStatus() {
527
+void CardReader::getStatus(
528
+  #if NUM_SERIAL > 1
529
+    const int8_t port/*= -1*/
530
+  #endif
531
+) {
504
   if (cardOK) {
532
   if (cardOK) {
505
-    SERIAL_PROTOCOLPGM(MSG_SD_PRINTING_BYTE);
506
-    SERIAL_PROTOCOL(sdpos);
507
-    SERIAL_PROTOCOLCHAR('/');
508
-    SERIAL_PROTOCOLLN(filesize);
533
+    SERIAL_PROTOCOLPGM_P(port, MSG_SD_PRINTING_BYTE);
534
+    SERIAL_PROTOCOL_P(port, sdpos);
535
+    SERIAL_PROTOCOLCHAR_P(port, '/');
536
+    SERIAL_PROTOCOLLN_P(port, filesize);
509
   }
537
   }
510
   else
538
   else
511
-    SERIAL_PROTOCOLLNPGM(MSG_SD_NOT_PRINTING);
539
+    SERIAL_PROTOCOLLNPGM_P(port, MSG_SD_NOT_PRINTING);
512
 }
540
 }
513
 
541
 
514
 void CardReader::write_command(char *buf) {
542
 void CardReader::write_command(char *buf) {

+ 20
- 4
Marlin/src/sd/cardreader.h 查看文件

49
   void openAndPrintFile(const char *name);
49
   void openAndPrintFile(const char *name);
50
   void startFileprint();
50
   void startFileprint();
51
   void stopSDPrint();
51
   void stopSDPrint();
52
-  void getStatus();
52
+  void getStatus(
53
+    #if NUM_SERIAL > 1
54
+      const int8_t port = -1
55
+    #endif
56
+  );
53
   void printingHasFinished();
57
   void printingHasFinished();
54
 
58
 
55
   #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
59
   #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
56
-    void printLongPath(char *path);
60
+    void printLongPath(char *path
61
+      #if NUM_SERIAL > 1
62
+        , const int8_t port = -1
63
+      #endif
64
+    );
57
   #endif
65
   #endif
58
 
66
 
59
   void getfilename(uint16_t nr, const char* const match=NULL);
67
   void getfilename(uint16_t nr, const char* const match=NULL);
61
 
69
 
62
   void getAbsFilename(char *t);
70
   void getAbsFilename(char *t);
63
 
71
 
64
-  void ls();
72
+  void ls(
73
+    #if NUM_SERIAL > 1
74
+      const int8_t port = -1
75
+    #endif
76
+  );
65
   void chdir(const char *relpath);
77
   void chdir(const char *relpath);
66
   int8_t updir();
78
   int8_t updir();
67
   void setroot();
79
   void setroot();
162
   LsAction lsAction; //stored for recursion.
174
   LsAction lsAction; //stored for recursion.
163
   uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
175
   uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
164
   char* diveDirName;
176
   char* diveDirName;
165
-  void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
177
+  void lsDive(const char *prepend, SdFile parent, const char * const match=NULL  
178
+    #if NUM_SERIAL > 1
179
+      , const int8_t port = -1
180
+    #endif
181
+  );
166
 
182
 
167
   #if ENABLED(SDCARD_SORT_ALPHA)
183
   #if ENABLED(SDCARD_SORT_ALPHA)
168
     void flush_presort();
184
     void flush_presort();

Loading…
取消
儲存