Skip to content

Commit

Permalink
Merge pull request #30 from ZeusWPI/move-to-koin
Browse files Browse the repository at this point in the history
Move SCC to koin: use beep command instead of gpio PWM
  • Loading branch information
Reavershark authored Oct 10, 2024
2 parents 7c326fa + ec8580c commit ef31ebd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 37 deletions.
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

0 comments on commit ef31ebd

Please sign in to comment.