Skip to content

Commit

Permalink
burning man 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
cacktopus committed Oct 11, 2022
1 parent c2c4306 commit 993246c
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 49 deletions.
2 changes: 1 addition & 1 deletion arm/Dockerfile.build-arm64
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update -y
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y wget dpkg-dev

RUN arch=`dpkg-architecture -q DEB_BUILD_ARCH` && \
wget https://theheads.sfo2.digitaloceanspaces.com/builds/opencv_4.5.5-2_${arch}.deb
wget https://theheads.sfo2.digitaloceanspaces.com/shared/builds/arm64/opencv_4.5.5-2_${arch}.deb

RUN DEBIAN_FRONTEND=noninteractive apt-get install -y ./opencv_4.5.5-2_*.deb
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y ffmpeg
Expand Down
2 changes: 1 addition & 1 deletion arm/Dockerfile.build-armhf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update -y
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y wget dpkg-dev

RUN arch=`dpkg-architecture -q DEB_BUILD_ARCH`; \
wget https://theheads.sfo2.digitaloceanspaces.com/builds/opencv_4.5.5-2_${arch}.deb
wget https://theheads.sfo2.digitaloceanspaces.com/shared/builds/armhf/opencv_4.5.5-2_${arch}.deb

RUN echo '16a9489dde466c101e65cd0f91d664a83d496392e3b879ade607c2c038041666 opencv_4.5.5-2_armhf.deb' | shasum -c

Expand Down
3 changes: 3 additions & 0 deletions boss/app/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ type Cfg struct {
DayDetector []string `envconfig:"default=time-based;7h30m;20h15m"`

Debug bool `envconfig:"optional"`

CheckInTime time.Duration `envconfig:"default=500ms"`
FearfulCount int `envconfig:"default=3"`
}
2 changes: 2 additions & 0 deletions boss/dj/dj.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func NewDJ(
FloodlightController: boss.FloodlightControl,

interrupted: atomic.NewString(""),

Boss: boss,
}
}

Expand Down
21 changes: 20 additions & 1 deletion boss/head_manager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ func (h *HeadManager) Say(
}
}

func (h *HeadManager) SetVolume(
ctx context.Context,
logger *zap.Logger,
headURI string,
) {
conn, err := h.GetConn(headURI)
if err != nil {
logger.Error("error fetching head connection", zap.Error(err))
} else {
client := gen.NewVoicesClient(conn.Conn)
_, err = client.SetVolume(ctx, &gen.SetVolumeIn{VolDb: -1})
if err != nil {
logger.Error("error setting volume", zap.Error(err))
}
}
}

