Browse Source

light: fix value2pwm range conversion (#1902, #1905)

master
Max Prokhorov 5 years ago
committed by GitHub
parent
commit
cf3bd49bde
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions
  1. +3
    -3
      code/espurna/light.ino

+ 3
- 3
code/espurna/light.ino View File

@ -458,8 +458,8 @@ void _toCSV(char * buffer, size_t len, bool applyBrightness) {
// See cores/esp8266/WMath.cpp::map
// Redefining as local method here to avoid breaking in unexpected ways in inputs like (0, 0, 0, 0, 1)
template <typename T, typename T2> T _lightMap(T x, T in_min, T in_max, T2 out_min, T2 out_max) {
T divisor = (in_max - in_min);
template <typename T, typename Tin, typename Tout> T _lightMap(T x, Tin in_min, Tin in_max, Tout out_min, Tout out_max) {
auto divisor = (in_max - in_min);
if (divisor == 0){
return -1; //AVR returns -1, SAM returns 0
}
@ -470,7 +470,7 @@ template <typename T, typename T2> T _lightMap(T x, T in_min, T in_max, T2 out_m
// PROVIDER
// -----------------------------------------------------------------------------
unsigned int _toPWM(unsigned char value, bool gamma, bool reverse) {
unsigned int _toPWM(unsigned int value, bool gamma, bool reverse) {
value = constrain(value, Light::VALUE_MIN, Light::VALUE_MAX);
if (gamma) value = pgm_read_byte(_light_gamma_table + value);
if (Light::VALUE_MAX != Light::PWM_LIMIT) value = _lightMap(value, Light::VALUE_MIN, Light::VALUE_MAX, Light::PWM_MIN, Light::PWM_LIMIT);


Loading…
Cancel
Save