only min max if they are specified

This commit is contained in:
SGE 2023-12-18 15:30:32 +01:00
parent a10b48a8a4
commit b84741e7b8

View file

@ -118,19 +118,27 @@ void Touchscreen::send_touches_() {
}
int16_t Touchscreen::normalize_(int16_t val, int16_t min_val, int16_t max_val, bool inverted) {
int16_t ret;
//only normalize when min and max value are specified
if(min_val && max_val)
{
if (val <= min_val) {
ret = 0;
} else if (val >= max_val) {
ret = 0xfff;
} else {
ret = (int16_t) ((int) 0xfff * (val - min_val) / (max_val - min_val));
ret = (int16_t) ((int) 0xfff * (val - min_val) / (max_val - min_val));
}
}
else
{
ret = val;
}
ret = (inverted) ? 0xfff - ret : ret;
ret = (inverted) ? 0xfff - ret : ret;
return ret;
return ret;
}
} // namespace touchscreen