Fix invert, add log dimming (#629)

This commit is contained in:
Darrell 2022-08-30 14:30:18 -04:00 committed by GitHub
parent 0fadc5b7bc
commit 98b2034d8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 10 deletions

View File

@ -27,7 +27,7 @@ LED* newLed(uint8_t index, ControlType cntrl, int type, int pin, int cnt) {
if (type >= 2)
return new Addressable(index, cntrl, type - 2, pin, cnt);
else
return new SinglePWM(index, cntrl, type, pin, cnt);
return new SinglePWM(index, cntrl, type == 1, pin);
}
void ConnectToWifi() {

View File

@ -1,9 +1,8 @@
#include "SinglePWM.h"
SinglePWM::SinglePWM(uint8_t index, ControlType controlType, int type, int pin, int cnt) : LED(index, controlType) {
this->type = type;
SinglePWM::SinglePWM(uint8_t index, ControlType controlType, bool inverted, int pin) : LED(index, controlType) {
this->inverted = inverted;
this->pin = pin;
this->cnt = cnt;
}
void SinglePWM::begin() {
@ -12,8 +11,9 @@ void SinglePWM::begin() {
setDuty(LED::getBrightness());
}
void SinglePWM::setDuty(uint32_t value) {
uint32_t duty = (type & 0x1 == 0) ? map(value, 0, 255, 0, 4095) : map(value, 0, 255, 4095, 0);
void SinglePWM::setDuty(uint32_t x) {
uint32_t duty = x >= 255 ? 4096 : (x <= 0 ? 0 : round(4096.0 * pow(10.0, 0.0055 * (x - 255.0))));
if (inverted) duty = 4096 - duty;
ledcWrite(LED::getIndex(), duty);
}

View File

@ -4,7 +4,8 @@
class SinglePWM : public LED {
public:
SinglePWM(uint8_t index, ControlType controlType, int type, int pin, int cnt);
SinglePWM(uint8_t index, ControlType controlType, bool inverted, int pin);
void begin() override;
void service() override;
@ -13,8 +14,6 @@ class SinglePWM : public LED {
private:
void setDuty(uint32_t value);
int type;
bool inverted;
int pin;
int cnt;
int cntrl;
};