Skip to content

Commit

Permalink
fix integer overflow in temerature compensation
Browse files Browse the repository at this point in the history
  • Loading branch information
joba-1 committed Feb 21, 2018
1 parent 9623e85 commit d4ac4dc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Tsl2561Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t
bool compensateTemperature( int16_t centiCelsius, uint32_t &full, uint32_t &ir ) {
// assume linear gradient 0% at 25°C to +20% at 70°C
if( centiCelsius >= -3000 && centiCelsius <= 7000 ) {
full -= (full * (centiCelsius - 2500) * 20) / (100 * (7000 - 2500));
ir -= (ir * (centiCelsius - 2500) * 20) / (100 * (7000 - 2500));
full -= (full * (centiCelsius - 2500)) / (5 * (7000 - 2500));
ir -= (ir * (centiCelsius - 2500)) / (5 * (7000 - 2500));
return true;
}

Expand Down

0 comments on commit d4ac4dc

Please sign in to comment.