Bläddra i källkod

Improve Malyan M200 integration (#15462)

Me No Dev 4 år sedan
förälder
incheckning
fc6a0937b8

+ 62
- 29
Marlin/src/lcd/extui_malyan_lcd.cpp Visa fil

117
  * the command portion begins after the :
117
  * the command portion begins after the :
118
  */
118
  */
119
 void process_lcd_c_command(const char* command) {
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
   switch (command[0]) {
125
   switch (command[0]) {
121
     case 'C': // Cope with both V1 early rev and later LCDs.
126
     case 'C': // Cope with both V1 early rev and later LCDs.
122
     case 'S':
127
     case 'S':
123
-      feedrate_percentage = atoi(command + 1) * 10;
128
+      feedrate_percentage = target_val * 10;
124
       LIMIT(feedrate_percentage, 10, 999);
129
       LIMIT(feedrate_percentage, 10, 999);
125
       break;
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
     #if HAS_HEATED_BED
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
     #endif
141
     #endif
132
 
142
 
133
     default: DEBUG_ECHOLNPAIR("UNKNOWN C COMMAND ", command);
143
     default: DEBUG_ECHOLNPAIR("UNKNOWN C COMMAND ", command);
143
  */
153
  */
144
 void process_lcd_eb_command(const char* command) {
154
 void process_lcd_eb_command(const char* command) {
145
   char elapsed_buffer[10];
155
   char elapsed_buffer[10];
156
+  static uint8_t iteration = 0;
146
   duration_t elapsed;
157
   duration_t elapsed;
147
   switch (command[0]) {
158
   switch (command[0]) {
148
     case '0': {
159
     case '0': {
150
       sprintf_P(elapsed_buffer, PSTR("%02u%02u%02u"), uint16_t(elapsed.hour()), uint16_t(elapsed.minute()) % 60, uint16_t(elapsed.second()) % 60);
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
       char message_buffer[MAX_CURLY_COMMAND];
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
       sprintf_P(message_buffer,
171
       sprintf_P(message_buffer,
154
         PSTR("{T0:%03i/%03i}{T1:000/000}{TP:%03i/%03i}{TQ:%03i}{TT:%s}"),
172
         PSTR("{T0:%03i/%03i}{T1:000/000}{TP:%03i/%03i}{TQ:%03i}{TT:%s}"),
155
         int(thermalManager.degHotend(0)), thermalManager.degTargetHotend(0),
173
         int(thermalManager.degHotend(0)), thermalManager.degTargetHotend(0),
159
           0, 0,
177
           0, 0,
160
         #endif
178
         #endif
161
         #if ENABLED(SDSUPPORT)
179
         #if ENABLED(SDSUPPORT)
162
-          card.percentDone(),
180
+          done_pct,
163
         #else
181
         #else
164
           0,
182
           0,
165
         #endif
183
         #endif
186
   auto move_axis = [command](const auto axis) {
204
   auto move_axis = [command](const auto axis) {
187
     const float dist = atof(command + 1) / 10.0;
205
     const float dist = atof(command + 1) / 10.0;
188
     ExtUI::setAxisPosition_mm(ExtUI::getAxisPosition_mm(axis) + dist, axis);
206
     ExtUI::setAxisPosition_mm(ExtUI::getAxisPosition_mm(axis) + dist, axis);
189
-  }
207
+  };
190
 
208
 
191
   switch (command[0]) {
209
   switch (command[0]) {
192
     case 'E': break;
210
     case 'E': break;
330
 void process_lcd_command(const char* command) {
348
 void process_lcd_command(const char* command) {
331
   const char *current = command;
349
   const char *current = command;
332
 
350
 
333
-  current++; // skip the leading {. The trailing one is already gone.
334
   byte command_code = *current++;
351
   byte command_code = *current++;
335
   if (*current == ':') {
352
   if (*current == ':') {
336
 
353
 
350
     DEBUG_ECHOLNPAIR("UNKNOWN COMMAND FORMAT ", command);
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
  * UC means connected.
396
  * UC means connected.
355
  * UD means disconnected
397
  * UD means disconnected
360
   // This is mildly different than stock, which
402
   // This is mildly different than stock, which
361
   // appears to use the usb discovery status.
403
   // appears to use the usb discovery status.
362
   // This is more logical.
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
     write_to_lcd_P(last_usb_connected_status ? PSTR("{R:UC}\r\n") : PSTR("{R:UD}\r\n"));
407
     write_to_lcd_P(last_usb_connected_status ? PSTR("{R:UC}\r\n") : PSTR("{R:UD}\r\n"));
366
   }
408
   }
367
 }
409
 }
391
     /**
433
     /**
392
      * - from printer on startup:
434
      * - from printer on startup:
393
      * {SYS:STARTED}{VER:29}{SYS:STARTED}{R:UD}
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
     // First report USB status.
438
     // First report USB status.
400
     update_usb_status(false);
439
     update_usb_status(false);
401
 
440
 
402
     // now drain commands...
441
     // now drain commands...
403
     while (LCD_SERIAL.available()) {
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
     #if ENABLED(SDSUPPORT)
446
     #if ENABLED(SDSUPPORT)
438
     write_to_lcd_P("}");
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
   // Not needed for Malyan LCD
477
   // Not needed for Malyan LCD
442
-  void onStatusChanged(const char * const msg) { UNUSED(msg); }
478
+  void onStatusChanged(const char * const) {}
443
   void onMediaInserted() {};
479
   void onMediaInserted() {};
444
   void onMediaError() {};
480
   void onMediaError() {};
445
   void onMediaRemoved() {};
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
   void onFilamentRunout(const extruder_t extruder) {}
483
   void onFilamentRunout(const extruder_t extruder) {}
451
-  void onUserConfirmRequired(const char * const msg) { UNUSED(msg); }
484
+  void onUserConfirmRequired(const char * const) {}
452
   void onFactoryReset() {}
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
 #endif // MALYAN_LCD
492
 #endif // MALYAN_LCD

+ 5
- 11
Marlin/src/pins/stm32/pins_MALYAN_M200.h Visa fil

42
 // On STM32F103:
42
 // On STM32F103:
43
 // PB3, PB6, PB7, and PB8 can be used with pwm, which rules out TIM2 and TIM4.
43
 // PB3, PB6, PB7, and PB8 can be used with pwm, which rules out TIM2 and TIM4.
44
 // On STM32F070, 16 and 17 are in use, but 1 and 3 are available.
44
 // On STM32F070, 16 and 17 are in use, but 1 and 3 are available.
45
+#undef STEP_TIMER
46
+#undef TEMP_TIMER
45
 #define STEP_TIMER 1
47
 #define STEP_TIMER 1
46
 #define TEMP_TIMER 3
48
 #define TEMP_TIMER 3
47
 
49
 
84
 #define HEATER_0_PIN       PB6   // HOTEND0 MOSFET
86
 #define HEATER_0_PIN       PB6   // HOTEND0 MOSFET
85
 #define HEATER_BED_PIN     PB7   // BED MOSFET
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 Visa fil

146
 #define EXTRUDERS 1
146
 #define EXTRUDERS 1
147
 
147
 
148
 // Generally expected filament diameter (1.75, 2.85, 3.0, ...). Used for Volumetric, Filament Width Sensor, etc.
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
 // For Cyclops or any "multi-extruder" that shares a single nozzle.
151
 // For Cyclops or any "multi-extruder" that shares a single nozzle.
152
 //#define SINGLENOZZLE
152
 //#define SINGLENOZZLE
474
   // If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it
474
   // If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it
475
 
475
 
476
   // Ultimaker
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
   // MakerGear
481
   // MakerGear
481
   //#define DEFAULT_Kp 7.0
482
   //#define DEFAULT_Kp 7.0
482
   //#define DEFAULT_Ki 0.1
483
   //#define DEFAULT_Ki 0.1
487
   //#define DEFAULT_Ki 2.25
488
   //#define DEFAULT_Ki 2.25
488
   //#define DEFAULT_Kd 440
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
 #endif // PIDTEMP
496
 #endif // PIDTEMP
491
 
497
 
492
 //===========================================================================
498
 //===========================================================================
506
  * heater. If your configuration is significantly different than this and you don't understand
512
  * heater. If your configuration is significantly different than this and you don't understand
507
  * the issues involved, don't use bed PID until someone else verifies that your hardware works.
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
 //#define BED_LIMIT_SWITCHING
517
 //#define BED_LIMIT_SWITCHING
512
 
518
 
524
 
530
 
525
   //120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
531
   //120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
526
   //from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10)
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
   //120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
537
   //120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
532
   //from pidautotune
538
   //from pidautotune
534
   //#define DEFAULT_bedKi 1.41
540
   //#define DEFAULT_bedKi 1.41
535
   //#define DEFAULT_bedKd 1675.16
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
   // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
548
   // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
538
 #endif // PIDTEMPBED
549
 #endif // PIDTEMPBED
539
 
550
 
1051
 // @section machine
1062
 // @section machine
1052
 
1063
 
1053
 // The size of the print bed
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
 // Travel limits (mm) after homing, corresponding to endstop positions.
1068
 // Travel limits (mm) after homing, corresponding to endstop positions.
1058
 #define X_MIN_POS 0
1069
 #define X_MIN_POS 0
1060
 #define Z_MIN_POS 0
1071
 #define Z_MIN_POS 0
1061
 #define X_MAX_POS X_BED_SIZE
1072
 #define X_MAX_POS X_BED_SIZE
1062
 #define Y_MAX_POS Y_BED_SIZE
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
  * Software Endstops
1077
  * Software Endstops
1278
 #endif
1289
 #endif
1279
 
1290
 
1280
 // Add a menu item to move between bed corners for manual bed adjustment
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
 #if ENABLED(LEVEL_BED_CORNERS)
1294
 #if ENABLED(LEVEL_BED_CORNERS)
1284
   #define LEVEL_CORNERS_INSET 30    // (mm) An inset for corner leveling
1295
   #define LEVEL_CORNERS_INSET 30    // (mm) An inset for corner leveling
1627
  */
1638
  */
1628
 //#define SPI_SPEED SPI_HALF_SPEED
1639
 //#define SPI_SPEED SPI_HALF_SPEED
1629
 //#define SPI_SPEED SPI_QUARTER_SPEED
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
  * SD CARD: ENABLE CRC
1644
  * SD CARD: ENABLE CRC

+ 5
- 3
config/examples/Malyan/M200/Configuration_adv.h Visa fil

277
  * The fan will turn on automatically whenever any stepper is enabled
277
  * The fan will turn on automatically whenever any stepper is enabled
278
  * and turn off after a set period after all steppers are turned off.
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
 #if ENABLED(USE_CONTROLLER_FAN)
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
   #define CONTROLLERFAN_SECS 60             // Duration in seconds for the fan to run after all motors are disabled
283
   #define CONTROLLERFAN_SECS 60             // Duration in seconds for the fan to run after all motors are disabled
284
   #define CONTROLLERFAN_SPEED 255           // 255 == full speed
284
   #define CONTROLLERFAN_SPEED 255           // 255 == full speed
285
   //#define CONTROLLERFAN_SPEED_Z_ONLY 127  // Reduce noise on machines that keep Z enabled
285
   //#define CONTROLLERFAN_SPEED_Z_ONLY 127  // Reduce noise on machines that keep Z enabled
346
  * Multiple extruders can be assigned to the same pin in which case
346
  * Multiple extruders can be assigned to the same pin in which case
347
  * the fan will turn on when any selected extruder is above the threshold.
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
 #define E1_AUTO_FAN_PIN -1
352
 #define E1_AUTO_FAN_PIN -1
351
 #define E2_AUTO_FAN_PIN -1
353
 #define E2_AUTO_FAN_PIN -1
352
 #define E3_AUTO_FAN_PIN -1
354
 #define E3_AUTO_FAN_PIN -1

Laddar…
Avbryt
Spara