correctly scale return value, with comment about linearity
This commit is contained in:
parent
cd884a8593
commit
6cd9a9e6df
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue