diff --git a/buzzer/buzzer.go b/buzzer/buzzer.go index ffb2299..d7adb97 100644 --- a/buzzer/buzzer.go +++ b/buzzer/buzzer.go @@ -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", "-f587", "-l100", "-d0", + "-n", "-f988", "-l100", "-d0", + "-n", "-f659", "-l200", "-d0", + "-n", "-f659", "-l200", "-d0", + "-n", "-f587", "-l100", "-d0", + "-n", "-f554", "-l100", "-d0", + "-n", "-f494", "-l100", "-d0", + ) + err := cmd.Run() + if err != nil { + log.Printf("Error running command 'beep': %s\n", err) + } } diff --git a/config/config.go b/config/config.go index 08a8849..f0262c4 100644 --- a/config/config.go +++ b/config/config.go @@ -15,7 +15,6 @@ type cammieConfig struct { } type buzzerConfig struct { - Pin int `yaml:"pin"` Song string `yaml:"song"` } diff --git a/restart.sh b/restart.sh index 220410f..d5f268d 100755 --- a/restart.sh +++ b/restart.sh @@ -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 diff --git a/run-forever.sh b/run-forever.sh index 22b0be8..593fbf1 100755 --- a/run-forever.sh +++ b/run-forever.sh @@ -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 \ No newline at end of file