func (h *HeadManager) SayRandom(ctx context.Context, headURI string) error {
conn, err := h.GetConn(headURI)
if err != nil {
Expand All @@ -84,11 +101,13 @@ func (h *HeadManager) SayRandom(ctx context.Context, headURI string) error {

func (h *HeadManager) SetLedsAnimation(
ctx context.Context,
logger *zap.Logger,
parentLogger *zap.Logger,
uri string,
animationName string,
startTime time.Time,
) {
logger := parentLogger.With(zap.String("uri", uri))

conn, err := h.GetConn(uri)
if err != nil {
logger.Error("error fetching head connection", zap.Error(err))
Expand Down
3 changes: 2 additions & 1 deletion boss/head_manager/head_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (h *HeadManager) CheckIn(
ctx context.Context,
logger *zap.Logger,
sc *scene.Scene,
timeout time.Duration,
) {
logger.Info("checkin")
t0 := time.Now()
Expand All @@ -83,7 +84,7 @@ func (h *HeadManager) CheckIn(

found := make(chan *Connection)

ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()

remaining := map[string]bool{}
Expand Down
8 changes: 7 additions & 1 deletion boss/scenes/find_zeros/find_zeros.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import (
func FindZeros(sp *dj.SceneParams) {
sp.DJ.Scene.ClearFearful()

sp.DJ.HeadManager.CheckIn(sp.Ctx, sp.Logger, sp.DJ.Scene)
sp.DJ.HeadManager.CheckIn(
sp.Ctx,
sp.Logger,
sp.DJ.Scene,
sp.DJ.Boss.Env.CheckInTime,
)

scenes.SceneSetup(sp, "rainbow")

go setupFloodLights(sp)
go setVolume(sp)
go findHeadZeros(sp)

<-sp.Done.Chan()
Expand Down
12 changes: 12 additions & 0 deletions boss/scenes/find_zeros/floodlights.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ func setupFloodLights(sp *dj.SceneParams) {
go setupFloodLight(newSp, cameraURI, sp.DJ.FloodlightController())
}
}

func setVolume(sp *dj.SceneParams) {
for _, h := range sp.DJ.Scene.Heads {
uri := h.URI()
logger := sp.Logger.With(zap.String("uri", uri))
go sp.DJ.HeadManager.SetVolume(
sp.Ctx,
logger,
uri,
)
}
}
2 changes: 1 addition & 1 deletion boss/scenes/follow_convo/follow_convo.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (f *FollowConvo) Run(sp *dj.SceneParams) {
f.setup(sp.DJ)

//go f.interruptScene(sp, randomlyInterrupt())
go f.interruptScene(sp, fearfulInterrupt(sp, 1, 90*time.Second))
go f.interruptScene(sp, fearfulInterrupt(sp, sp.DJ.Boss.Env.FearfulCount, 90*time.Second))

scenes.SceneSetup(sp, "rainbow")

Expand Down
6 changes: 5 additions & 1 deletion cmd/leds/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package main

import (
"github.com/cacktopus/theheads/common/dotenv"
"github.com/cacktopus/theheads/common/util"
"github.com/cacktopus/theheads/leds"
"go.uber.org/zap"
)

func main() {
logger, _ := zap.NewProduction()
logger, _ := util.NewLogger(false)

dotenv.EnvOverrideFromFile(logger, "/boot/leds.env")

err := leds.Run(logger)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/set-system-time/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
}

fmt.Println("setting system time:", t.String())
err = util.SetTime(util.TimeToFloat64(t))
err = util.SetTime(t)
if err != nil {
fmt.Println("error setting system time:", err.Error())
return
Expand Down
25 changes: 24 additions & 1 deletion common/dotenv/dotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ package dotenv
import (
"bufio"
"github.com/pkg/errors"
"go.uber.org/zap"
"io/ioutil"
"os"
"strings"
)

func SetEnvFromContent(content string) error {
return setEnvFromContent(content, false)
}

func setEnvFromContent(content string, override bool) error {
env := ParseEnvFromContent(content)

for key, value := range env {
_, present := os.LookupEnv(key)
if present {
if present && !override {
continue
}

Expand Down Expand Up @@ -50,3 +56,20 @@ func ParseEnvFromContent(content string) map[string]string {

return env
}

func EnvOverrideFromFile(parentLogger *zap.Logger, filename string) {
logger := parentLogger.With(zap.String("filename", filename))
content, err := ioutil.ReadFile(filename)
if err != nil {
logger.Info("unable to load env override", zap.Error(err))
return
}

err = setEnvFromContent(string(content), true)
if err != nil {
logger.Error("error setting env override", zap.Error(err))
return
}

logger.Info("set env override")
}
62 changes: 62 additions & 0 deletions layout/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"fmt"
"io/ioutil"
"math"
"os"
)

func Radians(degrees float64) float64 {
return degrees * math.Pi / 180
}

func Degrees(radians float64) float64 {
return radians * 180 / math.Pi
}

func cmToFeet(x float64) float64 {
return x / 12 / 2.54
}

var headPos = []int{4, 3, 1, 7, 8, 2, 5, 6, 9}

var tmpl = `
cameras: [ camera-%02d ]
heads: [ head-%02d ]
name: stand-%02d
pos: { x: %2f, y: %2f }
rot: -90
`

func main() {
const (
a = 1323.34 / 100
b = 121.92 / 100
thetaDegrees = 5.28
)

theta := Radians(thetaDegrees)

for i := -4; i <= 4; i++ {
phi := float64(i) * theta
x := a * math.Sin(phi)
y := -a + a*math.Cos(phi)

pos := headPos[i+4]

//fmt.Println(i, x, y, cmToFeet(x), cmToFeet(y))
stand := fmt.Sprintf(tmpl, pos, pos, pos, x, y)

outdir := os.ExpandEnv("$HOME/shared/theheads/scenes/hb2021/stands")

err := ioutil.WriteFile(outdir+fmt.Sprintf("/stand-%02d.yaml", pos), []byte(stand), 0o600)
noError(err)
}
}

func noError(err error) {
if err != nil {
panic(err)
}
}
2 changes: 2 additions & 0 deletions leds/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ type config struct {
}

Debug bool `envconfig:"default=false"`

ConfigFile string `envconfig:"default=/boot/leds-cfg.json"`
}
15 changes: 8 additions & 7 deletions leds/ir_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,32 @@ func runIR(app *App) {

switch event.Value {
case 48912: // 1
req.callback = app.animations["bounce"]
req.name = "bounce"
app.ch <- req
case 48913: // 2
req.callback = app.animations["rainbow1"]
req.name = "rainbow1"
app.ch <- req
case 48914: // 3
req.callback = app.animations["rainbow2"]
req.name = "rainbow2"
app.ch <- req

case 48916: // 4
req.callback = app.animations["raindrops"]
req.name = "raindrops"
app.ch <- req

case 48917: // 5
case 48918: // 6

case 48920: // 7
case 48921: // 8
req.callback = solidRandom(app)
app.ch <- req
//req.name = solidRandom(app)
//app.ch <- req
case 48922: // 9
req.callback = app.animations["white"]
req.name = "white"
app.ch <- req

case 48905: // enter/save
app.saveSettings()

case 48896: // vol-
app.strip.ScaleDown()
Expand Down
Loading

0 comments on commit 993246c

Please sign in to comment.