Преглед изворни кода

Allow POWER_SUPPLY 0 for no power switch

Scott Lahteine пре 10 година
родитељ
комит
2faed961ce
3 измењених фајлова са 147 додато и 165 уклоњено
  1. 3
    4
      Marlin/Conditionals.h
  2. 41
    41
      Marlin/Marlin_main.cpp
  3. 103
    120
      Marlin/ultralcd.cpp

+ 3
- 4
Marlin/Conditionals.h Прегледај датотеку

@@ -265,16 +265,15 @@
265 265
   #ifndef POWER_SUPPLY
266 266
     #define POWER_SUPPLY 1
267 267
   #endif
268
-  // 1 = ATX
269
-  #if (POWER_SUPPLY == 1)
268
+  #if (POWER_SUPPLY == 1)   // 1 = ATX
270 269
     #define PS_ON_AWAKE  LOW
271 270
     #define PS_ON_ASLEEP HIGH
272 271
   #endif
273
-  // 2 = X-Box 360 203W
274
-  #if (POWER_SUPPLY == 2)
272
+  #if (POWER_SUPPLY == 2)   // 2 = X-Box 360 203W
275 273
     #define PS_ON_AWAKE  HIGH
276 274
     #define PS_ON_ASLEEP LOW
277 275
   #endif
276
+  HAS_POWER_SWITCH = POWER_SUPPLY > 0 && defined(PS_ON_PIN) && PS_ON_PIN >= 0
278 277
 
