Compare commits
No commits in common. "5f8e68662f1165f92248ee5c6f9905278fee7b0f" and "209bebe51d4b4efc67986de9656f157d72592e9c" have entirely different histories.
5f8e68662f
...
209bebe51d
3 changed files with 25 additions and 73 deletions
|
@ -24,12 +24,11 @@ var sema = make(chan struct{}, 1) // a binary semaphore guarding currentFrame
|
||||||
|
|
||||||
var currentEffect queue.QueueItem
|
var currentEffect queue.QueueItem
|
||||||
var globalEffectChannel = make(chan queue.QueueItem, 1024)
|
var globalEffectChannel = make(chan queue.QueueItem, 1024)
|
||||||
var universeCount int = 0
|
|
||||||
|
|
||||||
func foreverLoop() {
|
func foreverLoop() {
|
||||||
for /*ever*/ {
|
for /*ever*/ {
|
||||||
time.Sleep(40 * time.Millisecond) //25fps
|
time.Sleep(40 * time.Millisecond) //25fps
|
||||||
for u := 0; u < universeCount; u++ {
|
for u := 0; u < 2; u++ {
|
||||||
sema <- struct{}{} // acquire token
|
sema <- struct{}{} // acquire token
|
||||||
channels[u] <- currentFrame[u]
|
channels[u] <- currentFrame[u]
|
||||||
<-sema
|
<-sema
|
||||||
|
@ -44,6 +43,8 @@ func reduceBrightness(universe [512]byte, percentage int) [512]byte {
|
||||||
return universe
|
return universe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var universeCount int = 0
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
go func() {
|
go func() {
|
||||||
var err error
|
var err error
|
||||||
|
@ -73,7 +74,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
universeCount = int(math.Ceil(float64(PanelHeight*PanelWidth*3) / 510))
|
universeCount = int(math.Ceil(float64(PanelHeight*PanelWidth*3) / 510))
|
||||||
fmt.Printf("Universe count is %d\n", universeCount)
|
fmt.Printf("Universe count is %d", universeCount)
|
||||||
|
|
||||||
PanelBrightness, err := strconv.Atoi(os.Getenv("PANEL_BRIGHTNESS"))
|
PanelBrightness, err := strconv.Atoi(os.Getenv("PANEL_BRIGHTNESS"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -110,8 +111,7 @@ func main() {
|
||||||
e.SeedColour[1] = 255
|
e.SeedColour[1] = 255
|
||||||
e.SeedColour[2] = 0
|
e.SeedColour[2] = 0
|
||||||
globalEffectChannel <- e
|
globalEffectChannel <- e
|
||||||
e.Effect = "plasma"
|
e.Effect = "default"
|
||||||
e.Speed = 40
|
|
||||||
globalEffectChannel <- e
|
globalEffectChannel <- e
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -120,11 +120,7 @@ func main() {
|
||||||
currentEffect.Duration -= 40
|
currentEffect.Duration -= 40
|
||||||
} else {
|
} else {
|
||||||
if len(globalEffectChannel) > 0 {
|
if len(globalEffectChannel) > 0 {
|
||||||
lastEffect := currentEffect
|
|
||||||
currentEffect = <-globalEffectChannel
|
currentEffect = <-globalEffectChannel
|
||||||
if lastEffect != currentEffect {
|
|
||||||
fmt.Printf("New effect selected : %s\n", currentEffect.Effect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var rearranged [][]byte
|
var rearranged [][]byte
|
||||||
|
|
|
@ -1,15 +1,9 @@
|
||||||
package patterns
|
package patterns
|
||||||
|
|
||||||
import (
|
import "math"
|
||||||
"math"
|
|
||||||
)
|
|
||||||
|
|
||||||
type RGBcolor = [3]byte
|
type RGBcolor = [3]byte
|
||||||
|
|
||||||
func floatColorToIntColor(val float64) byte {
|
|
||||||
return byte(val*256 - 0.5)
|
|
||||||
}
|
|
||||||
|
|
||||||
func plasmaRGBFromVal(val byte) (byte, byte, byte) {
|
func plasmaRGBFromVal(val byte) (byte, byte, byte) {
|
||||||
var r byte
|
var r byte
|
||||||
var g byte
|
var g byte
|
||||||
|
@ -30,6 +24,7 @@ func plasmaRGBFromVal(val byte) (byte, byte, byte) {
|
||||||
return r, g, b
|
return r, g, b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func LinearPlasma(l int) []byte {
|
func LinearPlasma(l int) []byte {
|
||||||
line := make([]byte, l*3)
|
line := make([]byte, l*3)
|
||||||
for i := 0; i < l*3; i += 3 {
|
for i := 0; i < l*3; i += 3 {
|
||||||
|
@ -42,66 +37,26 @@ func LinearPlasma(l int) []byte {
|
||||||
return line
|
return line
|
||||||
}
|
}
|
||||||
|
|
||||||
func linearFromVal(val byte) (byte, byte, byte) {
|
var offset float64 = 0.5
|
||||||
var r byte = val
|
|
||||||
var g byte = 0
|
|
||||||
var b byte = 0
|
|
||||||
return r, g, b
|
|
||||||
}
|
|
||||||
|
|
||||||
func positiveModF(val float64) float64 {
|
|
||||||
_, val = math.Modf(val)
|
|
||||||
if val < 0 {
|
|
||||||
return val + 1.0
|
|
||||||
}
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
|
|
||||||
func colorPlasmaFromFloatVal(val float64) (byte, byte, byte) {
|
|
||||||
var r byte
|
|
||||||
var g byte
|
|
||||||
var b byte
|
|
||||||
val = positiveModF(val) * 3.0
|
|
||||||
if val < 1.0 {
|
|
||||||
r = floatColorToIntColor(val)
|
|
||||||
g = floatColorToIntColor(1.0 - val)
|
|
||||||
b = 0
|
|
||||||
} else if val < 2.0 {
|
|
||||||
b = floatColorToIntColor(val - 1.0)
|
|
||||||
r = floatColorToIntColor(1.0 - (val - 1.0))
|
|
||||||
g = 0.0
|
|
||||||
} else {
|
|
||||||
g = floatColorToIntColor(val - 2.0)
|
|
||||||
b = floatColorToIntColor(1.0 - (val - 2.0))
|
|
||||||
r = 0.0
|
|
||||||
}
|
|
||||||
return r, g, b
|
|
||||||
}
|
|
||||||
|
|
||||||
var palletteOffset float64 = 0.0
|
|
||||||
|
|
||||||
func PlasmaPanel(w int, h int, speed uint16) [][]RGBcolor {
|
func PlasmaPanel(w int, h int, speed uint16) [][]RGBcolor {
|
||||||
grid := make([][]RGBcolor, w)
|
grid := make([][]RGBcolor, w)
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
grid[i] = make([]RGBcolor, h)
|
grid[i] = make([]RGBcolor, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pbrook didn't say what DT is for... so it resolves to 0.05
|
|
||||||
palletteOffset -= 0.05 / 1.0
|
|
||||||
if palletteOffset < 0 {
|
|
||||||
palletteOffset += 1.0
|
|
||||||
}
|
|
||||||
|
|
||||||
offset := 0.5 // center offset
|
|
||||||
scale := math.Pi * 2.0 / float64(w)
|
scale := math.Pi * 2.0 / float64(w)
|
||||||
|
step := float64(5 * speed / 40)
|
||||||
|
offset -= step
|
||||||
|
if offset < 0 {
|
||||||
|
offset += 1.0
|
||||||
|
}
|
||||||
for y := 0; y < h; y++ {
|
for y := 0; y < h; y++ {
|
||||||
for x := 0; x < w; x++ {
|
for x := 0; x < w; x++ {
|
||||||
u := math.Cos((float64(x) + offset) * scale)
|
u := math.Cos((float64(x) + offset) * scale)
|
||||||
v := math.Cos((float64(y) + offset) * scale)
|
v := math.Cos((float64(y) + offset) * scale)
|
||||||
j := math.Cos(offset * scale) // 2D - No Z
|
w := math.Cos((float64(w) + offset) * scale)
|
||||||
e := (u + v + j + 3.0) / 6.0
|
e := (u + v + w + 3.0) / 6.0
|
||||||
r, g, b := colorPlasmaFromFloatVal(palletteOffset + e)
|
r, g, b := plasmaRGBFromVal(byte((offset + e) * 255))
|
||||||
var rgb [3]byte
|
var rgb [3]byte
|
||||||
rgb[0] = r
|
rgb[0] = r
|
||||||
rgb[1] = g
|
rgb[1] = g
|
||||||
|
@ -110,4 +65,4 @@ func PlasmaPanel(w int, h int, speed uint16) [][]RGBcolor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return grid
|
return grid
|
||||||
}
|
}
|
|
@ -1,17 +1,18 @@
|
||||||
package webserver
|
package webserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
queue "git.martyn.berlin/martyn/LEDController/internal/queue"
|
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
queue "git.martyn.berlin/martyn/LEDController/internal/queue"
|
||||||
"golang.org/x/image/colornames"
|
"golang.org/x/image/colornames"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func HealthHandler(response http.ResponseWriter, request *http.Request) {
|
func HealthHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
|
@ -29,7 +30,7 @@ func RootHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
fmt.Fprint(response, "Not implemented")
|
fmt.Fprint(response, "Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
var globalQueue chan queue.QueueItem
|
var globalQueue chan queue.QueueItem;
|
||||||
|
|
||||||
func PatternHandler(response http.ResponseWriter, request *http.Request) {
|
func PatternHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
vars := mux.Vars(request)
|
vars := mux.Vars(request)
|
||||||
|
@ -67,7 +68,7 @@ func ColourHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
e.Duration = 5000
|
e.Duration = 5000
|
||||||
}
|
}
|
||||||
var c queue.RGBcolor
|
var c queue.RGBcolor
|
||||||
for cn, cv := range colornames.Map {
|
for cn, cv := range(colornames.Map) {
|
||||||
if cn == strings.ToLower(vars["name"]) {
|
if cn == strings.ToLower(vars["name"]) {
|
||||||
c[0] = cv.R
|
c[0] = cv.R
|
||||||
c[1] = cv.G
|
c[1] = cv.G
|
||||||
|
@ -92,7 +93,7 @@ func FadeHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
e.Duration = 5000
|
e.Duration = 5000
|
||||||
}
|
}
|
||||||
var c queue.RGBcolor
|
var c queue.RGBcolor
|
||||||
for cn, cv := range colornames.Map {
|
for cn, cv := range(colornames.Map) {
|
||||||
if cn == strings.ToLower(vars["namefrom"]) {
|
if cn == strings.ToLower(vars["namefrom"]) {
|
||||||
c[0] = cv.R
|
c[0] = cv.R
|
||||||
c[1] = cv.G
|
c[1] = cv.G
|
||||||
|
@ -100,7 +101,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 == strings.ToLower(vars["nameto"]) {
|
if cn == strings.ToLower(vars["nameto"]) {
|
||||||
c[0] = cv.R
|
c[0] = cv.R
|
||||||
c[1] = cv.G
|
c[1] = cv.G
|
||||||
|
@ -131,7 +132,7 @@ func HandleHTTP(queueChannel chan queue.QueueItem, Port int) {
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Handler: loggedRouter,
|
Handler: loggedRouter,
|
||||||
Addr: "0.0.0.0:" + strconv.Itoa(Port),
|
Addr: "0.0.0.0:"+strconv.Itoa(Port),
|
||||||
WriteTimeout: 15 * time.Second,
|
WriteTimeout: 15 * time.Second,
|
||||||
ReadTimeout: 15 * time.Second,
|
ReadTimeout: 15 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue