diff --git a/README.md b/README.md index 47c77b3..52f7258 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ Some basic CAT control hotkeys are also supported: - `v`, `b`: cycles through bands - `p`: toggles preamp - `a`: toggles AGC +- `o`: toggles VFO A/B ## Icom IC-705 Wi-Fi notes diff --git a/civcontrol.go b/civcontrol.go index 881622a..c2059fd 100644 --- a/civcontrol.go +++ b/civcontrol.go @@ -97,6 +97,7 @@ type civControlStruct struct { setAGCSent bool setNREnabledSent bool setTSSent bool + setVFOSent bool freq uint ptt bool @@ -115,6 +116,7 @@ type civControlStruct struct { agc int tsValue byte ts uint + vfoBActive bool } } @@ -141,6 +143,8 @@ func (s *civControlStruct) decode(d []byte) bool { return s.decodeFreq(payload) case 0x06: return s.decodeMode(payload) + case 0x07: + return s.decodeVFO(payload) case 0x10: return s.decodeTS(payload) case 0x1a: @@ -237,6 +241,29 @@ func (s *civControlStruct) decodeMode(d []byte) bool { return true } +func (s *civControlStruct) decodeVFO(d []byte) bool { + if len(d) < 1 { + return !s.state.setVFOSent + } + + if d[0] == 1 { + s.state.vfoBActive = true + log.Print("active vfo: B") + } else { + s.state.vfoBActive = false + log.Print("active vfo: A") + } + + if s.state.setVFOSent { + // The radio does not send the VFO's frequency automatically. + _ = s.getFreq() + + s.state.setVFOSent = false + return false + } + return true +} + func (s *civControlStruct) decodeTS(d []byte) bool { if len(d) < 1 { return !s.state.setTSSent @@ -820,6 +847,15 @@ func (s *civControlStruct) decTS() error { return s.st.send([]byte{254, 254, civAddress, 224, 0x10, b, 253}) } +func (s *civControlStruct) toggleVFO() error { + s.state.setVFOSent = true + var b byte + if !s.state.vfoBActive { + b = 1 + } + return s.st.send([]byte{254, 254, civAddress, 224, 0x07, b, 253}) +} + func (s *civControlStruct) getFreq() error { s.state.getFreqSent = true return s.st.send([]byte{254, 254, civAddress, 224, 3, 253}) diff --git a/hotkeys.go b/hotkeys.go index cb4320a..15fc445 100644 --- a/hotkeys.go +++ b/hotkeys.go @@ -212,6 +212,12 @@ func handleHotkey(k byte) { log.Error("can't change agc: ", err) } } + case 'o': + if civControl != nil { + if err := civControl.toggleVFO(); err != nil { + log.Error("can't change vfo: ", err) + } + } case '\n': if statusLog.isRealtime() { statusLog.mutex.Lock()