diff --git a/keywords.txt b/keywords.txt index 954960b..a391df8 100755 --- a/keywords.txt +++ b/keywords.txt @@ -16,6 +16,8 @@ on KEYWORD2 toggle KEYWORD2 getValue KEYWORD2 getState KEYWORD2 +getSetValue KEYWORD2 +setRampTime KEYWORD2 set KEYWORD2 ####################################### diff --git a/library.properties b/library.properties index f7c59da..76011ab 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Dimmer -version=1.0 +version=1.1 author=Alex Monteiro Sartin maintainer=Luis Chavier sentence=A library to control dimmable lamps and other AC loads. diff --git a/src/Dimmer.cpp b/src/Dimmer.cpp index c2ca3ce..9c27de1 100644 --- a/src/Dimmer.cpp +++ b/src/Dimmer.cpp @@ -187,6 +187,10 @@ uint8_t Dimmer::getValue() { } } +uint8_t Dimmer::getSetValue() { + return lampValue; +} + void Dimmer::set(uint8_t value) { if (value > 100) { value = 100; @@ -200,6 +204,8 @@ void Dimmer::set(uint8_t value) { if (value != lampValue) { if (operatingMode == DIMMER_RAMP) { rampStartValue = getValue(); + rampCycles = (((int32_t)abs(value-rampStartValue))*totalRampCycles)/100; + if(rampCycles<1){rampCycles=1;} rampCounter = 0; } else if (operatingMode == DIMMER_COUNT) { pulsesHigh = 0; @@ -234,8 +240,8 @@ void Dimmer::setMinimum(uint8_t value) { void Dimmer::setRampTime(double rampTime) { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { rampTime = rampTime * 2 * acFreq; - rampCycles = rampTime > 0xFFFF ? 0xFFFF : rampTime; - rampCounter = rampCycles; + totalRampCycles = rampTime > 0xFFFF ? 0xFFFF : rampTime; + rampCounter = rampCycles= totalRampCycles; } } diff --git a/src/Dimmer.h b/src/Dimmer.h index 1e7f9c1..508ff6d 100644 --- a/src/Dimmer.h +++ b/src/Dimmer.h @@ -99,6 +99,13 @@ class Dimmer { */ uint8_t getValue(); + /** + * Gets the current set value (intensity) of the lamp. + * + * @return current set lamp value, from 0 to 100. + */ + uint8_t getSetValue(); + /** * Gets the current state of the lamp. * @@ -147,6 +154,7 @@ class Dimmer { uint8_t rampStartValue; uint16_t rampCounter; uint16_t rampCycles; + uint16_t totalRampCycles; uint8_t acFreq; uint8_t pulseCount; uint8_t pulsesUsed;