Skip to content

Commit

Permalink
feat(light): create new light software (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored Apr 30, 2019
1 parent 47538cf commit 2613b91
Show file tree
Hide file tree
Showing 29 changed files with 174 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .debpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Video game console operating system that displays on a 16*9 RGB LED matrix.

<p align="center">
<br/>
<img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/gamepad.gif" width="400"/>
<img src="./docs/gamepad.gif" width="400"/>
<br/>
<br/>
</p>
Expand All @@ -15,16 +15,17 @@ Video game console operating system that displays on a 16*9 RGB LED matrix.

| | Name | Description | |
| - | - | - | - |
| <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/demo.png" width="60"/> | Demo | A demo software that uses all drivers from the SDK. | <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/demo.gif" width="150"/> |
| <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/yumyum.png" width="60"/> | Yumyum | Eat all the candies with your monster to win the game. | <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/yumyum.gif" width="150"/> |
| <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/clock.png" width="60"/> | Clock | What time is it? | <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/clock.gif" width="150"/> |
| <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/zigzag.png" width="60"/> | Zigzag | Turn left then right, eat candies but not yourself. | <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/zigzag.gif" width="150"/> |
| <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/draw.png" width="60"/> | Draw | For those who like pixel art. | <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/draw.gif" width="150"/> |
| <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/device.png" width="60"/> | Device | The Device software allows you to change the luminosity of the LEDs. | <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/device.gif" width="150"/> |
| <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/blocks.png" width="60"/> | Blocks | A puzzle game, score a maximum of points by clearing complete lines. | <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/blocks.gif" width="150"/> |
| <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/getout.png" width="60"/> | Getout | A labyrinth game, try to get out if you can. | <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/getout.gif" width="150"/> |
| <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/rollup-dice.png" width="60"/> | Rollup dice | Random dice generator (https://github.com/gwenker/matrix-rollup-dice). | <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/rollup-dice.gif" width="150"/> |
| <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/animate.png" width="60"/> | Animate | Player for animations generated with Glediator (http://www.solderlab.de/index.php/software/glediator). | <img src="https://raw.githubusercontent.com/richardlt/matrix/master/docs/animate.gif" width="150"/> |
| <img src="./docs/demo.png" width="60"/> | Demo | A demo software that uses all drivers from the SDK. | <img src="./docs/demo.gif" width="150"/> |
| <img src="./docs/yumyum.png" width="60"/> | Yumyum | Eat all the candies with your monster to win the game. | <img src="./docs/yumyum.gif" width="150"/> |
| <img src="./docs/clock.png" width="60"/> | Clock | What time is it? | <img src="./docs/clock.gif" width="150"/> |
| <img src="./docs/zigzag.png" width="60"/> | Zigzag | Turn left then right, eat candies but not yourself. | <img src="./docs/zigzag.gif" width="150"/> |
| <img src="./docs/draw.png" width="60"/> | Draw | For those who like pixel art. | <img src="./docs/draw.gif" width="150"/> |
| <img src="./docs/device.png" width="60"/> | Device | The Device software allows you to change the luminosity of the LEDs. | <img src="./docs/device.gif" width="150"/> |
| <img src="./docs/blocks.png" width="60"/> | Blocks | A puzzle game, score a maximum of points by clearing complete lines. | <img src="./docs/blocks.gif" width="150"/> |
| <img src="./docs/getout.png" width="60"/> | Getout | A labyrinth game, try to get out if you can. | <img src="./docs/getout.gif" width="150"/> |
| <img src="./docs/rollup-dice.png" width="60"/> | Rollup dice | Random dice generator (https://github.com/gwenker/matrix-rollup-dice). | <img src="./docs/rollup-dice.gif" width="150"/> |
| <img src="./docs/animate.png" width="60"/> | Animate | Player for animations generated with Glediator (http://www.solderlab.de/index.php/software/glediator). | <img src="./docs/animate.gif" width="150"/> |
| <img src="./docs/light.png" width="60"/> | Light | Simple software to generate mood light. | <img src="./docs/light.gif" width="150"/> |

## Matrix types

Expand Down
3 changes: 2 additions & 1 deletion blocks/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"time"

"github.com/sirupsen/logrus"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/software"
"github.com/sirupsen/logrus"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion clock/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"strconv"
"time"

"github.com/sirupsen/logrus"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/software"
"github.com/sirupsen/logrus"
)

// Start the clock software.
Expand Down
5 changes: 3 additions & 2 deletions core/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"fmt"
"net"

"github.com/sirupsen/logrus"
"github.com/pkg/errors"
"google.golang.org/grpc"

"github.com/richardlt/matrix/core/os"
"github.com/richardlt/matrix/core/render"
"github.com/richardlt/matrix/core/system"
"github.com/richardlt/matrix/sdk-go/display"
"github.com/richardlt/matrix/sdk-go/player"
"github.com/richardlt/matrix/sdk-go/software"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
)

// Start the matrix core.
Expand Down
5 changes: 2 additions & 3 deletions core/render/font.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"encoding/json"
"fmt"

"github.com/richardlt/matrix/sdk-go/software"

"github.com/pkg/errors"

"github.com/richardlt/matrix/sdk-go/software"
)

