diff --git a/client.go b/client.go index 8b3f4cf..c0f73bb 100644 --- a/client.go +++ b/client.go @@ -34,6 +34,10 @@ func (b *Barnard) start() { b.connect(false) } +func (b *Barnard) toneTestAutoTransmit() bool { + return b.ToneTest && b.AutoTransmit +} + func (b *Barnard) exitWithError(err error) { b.Ui.Close() b.exitStatus = 1 @@ -66,15 +70,14 @@ func (b *Barnard) connect(reconnect bool) bool { b.toneTestSaver = saver b.Client.Config.AttachAudio(saver) - b.toneTestStop = make(chan struct{}) - go StartToneGenerator(b.Client, b.toneTestStop) - b.Tx = true - // Tone mode starts transmitting immediately. Reflect that in the UI so - // the F8 toggle has a visible initial state and transition. - b.UpdateGeneralStatus(" Tx ", true) - b.AddOutputLine("Tone test transmission started") - b.Connected = true + if b.toneTestAutoTransmit() { + b.toneTestStop = make(chan struct{}) + go StartToneGenerator(b.Client, b.toneTestStop) + b.Tx = true + b.UpdateGeneralStatus(" Tx ", true) + b.AddOutputLine("Tone test transmission started") + } return true } diff --git a/tonetest_test.go b/tonetest_test.go index bf42ff2..7e5fcd2 100644 --- a/tonetest_test.go +++ b/tonetest_test.go @@ -7,6 +7,17 @@ import ( // Regression: tone transmission was started before opening its output file, // so a creation error left audio transmission running without cleanup. +// Regression: tone test transmitted immediately, preventing the configured +// talk key from controlling it. +func TestToneTestRequiresAutoTransmit(t *testing.T) { + if (&Barnard{ToneTest: true}).toneTestAutoTransmit() { + t.Fatal("tone test started without auto-transmit") + } + if !(&Barnard{ToneTest: true, AutoTransmit: true}).toneTestAutoTransmit() { + t.Fatal("tone test did not auto-transmit") + } +} + func TestNewAudioFileSaverReportsUnavailableOutputPath(t *testing.T) { path := filepath.Join(t.TempDir(), "missing", "tone.pcm") if saver, err := NewAudioFileSaver(path); err == nil || saver != nil {