Skip to content

Commit

Permalink
Change how brightness controls to [1, 0] format
Browse files Browse the repository at this point in the history
  • Loading branch information
Flonja committed Oct 22, 2023
1 parent aaa6971 commit aab34a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions light.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type Light interface {
On()
Off()
Powered() bool
Brightness() byte
SetBrightness(byte)
Brightness() float64
SetBrightness(float64)
Model() string
}

Expand Down
8 changes: 4 additions & 4 deletions models/centura_color_spot.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func (c *CenturaColorSpot) Powered() bool {
return c.mustReadCharacteristics("932c32bd-0002-47a2-835a-a8d455b859dd")[0] == 1
}

func (c *CenturaColorSpot) Brightness() byte {
return c.mustReadCharacteristics("932c32bd-0003-47a2-835a-a8d455b859dd")[0]
func (c *CenturaColorSpot) Brightness() float64 {
return float64(c.mustReadCharacteristics("932c32bd-0003-47a2-835a-a8d455b859dd")[0]) / 254
}

func (c *CenturaColorSpot) SetBrightness(b byte) {
c.mustWriteCharacteristics("932c32bd-0003-47a2-835a-a8d455b859dd", []byte{byte(min(max(float64(b), 1), 254))})
func (c *CenturaColorSpot) SetBrightness(b float64) {
c.mustWriteCharacteristics("932c32bd-0003-47a2-835a-a8d455b859dd", []byte{byte(min(max(b*254, 1), 254))})
}

func (c *CenturaColorSpot) Model() string {
Expand Down

0 comments on commit aab34a6

Please sign in to comment.