1
0
Fork 0

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
1 changed files with 3 additions and 4 deletions

View File

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