浏览代码

Merge pull request #1746 from thinkyhead/power_supply

Allow POWER_SUPPLY to be 0
Scott Lahteine 10 年前
父节点
当前提交
b8973051c3
共有 3 个文件被更改,包括 143 次插入157 次删除
  1. 3
    5
      Marlin/Conditionals.h
  2. 34
    31
      Marlin/Marlin_main.cpp
  3. 106
    121
      Marlin/ultralcd.cpp

+ 3
- 5
Marlin/Conditionals.h 查看文件

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

+ 34
- 31
Marlin/Marlin_main.cpp 查看文件

168
 // M401 - Lower z-probe if present
168
 // M401 - Lower z-probe if present
169
 // M402 - Raise z-probe if present
169
 // M402 - Raise z-probe if present
170
 // M404 - N<dia in mm> Enter the nominal filament width (3mm, 1.75mm ) or will display nominal filament width without parameters
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
 // M500 - Store parameters in EEPROM
174
 // M500 - Store parameters in EEPROM
175
 // M501 - Read parameters from EEPROM (if you need reset them after you changed them temporarily).
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
 // M503 - Print the current settings (from memory not from EEPROM). Use S0 to leave off headings.
177
 // M503 - Print the current settings (from memory not from EEPROM). Use S0 to leave off headings.
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)
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
 // M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]
179
 // M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]
272
 
272
 
273
 #endif // FWRETRACT
273
 #endif // FWRETRACT
274
 
274
 
275
-#ifdef ULTIPANEL
275
+#if defined(ULTIPANEL) && HAS_POWER_SWITCH
276
   bool powersupply = 
276
   bool powersupply = 
277
     #ifdef PS_DEFAULT_OFF
277
     #ifdef PS_DEFAULT_OFF
278
       false
278
       false
310
 bool cancel_heatup = false;
310
 bool cancel_heatup = false;
311
 
311
 
312
 #ifdef FILAMENT_SENSOR
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
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
321
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
322
 #endif
322
 #endif
323
 
323
 
516
   #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
516
   #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
517
     OUT_WRITE(SUICIDE_PIN, HIGH);
517
     OUT_WRITE(SUICIDE_PIN, HIGH);
518
   #endif
518
   #endif
519
-  #if defined(PS_ON_PIN) && PS_ON_PIN > -1
520
-    #if defined(PS_DEFAULT_OFF)
519
+  #if HAS_POWER_SWITCH
520
+    #ifdef PS_DEFAULT_OFF
521
       OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP);
521
       OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP);
522
     #else
522
     #else
523
       OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE);
523
       OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE);
898
   strchr_pointer = strchr(cmdbuffer[bufindr], code);
898
   strchr_pointer = strchr(cmdbuffer[bufindr], code);
899
   return (strchr_pointer != NULL);  //Return True if a character was found
899
   return (strchr_pointer != NULL);  //Return True if a character was found
900
 }
900
 }
901
-  
901
+
902
 #define DEFINE_PGM_READ_ANY(type, reader)       \
902
 #define DEFINE_PGM_READ_ANY(type, reader)       \
903
     static inline type pgm_read_any(const type *p)  \
903
     static inline type pgm_read_any(const type *p)  \
904
     { return pgm_read_##reader##_near(p); }
904
     { return pgm_read_##reader##_near(p); }
3291
   if (code_seen('S')) setTargetBed(code_value());
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
    * M80: Turn on Power Supply
3297
    * M80: Turn on Power Supply
3313
     #endif
3313
     #endif
3314
   }
3314
   }
3315
 
3315
 
3316
-#endif // PS_ON_PIN
3316
+#endif // HAS_POWER_SWITCH
3317
 
3317
 
3318
 /**
3318
 /**
3319
- * M81: Turn off Power Supply
3319
+ * M81: Turn off Power, including Power Supply, if there is one.
3320
+ *
3321
+ *      This code should ALWAYS be available for EMERGENCY SHUTDOWN!
3320
  */
