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

Move SCC to koin: use beep command instead of gpio PWM #30

Merged
merged 1 commit into from
Oct 10, 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
51 changes: 22 additions & 29 deletions buzzer/buzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,40 @@ package buzzer

import (
"log"
"os/exec"
"scc/config"

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

var buzzerOptions = map[string]func(rpio.Pin){
var buzzerOptions = map[string]func(){
"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]
fun, ok := buzzerOptions[buzzerSong]
if !ok {
log.Printf("Error: Selected buzzer song: %s does not exist\n", buzzerSong)
return
}

val(pin)
fun()
}

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)
func playMusic() {
// See 'man beep'
cmd := exec.Command(
"beep",
"-n", "-f880", "-l100", "-d0",
"-n", "-f988", "-l100", "-d0",
"-n", "-f588", "-l100", "-d0",
"-n", "-f989", "-l100", "-d0",
"-n", "-f660", "-l200", "-d0",
"-n", "-f660", "-l200", "-d0",
"-n", "-f588", "-l100", "-d0",
"-n", "-f555", "-l100", "-d0",
"-n", "-f495", "-l100", "-d0",
)
err := cmd.Run()
if err != nil {
log.Printf("Error running command 'beep': %s\n", err)
}
}
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type cammieConfig struct {
}

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

Expand Down
8 changes: 3 additions & 5 deletions restart.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/bin/bash
#!/usr/bin/env bash

git fetch
git pull
cd "$(dirname "${BASH_SOURCE[0]}")"

go mod tidy
echo "Building..."
go build .
go build

pkill scc
6 changes: 4 additions & 2 deletions run-forever.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash
#!/usr/bin/env bash

cd "$(dirname "${BASH_SOURCE[0]}")"

while true
do
./scc
PORT=8888 ./scc
echo 'scc has quit! restarting in 1 second'
sleep 1
done
Loading