diff --git a/CHANGELOG.md b/CHANGELOG.md index fda2aca8..07a30ae6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Please add a note of your changes below this heading if you make a Pull Request. # Releases +## [0.4.6] - 2018-10-07 +### Fixed +* Broken printing of floats on ascii protocol ## [0.4.5] - 2018-10-06 ### Added diff --git a/Firmware/fibre/cpp/include/fibre/protocol.hpp b/Firmware/fibre/cpp/include/fibre/protocol.hpp index e599c0d9..4b503e68 100644 --- a/Firmware/fibre/cpp/include/fibre/protocol.hpp +++ b/Firmware/fibre/cpp/include/fibre/protocol.hpp @@ -603,6 +603,14 @@ struct format_traits_t; // 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 = "%lld"; + static constexpr const char * fmtp = "%lld"; +}; +template<> struct format_traits_t { using type = void; + static constexpr const char * fmt = "%llu"; + static constexpr const char * fmtp = "%llu"; +}; template<> struct format_traits_t { using type = void; static constexpr const char * fmt = "%ld"; static constexpr const char * fmtp = "%ld"; @@ -634,14 +642,12 @@ static bool to_string(const T& value, char * buffer, size_t length, int) { return true; } // Special case for float because printf promotes float to double, and we get warnings -template +template static bool to_string(const float& value, char * buffer, size_t length, int) { snprintf(buffer, length, "%f", (double)value); return true; } - - -template +template static bool to_string(const bool& value, char * buffer, size_t length, int) { buffer[0] = value ? '1' : '0'; buffer[1] = 0; @@ -657,11 +663,11 @@ static bool from_string(const char * buffer, size_t length, T* property, int) { return sscanf(buffer, format_traits_t::fmt, property) == 1; } // Special case for float because printf promotes float to double, and we get warnings -template +template static bool from_string(const char * buffer, size_t length, float* property, int) { return sscanf(buffer, "%f", property) == 1; } -template +template static bool from_string(const char * buffer, size_t length, bool* property, int) { int val; if (sscanf(buffer, "%d", &val) != 1)