77 "strconv"
88 "strings"
99 "text/template"
10+ "time"
1011
1112 "github.com/ftl/hamradio/callsign"
1213
@@ -32,6 +33,7 @@ type SettingsView interface {
3233 SetMacro (core.Workmode , int , string )
3334 SetPresetNames ([]string )
3435 SetPreset (string )
36+ SetParrotIntervalSeconds (int )
3537}
3638
3739// CWClient defines the interface used by the Keyer to output the CW.
@@ -53,10 +55,16 @@ type KeyerStoppedListener interface {
5355 KeyerStopped ()
5456}
5557
58+ type Parrot interface {
59+ KeyerStoppedListener
60+ SetInterval (time.Duration )
61+ }
62+
5663// New returns a new Keyer that has no patterns or templates defined yet.
5764func New (settings core.Settings , client CWClient , keyerSettings core.KeyerSettings , workmode core.Workmode , presets []core.KeyerPreset ) * Keyer {
5865 result := & Keyer {
5966 writer : new (nullWriter ),
67+ parrot : new (nullParrot ),
6068 stationCallsign : settings .Station ().Callsign ,
6169 workmode : workmode ,
6270 spLabels : make (map [int ]string ),
@@ -88,6 +96,7 @@ func presetNames(presets []core.KeyerPreset) []string {
8896
8997type Keyer struct {
9098 writer Writer
99+ parrot Parrot
91100 buttonView ButtonView
92101 settingsView SettingsView
93102 client CWClient
@@ -99,18 +108,19 @@ type Keyer struct {
99108
100109 listeners []any
101110
102- stationCallsign callsign.Callsign
103- workmode core.Workmode
104- wpm int
105- spLabels map [int ]string
106- spPatterns map [int ]string
107- spTemplates map [int ]* template.Template
108- runLabels map [int ]string
109- runPatterns map [int ]string
110- runTemplates map [int ]* template.Template
111- labels * map [int ]string
112- patterns * map [int ]string
113- templates * map [int ]* template.Template
111+ stationCallsign callsign.Callsign
112+ workmode core.Workmode
113+ wpm int
114+ parrotIntervalSeconds int
115+ spLabels map [int ]string
116+ spPatterns map [int ]string
117+ spTemplates map [int ]* template.Template
118+ runLabels map [int ]string
119+ runPatterns map [int ]string
120+ runTemplates map [int ]* template.Template
121+ labels * map [int ]string
122+ patterns * map [int ]string
123+ templates * map [int ]* template.Template
114124}
115125
116126func (k * Keyer ) setWorkmode (workmode core.Workmode ) {
@@ -135,6 +145,15 @@ func (k *Keyer) SetWriter(writer Writer) {
135145 k .writer = writer
136146}
137147
148+ func (k * Keyer ) SetParrot (parrot Parrot ) {
149+ if parrot == nil {
150+ k .parrot = new (nullParrot )
151+ return
152+ }
153+ k .parrot = parrot
154+ k .parrot .SetInterval (time .Duration (k .parrotIntervalSeconds ) * time .Second )
155+ }
156+
138157func (k * Keyer ) SetSettings (settings core.KeyerSettings ) {
139158 k .savedSettings = settings
140159
@@ -167,6 +186,9 @@ func (k *Keyer) SetSettings(settings core.KeyerSettings) {
167186 k .runTemplates [i ], _ = template .New ("" ).Parse (pattern )
168187 }
169188
189+ k .parrotIntervalSeconds = settings .ParrotIntervalSeconds
190+ k .parrot .SetInterval (time .Duration (k .parrotIntervalSeconds ) * time .Second )
191+
170192 k .showPatterns ()
171193 if k .buttonView != nil {
172194 k .buttonView .SetSpeed (k .wpm )
@@ -266,6 +288,7 @@ func (k *Keyer) showKeyerSettings() {
266288 for i , pattern := range k .runPatterns {
267289 k .settingsView .SetMacro (core .Run , i , pattern )
268290 }
291+ k .settingsView .SetParrotIntervalSeconds (k .parrotIntervalSeconds )
269292}
270293
271294func (k * Keyer ) WorkmodeChanged (workmode core.Workmode ) {
@@ -298,6 +321,7 @@ func (k *Keyer) KeyerSettings() core.KeyerSettings {
298321func (k * Keyer ) getKeyerSettings () (core.KeyerSettings , bool ) {
299322 var keyer core.KeyerSettings
300323 keyer .WPM = k .wpm
324+ keyer .ParrotIntervalSeconds = k .parrotIntervalSeconds
301325 keyer .SPLabels = make ([]string , len (k .spLabels ))
302326 for i := range keyer .SPLabels {
303327 label , ok := k .spLabels [i ]
@@ -351,12 +375,13 @@ func (k *Keyer) SelectPreset(name string) {
351375 k .settingsView .SetPreset (preset .Name )
352376
353377 settings := core.KeyerSettings {
354- WPM : k .savedSettings .WPM ,
355- Preset : name ,
356- SPLabels : make ([]string , len (preset .SPLabels )),
357- SPMacros : make ([]string , len (preset .SPMacros )),
358- RunLabels : make ([]string , len (preset .RunLabels )),
359- RunMacros : make ([]string , len (preset .RunMacros )),
378+ WPM : k .savedSettings .WPM ,
379+ ParrotIntervalSeconds : k .savedSettings .ParrotIntervalSeconds ,
380+ Preset : name ,
381+ SPLabels : make ([]string , len (preset .SPLabels )),
382+ SPMacros : make ([]string , len (preset .SPMacros )),
383+ RunLabels : make ([]string , len (preset .RunLabels )),
384+ RunMacros : make ([]string , len (preset .RunMacros )),
360385 }
361386 copy (settings .SPLabels , preset .SPLabels )
362387 copy (settings .SPMacros , preset .SPMacros )
@@ -372,6 +397,12 @@ func (k *Keyer) EnterSpeed(speed int) {
372397 k .client .Speed (k .wpm )
373398}
374399
400+ func (k * Keyer ) EnterParrotIntervalSeconds (interval int ) {
401+ log .Printf ("parrot interval entered: %d" , interval )
402+ k .parrotIntervalSeconds = interval
403+ k .parrot .SetInterval (time .Duration (k .parrotIntervalSeconds ) * time .Second )
404+ }
405+
375406func (k * Keyer ) EnterLabel (workmode core.Workmode , index int , text string ) {
376407 switch workmode {
377408 case core .SearchPounce :
@@ -514,6 +545,7 @@ func (k *Keyer) send(s string) {
514545func (k * Keyer ) Stop () {
515546 log .Println ("abort sending" )
516547 k .client .Abort ()
548+ k .parrot .KeyerStopped ()
517549 k .emitKeyerStopped ()
518550}
519551
@@ -567,7 +599,7 @@ func noValues() core.KeyerValues {
567599
568600type nullWriter struct {}
569601
570- func (w * nullWriter ) WriteKeyer (core.KeyerSettings ) error { return nil }
602+ func (* nullWriter ) WriteKeyer (core.KeyerSettings ) error { return nil }
571603
572604type nullClient struct {}
573605
@@ -576,3 +608,8 @@ func (*nullClient) IsConnected() bool { return true }
576608func (* nullClient ) Speed (int ) {}
577609func (* nullClient ) Send (text string ) {}
578610func (* nullClient ) Abort () {}
611+
612+ type nullParrot struct {}
613+
614+ func (* nullParrot ) KeyerStopped () {}
615+ func (* nullParrot ) SetInterval (time.Duration ) {}
0 commit comments