From 7aa98a8ebdcc41e9694bfa226322570960540bc7 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Mon, 13 Apr 2020 01:13:44 +0200 Subject: [PATCH] Replace sprintf with dtostrf to save about 1.5k of flash --- fantemp/fantemp.cppproj | 231 +++++++++++++++++++++------------------- fantemp/terminal.hpp | 8 +- 2 files changed, 123 insertions(+), 116 deletions(-) diff --git a/fantemp/fantemp.cppproj b/fantemp/fantemp.cppproj index 8df4960..86d5b66 100644 --- a/fantemp/fantemp.cppproj +++ b/fantemp/fantemp.cppproj @@ -82,129 +82,136 @@ Custom Programming Tool - + + + \Debug\fantemp.lss + + + .lss + ^\s*(?<address>[a-f0-9]*):\s*.*$ + true + address + $pc + + - -mmcu=atmega328p - True - True - True - True - False - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - Optimize for size (-Os) - True - True - True - True - -fno-threadsafe-statics -std=c11 - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - Optimize for size (-Os) - True - True - True - -fno-threadsafe-statics -Wextra -std=c++17 - True - - - libm - libprintf_flt - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - + -mmcu=atmega328p + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + Optimize for size (-Os) + True + True + True + True + -fno-threadsafe-statics -std=c11 + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + Optimize for size (-Os) + True + True + True + -fno-threadsafe-statics -Wextra -std=c++17 + + + libm + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + - -mmcu=atmega328p - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - Optimize (-O1) - True - Maximum (-g3) - True - True - True - -fno-threadsafe-statics -std=c11 - True - True - - - DEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - Optimize (-O1) - True - Maximum (-g3) - True - True - -fno-threadsafe-statics -Wextra -std=c++17 - True - - - libm - libprintf_flt - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - Default (-Wa,-g) - + -mmcu=atmega328p + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + Optimize (-O1) + True + Maximum (-g3) + True + True + True + -fno-threadsafe-statics -std=c11 + True + True + + + DEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + Optimize (-O1) + True + Maximum (-g3) + True + True + -fno-threadsafe-statics -Wextra -std=c++17 + + + libm + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + Default (-Wa,-g) + diff --git a/fantemp/terminal.hpp b/fantemp/terminal.hpp index 522180a..2f92453 100644 --- a/fantemp/terminal.hpp +++ b/fantemp/terminal.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include @@ -191,11 +191,11 @@ class Terminal { if (Controller::m_dataAvailable) { char floatBuffer[16]; - sprintf(floatBuffer, "%.2f", Controller::m_adcSample); + dtostrf(Controller::m_adcSample, 0, 2, floatBuffer); m_serial << F("ADC value ...: ") << floatBuffer << F(" / 1023") << detail::ENDL; - sprintf(floatBuffer, "%.2f", Controller::m_resistance); + dtostrf(Controller::m_resistance, 0, 2, floatBuffer); m_serial << F("Resistance ..: ") << floatBuffer << F(" Ohm") << detail::ENDL; - sprintf(floatBuffer, "%.2f", Controller::m_temperature); + dtostrf(Controller::m_temperature, 0, 2, floatBuffer); m_serial << F("Temperature .: ") << floatBuffer << F(" C") << detail::ENDL; m_serial << F("Fan speed ...: ") << Controller::m_fanSpeed << F("%") << detail::ENDL; } else {