279 278
   /**
280 279
    * Temp Sensor defines

+ 41
- 41
Marlin/Marlin_main.cpp Прегледај датотеку

@@ -168,12 +168,12 @@
168 168
 // M401 - Lower z-probe if present
169 169
 // M402 - Raise z-probe if present
170 170
 // M404 - N<dia in mm> Enter the nominal filament width (3mm, 1.75mm ) or will display nominal filament width without parameters
171
-// M405 - Turn on Filament Sensor extrusion control.  Optional D<delay in cm> to set delay in centimeters between sensor and extruder 
172
-// M406 - Turn off Filament Sensor extrusion control 
173
-// M407 - Displays measured filament diameter 
171
+// M405 - Turn on Filament Sensor extrusion control.  Optional D<delay in cm> to set delay in centimeters between sensor and extruder
172
+// M406 - Turn off Filament Sensor extrusion control
173
+// M407 - Display measured filament diameter
174 174
 // M500 - Store parameters in EEPROM
175 175
 // M501 - Read parameters from EEPROM (if you need reset them after you changed them temporarily).
176
-// M502 - Revert to the default "factory settings".  You still need to store them in EEPROM afterwards if you want to.
176
+// M502 - Revert to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
177 177
 // M503 - Print the current settings (from memory not from EEPROM). Use S0 to leave off headings.
178 178
 // M540 - Use S[0|1] to enable or disable the stop SD card print on endstop hit (requires ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
179 179
 // M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]
@@ -310,14 +310,14 @@ int fanSpeed = 0;
310 310
 bool cancel_heatup = false;
311 311
 
312 312
 #ifdef FILAMENT_SENSOR
313
-  //Variables for Filament Sensor input 
314
-  float filament_width_nominal=DEFAULT_NOMINAL_FILAMENT_DIA;  //Set nominal filament width, can be changed with M404 
315
-  bool filament_sensor=false;  //M405 turns on filament_sensor control, M406 turns it off 
316
-  float filament_width_meas=DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter 
317
-  signed char measurement_delay[MAX_MEASUREMENT_DELAY+1];  //ring buffer to delay measurement  store extruder factor after subtracting 100 
318
-  int delay_index1=0;  //index into ring buffer
319
-  int delay_index2=-1;  //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized
320
-  float delay_dist=0; //delay distance counter  
313
+  //Variables for Filament Sensor input
314
+  float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA;  //Set nominal filament width, can be changed with M404
315
+  bool filament_sensor = false;  //M405 turns on filament_sensor control, M406 turns it off
316
+  float filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter
317
+  signed char measurement_delay[MAX_MEASUREMENT_DELAY+1];  //ring buffer to delay measurement  store extruder factor after subtracting 100
318
+  int delay_index1 = 0;  //index into ring buffer
319
+  int delay_index2 = -1;  //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized
320
+  float delay_dist = 0; //delay distance counter
321 321
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
322 322
 #endif
323 323
 
@@ -516,7 +516,7 @@ void setup_powerhold()
516 516
   #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
517 517
     OUT_WRITE(SUICIDE_PIN, HIGH);
518 518
   #endif
519
-  #if defined(PS_ON_PIN) && PS_ON_PIN > -1
519
+  #if HAS_POWER_SWITCH
520 520
     #if defined(PS_DEFAULT_OFF)
521 521
       OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP);
522 522
     #else
@@ -898,7 +898,7 @@ bool code_seen(char code) {
898 898
   strchr_pointer = strchr(cmdbuffer[bufindr], code);
899 899
   return (strchr_pointer != NULL);  //Return True if a character was found
900 900
 }
901
-  
901
+
902 902
 #define DEFINE_PGM_READ_ANY(type, reader)       \
903 903
     static inline type pgm_read_any(const type *p)  \
904 904
     { return pgm_read_##reader##_near(p); }
@@ -3291,7 +3291,7 @@ inline void gcode_M140() {
3291 3291
   if (code_seen('S')) setTargetBed(code_value());
3292 3292
 }
3293 3293
 
3294
-#if defined(PS_ON_PIN) && PS_ON_PIN > -1
3294
+#if HAS_POWER_SWITCH
3295 3295
 
3296 3296
   /**
3297 3297
    * M80: Turn on Power Supply
@@ -3313,33 +3313,33 @@ inline void gcode_M140() {
3313 3313
     #endif
3314 3314
   }
3315 3315
 
3316
-#endif // PS_ON_PIN
3317
-
3318
-/**
3319
- * M81: Turn off Power Supply
3320
- */
3321
-inline void gcode_M81() {
3322
-  disable_heater();
3323
-  st_synchronize();
3324
-  disable_e0();
3325
-  disable_e1();
3326
-  disable_e2();
3327
-  disable_e3();
3328
-  finishAndDisableSteppers();
3329
-  fanSpeed = 0;
3330
-  delay(1000); // Wait 1 second before switching off
3331
-  #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
3316
+  /**
3317
+   * M81: Turn off Power Supply
3318
+   */
3319
+  inline void gcode_M81() {
3320
+    disable_heater();
3332 3321
     st_synchronize();
3333
-    suicide();
3334
-  #elif defined(PS_ON_PIN) && PS_ON_PIN > -1
3335
-    OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP);
3336
-  #endif
3337
-  #ifdef ULTIPANEL
3338
-    powersupply = false;
3339
-    LCD_MESSAGEPGM(MACHINE_NAME " " MSG_OFF ".");
3340
-    lcd_update();
3341
-  #endif
3342
-}
3322
+    disable_e0();
3323
+    disable_e1();
3324
+    disable_e2();
3325
+    disable_e3();
3326
+    finishAndDisableSteppers();
3327
+    fanSpeed = 0;
3328
+    delay(1000); // Wait 1 second before switching off
3329
+    #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
3330
+      st_synchronize();
3331
+      suicide();
3332
+    #elif HAS_POWER_SWITCH
3333
+      OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP);
3334
+    #endif
3335
+    #ifdef ULTIPANEL
3336
+      powersupply = false;
3337
+      LCD_MESSAGEPGM(MACHINE_NAME " " MSG_OFF ".");
3338
+      lcd_update();
3339
+    #endif
3340
+  }
3341
+
3342
+#endif // PS_ON_PIN
3343 3343
 
