Extend LogField to support scaled_channel divisors. (#3575)

Also move the type field and shrink the size field for better packing.
Saves about 800 bytes of flash.  This fixes #3574.
This commit is contained in:
Scott Smith 2021-11-18 23:29:19 -08:00 committed by GitHub
parent d91e5f2ad0
commit df3e60c07c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -34,7 +34,7 @@ void LogField::writeHeader(Writer& outBuffer) const {
buffer[45] = 0;
// Offset 46, length 4 = Scale
copyFloat(buffer + 46, 1.0f / m_multiplier);
copyFloat(buffer + 46, m_multiplier);
// Offset 50, length 4 = shift before scaling (always 0)
copyFloat(buffer + 50, 0);

View File

@ -7,11 +7,12 @@
struct Writer;
class LogField {
public:
template <typename TValue, int TMult = 1>
constexpr LogField(const scaled_channel<TValue, TMult>& toRead, const char* name, const char* units, int8_t digits)
: m_type(resolveType<TValue>())
, m_multiplier(TMult)
template <typename TValue, int TMult, int TDiv>
constexpr LogField(const scaled_channel<TValue, TMult, TDiv>& toRead,
const char* name, const char* units, int8_t digits)
: m_multiplier(float(TDiv) / TMult)
, m_addr(toRead.getFirstByteAddr())
, m_type(resolveType<TValue>())
, m_digits(digits)
, m_size(sizeForType(resolveType<TValue>()))
, m_name(name)
@ -59,11 +60,11 @@ private:
}
}
const Type m_type;
const float m_multiplier;
const char* const m_addr;
const Type m_type;
const int8_t m_digits;
const size_t m_size;
const uint8_t m_size;
const char* const m_name;
const char* const m_units;