From 6e809c7baf54febcb7737653964b3db0786b846f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Tue, 24 Oct 2017 12:15:38 +0200 Subject: [PATCH] Option to prevent 100% PWM output --- README.md | 2 ++ code/espurna/config/general.h | 14 ++++++++++++++ code/espurna/light.ino | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b3fd2ac9..908dff13 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,8 @@ Here is the list of supported hardware. For more information please refer to the |![EXS Wifi Relay v3.1](images/devices/exs-wifi-relay-v31.jpg)||| |**EXS Wifi Relay v3.1**||| +**Other supported boards:** Itead Sonoff LED, Huacanxing H802, WiOn 50055, ManCaveMade ESP-Live, InterMitTech QuinLED 2.6, Arilux AL-LC06, Xenon SM-PW702U, Authometion LYT8266. + ## License Copyright (C) 2016-2017 by Xose PĂ©rez (@xoseperez) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index df404ebf..2cd263ef 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -491,9 +491,23 @@ PROGMEM const char* const custom_reset_string[] = { #endif #define LIGHT_SAVE_DELAY 5 // Persist color after 5 seconds to avoid wearing out + +#ifndef LIGHT_PWM_FREQUENCY #define LIGHT_PWM_FREQUENCY 1000 // PWM frequency +#endif + +#ifndef LIGHT_MAX_PWM #define LIGHT_MAX_PWM 4095 // Maximum PWM value +#endif + +#ifndef LIGHT_LIMIT_PWM +#define LIGHT_LIMIT_PWM LIGHT_MAX_PWM // Limit PWM to this value (prevent 100% power) +#endif + +#ifndef LIGHT_MAX_VALUE #define LIGHT_MAX_VALUE 255 // Maximum light value +#endif + #define LIGHT_MAX_BRIGHTNESS 255 // Maximun brightness value #define LIGHT_USE_COLOR 1 // Use 3 first channels as RGB #define LIGHT_USE_WHITE 0 // Use white channel whenever RGB have the same value diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 607548ef..6e9817ab 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -197,8 +197,8 @@ void _fromMireds(unsigned long mireds) { unsigned int _toPWM(unsigned long value, bool bright, bool gamma, bool reverse) { value = constrain(value, 0, LIGHT_MAX_VALUE); if (bright) value *= ((float) _brightness / LIGHT_MAX_BRIGHTNESS); - unsigned int pwm = gamma ? gamma_table[value] : map(value, 0, LIGHT_MAX_VALUE, 0, LIGHT_MAX_PWM); - if (reverse) pwm = LIGHT_MAX_PWM - pwm; + unsigned int pwm = gamma ? gamma_table[value] : map(value, 0, LIGHT_MAX_VALUE, 0, LIGHT_LIMIT_PWM); + if (reverse) pwm = LIGHT_LIMIT_PWM - pwm; return pwm; }