Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@

[[constraint]]
name = "github.com/qmsk/go-web"
version = "0.1.0"
version = "~0.2.0"
51 changes: 51 additions & 0 deletions api/channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package api

type ChannelColor string

const (
ChannelColorRed = "red"
ChannelColorGreen = "green"
ChannelColorBlue = "blue"
)

type ChannelConfig struct {
Control string `json:",omitempty"`
Intensity bool `json:",omitempty"`
Color ChannelColor `json:",omitempty"`
}

func (config ChannelConfig) String() string {
if config.Control != "" {
return "control:" + config.Control
}
if config.Intensity {
return "intensity"
}
if config.Color != "" {
return "color:" + string(config.Color)
}

return ""
}

func (config ChannelConfig) ID() ChannelID {
return ChannelID(config.String())
}

type ChannelID string
type Channels map[ChannelID]Channel

type Channel struct {
ID ChannelID
Config ChannelConfig
Index uint
Address DMXAddress

DMX DMXValue
Value Value
}

type ChannelParams struct {
DMX *DMXValue `json:",omitempty"`
Value *Value `json:",omitempty"`
}
44 changes: 44 additions & 0 deletions api/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package api

type ColorID string

type Colors map[ColorID]Color

// Merge in colors from given map, overriding colors in this map
func (colors Colors) Merge(merge Colors) Colors {
var merged = make(Colors)

for colorID, color := range colors {
merged[colorID] = color
}

for colorID, color := range merge {
merged[colorID] = color
}

return merged
}

type Color struct {
Red Value
Green Value
Blue Value
}

func (color Color) IsZero() bool {
return color.Red == 0.0 && color.Green == 0.0 && color.Blue == 0.0
}

// Linear RGB intensity scaling
func (color Color) Scale(intensity Value) Color {
return Color{
Red: color.Red * intensity,
Green: color.Green * intensity,
Blue: color.Blue * intensity,
}
}

type ColorParams struct {
ScaleIntensity *Value
Color
}
11 changes: 11 additions & 0 deletions api/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package api

type Config struct {
HeadTypes map[TypeID]HeadType
Colors Colors

Heads map[HeadID]HeadConfig
Groups map[GroupID]GroupConfig

Presets map[PresetID]PresetConfig
}
7 changes: 7 additions & 0 deletions api/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package api

type Event struct {
Outputs Outputs
Heads Heads
Groups Groups
}
25 changes: 25 additions & 0 deletions api/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package api

type GroupConfig struct {
Heads []HeadID
Name string
}

type GroupID string

type Groups map[GroupID]Group

type Group struct {
GroupConfig // TODO: separate config field
ID GroupID
Heads []HeadID
Colors Colors

Intensity *Intensity
Color *Color
}

type GroupParams struct {
Intensity *IntensityParams `json:",omitempty"`
Color *ColorParams `json:",omitempty"`
}
49 changes: 49 additions & 0 deletions api/head.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package api

import (
"fmt"
)

type TypeID string
type HeadType struct {
Vendor string
Model string
Mode string
URL string

Channels []ChannelConfig
Colors Colors
}

func (headType HeadType) String() string {
return fmt.Sprintf("%v/%v=%v", headType.Vendor, headType.Model, headType.Mode)
}

type HeadConfig struct {
Type TypeID
Universe Universe
Address DMXAddress
Name string
Count uint // Clone multiple copies of the head at id.N
Groups []GroupID
}

type HeadID string

type Heads map[HeadID]Head

type Head struct {
ID HeadID
Config HeadConfig
Type HeadType

Channels Channels `json:",omitempty"`
Intensity *Intensity `json:",omitempty"`
Color *Color `json:",omitempty"`
}

type HeadParams struct {
Channels map[ChannelID]ChannelParams `json:",omitempty"`
Intensity *IntensityParams `json:",omitempty"`
Color *ColorParams `json:",omitempty"`
}
8 changes: 8 additions & 0 deletions api/index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package api

type Index struct {
Outputs Outputs
Heads Heads
Groups Groups
Presets Presets
}
14 changes: 14 additions & 0 deletions api/intensity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package api

type Intensity struct {
Intensity Value
}

func (intensity Intensity) Scale(scale Value) Intensity {
return Intensity{Intensity: intensity.Intensity * scale}
}

type IntensityParams struct {
ScaleIntensity *Value
Intensity
}
24 changes: 24 additions & 0 deletions api/output.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package api

import (
"time"
)

type OutputStatus struct {
Seen time.Time
Address string
Port int

Artnet interface{} // metadata
}

type OutputID string
type Outputs map[OutputID]Output

type Output struct {
ID OutputID
Universe Universe
Connected *time.Time

OutputStatus
}
52 changes: 52 additions & 0 deletions api/preset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package api

type PresetConfigParams struct {
Intensity *IntensityParams
Color *ColorParams
}

func (params PresetConfigParams) Scale(scale Value) PresetConfigParams {
var ret PresetConfigParams

if params.Intensity != nil {
var intensity = *params.Intensity

ret.Intensity = &intensity
ret.Intensity.ScaleIntensity = &scale
}

if params.Color != nil {
var color = *params.Color

ret.Color = &color
ret.Color.ScaleIntensity = &scale
}

return ret
}

type PresetGroups map[GroupID]PresetConfigParams
type PresetHeads map[HeadID]PresetConfigParams

type PresetConfig struct {
Name string
All *PresetConfigParams
Groups PresetGroups
Heads PresetHeads
}

type PresetID string
type Presets map[PresetID]Preset

type Preset struct {
ID PresetID
Config PresetConfig

// TODO: superfluous re config?
Groups PresetGroups
Heads PresetHeads
}

type PresetParams struct {
Intensity *Value // TODO: rename to Scale
}
6 changes: 6 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package api

type Universe int
type DMXAddress int
type DMXValue uint8
type Value float64
Loading