Skip to content

Commit

Permalink
make sure vfo events triggered by a refresh are actually emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed Jul 26, 2023
1 parent a713ff0 commit 436e81e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions core/hamlib/hamlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ func (c *Client) SetMode(mode core.Mode) {

func (c *Client) Refresh() {
if c.incoming.frequency != 0 {
log.Printf("Refreshing VFO frequency")
log.Printf("Refreshing VFO frequency: %f", c.incoming.frequency)
c.emitFrequencyChanged(c.incoming.frequency)
}
if c.incoming.band != core.NoBand {
log.Printf("Refreshing VFO band")
log.Printf("Refreshing VFO band: %s", c.incoming.band)
c.emitBandChanged(c.incoming.band)
}
if c.incoming.mode != core.NoMode {
log.Printf("Refreshing VFO mode")
log.Printf("Refreshing VFO mode: %s", c.incoming.mode)
c.emitModeChanged(c.incoming.mode)
}
}
Expand Down Expand Up @@ -318,6 +318,7 @@ func (c *Client) emitFrequencyChanged(f core.Frequency) {
func (c *Client) emitBandChanged(b core.Band) {
for _, listener := range c.listeners {
if bandListener, ok := listener.(core.VFOBandListener); ok {
log.Printf("triggering band change on %T", bandListener)
bandListener.VFOBandChanged(b)
}
}
Expand Down
7 changes: 5 additions & 2 deletions core/vfo/vfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type VFO struct {
bandplan bandplan.Bandplan
client Client
offlineClient *offlineClient
refreshing bool

listeners []any
}
Expand Down Expand Up @@ -59,11 +60,13 @@ func (v *VFO) online() bool {
}

func (v *VFO) Refresh() {
v.refreshing = true
if !v.online() {
v.offlineClient.Refresh()
return
}
v.client.Refresh()
v.refreshing = false
}

func (v *VFO) SetFrequency(frequency core.Frequency) {
Expand Down Expand Up @@ -220,8 +223,8 @@ func (c *offlineClient) SetBand(band core.Band) {
return
}
newBand := core.Band(plan.Name)
if newBand == c.currentBand {
// log.Printf("Band %s already selected!", band)
if newBand == c.currentBand && !c.vfo.refreshing {
log.Printf("Band %s already selected!", band)
return
}

Expand Down

0 comments on commit 436e81e

Please sign in to comment.