Skip to content

Commit

Permalink
Linux client support (#16)
Browse files Browse the repository at this point in the history
* Allow building linux client, go fmt, misc
  • Loading branch information
rdnt authored Dec 23, 2021
1 parent a1d19a5 commit 138a678
Show file tree
Hide file tree
Showing 24 changed files with 183 additions and 56 deletions.
4 changes: 2 additions & 2 deletions cmd/mockserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"github.com/gookit/color"
"github.com/vmihailenco/msgpack/v5"
"ledctl3/pkg/events"
"ledctl3/internal/pkg/events"
"ledctl3/pkg/udp"
)

Expand All @@ -28,7 +28,7 @@ func main() {
}

fmt.Print("\r")
for i:=0; i<len(e.Data); i+= 4 {
for i := 0; i < len(e.Data); i += 4 {
color.RGB(e.Data[i], e.Data[i+1], e.Data[i+2], true).Print(" ")
}
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"time"
)

func main() {
func main() {
ctl, err := server.New()
if err != nil {
panic(err)
}
panic(err)
}

err= ctl.Start()
err = ctl.Start()
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/client/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

type Client struct {
id string
mux sync.Mutex
id string
mux sync.Mutex
conn *websocket.Conn
}

Expand All @@ -30,7 +30,7 @@ func (c *Client) Receive() ([]byte, error) {

func NewClient(conn *websocket.Conn) *Client {
return &Client{
id: shortuuid.New(),
id: shortuuid.New(),
conn: conn,
}
}
6 changes: 3 additions & 3 deletions internal/client/api/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (h *Hub) AcceptWebsocketConnection(w http.ResponseWriter, req *http.Request

// trigger the event
h.evts <- Event{
ClientId: client.id,
Data: b,
}
ClientId: client.id,
Data: b,
}
}
}
6 changes: 3 additions & 3 deletions internal/client/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"ledctl3/internal/client/controller"
"ledctl3/internal/client/controller/ambilight"
"ledctl3/internal/client/interfaces"
"ledctl3/pkg/events"
"ledctl3/internal/pkg/events"
"ledctl3/pkg/udp"
)

type App struct {
DefaultMode controller.Mode
BlackPoint int
DefaultMode controller.Mode
BlackPoint int

Host string
Port int
Expand Down
15 changes: 9 additions & 6 deletions internal/client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"gopkg.in/yaml.v3"
"ledctl3/internal/client"
"os"
)

Expand All @@ -27,10 +28,10 @@ type Server struct {
}

type Display struct {
Width int `yaml:"width" json:"width"`
Height int `yaml:"height" json:"height"`
Leds int `yaml:"leds" json:"leds"`
Bounds Bounds `yaml:"bounds" json:"bounds"`
Width int `yaml:"width" json:"width"`
Height int `yaml:"height" json:"height"`
Leds int `yaml:"leds" json:"leds"`
Bounds Bounds `yaml:"bounds" json:"bounds"`
}

