Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buzzer #13

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/cammie.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"fmt"
"net/http"
"scc/buzzer"
"scc/config"
"scc/screen"
"slices"
Expand Down Expand Up @@ -77,6 +78,7 @@ func cammiePostMessage(app *screen.ScreenApp, c *gin.Context) {
cammieMessages++

app.Cammie.Update(newMessage)
go buzzer.PlayBuzzer()

c.JSON(http.StatusOK, gin.H{"message": "Message received"})
}
48 changes: 48 additions & 0 deletions buzzer/buzzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package buzzer

import (
"log"
"scc/config"

"github.com/a-h/beeper"
"github.com/stianeikeland/go-rpio"
)

var buzzerOptions = map[string]func(rpio.Pin){
"default": playMusic,
}

func PlayBuzzer() {
err := rpio.Open()
if err != nil {
log.Printf("Error: Unable to open pin: %s", err)
return
}
defer rpio.Close()

pin := rpio.Pin(config.GetConfig().Buzzer.Pin)

buzzerSong := config.GetConfig().Buzzer.Song
val, ok := buzzerOptions[buzzerSong]
if !ok {
log.Printf("Error: Selected buzzer song: %s does not exist\n", buzzerSong)
return
}

val(pin)
}

func playMusic(pin rpio.Pin) {
bpm := 300
music := beeper.NewMusic(pin, bpm)

music.Note("A5", beeper.Quaver)
music.Note("B5", beeper.Quaver)
music.Note("D5", beeper.Quaver)
music.Note("B5", beeper.Quaver)
music.Note("E5", beeper.Crotchet)
music.Note("E5", beeper.Crotchet)
music.Note("D5", beeper.Quaver)
music.Note("C#5", beeper.Quaver)
music.Note("B4", beeper.Quaver)
}
30 changes: 30 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cammie:
blocked_names:
- Name 1
- Name 2
blocked_ips:
- 10.0.0.10
max_message_length: 200
buzzer:
pin: 12
song: default
spotify:
client_id: abcd
client_secret: dcba
tap:
url: "https://tap.zeus.gent/recent"
beer:
- Schelfaut
- Duvel
- Fourchette
- Jupiler
- Karmeliet
- Kriek
- Chouffe
- Maes
- Somersby
- Sportzot
- Stella
zess:
url: "https://zess.zeus.gent/recent_scans"
day_amount: 40
27 changes: 0 additions & 27 deletions config.example.yml

This file was deleted.

3 changes: 3 additions & 0 deletions config.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ cammie:
blocked_names: [] # List of names that don't get shown
blocked_ips: [] # List of IP's that don't get shown
max_message_length: # Max message list
buzzer:
pin: # PWM pin used by the buzzer
song: # Options are - default
spotify:
client_id: # Client ID of the Zeus spotify account
client_secret: # Client secret of the Zeus spotify account
Expand Down
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ type cammieConfig struct {
MaxMessageLength int `yaml:"max_message_length"`
}

type buzzerConfig struct {
Pin int `yaml:"pin"`
Song string `yaml:"song"`
}

type spotifyConfig struct {
ClientID string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
Expand All @@ -31,6 +36,7 @@ type zessConfig struct {

type Config struct {
Cammie cammieConfig `yaml:"cammie"`
Buzzer buzzerConfig `yaml:"buzzer"`
Spotify spotifyConfig `yaml:"spotify"`
Tap tapConfig `yaml:"tap"`
Zess zessConfig `yaml:"zess"`
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
)

require (
github.com/a-h/beeper v0.0.0-20190929170045-fc4b1a97b0b2
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
Expand All @@ -30,6 +31,7 @@ require (
github.com/navidys/tvxwidgets v0.7.0
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/stianeikeland/go-rpio v4.2.0+incompatible
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/a-h/beeper v0.0.0-20190929170045-fc4b1a97b0b2 h1:QXbKN2ADvvIPBw0RA5TT61Uk50vHxXflk2bDtWKD3zI=
github.com/a-h/beeper v0.0.0-20190929170045-fc4b1a97b0b2/go.mod h1:DxLcR2/OjZbhGzSvGfrtm6Kfij2L+mYFnw3YuxGcee4=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
Expand Down Expand Up @@ -70,6 +72,8 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/stianeikeland/go-rpio v4.2.0+incompatible h1:CUOlIxdJdT+H1obJPsmg8byu7jMSECLfAN9zynm5QGo=
github.com/stianeikeland/go-rpio v4.2.0+incompatible/go.mod h1:Sh81rdJwD96E2wja2Gd7rrKM+XZ9LrwvN2w4IXrqLR8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
Loading