refactor dynamic universes

Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
Martyn 2020-05-19 10:45:42 +02:00
parent 3e04b69b97
commit 209bebe51d
2 changed files with 87 additions and 51 deletions

View File

@ -1,16 +1,44 @@
package main
import (
"image/color"
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
fynewidget "git.martyn.berlin/martyn/LEDController/internal/fynewidget"
"log"
)
type tappableIcon struct {
widget.Icon
}
func newTappableIcon(res fyne.Resource) *tappableIcon {
icon := &tappableIcon{}
icon.ExtendBaseWidget(icon)
icon.SetResource(res)
return icon
}
func (t *tappableIcon) Tapped(_ *fyne.PointEvent) {
log.Println("I have been tapped")
}
func (t *tappableIcon) TappedSecondary(_ *fyne.PointEvent) {
}
func main() {
app := app.New()
w := app.NewWindow("Hello")
w.SetContent(widget.NewVBox(
widget.NewLabel("Hello Fyne!"),
newTappableIcon(theme.FyneLogo()),
fynewidget.NewOutputWidget(color.Black),
widget.NewButton("Quit", func() {
app.Quit()
}),

View File

@ -3,14 +3,15 @@ package main
import (
"fmt"
"log"
"time"
"strconv"
"math"
"os"
"strconv"
"time"
webserver "git.martyn.berlin/martyn/LEDController/internal/webserver"
patterns "git.martyn.berlin/martyn/LEDController/internal/patterns"
queue "git.martyn.berlin/martyn/LEDController/internal/queue"
remapping "git.martyn.berlin/martyn/LEDController/internal/remapping"
patterns "git.martyn.berlin/martyn/LEDController/internal/patterns"
webserver "git.martyn.berlin/martyn/LEDController/internal/webserver"
"github.com/Hundemeier/go-sacn/sacn"
)
@ -21,7 +22,7 @@ var currentFrame [2][512]byte
var channels [2]chan<- [512]byte
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)
func foreverLoop() {
@ -36,12 +37,14 @@ func foreverLoop() {
}
func reduceBrightness(universe [512]byte, percentage int) [512]byte {
for i := range(universe) {
for i := range universe {
universe[i] = byte(float64(universe[i]) * (float64(percentage) / float64(100)))
}
return universe
}
var universeCount int = 0
func main() {
go func() {
var err error
@ -70,6 +73,9 @@ func main() {
PanelHeight = 4
}
universeCount = int(math.Ceil(float64(PanelHeight*PanelWidth*3) / 510))
fmt.Printf("Universe count is %d", universeCount)
PanelBrightness, err := strconv.Atoi(os.Getenv("PANEL_BRIGHTNESS"))
if err != nil {
PanelBrightness = 100
@ -82,7 +88,7 @@ func main() {
}
//activates the universes
for i := 0; i < 2; i++ {
for i := 0; i < universeCount; i++ {
channels[i], err = trans.Activate(uint16(i + 1))
//deactivate the channel on exit
defer close(channels[i])
@ -91,9 +97,10 @@ func main() {
}
// Plasma for start frame
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])
/*rearranged := reduceBrightness(remapping.SliceRearrange(PanelWidth, PanelHeight, true, remapping.XYGridToLinear(PanelWidth, PanelHeight, patterns.PlasmaPanel(PanelWidth, PanelHeight, 40))), PanelBrightness)
for i := 0; i < universeCount; i++ {
currentFrame[i] = remapping.Slice512(rearranged[i])
}*/
var e queue.QueueItem
e.Effect = "red"
e.Duration = 40 * 50
@ -151,11 +158,12 @@ func main() {
}
//rearranged := remapping.SliceRearrange(PanelWidth,PanelHeight,true,linearPlasma(PanelWidth*PanelHeight))
sema <- struct{}{} // acquire token
currentFrame[0] = reduceBrightness(remapping.Slice512(rearranged[0]),PanelBrightness)
currentFrame[1] = reduceBrightness(remapping.Slice512(rearranged[1]),PanelBrightness)
for i := 0; i < universeCount; i++ {
currentFrame[i] = reduceBrightness(remapping.Slice512(rearranged[i]), PanelBrightness)
}
<-sema
time.Sleep(40 * time.Millisecond)
}
}()
foreverLoop();
foreverLoop()
}