-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(light): create new light software (#24)
- Loading branch information
Showing
29 changed files
with
174 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ maintainer: "[email protected]" | |
systemd-configuration: | ||
user: "root" | ||
after: network.target | ||
args: ["start", "--log-level", "info", "--gamepad-port", "80", "core", "device", "gamepad", "emulator", "demo", "zigzag", "yumyum", "clock", "draw", "blocks", "getout", "animate"] | ||
args: ["start", "--log-level", "info", "--gamepad-port", "80", "core", "device", "gamepad", "emulator", "demo", "zigzag", "yumyum", "clock", "draw", "blocks", "getout", "animate", "light"] | ||
stop-command: /bin/kill $MAINPID | ||
restart: always | ||
wanted-by: multi-user.target | ||
|
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
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,17 @@ | ||
{ | ||
"name": "light", | ||
"height": 5, | ||
"width": 10, | ||
"colors": [ | ||
{ "r": 0, "g": 0, "b": 0, "a": 0 }, | ||
{ "r": 44, "g": 62, "b": 80, "a": 1 }, | ||
{ "r": 241, "g": 196, "b": 15, "a": 1 } | ||
], | ||
"mask": [ | ||
0, 0, 0, 0, 0, 1, 1, 0, 0, 2, | ||
0, 0, 0, 1, 1, 1, 2, 0, 2, 0, | ||
1, 1, 1, 1, 1, 1, 2, 0, 0, 0, | ||
0, 0, 0, 1, 1, 1, 2, 0, 2, 0, | ||
0, 0, 0, 0, 0, 1, 1, 0, 0, 2 | ||
] | ||
} |
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,94 @@ | ||
package light | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/richardlt/matrix/sdk-go/common" | ||
"github.com/richardlt/matrix/sdk-go/software" | ||
) | ||
|
||
// Start the light software. | ||
func Start(uri string) error { | ||
logrus.Infof("Start light for uri %s\n", uri) | ||
|
||
d := &light{} | ||
|
||
return software.Connect(uri, d, true) | ||
} | ||
|
||
type light struct { | ||
api software.API | ||
layer software.Layer | ||
colors []common.Color | ||
selected int | ||
} | ||
|
||
func (l *light) Init(a software.API) (err error) { | ||
logrus.Debug("Init light") | ||
|
||
l.api = a | ||
|
||
logo := a.GetImageFromLocal("light") | ||
|
||
a.SetConfig(software.ConnectRequest_SoftwareData_Config{ | ||
Logo: &logo, | ||
MinPlayerCount: 1, | ||
MaxPlayerCount: 1, | ||
}) | ||
|
||
l.layer, err = l.api.NewLayer() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
l.colors = []common.Color{ | ||
l.api.GetColorFromLocalThemeByName("flat", "white_1"), | ||
l.api.GetColorFromLocalThemeByName("flat", "turquoise_1"), | ||
l.api.GetColorFromLocalThemeByName("flat", "green_1"), | ||
l.api.GetColorFromLocalThemeByName("flat", "blue_1"), | ||
l.api.GetColorFromLocalThemeByName("flat", "violet_1"), | ||
l.api.GetColorFromLocalThemeByName("flat", "dark_grey_1"), | ||
l.api.GetColorFromLocalThemeByName("flat", "red_1"), | ||
l.api.GetColorFromLocalThemeByName("flat", "orange_1"), | ||
l.api.GetColorFromLocalThemeByName("flat", "yellow_1"), | ||
} | ||
|
||
return a.Ready() | ||
} | ||
|
||
func (l *light) Start(playerCount uint64) { | ||
l.print() | ||
} | ||
|
||
func (l light) Close() {} | ||
|
||
func (l *light) ActionReceived(slot uint64, cmd common.Command) { | ||
switch cmd { | ||
case common.Command_LEFT_UP: | ||
if 0 < l.selected { | ||
l.selected-- | ||
} else { | ||
l.selected = len(l.colors) - 1 | ||
} | ||
l.print() | ||
case common.Command_RIGHT_UP: | ||
if l.selected < len(l.colors)-1 { | ||
l.selected++ | ||
} else { | ||
l.selected = 0 | ||
} | ||
l.print() | ||
} | ||
} | ||
|
||
func (l *light) print() { | ||
for x := 0; x < 16; x++ { | ||
for y := 0; y < 9; y++ { | ||
l.layer.SetWithCoord(common.Coord{ | ||
X: int64(x), | ||
Y: int64(y), | ||
}, l.colors[l.selected]) | ||
} | ||
} | ||
l.api.Print() | ||
} |
Oops, something went wrong.