type Bounds struct {
Expand Down Expand Up @@ -118,19 +119,21 @@ func Load() (*Config, error) {
func createDefault() (*Config, error) {
c := Config{
DefaultMode: "ambilight",
CapturerType: "dxgi",
CapturerType: "bitblt",
Server: Server{
Host: "0.0.0.0",
Port: 4197,
Leds: 100,
StripType: "GRB",
StripType: string(client.GRB),
GpioPin: 18,
Brightness: 255,
BlackPoint: 0,
},
Displays: []Display{
{
Leds: 100,
Width: 1920,
Height: 1080,
Bounds: Bounds{
From: Vector2{X: 0, Y: 0},
To: Vector2{X: 0, Y: 0},
Expand Down
6 changes: 3 additions & 3 deletions internal/client/controller/ambilight/ambilight.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func (v *Visualizer) process(d interfaces.Display, pix []byte) {
pix = adjustWhitePoint(pix, 16, 256)

v.events <- interfaces.UpdateEvent{
Display: d,
Data: pix,
}
Display: d,
Data: pix,
}
}

// adjustWhitePoint adjusts the white point for each color individually.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

var scaleFactor = 8

type bitbltCapturer struct{
type bitbltCapturer struct {
displays []interfaces.Display
}

Expand Down
12 changes: 6 additions & 6 deletions internal/client/controller/ambilight/capturer/bitblt/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
)

type display struct {
id int
width int
height int
x int
y int
scaler draw.Scaler
id int
width int
height int
x int
y int
scaler draw.Scaler
}

func (d *display) SyncCapture(ctx context.Context, frames chan []byte) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func (c *dxgiCapturer) All() ([]interfaces.Display, error) {

count := screenshot.NumActiveDisplays()
for i := 0; i < count; i++ {
bounds := screenshot.GetDisplayBounds(1-i) // TODO: fix weird displays order
bounds := screenshot.GetDisplayBounds(1 - i) // TODO: fix weird displays order

d := &display{
id: i,
id: i,
width: bounds.Dx(),
height: bounds.Dy(),
x: bounds.Min.X,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package dxgi

import (
"context"
"fmt"
"golang.org/x/image/draw"
"image"
)

type display struct {
index int
id int
width int
height int
x int
y int
scaler draw.Scaler
buf *image.RGBA
}

func (d *display) Id() int {
return 0
}

func (d *display) Width() int {
return d.width
}

func (d *display) Height() int {
return d.height
}

func (d *display) X() int {
return d.x
}

func (d *display) Y() int {
return d.y
}

func (d *display) Scaler() draw.Scaler {
return d.scaler
}

func (d *display) Resolution() string {
return fmt.Sprintf("%dx%d", d.width, d.height)
}


func (d *display) String() string {
return fmt.Sprintf("{id: %d, width: %d, height: %d, left: %d, top: %d}", d.id, d.width, d.height, d.x, d.y)
}

func (d *display) Capture(ctx context.Context) chan []byte {
return nil
}

func (d *display) reset() error {
return nil
}

func (d *display) SyncCapture(ctx context.Context, frames chan []byte) {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ var framerate = 1000
var ErrNoFrame = fmt.Errorf("no frame")

type display struct {
index int
id int
width int
height int
x int
y int
scaler draw.Scaler
buf *image.RGBA
dev *d3d.ID3D11Device
devCtx *d3d.ID3D11DeviceContext
ddup *d3d.OutputDuplicator
index int
id int
width int
height int
x int
y int
scaler draw.Scaler
buf *image.RGBA
dev *d3d.ID3D11Device
devCtx *d3d.ID3D11DeviceContext
ddup *d3d.OutputDuplicator
}

func (d *display) Id() int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (c *dxgiCapturer) All() ([]interfaces.Display, error) {
bounds := screenshot.GetDisplayBounds(i)

d := &display{
index: i,
index: i,
width: bounds.Dx(),
height: bounds.Dy(),
x: bounds.Min.X,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package scrap

import (
"context"
"fmt"
"golang.org/x/image/draw"
"image"
)

type display struct {
index int
id int
width int
height int
x int
y int
scaler draw.Scaler
buf *image.RGBA
}

func (d *display) Id() int {
return 0
}

func (d *display) Width() int {
return d.width
}

func (d *display) Height() int {
return d.height
}

func (d *display) X() int {
return d.x
}

func (d *display) Y() int {
return d.y
}

func (d *display) Scaler() draw.Scaler {
return d.scaler
}

func (d *display) Resolution() string {
return fmt.Sprintf("%dx%d", d.width, d.height)
}


func (d *display) String() string {
return fmt.Sprintf("{id: %d, width: %d, height: %d, left: %d, top: %d}", d.id, d.width, d.height, d.x, d.y)
}

func (d *display) Capture(ctx context.Context) chan []byte {
return nil
}

func (d *display) reset() error {
return nil
}

func (d *display) SyncCapture(ctx context.Context, frames chan []byte) {}
1 change: 0 additions & 1 deletion internal/client/controller/ambilight/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ func WithDisplayConfig(cfg []DisplayConfig) Option {
return nil
}
}

2 changes: 1 addition & 1 deletion internal/client/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package controller
import (
"github.com/vmihailenco/msgpack/v5"
"ledctl3/internal/client/interfaces"
"ledctl3/pkg/events"
"ledctl3/internal/pkg/events"
)

type Controller struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/client/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Visualizer interface {

type UpdateEvent struct {
Display Display
Data []byte
Data []byte
}

type Updater interface {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/server/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package server
import (
"fmt"
"github.com/vmihailenco/msgpack/v5"
"ledctl3/pkg/events"
"ledctl3/internal/pkg/events"
"ledctl3/pkg/udp"
"ledctl3/pkg/ws281x"
)
Expand Down
Loading

0 comments on commit 138a678

Please sign in to comment.