diff --git a/CHANGELOG.md b/CHANGELOG.md index 281b74a2..88668ace 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ Please add a note of your changes below this heading if you make a Pull Request. # Unreleased +### Added +* -Wdouble-promotion warning to compilation + ### Changed * Make python tools compatible with python 2.7 (so it can be used with ROS) * Threading API constructor can't take the daemon parameter, so all thread creation had to be expanded out. diff --git a/Firmware/Tupfile.lua b/Firmware/Tupfile.lua index f242b259..fe59828d 100644 --- a/Firmware/Tupfile.lua +++ b/Firmware/Tupfile.lua @@ -89,7 +89,7 @@ FLAGS += '-mthumb' FLAGS += '-mcpu=cortex-m4' FLAGS += '-mfpu=fpv4-sp-d16' FLAGS += '-mfloat-abi=hard' -FLAGS += { '-Wall', '-Wfloat-conversion', '-fdata-sections', '-ffunction-sections'} +FLAGS += { '-Wall', '-Wdouble-promotion', '-Wfloat-conversion', '-fdata-sections', '-ffunction-sections'} -- debug build FLAGS += '-g -gdwarf-2' diff --git a/Firmware/fibre/cpp/include/fibre/protocol.hpp b/Firmware/fibre/cpp/include/fibre/protocol.hpp index ed174dd9..d203e76d 100644 --- a/Firmware/fibre/cpp/include/fibre/protocol.hpp +++ b/Firmware/fibre/cpp/include/fibre/protocol.hpp @@ -592,10 +592,10 @@ private: template struct format_traits_t; -template<> struct format_traits_t { using type = void; - static constexpr const char * fmt = "%f"; - static constexpr const char * fmtp = "%f"; -}; +// template<> struct format_traits_t { using type = void; +// static constexpr const char * fmt = "%f"; +// static constexpr const char * fmtp = "%f"; +// }; template<> struct format_traits_t { using type = void; static constexpr const char * fmt = "%ld"; static constexpr const char * fmtp = "%ld"; @@ -626,8 +626,15 @@ static bool to_string(const T& value, char * buffer, size_t length, int) { snprintf(buffer, length, format_traits_t::fmtp, value); return true; } +// Special case for float because printf promotes float to double, and we get warnings +template +static bool to_string(const float& value, char * buffer, size_t length, int) { + snprintf(buffer, length, "%f", (double)value); + return true; +} + + template -//__attribute__((__unused__)) static bool to_string(const bool& value, char * buffer, size_t length, int) { buffer[0] = value ? '1' : '0'; buffer[1] = 0; @@ -642,7 +649,11 @@ template::type> static bool from_string(const char * buffer, size_t length, T* property, int) { return sscanf(buffer, format_traits_t::fmt, property) == 1; } -//__attribute__((__unused__)) +// Special case for float because printf promotes float to double, and we get warnings +template +static bool from_string(const char * buffer, size_t length, float* property, int) { + return sscanf(buffer, "%f", property) == 1; +} template static bool from_string(const char * buffer, size_t length, bool* property, int) { int val;