diff --git a/civcontrol.go b/civcontrol.go index 0941234..abdcf4f 100644 --- a/civcontrol.go +++ b/civcontrol.go @@ -6,7 +6,6 @@ import ( ) const civAddress = 0xa4 -const vdReadInterval = time.Minute type civOperatingMode struct { name string @@ -62,8 +61,7 @@ var civBands = []civBand{ } type civControlStruct struct { - st *serialStream - vdReadTimer *time.Timer + st *serialStream state struct { freq uint @@ -211,7 +209,10 @@ func (s *civControlStruct) decodeTransmitStatus(d []byte) { if d[1] == 1 { s.state.ptt = true } else { - s.state.ptt = false + if s.state.ptt { // PTT released? + s.state.ptt = false + _ = s.getVd() + } } case 1: if d[1] == 2 { @@ -222,7 +223,10 @@ func (s *civControlStruct) decodeTransmitStatus(d []byte) { _ = s.getTransmitStatus() }) } else { - s.state.tune = false + if s.state.tune { // Tune finished? + s.state.tune = false + _ = s.getVd() + } } } statusLog.reportPTT(s.state.ptt, s.state.tune) @@ -239,9 +243,6 @@ func (s *civControlStruct) decodeVd(d []byte) { return } statusLog.reportVd(((float64(int(d[1])<<8) + float64(d[2])) / 0x0241) * 16) - s.vdReadTimer = time.AfterFunc(vdReadInterval, func() { - _ = s.getVd() - }) } } @@ -480,10 +481,3 @@ func (s *civControlStruct) init(st *serialStream) error { } return nil } - -func (s *civControlStruct) deinit() { - if s.vdReadTimer != nil { - s.vdReadTimer.Stop() - s.vdReadTimer = nil - } -} diff --git a/serialstream.go b/serialstream.go index 2a0a7dc..5ce4806 100644 --- a/serialstream.go +++ b/serialstream.go @@ -270,9 +270,6 @@ func (s *serialStream) deinit() { s.deinitNeededChan <- true <-s.deinitFinishedChan } - if civControl != nil { - civControl.deinit() - } civControl = nil s.common.deinit() s.rxSeqBuf.deinit()