Skip to content

Commit

Permalink
Remove the opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
jannickfahlbusch committed Dec 16, 2016
1 parent f81972b commit bcb6182
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
25 changes: 6 additions & 19 deletions dioder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
Expand Down Expand Up @@ -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)
}
9 changes: 3 additions & 6 deletions dioder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit bcb6182

Please sign in to comment.