More configurability and locase colournames
continuous-integration/drone/tag Build was killed Details

Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
Martyn 2020-05-17 17:03:26 +02:00
parent 8a18a1f4b7
commit c278cd2a58
3 changed files with 78 additions and 32 deletions

View File

@ -3,7 +3,7 @@ kind: Deployment
metadata: metadata:
labels: labels:
run: LEDController run: LEDController
name: LEDController name: ledcontroller
spec: spec:
progressDeadlineSeconds: 600 progressDeadlineSeconds: 600
replicas: 1 replicas: 1
@ -23,9 +23,20 @@ spec:
run: LEDController run: LEDController
spec: spec:
containers: containers:
- image: imartyn/LEDController:devel - env:
- name: LISTEN_PORT
value: "5353"
- name: PANEL_IP
value: "192.168.1.139"
- name: PANEL_WIDTH
value: "68"
- name: PANEL_HEIGHT
value: "4"
- name: PANEL_BRIGHTNESS
value: "10"
image: imartyn/ledcontroller:0.0-linux-amd64
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
name: LEDController name: ledcontroller
ports: ports:
- name: web - name: web
containerPort: 5353 containerPort: 5353

View File

@ -12,6 +12,7 @@ import (
"os" "os"
"time" "time"
"strconv" "strconv"
"strings"
) )
func HealthHandler(response http.ResponseWriter, request *http.Request) { func HealthHandler(response http.ResponseWriter, request *http.Request) {
@ -35,7 +36,7 @@ func PatternHandler(response http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request) vars := mux.Vars(request)
response.Header().Add("Content-type", "text/plain") response.Header().Add("Content-type", "text/plain")
var e queue.QueueItem var e queue.QueueItem
e.Effect = vars["pattern"] e.Effect = strings.ToLower(vars["pattern"])
_, found := vars["duration"] _, found := vars["duration"]
if found { if found {
i, _ := strconv.Atoi(vars["duration"]) i, _ := strconv.Atoi(vars["duration"])
@ -68,7 +69,7 @@ func ColourHandler(response http.ResponseWriter, request *http.Request) {
} }
var c queue.RGBcolor var c queue.RGBcolor
for cn, cv := range(colornames.Map) { for cn, cv := range(colornames.Map) {
if cn == vars["name"] { if cn == strings.ToLower(vars["name"]) {
c[0] = cv.R c[0] = cv.R
c[1] = cv.G c[1] = cv.G
c[2] = cv.B c[2] = cv.B
@ -93,7 +94,7 @@ func FadeHandler(response http.ResponseWriter, request *http.Request) {
} }
var c queue.RGBcolor var c queue.RGBcolor
for cn, cv := range(colornames.Map) { for cn, cv := range(colornames.Map) {
if cn == vars["namefrom"] { if cn == strings.ToLower(vars["namefrom"]) {
c[0] = cv.R c[0] = cv.R
c[1] = cv.G c[1] = cv.G
c[2] = cv.B c[2] = cv.B
@ -101,7 +102,7 @@ func FadeHandler(response http.ResponseWriter, request *http.Request) {
} }
e.SeedColour = c e.SeedColour = c
for cn, cv := range(colornames.Map) { for cn, cv := range(colornames.Map) {
if cn == vars["nameto"] { if cn == strings.ToLower(vars["nameto"]) {
c[0] = cv.R c[0] = cv.R
c[1] = cv.G c[1] = cv.G
c[2] = cv.B c[2] = cv.B
@ -112,7 +113,7 @@ func FadeHandler(response http.ResponseWriter, request *http.Request) {
fmt.Fprint(response, "OKAY") fmt.Fprint(response, "OKAY")
} }
func HandleHTTP(queueChannel chan queue.QueueItem) { func HandleHTTP(queueChannel chan queue.QueueItem, Port int) {
globalQueue = queueChannel globalQueue = queueChannel
r := mux.NewRouter() r := mux.NewRouter()
loggedRouter := handlers.LoggingHandler(os.Stdout, r) loggedRouter := handlers.LoggingHandler(os.Stdout, r)
@ -131,10 +132,10 @@ func HandleHTTP(queueChannel chan queue.QueueItem) {
http.Handle("/", r) http.Handle("/", r)
srv := &http.Server{ srv := &http.Server{
Handler: loggedRouter, Handler: loggedRouter,
Addr: "0.0.0.0:5353", Addr: "0.0.0.0:"+strconv.Itoa(Port),
WriteTimeout: 15 * time.Second, WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second, ReadTimeout: 15 * time.Second,
} }
fmt.Println("Listening on 0.0.0.0:5353") fmt.Printf("Listening on 0.0.0.0:%d", Port)
srv.ListenAndServe() srv.ListenAndServe()
} }

78
main.go
View File

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"log" "log"
"time" "time"
"strconv"
"os"
webserver "git.martyn.berlin/martyn/LEDController/internal/webserver" webserver "git.martyn.berlin/martyn/LEDController/internal/webserver"
queue "git.martyn.berlin/martyn/LEDController/internal/queue" queue "git.martyn.berlin/martyn/LEDController/internal/queue"
@ -42,9 +44,37 @@ func reduceBrightness(universe [512]byte, percentage int) [512]byte{
func main() { func main() {
go func() { go func() {
fmt.Printf("Starting webserver on port %s\n", "5353") var err error
webserver.HandleHTTP(globalEffectChannel) listenPort := 5353
if os.Getenv("LISTEN_PORT") != "" {
listenPort, err = strconv.Atoi(os.Getenv("LISTEN_PORT"))
if err != nil {
listenPort = 5353
}
}
fmt.Printf("Starting webserver on port %d\n", listenPort)
webserver.HandleHTTP(globalEffectChannel, listenPort)
}() }()
PanelIP := os.Getenv("PANEL_IP")
if PanelIP == "" {
PanelIP = "127.0.0.1"
}
PanelWidth, err := strconv.Atoi(os.Getenv("PANEL_WIDTH"))
if err != nil {
PanelWidth = 68
}
PanelHeight, err := strconv.Atoi(os.Getenv("PANEL_HEIGHT"))
if err != nil {
PanelHeight = 4
}
PanelBrightness, err := strconv.Atoi(os.Getenv("PANEL_BRIGHTNESS"))
if err != nil {
PanelBrightness = 100
}
//instead of "" you could provide an ip-address that the socket should bind to //instead of "" you could provide an ip-address that the socket should bind to
trans, err := sacn.NewTransmitter("", [16]byte{1, 2}, "test") trans, err := sacn.NewTransmitter("", [16]byte{1, 2}, "test")
if err != nil { if err != nil {
@ -57,20 +87,24 @@ func main() {
//deactivate the channel on exit //deactivate the channel on exit
defer close(channels[i]) defer close(channels[i])
trans.SetMulticast(uint16(i+1), false) //this specific setup will not multicast on windows, trans.SetMulticast(uint16(i+1), false) //this specific setup will not multicast on windows,
trans.SetDestinations(uint16(i+1), []string{"192.168.1.139"}) trans.SetDestinations(uint16(i+1), []string{PanelIP})
} }
// Plasma for start frame // Plasma for start frame
rearranged := remapping.SliceRearrange(68, 4, true, remapping.XYGridToLinear(68, 4, patterns.PlasmaPanel(68, 4, 40))) rearranged := remapping.SliceRearrange(PanelWidth, PanelHeight, true, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.PlasmaPanel(PanelWidth, PanelHeight, 40)))
currentFrame[0] = remapping.Slice512(rearranged[0]) currentFrame[0] = remapping.Slice512(rearranged[0])
currentFrame[1] = remapping.Slice512(rearranged[1]) currentFrame[1] = remapping.Slice512(rearranged[1])
var e queue.QueueItem var e queue.QueueItem
e.Effect = "red" e.Effect = "red"
e.Duration = 40 * 50 e.Duration = 40 * 50
globalEffectChannel <- e globalEffectChannel <- e
e.Effect = "plasma" e.Effect = "colour"
e.Duration = 0 e.Duration = 40 * 10
e.Speed = 40 e.SeedColour[0] = 0
e.SeedColour[1] = 255
e.SeedColour[2] = 0
globalEffectChannel <- e
e.Effect = "default"
globalEffectChannel <- e globalEffectChannel <- e
go func() { go func() {
@ -85,40 +119,40 @@ func main() {
var rearranged [][]byte var rearranged [][]byte
switch currentEffect.Effect { switch currentEffect.Effect {
case "line": case "line":
rearranged = remapping.SliceRearrange(68, 4, true, remapping.XYGridToLinear(68, 4, patterns.ZigZag(68, 4))) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, true, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.ZigZag(PanelWidth, PanelHeight)))
case "plasma": case "plasma":
rearranged = remapping.SliceRearrange(68, 4, true, remapping.XYGridToLinear(68, 4, patterns.PlasmaPanel(68, 4, currentEffect.Speed))) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, true, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.PlasmaPanel(PanelWidth, PanelHeight, currentEffect.Speed)))
case "red": case "red":
rearranged = remapping.SliceRearrange(68, 4, false, remapping.XYGridToLinear(68, 4, patterns.RedPanel(68,4))) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, false, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.RedPanel(PanelWidth,PanelHeight)))
case "random": case "random":
rearranged = remapping.SliceRearrange(68, 4, false, remapping.XYGridToLinear(68, 4, patterns.RandomColourPanel(68,4,currentEffect.Speed))) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, false, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.RandomColourPanel(PanelWidth,PanelHeight,currentEffect.Speed)))
case "linearplasma": case "linearplasma":
rearranged = remapping.SliceRearrange(68, 4, false, patterns.LinearPlasma(68*4)) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, false, patterns.LinearPlasma(PanelWidth*PanelHeight))
case "gradientred": case "gradientred":
rearranged = remapping.SliceRearrange(68, 4, false, patterns.Gradient(255, 0, 0, 0, 0, 255, 0, 68*4)) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, false, patterns.Gradient(255, 0, 0, 0, 0, 255, 0, PanelWidth*PanelHeight))
case "sine": case "sine":
var black patterns.RGBcolor var black patterns.RGBcolor
var red patterns.RGBcolor var red patterns.RGBcolor
red[0] = 255 red[0] = 255
rearranged = remapping.SliceRearrange(68, 4, true, remapping.XYGridToLinear(68, 4, patterns.Sinewave(68, 4, black, red, currentEffect.Speed))) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, true, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.Sinewave(PanelWidth, PanelHeight, black, red, currentEffect.Speed)))
case "sinechase": case "sinechase":
var black patterns.RGBcolor var black patterns.RGBcolor
var red patterns.RGBcolor var red patterns.RGBcolor
red[0] = 255 red[0] = 255
rearranged = remapping.SliceRearrange(68, 4, true, remapping.XYGridToLinear(68, 4, patterns.SineChase(68, 4, black, red, currentEffect.Speed))) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, true, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.SineChase(PanelWidth, PanelHeight, black, red, currentEffect.Speed)))
case "plasmapulse": case "plasmapulse":
rearranged = remapping.SliceRearrange(68, 4, false, remapping.XYGridToLinear(68, 4, patterns.PlasmaColourPanel(68,4, currentEffect.Speed))) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, false, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.PlasmaColourPanel(PanelWidth,PanelHeight, currentEffect.Speed)))
case "colour": case "colour":
rearranged = remapping.SliceRearrange(68, 4, false, remapping.XYGridToLinear(68, 4, patterns.FillPanel(68,4, currentEffect.SeedColour[0], currentEffect.SeedColour[1], currentEffect.SeedColour[2]))) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, false, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.FillPanel(PanelWidth,PanelHeight, currentEffect.SeedColour[0], currentEffect.SeedColour[1], currentEffect.SeedColour[2])))
case "fade": case "fade":
rearranged = remapping.SliceRearrange(68, 4, true, remapping.XYGridToLinear(68, 4, patterns.GradientPanel(68,4, currentEffect.SeedColour, currentEffect.SecondColour))) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, true, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.GradientPanel(PanelWidth,PanelHeight, currentEffect.SeedColour, currentEffect.SecondColour)))
default: default:
rearranged = remapping.SliceRearrange(68, 4, false, remapping.XYGridToLinear(68, 4, patterns.FillPanel(68,4, 128,0,128))) rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, false, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.FillPanel(PanelWidth,PanelHeight, 128,0,128)))
} }
//rearranged := remapping.SliceRearrange(68,4,true,linearPlasma(68*4)) //rearranged := remapping.SliceRearrange(PanelWidth,PanelHeight,true,linearPlasma(PanelWidth*PanelHeight))
sema <- struct{}{} // acquire token sema <- struct{}{} // acquire token
currentFrame[0] = reduceBrightness(remapping.Slice512(rearranged[0]),10) currentFrame[0] = reduceBrightness(remapping.Slice512(rearranged[0]),PanelBrightness)
currentFrame[1] = reduceBrightness(remapping.Slice512(rearranged[1]),10) currentFrame[1] = reduceBrightness(remapping.Slice512(rearranged[1]),PanelBrightness)
<- sema <- sema
time.Sleep(40 * time.Millisecond) time.Sleep(40 * time.Millisecond)
} }