// GetFontCaracterByValue returns a font's caracter from given value.
Expand All @@ -16,7 +16,6 @@ func GetFontCaracterByValue(f software.Font, value rune) software.Font_Caracter
return *c
}
}

return software.Font_Caracter{}
}

Expand Down
1 change: 1 addition & 0 deletions core/render/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/pkg/errors"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/software"
)
Expand Down
1 change: 1 addition & 0 deletions core/render/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/pkg/errors"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/software"
)
Expand Down
5 changes: 3 additions & 2 deletions core/system/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"time"

"github.com/pkg/errors"
"github.com/satori/go.uuid"
"github.com/sirupsen/logrus"

"github.com/richardlt/matrix/core/render"
"github.com/richardlt/matrix/sdk-go/common"
displaySDK "github.com/richardlt/matrix/sdk-go/display"
"github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
)

// NewDisplayServer return new display server.
Expand Down
5 changes: 3 additions & 2 deletions core/system/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"time"

"github.com/pkg/errors"
"github.com/richardlt/matrix/sdk-go/common"
playerSDK "github.com/richardlt/matrix/sdk-go/player"
"github.com/satori/go.uuid"
"github.com/sirupsen/logrus"

"github.com/richardlt/matrix/sdk-go/common"
playerSDK "github.com/richardlt/matrix/sdk-go/player"
)

// NewPlayerServer returns new player server.
Expand Down
5 changes: 3 additions & 2 deletions core/system/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"time"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
uuid "github.com/satori/go.uuid"

"github.com/richardlt/matrix/core/drivers"
"github.com/richardlt/matrix/core/render"
"github.com/richardlt/matrix/sdk-go/common"
softwareSDK "github.com/richardlt/matrix/sdk-go/software"
uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
)

// NewSoftwareServer returns new software server.
Expand Down
3 changes: 2 additions & 1 deletion demo/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"time"

"github.com/sirupsen/logrus"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/software"
"github.com/sirupsen/logrus"
)

// Start the demo software.
Expand Down
3 changes: 2 additions & 1 deletion device/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package device

import (
"context"

"github.com/sirupsen/logrus"

"github.com/richardlt/matrix/sdk-go/display"
"github.com/richardlt/matrix/sdk-go/player"
"github.com/richardlt/matrix/sdk-go/software"
"github.com/sirupsen/logrus"
)

// Start device deamon.
Expand Down
3 changes: 2 additions & 1 deletion device/gamepad.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

"github.com/karalabe/hid"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/player"
"github.com/sirupsen/logrus"
)

func newGamepad() *gamepad {
Expand Down
5 changes: 3 additions & 2 deletions device/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"time"

"github.com/pkg/errors"
"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/software"
"github.com/sirupsen/logrus"
serial "go.bug.st/serial.v1"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/software"
)

const refreshDelay = time.Millisecond * 30
Expand Down
Binary file added docs/light.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion draw/daemon.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package draw

import (
"github.com/sirupsen/logrus"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/software"
"github.com/sirupsen/logrus"
)

// Start the draw software.
Expand Down
2 changes: 1 addition & 1 deletion emulator/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"

"github.com/sirupsen/logrus"

"github.com/googollee/go-socket.io"
"github.com/labstack/echo"
"github.com/pkg/errors"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/display"
)
Expand Down
3 changes: 2 additions & 1 deletion gamepad/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (

"github.com/googollee/go-socket.io"
"github.com/labstack/echo"
"github.com/sirupsen/logrus"
"github.com/pkg/errors"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/display"
"github.com/richardlt/matrix/sdk-go/player"
"github.com/sirupsen/logrus"
)

type frame struct {
Expand Down
3 changes: 2 additions & 1 deletion getout/daemon.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package getout

import (
"github.com/sirupsen/logrus"

"github.com/richardlt/matrix/sdk-go/common"
"github.com/richardlt/matrix/sdk-go/software"
"github.com/sirupsen/logrus"
)

// Start the getout software.
Expand Down
17 changes: 17 additions & 0 deletions images/light.json
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
]
}
94 changes: 94 additions & 0 deletions light/daemon.go
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()
}
Loading

0 comments on commit 2613b91

Please sign in to comment.