From 17e6f1b75edd2199d21a5938ccdca6639c04e231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Tue, 17 Jan 2023 18:22:25 +0000 Subject: [PATCH] optimisation: remove conv2str.cpp Change in memory: Flash: -288 bytes SRAM: -8 bytes --- CMakeLists.txt | 1 - Firmware/Prusa_farm.cpp | 5 +- Firmware/cardreader.cpp | 5 +- Firmware/conv2str.cpp | 292 ---------------------------------------- Firmware/conv2str.h | 28 ---- Firmware/ultralcd.cpp | 17 +-- 6 files changed, 10 insertions(+), 338 deletions(-) delete mode 100644 Firmware/conv2str.cpp delete mode 100644 Firmware/conv2str.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b5483854e..d33399b4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,7 +131,6 @@ set(FW_SOURCES cmdqueue.cpp Configuration.cpp ConfigurationStore.cpp - conv2str.cpp Dcodes.cpp eeprom.cpp fancheck.cpp diff --git a/Firmware/Prusa_farm.cpp b/Firmware/Prusa_farm.cpp index 71c180d86..80cb5af79 100644 --- a/Firmware/Prusa_farm.cpp +++ b/Firmware/Prusa_farm.cpp @@ -4,7 +4,6 @@ #include "cmdqueue.h" #include "temperature.h" #include "cardreader.h" -#include "conv2str.h" #include "util.h" #include "ultralcd.h" #include "Filament_sensor.h" @@ -86,9 +85,9 @@ static void prusa_stat_printinfo() { SERIAL_ECHOPGM("[TFU:"); SERIAL_ECHO(total_filament_used); SERIAL_ECHOPGM("][PCD:"); - SERIAL_ECHO(itostr3(card.percentDone())); + SERIAL_ECHO((int)card.percentDone()); SERIAL_ECHOPGM("][FEM:"); - SERIAL_ECHO(itostr3(feedmultiply)); + SERIAL_ECHO(feedmultiply); SERIAL_ECHOPGM("][FNM:"); SERIAL_ECHO(card.longFilename[0] ? card.longFilename : card.filename); SERIAL_ECHOPGM("][TIM:"); diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index 5aa977e3b..4f8ee6c58 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -2,7 +2,6 @@ #include "cmdqueue.h" #include "cardreader.h" #include "ultralcd.h" -#include "conv2str.h" #include "menu.h" #include "stepper.h" #include "temperature.h" @@ -578,9 +577,9 @@ void CardReader::getStatus(bool arg_P) SERIAL_PROTOCOL('/'); SERIAL_PROTOCOLLN(filesize); uint16_t time = ( _millis() - starttime ) / 60000U; - SERIAL_PROTOCOL(itostr2(time/60)); + SERIAL_PROTOCOL((int)(time / 60)); SERIAL_PROTOCOL(':'); - SERIAL_PROTOCOLLN(itostr2(time%60)); + SERIAL_PROTOCOLLN((int)(time % 60)); } else SERIAL_PROTOCOLLNPGM("Not SD printing"); diff --git a/Firmware/conv2str.cpp b/Firmware/conv2str.cpp deleted file mode 100644 index 291c15848..000000000 --- a/Firmware/conv2str.cpp +++ /dev/null @@ -1,292 +0,0 @@ -//conv2str.cpp - Float conversion utilities - -#include "conv2str.h" -#include - - -// convert float to string with +123.4 format -char conv[8]; - -char *ftostr3(const float &x) -{ - return itostr3((int)x); -} - -char *itostr2(const uint8_t &x) -{ - //sprintf(conv,"%5.1f",x); - int xx = x; - conv[0] = (xx / 10) % 10 + '0'; - conv[1] = (xx) % 10 + '0'; - conv[2] = 0; - return conv; -} - -// Convert float to string with 123.4 format, dropping sign -char *ftostr31(const float &x) -{ - int xx = x * 10; - conv[0] = (xx >= 0) ? '+' : '-'; - xx = abs(xx); - conv[1] = (xx / 1000) % 10 + '0'; - conv[2] = (xx / 100) % 10 + '0'; - conv[3] = (xx / 10) % 10 + '0'; - conv[4] = '.'; - conv[5] = (xx) % 10 + '0'; - conv[6] = 0; - return conv; -} - -// Convert float to string with 123.4 format -char *ftostr31ns(const float &x) -{ - int xx = x * 10; - //conv[0]=(xx>=0)?'+':'-'; - xx = abs(xx); - conv[0] = (xx / 1000) % 10 + '0'; - conv[1] = (xx / 100) % 10 + '0'; - conv[2] = (xx / 10) % 10 + '0'; - conv[3] = '.'; - conv[4] = (xx) % 10 + '0'; - conv[5] = 0; - return conv; -} - -char *ftostr32(const float &x) -{ - long xx = x * 100; - if (xx >= 0) - conv[0] = (xx / 10000) % 10 + '0'; - else - conv[0] = '-'; - xx = abs(xx); - conv[1] = (xx / 1000) % 10 + '0'; - conv[2] = (xx / 100) % 10 + '0'; - conv[3] = '.'; - conv[4] = (xx / 10) % 10 + '0'; - conv[5] = (xx) % 10 + '0'; - conv[6] = 0; - return conv; -} - -//// Convert float to rj string with 123.45 format -char *ftostr32ns(const float &x) { - long xx = abs(x); - conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' '; - conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' '; - conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0'; - conv[3] = '.'; - conv[4] = (xx / 10) % 10 + '0'; - conv[5] = xx % 10 + '0'; - return conv; -} - - -// Convert float to string with 1.234 format -char *ftostr43(const float &x, uint8_t offset) -{ - const size_t maxOffset = sizeof(conv)/sizeof(conv[0]) - 6; - if (offset>maxOffset) offset = maxOffset; - long xx = x * 1000; - if (xx >= 0) - conv[offset] = (xx / 1000) % 10 + '0'; - else - conv[offset] = '-'; - xx = abs(xx); - conv[offset + 1] = '.'; - conv[offset + 2] = (xx / 100) % 10 + '0'; - conv[offset + 3] = (xx / 10) % 10 + '0'; - conv[offset + 4] = (xx) % 10 + '0'; - conv[offset + 5] = 0; - return conv; -} - -//Float to string with 1.23 format -char *ftostr12ns(const float &x) -{ - int xx = x * 100; - - xx = abs(xx); - conv[0] = (xx / 100) % 10 + '0'; - conv[1] = '.'; - conv[2] = (xx / 10) % 10 + '0'; - conv[3] = (xx) % 10 + '0'; - conv[4] = 0; - return conv; -} - -//Float to string with 1.234 format -char *ftostr13ns(const float &x) -{ - long xx = x * 1000; - if (xx >= 0) - conv[0] = ' '; - else - conv[0] = '-'; - xx = abs(xx); - conv[1] = (xx / 1000) % 10 + '0'; - conv[2] = '.'; - conv[3] = (xx / 100) % 10 + '0'; - conv[4] = (xx / 10) % 10 + '0'; - conv[5] = (xx) % 10 + '0'; - conv[6] = 0; - return conv; -} - -// convert float to space-padded string with -_23.4_ format -char *ftostr32sp(const float &x) { - long xx = abs(x * 100); - uint8_t dig; - - if (x < 0) { // negative val = -_0 - conv[0] = '-'; - dig = (xx / 1000) % 10; - conv[1] = dig ? '0' + dig : ' '; - } - else { // positive val = __0 - dig = (xx / 10000) % 10; - if (dig) { - conv[0] = '0' + dig; - conv[1] = '0' + (xx / 1000) % 10; - } - else { - conv[0] = ' '; - dig = (xx / 1000) % 10; - conv[1] = dig ? '0' + dig : ' '; - } - } - - conv[2] = '0' + (xx / 100) % 10; // lsd always - - dig = xx % 10; - if (dig) { // 2 decimal places - conv[5] = '0' + dig; - conv[4] = '0' + (xx / 10) % 10; - conv[3] = '.'; - } - else { // 1 or 0 decimal place - dig = (xx / 10) % 10; - if (dig) { - conv[4] = '0' + dig; - conv[3] = '.'; - } - else { - conv[3] = conv[4] = ' '; - } - conv[5] = ' '; - } - conv[6] = '\0'; - return conv; -} - -char *itostr31(const int &xx) -{ - conv[0] = (xx >= 0) ? '+' : '-'; - conv[1] = (xx / 1000) % 10 + '0'; - conv[2] = (xx / 100) % 10 + '0'; - conv[3] = (xx / 10) % 10 + '0'; - conv[4] = '.'; - conv[5] = (xx) % 10 + '0'; - conv[6] = 0; - return conv; -} - -// Convert int to rj string with 123 or -12 format -char *itostr3(const int &x) -{ - int xx = x; - if (xx < 0) { - conv[0] = '-'; - xx = -xx; - } else if (xx >= 100) - conv[0] = (xx / 100) % 10 + '0'; - else - conv[0] = ' '; - if (xx >= 10) - conv[1] = (xx / 10) % 10 + '0'; - else - conv[1] = ' '; - conv[2] = (xx) % 10 + '0'; - conv[3] = 0; - return conv; -} - -// Convert int to lj string with 123 format -char *itostr3left(const int &xx) -{ - if (xx >= 100) - { - conv[0] = (xx / 100) % 10 + '0'; - conv[1] = (xx / 10) % 10 + '0'; - conv[2] = (xx) % 10 + '0'; - conv[3] = 0; - } - else if (xx >= 10) - { - conv[0] = (xx / 10) % 10 + '0'; - conv[1] = (xx) % 10 + '0'; - conv[2] = 0; - } - else - { - conv[0] = (xx) % 10 + '0'; - conv[1] = 0; - } - return conv; -} - -// Convert int to rj string with 1234 format -char *itostr4(const int &xx) { - conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' '; - conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' '; - conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' '; - conv[3] = xx % 10 + '0'; - conv[4] = 0; - return conv; -} - -// Convert float to rj string with 12345 format -char *ftostr5(const float &x) { - long xx = abs(x); - conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' '; - conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' '; - conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' '; - conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' '; - conv[4] = xx % 10 + '0'; - conv[5] = 0; - return conv; -} - -// Convert float to string with +1234.5 format -char *ftostr51(const float &x) -{ - long xx = x * 10; - conv[0] = (xx >= 0) ? '+' : '-'; - xx = abs(xx); - conv[1] = (xx / 10000) % 10 + '0'; - conv[2] = (xx / 1000) % 10 + '0'; - conv[3] = (xx / 100) % 10 + '0'; - conv[4] = (xx / 10) % 10 + '0'; - conv[5] = '.'; - conv[6] = (xx) % 10 + '0'; - conv[7] = 0; - return conv; -} - -// Convert float to string with +123.45 format -char *ftostr52(const float &x) -{ - long xx = x * 100; - conv[0] = (xx >= 0) ? '+' : '-'; - xx = abs(xx); - conv[1] = (xx / 10000) % 10 + '0'; - conv[2] = (xx / 1000) % 10 + '0'; - conv[3] = (xx / 100) % 10 + '0'; - conv[4] = '.'; - conv[5] = (xx / 10) % 10 + '0'; - conv[6] = (xx) % 10 + '0'; - conv[7] = 0; - return conv; -} - - diff --git a/Firmware/conv2str.h b/Firmware/conv2str.h deleted file mode 100644 index c6cf176d2..000000000 --- a/Firmware/conv2str.h +++ /dev/null @@ -1,28 +0,0 @@ -//conv2str.h - Float conversion utilities -#ifndef _CONV2STR_H -#define _CONV2STR_H - -#include - - -char *itostr2(const uint8_t &x); -char *itostr31(const int &xx); -char *itostr3(const int &xx); -char *itostr3left(const int &xx); -char *itostr4(const int &xx); - -char *ftostr3(const float &x); -char *ftostr31ns(const float &x); // float to string without sign character -char *ftostr31(const float &x); -char *ftostr32(const float &x); -char *ftostr32ns(const float &x); -char *ftostr43(const float &x, uint8_t offset = 0); -char *ftostr12ns(const float &x); -char *ftostr13ns(const float &x); -char *ftostr32sp(const float &x); // remove zero-padding from ftostr32 -char *ftostr5(const float &x); -char *ftostr51(const float &x); -char *ftostr52(const float &x); - - -#endif //_CONV2STR_H diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index ed3d830f3..688d52465 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5,7 +5,6 @@ #include "temperature.h" #include "ultralcd.h" -#include "conv2str.h" #include "Marlin.h" #include "language.h" #include "cardreader.h" @@ -628,9 +627,7 @@ void lcdui_print_status_line(void) { lcd_print_pad(lcd_status_message, LCD_WIDTH); if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0) { lcd_set_cursor(10, 3); - lcd_print(itostr3(pid_cycle)); - lcd_print('/'); - lcd_print(itostr3left(pid_number_of_cycles)); + lcd_printf_P(PSTR("%3d/%-3d"), pid_cycle, pid_number_of_cycles); } break; case CustomMsg::TempCal: // PINDA temp calibration in progress @@ -4490,16 +4487,14 @@ static void lcd_nozzle_diameter_cycle(void) { #define SETTINGS_NOZZLE \ do\ {\ - float fNozzleDiam;\ switch(oNozzleDiameter)\ {\ - case ClNozzleDiameter::_Diameter_250: fNozzleDiam = 0.25f; break;\ - case ClNozzleDiameter::_Diameter_400: fNozzleDiam = 0.4f; break;\ - case ClNozzleDiameter::_Diameter_600: fNozzleDiam = 0.6f; break;\ - case ClNozzleDiameter::_Diameter_800: fNozzleDiam = 0.8f; break;\ - default: fNozzleDiam = 0.4f; break;\ + case ClNozzleDiameter::_Diameter_250: MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE_DIAMETER), PSTR("0.25"), lcd_nozzle_diameter_cycle); break;\ + case ClNozzleDiameter::_Diameter_Undef: \ + case ClNozzleDiameter::_Diameter_400: MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE_DIAMETER), PSTR("0.40"), lcd_nozzle_diameter_cycle); break;\ + case ClNozzleDiameter::_Diameter_600: MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE_DIAMETER), PSTR("0.60"), lcd_nozzle_diameter_cycle); break;\ + case ClNozzleDiameter::_Diameter_800: MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE_DIAMETER), PSTR("0.80"), lcd_nozzle_diameter_cycle); break;\ }\ - MENU_ITEM_TOGGLE(_T(MSG_NOZZLE_DIAMETER), ftostr12ns(fNozzleDiam), lcd_nozzle_diameter_cycle);\ }\ while (0)