Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ on KEYWORD2
toggle KEYWORD2
getValue KEYWORD2
getState KEYWORD2
getSetValue KEYWORD2
setRampTime KEYWORD2
set KEYWORD2

#######################################
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Dimmer
version=1.0
version=1.1
author=Alex Monteiro Sartin <[email protected]>
maintainer=Luis Chavier <[email protected]>
sentence=A library to control dimmable lamps and other AC loads.
Expand Down
10 changes: 8 additions & 2 deletions src/Dimmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/Dimmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down