correctly scale return value, with comment about linearity

This commit is contained in:
Kevin Matz 2023-03-30 20:14:59 -04:00
parent cd884a8593
commit 6cd9a9e6df

View File

@ -45,16 +45,15 @@ struct Receiver
/** /**
* @brief Convert millivolts to an 8-bit level. * @brief Convert millivolts to an 8-bit level.
* @param mV * @param mV
* @return * @return \cite ANALOG 5.4 Scale: control is intended to be linear
*/ */
uint8_t level(const int16_t mV) const uint8_t level(const int16_t mV) const
{ {
if (mV <= zero) if (mV <= zero)
return 0; return 0;
else if ( mV >= full) if ( mV >= full)
return UINT8_MAX; return UINT8_MAX;
else return UINT8_MAX * ((mV - zero) / (full - zero));
return (mV - zero) / (full - zero);
} }
/** /**