-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package lights | ||
|
||
type InvalidColorError struct { | ||
color string | ||
msg string | ||
} | ||
|
||
func (err *InvalidColorError) Error() string { | ||
return err.msg | ||
} | ||
|
||
type InvalidColorValue struct { | ||
value uint8 | ||
msg string | ||
} | ||
|
||
func (err *InvalidColorValue) Error() string { | ||
return err.msg | ||
} | ||
|
||
// Color represents a RGBW color | ||
type Color struct { | ||
R uint8 | ||
G uint8 | ||
B uint8 | ||
W uint8 | ||
} | ||
|
||
// NewColor initializes a new Color using valid RGBW values (between 0 - 255). | ||
func NewColor(r uint8, g uint8, b uint8, w uint8) (Color, error) { | ||
var color Color | ||
|
||
if r < 0 && r > 255 { | ||
return color, &InvalidColorValue{r, "Red value is not within range. e.g. Value must be between 0 - 255"} | ||
} | ||
if g < 0 && g > 255 { | ||
return color, &InvalidColorValue{r, "Green value is not within range. e.g. Value must be between 0 - 255"} | ||
} | ||
if b < 0 && b > 255 { | ||
return color, &InvalidColorValue{r, "Blue value is not within range. e.g. Value must be between 0 - 255"} | ||
} | ||
if w < 0 && w > 255 { | ||
return color, &InvalidColorValue{r, "White value is not within range. e.g. Value must be between 0 - 255"} | ||
} | ||
|
||
color = Color{ | ||
R: r, | ||
G: g, | ||
B: b, | ||
W: w, | ||
} | ||
|
||
return color, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters