aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-24 19:51:00 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-24 19:51:00 -0500
commit5fe626948a562eaa48517ef46ff6134916243abb (patch)
treebd06ba06b5a95caac476517d91a6d7037a0762ce
parent8ec7808b6aab7ee830b4f9eb49b82da3335245d3 (diff)
Implemented Light.Brighten to complement Light.Dim
-rw-r--r--light.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/light.go b/light.go
index cc4b502..8c79e8a 100644
--- a/light.go
+++ b/light.go
@@ -12,6 +12,7 @@ import (
"fmt"
"time"
"errors"
+ "log"
)
// Light struct defines attributes of a light.
@@ -204,6 +205,28 @@ func (light *Light) SetBrightness(percent int) error {
}
}
+
+// Light.Brighten will increase LightStruct.Bri by a given percent (integer)
+func (light *Light) Brighten(percent int) error {
+ if percent > 0 && percent <= 100 {
+ originalBri := light.State.Bri
+ increaseBri := float32(originalBri)*float32((float32(percent)/100.0))
+ newBri := uint8(originalBri+int(increaseBri))
+ if newBri > 254 { // LightState.Bri must be between 1 and 254 inclusive
+ newBri = 254
+ log.Println("Light.Brighten state set over 100%, setting brightness to 100%. ")
+ }
+ lightState := LightState{On: true, Bri: newBri}
+ err := light.SetState(lightState)
+ if err != nil {
+ return err
+ }
+ return nil
+ } else {
+ return errors.New("Light.Brighten percentage is not between 1 and 100. ")
+ }
+}
+
// Light.SetState modifyies light attributes. See `LightState` struct for attributes.
// Brightness must be between 1 and 254 (inclusive)
// Hue must be between 0 and 65535 (inclusive)