More configurability and locase colournames
continuous-integration/drone/tag Build was killed
Details
continuous-integration/drone/tag Build was killed
Details
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
parent
8a18a1f4b7
commit
c278cd2a58
|
@ -3,7 +3,7 @@ kind: Deployment
|
|||
metadata:
|
||||
labels:
|
||||
run: LEDController
|
||||
name: LEDController
|
||||
name: ledcontroller
|
||||
spec:
|
||||
progressDeadlineSeconds: 600
|
||||
replicas: 1
|
||||
|
@ -23,9 +23,20 @@ spec:
|
|||
run: LEDController
|
||||
spec:
|
||||
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
|
||||
name: LEDController
|
||||
name: ledcontroller
|
||||
ports:
|
||||
- name: web
|
||||
containerPort: 5353
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func HealthHandler(response http.ResponseWriter, request *http.Request) {
|
||||
|
@ -35,7 +36,7 @@ func PatternHandler(response http.ResponseWriter, request *http.Request) {
|
|||
vars := mux.Vars(request)
|
||||
response.Header().Add("Content-type", "text/plain")
|
||||
var e queue.QueueItem
|
||||
e.Effect = vars["pattern"]
|
||||
e.Effect = strings.ToLower(vars["pattern"])
|
||||
_, found := vars["duration"]
|
||||
if found {
|
||||
i, _ := strconv.Atoi(vars["duration"])
|
||||
|
@ -68,7 +69,7 @@ func ColourHandler(response http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
var c queue.RGBcolor
|
||||
for cn, cv := range(colornames.Map) {
|
||||
if cn == vars["name"] {
|
||||
if cn == strings.ToLower(vars["name"]) {
|
||||
c[0] = cv.R
|
||||
c[1] = cv.G
|
||||
c[2] = cv.B
|
||||
|
@ -93,7 +94,7 @@ func FadeHandler(response http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
var c queue.RGBcolor
|
||||
for cn, cv := range(colornames.Map) {
|
||||
if cn == vars["namefrom"] {
|
||||
if cn == strings.ToLower(vars["namefrom"]) {
|
||||
c[0] = cv.R
|
||||
c[1] = cv.G
|
||||
c[2] = cv.B
|
||||
|
@ -101,7 +102,7 @@ func FadeHandler(response http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
e.SeedColour = c
|
||||
for cn, cv := range(colornames.Map) {
|
||||
if cn == vars["nameto"] {
|
||||
if cn == strings.ToLower(vars["nameto"]) {
|
||||
c[0] = cv.R
|
||||
c[1] = cv.G
|
||||
c[2] = cv.B
|
||||
|
@ -112,7 +113,7 @@ func FadeHandler(response http.ResponseWriter, request *http.Request) {
|
|||
fmt.Fprint(response, "OKAY")
|
||||
}
|
||||
|
||||
func HandleHTTP(queueChannel chan queue.QueueItem) {
|
||||
func HandleHTTP(queueChannel chan queue.QueueItem, Port int) {
|
||||
globalQueue = queueChannel
|
||||
r := mux.NewRouter()
|
||||
loggedRouter := handlers.LoggingHandler(os.Stdout, r)
|
||||
|
@ -131,10 +132,10 @@ func HandleHTTP(queueChannel chan queue.QueueItem) {
|
|||
http.Handle("/", r)
|
||||
srv := &http.Server{
|
||||
Handler: loggedRouter,
|
||||
Addr: "0.0.0.0:5353",
|
||||
Addr: "0.0.0.0:"+strconv.Itoa(Port),
|
||||
WriteTimeout: 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()
|
||||
}
|
||||
|
|
78
main.go
78
main.go
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"strconv"
|
||||
"os"
|
||||
|
||||
webserver "git.martyn.berlin/martyn/LEDController/internal/webserver"
|
||||
queue "git.martyn.berlin/martyn/LEDController/internal/queue"
|
||||
|
@ -42,9 +44,37 @@ func reduceBrightness(universe [512]byte, percentage int) [512]byte{
|
|||
|
||||
func main() {
|
||||
go func() {
|
||||
fmt.Printf("Starting webserver on port %s\n", "5353")
|
||||
webserver.HandleHTTP(globalEffectChannel)
|
||||
var err error
|
||||
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
|
||||
trans, err := sacn.NewTransmitter("", [16]byte{1, 2}, "test")
|
||||
if err != nil {
|
||||
|
@ -57,20 +87,24 @@ func main() {
|
|||
//deactivate the channel on exit
|
||||
defer close(channels[i])
|
||||
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
|
||||
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[1] = remapping.Slice512(rearranged[1])
|
||||
var e queue.QueueItem
|
||||
e.Effect = "red"
|
||||
e.Duration = 40 * 50
|
||||
globalEffectChannel <- e
|
||||
e.Effect = "plasma"
|
||||
e.Duration = 0
|
||||
e.Speed = 40
|
||||
e.Effect = "colour"
|
||||
e.Duration = 40 * 10
|
||||
e.SeedColour[0] = 0
|
||||
e.SeedColour[1] = 255
|
||||
e.SeedColour[2] = 0
|
||||
globalEffectChannel <- e
|
||||
e.Effect = "default"
|
||||
globalEffectChannel <- e
|
||||
|
||||
go func() {
|
||||
|
@ -85,40 +119,40 @@ func main() {
|
|||
var rearranged [][]byte
|
||||
switch currentEffect.Effect {
|
||||
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":
|
||||
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":
|
||||
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":
|
||||
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":
|
||||
rearranged = remapping.SliceRearrange(68, 4, false, patterns.LinearPlasma(68*4))
|
||||
rearranged = remapping.SliceRearrange(PanelWidth, PanelHeight, false, patterns.LinearPlasma(PanelWidth*PanelHeight))
|
||||
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":
|
||||
var black patterns.RGBcolor
|
||||
var red patterns.RGBcolor
|
||||
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":
|
||||
var black patterns.RGBcolor
|
||||
var red patterns.RGBcolor
|
||||
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":
|
||||
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":
|
||||
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":
|
||||
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:
|
||||
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
|
||||
currentFrame[0] = reduceBrightness(remapping.Slice512(rearranged[0]),10)
|
||||
currentFrame[1] = reduceBrightness(remapping.Slice512(rearranged[1]),10)
|
||||
currentFrame[0] = reduceBrightness(remapping.Slice512(rearranged[0]),PanelBrightness)
|
||||
currentFrame[1] = reduceBrightness(remapping.Slice512(rearranged[1]),PanelBrightness)
|
||||
<- sema
|
||||
time.Sleep(40 * time.Millisecond)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue