Browse Source

Improve Malyan M200 integration (#15462)

Me No Dev 4 years ago
parent
commit
fc6a0937b8

+ 62
- 29
Marlin/src/lcd/extui_malyan_lcd.cpp View File

@@ -117,17 +117,27 @@ void write_to_lcd(const char * const message) {
117 117
  * the command portion begins after the :
118 118
  */
119 119
 void process_lcd_c_command(const char* command) {
120
+  const int target_val = command[1] ? atoi(command + 1) : -1;
121
+  if (target_val < 0) {
122
+    DEBUG_ECHOLNPAIR("UNKNOWN C COMMAND ", command);
123
+    return;
124
+  }
120 125
   switch (command[0]) {
121 126
     case 'C': // Cope with both V1 early rev and later LCDs.
122 127
     case 'S':
123
-      feedrate_percentage = atoi(command + 1) * 10;
128
+      feedrate_percentage = target_val * 10;
124 129
       LIMIT(feedrate_percentage, 10, 999);
125 130
       break;
126 131
 
127
-    case 'T': ExtUI::setTargetTemp_celsius(atoi(command + 1), ExtUI::extruder_t::E0); break;
132
+    case 'T':
133
+      // Sometimes the LCD will send commands to turn off both extruder and bed, though
134
+      // this should not happen since the printing screen is up. Better safe than sorry.
135
+      if (!print_job_timer.isRunning() || target_val > 0)
136
+        ExtUI::setTargetTemp_celsius(target_val, ExtUI::extruder_t::E0);
137
+      break;
128 138
 
129 139
     #if HAS_HEATED_BED
130
-      case 'P': ExtUI::setTargetTemp_celsius(atoi(command + 1), ExtUI::heater_t::BED); break;
140
+      case 'P': ExtUI::setTargetTemp_celsius(target_val, ExtUI::heater_t::BED); break;
131 141
     #endif
132 142
 
133 143
     default: DEBUG_ECHOLNPAIR("UNKNOWN C COMMAND ", command);
@@ -143,6 +153,7 @@ void process_lcd_c_command(const char* command) {
143 153
  */
144 154
 void process_lcd_eb_command(const char* command) {
145 155
   char elapsed_buffer[10];
156
+  static uint8_t iteration = 0;
146 157
   duration_t elapsed;
147 158
   switch (command[0]) {
148 159
     case '0': {
@@ -150,6 +161,13 @@ void process_lcd_eb_command(const char* command) {
150 161
       sprintf_P(elapsed_buffer, PSTR("%02u%02u%02u"), uint16_t(elapsed.hour()), uint16_t(elapsed.minute()) % 60, uint16_t(elapsed.second()) % 60);
151 162
 
152 163
       char message_buffer[MAX_CURLY_COMMAND];
164
+      uint8_t done_pct = print_job_timer.isRunning() ? (iteration * 10) : 100;
165
+      iteration = (iteration + 1) % 10; // Provide progress animation
166
+      #if ENABLED(SDSUPPORT)
167
+        if (ExtUI::isPrintingFromMedia() || ExtUI::isPrintingFromMediaPaused())
168
+          done_pct = card.percentDone();
169
+      #endif
170
+
153 171
       sprintf_P(message_buffer,
154 172
         PSTR("{T0:%03i/%03i}{T1:000/000}{TP:%03i/%03i}{TQ:%03i}{TT:%s}"),
155 173
         int(thermalManager.degHotend(0)), thermalManager.degTargetHotend(0),
@@ -159,7 +177,7 @@ void process_lcd_eb_command(const char* command) {
159 177
           0, 0,
160 178
         #endif
161 179
         #if ENABLED(SDSUPPORT)
162
-          card.percentDone(),
180
+          done_pct,
163 181
         #else
164 182
           0,
165 183
         #endif
@@ -186,7 +204,7 @@ void process_lcd_j_command(const char* command) {
186 204
   auto move_axis = [command](const auto axis) {
187 205
     const float dist = atof(command + 1) / 10.0;
188 206
     ExtUI::setAxisPosition_mm(ExtUI::getAxisPosition_mm(axis) + dist, axis);
189
-  }
207
+  };
190 208
 
191 209
   switch (command[0]) {
192 210
     case 'E': break;
@@ -330,7 +348,6 @@ void process_lcd_s_command(const char* command) {
330 348
 void process_lcd_command(const char* command) {
331 349
   const char *current = command;
332 350
 
333
-  current++; // skip the leading {. The trailing one is already gone.
334 351
   byte command_code = *current++;
335 352
   if (*current == ':') {
336 353
 
@@ -350,6 +367,31 @@ void process_lcd_command(const char* command) {
350 367
     DEBUG_ECHOLNPAIR("UNKNOWN COMMAND FORMAT ", command);
351 368
 }
352 369
 
370
+// Parse LCD commands mixed with G-Code
371
+void parse_lcd_byte(byte b) {
372
+  static bool parsing_lcd_cmd = false;
373
+  static char inbound_buffer[MAX_CURLY_COMMAND];
374
+
375
+  if (!parsing_lcd_cmd) {
376
+    if (b == '{' || b == '\n' || b == '\r') {   // A line-ending or opening brace
377
+      parsing_lcd_cmd = b == '{';               // Brace opens an LCD command
378
+      if (inbound_count) {                      // Looks like a G-code is in the buffer
379
+        inbound_buffer[inbound_count] = '\0';   // Reset before processing
380
+        inbound_count = 0;
381
+        queue.enqueue_one_now(inbound_buffer);  // Handle the G-code command
382
+      }
383
+    }
384
+  }
385
+  else if (b == '}') {                          // Closing brace on an LCD command
386
+    parsing_lcd_cmd = false;                    // Unflag and...
387
+    inbound_buffer[inbound_count] = '\0';       // reset before processing
388
+    inbound_count = 0;
389
+    process_lcd_command(inbound_buffer);        // Handle the LCD command
390
+  }
391
+  else if (inbound_count < MAX_CURLY_COMMAND - 2)
392
+    inbound_buffer[inbound_count++] = b;        // Buffer only if space remains
393
+}
394
+
353 395
 /**
354 396
  * UC means connected.
355 397
  * UD means disconnected
@@ -360,8 +402,8 @@ void update_usb_status(const bool forceUpdate) {
360 402
   // This is mildly different than stock, which
361 403
   // appears to use the usb discovery status.
362 404
   // This is more logical.
363
-  if (last_usb_connected_status != Serial || forceUpdate) {
364
-    last_usb_connected_status = Serial;
405
+  if (last_usb_connected_status != SerialUSB || forceUpdate) {
406
+    last_usb_connected_status = SerialUSB;
365 407
     write_to_lcd_P(last_usb_connected_status ? PSTR("{R:UC}\r\n") : PSTR("{R:UD}\r\n"));
366 408
   }
367 409
 }
@@ -391,24 +433,14 @@ namespace ExtUI {
391 433
     /**
392 434
      * - from printer on startup:
393 435
      * {SYS:STARTED}{VER:29}{SYS:STARTED}{R:UD}
394
-     * The optimize attribute fixes a register Compile
395
-     * error for amtel.
396 436
      */
397
-    static char inbound_buffer[MAX_CURLY_COMMAND];
398 437
 
399 438
     // First report USB status.
400 439
     update_usb_status(false);
401 440
 
402 441
     // now drain commands...
403 442
     while (LCD_SERIAL.available()) {
404
-      const byte b = (byte)LCD_SERIAL.read() & 0x7F;
405
-      inbound_buffer[inbound_count++] = b;
406
-      if (b == '}' || inbound_count == sizeof(inbound_buffer) - 1) {
407
-        inbound_buffer[inbound_count - 1] = '\0';
408
-        process_lcd_command(inbound_buffer);
409
-        inbound_count = 0;
410
-        inbound_buffer[0] = 0;
411
-      }
443
+      parse_lcd_byte((byte)LCD_SERIAL.read() & 0x7F);
412 444
     }
413 445
 
414 446
     #if ENABLED(SDSUPPORT)
@@ -438,22 +470,23 @@ namespace ExtUI {
438 470
     write_to_lcd_P("}");
439 471
   }
440 472
 
473
+  void onPrintTimerStarted() { write_to_lcd_P(PSTR("{SYS:BUILD}")); }
474
+  void onPrintTimerPaused() {}
475
+  void onPrintTimerStopped() { write_to_lcd_P(PSTR("{TQ:100}")); }
476
+
441 477
   // Not needed for Malyan LCD
442
-  void onStatusChanged(const char * const msg) { UNUSED(msg); }
478
+  void onStatusChanged(const char * const) {}
443 479
   void onMediaInserted() {};
444 480
   void onMediaError() {};
445 481
   void onMediaRemoved() {};
446
-  void onPlayTone(const uint16_t frequency, const uint16_t duration) { UNUSED(frequency); UNUSED(duration); }
447
-  void onPrintTimerStarted() {}
448
-  void onPrintTimerPaused() {}
449
-  void onPrintTimerStopped() {}
482
+  void onPlayTone(const uint16_t, const uint16_t) {}
450 483
   void onFilamentRunout(const extruder_t extruder) {}
451
-  void onUserConfirmRequired(const char * const msg) { UNUSED(msg); }
484
+  void onUserConfirmRequired(const char * const) {}
452 485
   void onFactoryReset() {}
453
-  void onStoreSettings(char *buff) { UNUSED(buff); }
454
-  void onLoadSettings(const char *buff) { UNUSED(buff); }
455
-  void onConfigurationStoreWritten(bool success) { UNUSED(success); }
456
-  void onConfigurationStoreRead(bool success) { UNUSED(success); }
486
+  void onStoreSettings(char*) {}
487
+  void onLoadSettings(const char*) {}
488
+  void onConfigurationStoreWritten(bool) {}
489
+  void onConfigurationStoreRead(bool) {}
457 490
 }
458 491
 
459 492
 #endif // MALYAN_LCD

+ 5
- 11
Marlin/src/pins/stm32/pins_MALYAN_M200.h View File

@@ -42,6 +42,8 @@
42 42
 // On STM32F103:
43 43
 // PB3, PB6, PB7, and PB8 can be used with pwm, which rules out TIM2 and TIM4.
44 44
 // On STM32F070, 16 and 17 are in use, but 1 and 3 are available.
45
+#undef STEP_TIMER
46
+#undef TEMP_TIMER
45 47
 #define STEP_TIMER 1
46 48
 #define TEMP_TIMER 3
47 49
 
@@ -84,15 +86,7 @@
84 86
 #define HEATER_0_PIN       PB6   // HOTEND0 MOSFET
85 87
 #define HEATER_BED_PIN     PB7   // BED MOSFET
86 88
 
87
-// FAN_PIN is commented out here because the M200 example
88
-// Configuration_adv.h does NOT override E0_AUTO_FAN_PIN.
89
-#ifndef FAN_PIN
90
-  //#define FAN_PIN        PB8   // FAN1 header on board - PRINT FAN
91
-#endif
92
-#define FAN1_PIN           PB3   // FAN2 header on board - CONTROLLER FAN
93
-#define FAN2_PIN           -1    // FAN3 header on board - EXTRUDER0 FAN
89
+#define MALYAN_FAN1_PIN    PB8   // FAN1 header on board - PRINT FAN
90
+#define MALYAN_FAN2_PIN    PB3   // FAN2 header on board - CONTROLLER FAN
94 91
 
95
-// This board has only the controller fan and the extruder fan
96
-// If someone hacks to put a direct power fan on the controller, PB3 could
97
-// be used as a separate print cooling fan.
98
-#define ORIG_E0_AUTO_FAN_PIN PB8
92
+#define FAN1_PIN           MALYAN_FAN2_PIN

+ 24
- 13
config/examples/Malyan/M200/Configuration.h View File

@@ -146,7 +146,7 @@
146 146
 #define EXTRUDERS 1
147 147
 
148 148
 // Generally expected filament diameter (1.75, 2.85, 3.0, ...). Used for Volumetric, Filament Width Sensor, etc.
149
-#define DEFAULT_NOMINAL_FILAMENT_DIA 3.0
149
+#define DEFAULT_NOMINAL_FILAMENT_DIA 1.75
150 150
 
151 151
 // For Cyclops or any "multi-extruder" that shares a single nozzle.
152 152
 //#define SINGLENOZZLE
@@ -474,9 +474,10 @@
474 474
   // If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it
475 475
 
476 476
   // Ultimaker
477
-  #define DEFAULT_Kp 26.15
478
-  #define DEFAULT_Ki 2.74
479
-  #define DEFAULT_Kd 62.35
477
+  //#define DEFAULT_Kp 26.15
478
+  //#define DEFAULT_Ki 2.74
479
+  //#define DEFAULT_Kd 62.35
480
+
480 481
   // MakerGear
481 482
   //#define DEFAULT_Kp 7.0
482 483
   //#define DEFAULT_Ki 0.1
@@ -487,6 +488,11 @@
487 488
   //#define DEFAULT_Ki 2.25
488 489
   //#define DEFAULT_Kd 440
489 490
 
491
+  // Malyan M200
492
+  #define DEFAULT_Kp 20.0
493
+  #define DEFAULT_Ki 2.02
494
+  #define DEFAULT_Kd 100.00
495
+
490 496
 #endif // PIDTEMP
491 497
 
492 498
 //===========================================================================
@@ -506,7 +512,7 @@
506 512
  * heater. If your configuration is significantly different than this and you don't understand
507 513
  * the issues involved, don't use bed PID until someone else verifies that your hardware works.
508 514
  */
509
-//#define PIDTEMPBED
515
+#define PIDTEMPBED
510 516
 
511 517
 //#define BED_LIMIT_SWITCHING
512 518
 
@@ -524,9 +530,9 @@
524 530
 
525 531
   //120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
526 532
   //from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10)
527
-  #define DEFAULT_bedKp 231.09
528
-  #define DEFAULT_bedKi 45.21
529
-  #define DEFAULT_bedKd 295.34
533
+  //#define DEFAULT_bedKp 231.09
534
+  //#define DEFAULT_bedKi 45.21
535
+  //#define DEFAULT_bedKd 295.34
530 536
 
531 537
   //120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
532 538
   //from pidautotune
@@ -534,6 +540,11 @@
534 540
   //#define DEFAULT_bedKi 1.41
535 541
   //#define DEFAULT_bedKd 1675.16
536 542
 
543
+  // Malyan M200
544
+  #define DEFAULT_bedKp 14.00
545
+  #define DEFAULT_bedKi 0.9
546
+  #define DEFAULT_bedKd 120.4
547
+
537 548
   // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
538 549
 #endif // PIDTEMPBED
539 550
 
@@ -1051,8 +1062,8 @@
1051 1062
 // @section machine
1052 1063
 
1053 1064
 // The size of the print bed
1054
-#define X_BED_SIZE 200
1055
-#define Y_BED_SIZE 200
1065
+#define X_BED_SIZE 120
1066
+#define Y_BED_SIZE 120
1056 1067
 
1057 1068
 // Travel limits (mm) after homing, corresponding to endstop positions.
1058 1069
 #define X_MIN_POS 0
@@ -1060,7 +1071,7 @@
1060 1071
 #define Z_MIN_POS 0
1061 1072
 #define X_MAX_POS X_BED_SIZE
1062 1073
 #define Y_MAX_POS Y_BED_SIZE
1063
-#define Z_MAX_POS 200
1074
+#define Z_MAX_POS 120
1064 1075
 
1065 1076
 /**
1066 1077
  * Software Endstops
@@ -1278,7 +1289,7 @@
1278 1289
 #endif
1279 1290
 
1280 1291
 // Add a menu item to move between bed corners for manual bed adjustment
1281
-#define LEVEL_BED_CORNERS
1292
+//#define LEVEL_BED_CORNERS
1282 1293
 
1283 1294
 #if ENABLED(LEVEL_BED_CORNERS)
1284 1295
   #define LEVEL_CORNERS_INSET 30    // (mm) An inset for corner leveling
@@ -1627,7 +1638,7 @@
1627 1638
  */
1628 1639
 //#define SPI_SPEED SPI_HALF_SPEED
1629 1640
 //#define SPI_SPEED SPI_QUARTER_SPEED
1630
-#define SPI_SPEED SPI_EIGHTH_SPEED
1641
+//#define SPI_SPEED SPI_EIGHTH_SPEED
1631 1642
 
1632 1643
 /**
1633 1644
  * SD CARD: ENABLE CRC

+ 5
- 3
config/examples/Malyan/M200/Configuration_adv.h View File

@@ -277,9 +277,9 @@
277 277
  * The fan will turn on automatically whenever any stepper is enabled
278 278
  * and turn off after a set period after all steppers are turned off.
279 279
  */
280
-//#define USE_CONTROLLER_FAN
280
+#define USE_CONTROLLER_FAN // Malyan M200: uncomment if you use FAN2 to cool the board (original)
281 281
 #if ENABLED(USE_CONTROLLER_FAN)
282
-  //#define CONTROLLER_FAN_PIN -1           // Set a custom pin for the controller fan
282
+  #define CONTROLLER_FAN_PIN MALYAN_FAN2_PIN     // Set a custom pin for the controller fan
283 283
   #define CONTROLLERFAN_SECS 60             // Duration in seconds for the fan to run after all motors are disabled
284 284
   #define CONTROLLERFAN_SPEED 255           // 255 == full speed
285 285
   //#define CONTROLLERFAN_SPEED_Z_ONLY 127  // Reduce noise on machines that keep Z enabled
@@ -346,7 +346,9 @@
346 346
  * Multiple extruders can be assigned to the same pin in which case
347 347
  * the fan will turn on when any selected extruder is above the threshold.
348 348
  */
349
-//#define E0_AUTO_FAN_PIN -1
349
+//#define FAN_PIN MALYAN_FAN1_PIN // Malyan M200: uncomment if you use FAN1 to cool the part and FAN2 to cool the extruder
350
+//#define E0_AUTO_FAN_PIN MALYAN_FAN2_PIN // Malyan M200: uncomment if you use FAN1 to cool the part and FAN2 to cool the extruder
351
+#define E0_AUTO_FAN_PIN MALYAN_FAN1_PIN // Malyan M200: uncomment if you use FAN1 to cool the extruder and the part (original)
350 352
 #define E1_AUTO_FAN_PIN -1
351 353
 #define E2_AUTO_FAN_PIN -1
352 354
 #define E3_AUTO_FAN_PIN -1

Loading…
Cancel
Save