3344 3344
 /**
3345 3345
  * M82: Set E codes absolute (default)

+ 103
- 120
Marlin/ultralcd.cpp Прегледај датотеку

@@ -616,6 +616,7 @@ static void lcd_prepare_menu() {
616 616
   MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
617 617
   MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
618 618
   //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
619
+
619 620
   #if TEMP_SENSOR_0 != 0
620 621
     #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0
621 622
       MENU_ITEM(submenu, MSG_PREHEAT_PLA, lcd_preheat_pla_menu);
@@ -625,15 +626,16 @@ static void lcd_prepare_menu() {
625 626
       MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs0);
626 627
     #endif
627 628
   #endif
629
+
628 630
   MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
629
-  #if defined(POWER_SUPPLY) && POWER_SUPPLY > 0 && defined(PS_ON_PIN) && PS_ON_PIN > -1
630
-    if (powersupply) {
631
+
632
+  #if HAS_POWER_SWITCH
633
+    if (powersupply)
631 634
       MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
632
-    }
633
-    else {
635
+    else
634 636
       MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
635
-    }
636 637
   #endif
638
+
637 639
   MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
638 640
 
639 641
   #if defined(MANUAL_BED_LEVELING)
@@ -1338,7 +1340,7 @@ void lcd_update() {
1338 1340
               }
1339 1341
 
1340 1342
               lastEncoderMovementMillis = ms;
1341
-            }
1343
+            } // encoderRateMultiplierEnabled
1342 1344
           #endif //ENCODER_RATE_MULTIPLIER
1343 1345
 
1344 1346
           lcdDrawUpdate = 1;
@@ -1541,70 +1543,62 @@ bool lcd_clicked() { return LCD_CLICKED; }
1541 1543
 
1542 1544
 #endif //ULTIPANEL
1543 1545
 
1544
-/********************************/
1545
-/** Float conversion utilities **/
1546
-/********************************/
1547
-//  convert float to string with +123.4 format
1546
+/*********************************/
1547
+/** Number to string conversion **/
1548
+/*********************************/
1549
+
1548 1550
 char conv[8];
