mirror of
https://github.com/esphome/esphome.git
synced 2025-01-11 23:23:17 +01:00
only min max if they are specified
This commit is contained in:
parent
a10b48a8a4
commit
b84741e7b8
1 changed files with 12 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue