From ec8580c01e3c2a19c73d92326d01ed069afc4c42 Mon Sep 17 00:00:00 2001 From: Jonas Meeuws Date: Thu, 10 Oct 2024 23:44:48 +0200 Subject: [PATCH] Move SCC to koin: use beep command instead of gpio PWM --- buzzer/buzzer.go | 51 +++++++++++++++++++++--------------------------- config/config.go | 1 - restart.sh | 8 +++----- run-forever.sh | 6 ++++-- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/buzzer/buzzer.go b/buzzer/buzzer.go index ffb2299..9fb9a3e 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", "-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) + } } 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