From bcb6182b4b506d895329c2ac5690e2a0fa15f30f Mon Sep 17 00:00:00 2001 From: Jannick Fahlbusch Date: Fri, 16 Dec 2016 19:29:11 +0100 Subject: [PATCH] Remove the opacity Reference: piLights/proto@c7cf44c6bf37b6245b50b5d0bde43c663be3d577 --- dioder.go | 25 ++++++------------------- dioder_test.go | 9 +++------ 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/dioder.go b/dioder.go index ecb44af..3fa23f5 100644 --- a/dioder.go +++ b/dioder.go @@ -57,14 +57,10 @@ func (d *Dioder) SetAll(colorSet color.RGBA) { d.ColorConfiguration = colorSet //Red - colorSet.R = calculateOpacity(colorSet.R, colorSet.A) d.SetChannelInteger(colorSet.R, d.PinConfiguration.Red) //Green - colorSet.G = calculateOpacity(colorSet.G, colorSet.A) d.SetChannelInteger(colorSet.G, d.PinConfiguration.Green) - //Blue - colorSet.B = calculateOpacity(colorSet.B, colorSet.A) d.SetChannelInteger(colorSet.B, d.PinConfiguration.Blue) } @@ -86,8 +82,12 @@ func (d *Dioder) TurnOff() { //TurnOn turns the dioder-strips on and restores the previous configuration func (d *Dioder) TurnOn() { - if d.ColorConfiguration.A == 0 && d.ColorConfiguration.B == 0 && d.ColorConfiguration.G == 0 && d.ColorConfiguration.R == 0 { - d.ColorConfiguration = color.RGBA{255, 255, 255, 100} + if d.ColorConfiguration.B == 0 && d.ColorConfiguration.G == 0 && d.ColorConfiguration.R == 0 { + d.ColorConfiguration = color.RGBA{ + R: 255, + G: 255, + B: 255, + } } //@ToDo: Refactor @@ -182,16 +182,3 @@ func (d *Dioder) Release() error { } }*/ - -//calculateOpacity calculates the value of colorValue after applying some opacity -func calculateOpacity(colorValue uint8, opacity uint8) uint8 { - var calculatedValue float32 - - if opacity != 100 { - calculatedValue = float32(colorValue) / 100 * float32(opacity) - } else { - calculatedValue = float32(colorValue) - } - - return uint8(calculatedValue) -} diff --git a/dioder_test.go b/dioder_test.go index 755622a..2c010f5 100644 --- a/dioder_test.go +++ b/dioder_test.go @@ -127,17 +127,14 @@ func TestDioderTurnOn(t *testing.T) { d.TurnOff() d.TurnOn() - if d.ColorConfiguration.A != 100 { - t.Errorf("Value for opacity is wrong. Expected 0, got %d", d.ColorConfiguration.A) - } if d.ColorConfiguration.R != 255 { - t.Errorf("Value for red is wrong. Expected 0, got %d", d.ColorConfiguration.R) + t.Errorf("Value for red is wrong. Expected 255, got %d", d.ColorConfiguration.R) } if d.ColorConfiguration.G != 255 { - t.Errorf("Value for green is wrong. Expected 0, got %d", d.ColorConfiguration.G) + t.Errorf("Value for green is wrong. Expected 255, got %d", d.ColorConfiguration.G) } if d.ColorConfiguration.B != 255 { - t.Errorf("Value for blue is wrong. Expected 0, got %d", d.ColorConfiguration.B) + t.Errorf("Value for blue is wrong. Expected 255, got %d", d.ColorConfiguration.B) } }