From 6cd9a9e6dffddc6bd6aef1797f2809cc2f397a00 Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Thu, 30 Mar 2023 20:14:59 -0400 Subject: [PATCH] correctly scale return value, with comment about linearity --- protocol/esta/analog/receiver.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/protocol/esta/analog/receiver.h b/protocol/esta/analog/receiver.h index 24b0db0..b7ba3c7 100644 --- a/protocol/esta/analog/receiver.h +++ b/protocol/esta/analog/receiver.h @@ -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)); } /**