3322
  */
3321
 inline void gcode_M81() {
3323
 inline void gcode_M81() {
3322
   disable_heater();
3324
   disable_heater();
3331
   #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
3333
   #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
3332
     st_synchronize();
3334
     st_synchronize();
3333
     suicide();
3335
     suicide();
3334
-  #elif defined(PS_ON_PIN) && PS_ON_PIN > -1
3336
+  #elif HAS_POWER_SWITCH
3335
     OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP);
3337
     OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP);
3336
   #endif
3338
   #endif
3337
   #ifdef ULTIPANEL
3339
   #ifdef ULTIPANEL
3338
-    powersupply = false;
3340
+    #if HAS_POWER_SWITCH
3341
+      powersupply = false;
3342
+    #endif
3339
     LCD_MESSAGEPGM(MACHINE_NAME " " MSG_OFF ".");
3343
     LCD_MESSAGEPGM(MACHINE_NAME " " MSG_OFF ".");
3340
     lcd_update();
3344
     lcd_update();
3341
   #endif
3345
   #endif
3342
 }
3346
 }
3343
 
3347
 
3348
+
3344
 /**
3349
 /**
3345
  * M82: Set E codes absolute (default)
3350
  * M82: Set E codes absolute (default)
3346
  */
3351
  */
4874
         #endif //HEATER_2_PIN
4879
         #endif //HEATER_2_PIN
4875
       #endif //BARICUDA
4880
       #endif //BARICUDA
4876
 
4881
 
4877
-      #if defined(PS_ON_PIN) && PS_ON_PIN > -1
4882
+      #if HAS_POWER_SWITCH
4878
 
4883
 
4879
         case 80: // M80 - Turn on Power Supply
4884
         case 80: // M80 - Turn on Power Supply
4880
           gcode_M80();
4885
           gcode_M80();
4881
           break;
4886
           break;
4882
 
4887
 
4883
-      #endif // PS_ON_PIN
4888
+      #endif // HAS_POWER_SWITCH
4884
 
4889
 
4885
-      case 81: // M81 - Turn off Power Supply
4890
+      case 81: // M81 - Turn off Power, including Power Supply, if possible
4886
         gcode_M81();
4891
         gcode_M81();
4887
         break;
4892
         break;
4888
 
4893
 
5859
   disable_e2();
5864
   disable_e2();
5860
   disable_e3();
5865
   disable_e3();
5861
 
5866
 
5862
-#if defined(PS_ON_PIN) && PS_ON_PIN > -1
5863
-  pinMode(PS_ON_PIN,INPUT);
5864
-#endif
5867
+  #if HAS_POWER_SWITCH
5868
+    pinMode(PS_ON_PIN, INPUT);
5869
+  #endif
5870
+
5865
   SERIAL_ERROR_START;
5871
   SERIAL_ERROR_START;
5866
   SERIAL_ERRORLNPGM(MSG_ERR_KILLED);
5872
   SERIAL_ERRORLNPGM(MSG_ERR_KILLED);
5867
   LCD_ALERTMESSAGEPGM(MSG_KILLED);
5873
   LCD_ALERTMESSAGEPGM(MSG_KILLED);
5868
   
5874
   
5869
   // FMC small patch to update the LCD before ending
5875
   // FMC small patch to update the LCD before ending
5870
   sei();   // enable interrupts
5876
   sei();   // enable interrupts
5871
-  for ( int i=5; i--; lcd_update())
5872
-  {
5873
-     delay(200);  
5874
-  }
5877
+  for (int i = 5; i--; lcd_update()) delay(200); // Wait a short time
5875
   cli();   // disable interrupts
5878
   cli();   // disable interrupts
5876
   suicide();
5879
   suicide();
5877
   while(1) { /* Intentionally left empty */ } // Wait for reset
5880
   while(1) { /* Intentionally left empty */ } // Wait for reset

+ 106
- 121
Marlin/ultralcd.cpp 查看文件

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

正在加载...
取消
保存