1549
-char *ftostr3(const float &x)
1550
-{
1551
+
1552
+// Convert float to string with +123.4 format
1553
+char *ftostr3(const float &x) {
1551 1554
   return itostr3((int)x);
1552 1555
 }
1553 1556
 
1554
-char *itostr2(const uint8_t &x)
1555
-{
1557
+// Convert int to string with 12 format
1558
+char *itostr2(const uint8_t &x) {
1556 1559
   //sprintf(conv,"%5.1f",x);
1557
-  int xx=x;
1558
-  conv[0]=(xx/10)%10+'0';
1559
-  conv[1]=(xx)%10+'0';
1560
-  conv[2]=0;
1560
+  int xx = x;
1561
+  conv[0] = (xx / 10) % 10 + '0';
1562
+  conv[1] = xx % 10 + '0';
1563
+  conv[2] = 0;
1561 1564
   return conv;
1562 1565
 }
1563 1566
 
1564
-// Convert float to string with 123.4 format, dropping sign
1565
-char *ftostr31(const float &x)
1566
-{
1567
-  int xx=x*10;
1568
-  conv[0]=(xx>=0)?'+':'-';
1569
-  xx=abs(xx);
1570
-  conv[1]=(xx/1000)%10+'0';
1571
-  conv[2]=(xx/100)%10+'0';
1572
-  conv[3]=(xx/10)%10+'0';
1573
-  conv[4]='.';
1574
-  conv[5]=(xx)%10+'0';
1575
-  conv[6]=0;
1567
+// Convert float to string with +123.4 format
1568
+char *ftostr31(const float &x) {
1569
+  int xx = abs(x * 10);
1570
+  conv[0] = (x >= 0) ? '+' : '-';
1571
+  conv[1] = (xx / 1000) % 10 + '0';
1572
+  conv[2] = (xx / 100) % 10 + '0';
1573
+  conv[3] = (xx / 10) % 10 + '0';
1574
+  conv[4] = '.';
1575
+  conv[5] = xx % 10 + '0';
1576
+  conv[6] = 0;
1576 1577
   return conv;
1577 1578
 }
1578 1579
 
1579
-// Convert float to string with 123.4 format
1580
-char *ftostr31ns(const float &x)
1581
-{
1582
-  int xx=x*10;
1583
-  //conv[0]=(xx>=0)?'+':'-';
1584
-  xx=abs(xx);
1585
-  conv[0]=(xx/1000)%10+'0';
1586
-  conv[1]=(xx/100)%10+'0';
1587
-  conv[2]=(xx/10)%10+'0';
1588
-  conv[3]='.';
1589
-  conv[4]=(xx)%10+'0';
1590
-  conv[5]=0;
1580
+// Convert float to string with 123.4 format, dropping sign
1581
+char *ftostr31ns(const float &x) {
1582
+  int xx = abs(x * 10);
1583
+  conv[0] = (xx / 1000) % 10 + '0';
1584
+  conv[1] = (xx / 100) % 10 + '0';
1585
+  conv[2] = (xx / 10) % 10 + '0';
1586
+  conv[3] = '.';
1587
+  conv[4] = xx % 10 + '0';
1588
+  conv[5] = 0;
1591 1589
   return conv;
1592 1590
 }
1593 1591
 
1594
-char *ftostr32(const float &x)
1595
-{
1596
-  long xx=x*100;
1597
-  if (xx >= 0)
1598
-    conv[0]=(xx/10000)%10+'0';
1599
-  else
1600
-    conv[0]='-';
1601
-  xx=abs(xx);
1602
-  conv[1]=(xx/1000)%10+'0';
1603
-  conv[2]=(xx/100)%10+'0';
1604
-  conv[3]='.';
1605
-  conv[4]=(xx/10)%10+'0';
1606
-  conv[5]=(xx)%10+'0';
1607
-  conv[6]=0;
1592
+// Convert float to string with 123.4 format
1593
+char *ftostr32(const float &x) {
1594
+  long xx = abs(x * 100);
1595
+  conv[0] = x >= 0 ? (xx / 10000) % 10 + '0' : '-';
1596
+  conv[1] = (xx / 1000) % 10 + '0';
1597
+  conv[2] = (xx / 100) % 10 + '0';
1598
+  conv[3] = '.';
1599
+  conv[4] = (xx / 10) % 10 + '0';
1600
+  conv[5] = xx % 10 + '0';
1601
+  conv[6] = 0;
1608 1602
   return conv;
1609 1603
 }
1610 1604
 
@@ -1625,7 +1619,7 @@ char *ftostr43(const float &x)
1625 1619
 	return conv;
1626 1620
 }
1627 1621
 
1628
-//Float to string with 1.23 format
1622
+// Convert float to string with 1.23 format
1629 1623
 char *ftostr12ns(const float &x)
1630 1624
 {
1631 1625
   long xx=x*100;
@@ -1639,7 +1633,7 @@ char *ftostr12ns(const float &x)
1639 1633
   return conv;
1640 1634
 }
1641 1635
 
1642
-//  convert float to space-padded string with -_23.4_ format
1636
+// Convert float to space-padded string with -_23.4_ format
1643 1637
 char *ftostr32sp(const float &x) {
1644 1638
   long xx = abs(x * 100);
1645 1639
   uint8_t dig;
@@ -1685,58 +1679,51 @@ char *ftostr32sp(const float &x) {
1685 1679
   return conv;
1686 1680
 }
1687 1681
 
1688
-char *itostr31(const int &xx)
1689
-{
1690
-  conv[0]=(xx>=0)?'+':'-';
1691
-  conv[1]=(xx/1000)%10+'0';
1692
-  conv[2]=(xx/100)%10+'0';
1693
-  conv[3]=(xx/10)%10+'0';
1694
-  conv[4]='.';
1695
-  conv[5]=(xx)%10+'0';
1696
-  conv[6]=0;
1682
+// Convert int to lj string with +123.0 format
1683
+char *itostr31(const int &x) {
1684
+  conv[0] = x >= 0 ? '+' : '-';
1685
+  int xx = abs(x);
1686
+  conv[1] = (xx / 100) % 10 + '0';
1687
+  conv[2] = (xx / 10) % 10 + '0';
1688
+  conv[3] = xx % 10 + '0';
1689
+  conv[4] = '.';
1690
+  conv[5] = '0';
1691
+  conv[6] = 0;
1697 1692
   return conv;
1698 1693
 }
1699 1694
 
1700 1695
 // Convert int to rj string with 123 or -12 format
1701
-char *itostr3(const int &x)
1702
-{
1696
+char *itostr3(const int &x) {
1703 1697
   int xx = x;
1704 1698
   if (xx < 0) {
1705
-     conv[0]='-';
1699
+     conv[0] = '-';
1706 1700
      xx = -xx;
1707
-  } else if (xx >= 100)
1708
-    conv[0]=(xx/100)%10+'0';
1709
-  else
1710
-    conv[0]=' ';
1711
-  if (xx >= 10)
1712
-    conv[1]=(xx/10)%10+'0';
1701
+  }
1713 1702
   else
1714
-    conv[1]=' ';
1715
-  conv[2]=(xx)%10+'0';
1716
-  conv[3]=0;
1703
+    conv[0] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
1704
+
1705
+  conv[1] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
1706
+  conv[2] = xx % 10 + '0';
1707
+  conv[3] = 0;
1717 1708
   return conv;
1718 1709
 }
1719 1710
 
1720 1711
 // Convert int to lj string with 123 format
1721
-char *itostr3left(const int &xx)
1722
-{
1723
-  if (xx >= 100)
1724
-  {
1725
-    conv[0]=(xx/100)%10+'0';
1726
-    conv[1]=(xx/10)%10+'0';
1727
-    conv[2]=(xx)%10+'0';
1728
-    conv[3]=0;
1712
+char *itostr3left(const int &xx) {
1713
+  if (xx >= 100) {
1714
+    conv[0] = (xx / 100) % 10 + '0';
1715
+    conv[1] = (xx / 10) % 10 + '0';
1716
+    conv[2] = xx % 10 + '0';
1717
+    conv[3] = 0;
1729 1718
   }
1730
-  else if (xx >= 10)
1731
-  {
1732
-    conv[0]=(xx/10)%10+'0';
1733
-    conv[1]=(xx)%10+'0';
1734
-    conv[2]=0;
1719
+  else if (xx >= 10) {
1720
+    conv[0] = (xx / 10) % 10 + '0';
1721
+    conv[1] = xx % 10 + '0';
1722
+    conv[2] = 0;
1735 1723
   }
1736
-  else
1737
-  {
1738
-    conv[0]=(xx)%10+'0';
1739
-    conv[1]=0;
1724
+  else {
1725
+    conv[0] = xx % 10 + '0';
1726
+    conv[1] = 0;
1740 1727
   }
1741 1728
   return conv;
1742 1729
 }
@@ -1764,34 +1751,30 @@ char *ftostr5(const float &x) {
1764 1751
 }
1765 1752
 
1766 1753
 // Convert float to string with +1234.5 format
1767
-char *ftostr51(const float &x)
1768
-{
1769
-  long xx=x*10;
1770
-  conv[0]=(xx>=0)?'+':'-';
1771
-  xx=abs(xx);
1772
-  conv[1]=(xx/10000)%10+'0';
1773
-  conv[2]=(xx/1000)%10+'0';
1774
-  conv[3]=(xx/100)%10+'0';
1775
-  conv[4]=(xx/10)%10+'0';
1776
-  conv[5]='.';
1777
-  conv[6]=(xx)%10+'0';
1778
-  conv[7]=0;
1754
+char *ftostr51(const float &x) {
1755
+  long xx = abs(x * 10);
1756
+  conv[0] = (x >= 0) ? '+' : '-';
1757
+  conv[1] = (xx / 10000) % 10 + '0';
1758
+  conv[2] = (xx / 1000) % 10 + '0';
1759
+  conv[3] = (xx / 100) % 10 + '0';
1760
+  conv[4] = (xx / 10) % 10 + '0';
1761
+  conv[5] = '.';
1762
+  conv[6] = xx % 10 + '0';
1763
+  conv[7] = 0;
1779 1764
   return conv;
1780 1765
 }
1781 1766
 
1782 1767
 // Convert float to string with +123.45 format
1783
-char *ftostr52(const float &x)
1784
-{
1785
-  long xx=x*100;
1786
-  conv[0]=(xx>=0)?'+':'-';
1787
-  xx=abs(xx);
1788
-  conv[1]=(xx/10000)%10+'0';
1789
-  conv[2]=(xx/1000)%10+'0';
1790
-  conv[3]=(xx/100)%10+'0';
1791
-  conv[4]='.';
1792
-  conv[5]=(xx/10)%10+'0';
1793
-  conv[6]=(xx)%10+'0';
1794
-  conv[7]=0;
1768
+char *ftostr52(const float &x) {
1769
+  conv[0] = (x >= 0) ? '+' : '-';
1770
+  long xx = abs(x * 100);
1771
+  conv[1] = (xx / 10000) % 10 + '0';
1772
+  conv[2] = (xx / 1000) % 10 + '0';
1773
+  conv[3] = (xx / 100) % 10 + '0';
1774
+  conv[4] = '.';
1775
+  conv[5] = (xx / 10) % 10 + '0';
1776
+  conv[6] = xx % 10 + '0';
1777
+  conv[7] = 0;
1795 1778
   return conv;
1796 1779
 }
1797 1780
 

Loading…
Откажи
Сачувај