Add display/adjustment of the squelch level

This commit is contained in:
Nonoo 2020-11-04 09:47:41 +01:00
parent c5dd923897
commit 1935b7bf24
4 changed files with 63 additions and 3 deletions

View file

@ -88,6 +88,7 @@ is up) with the following info:
- `S meter`: periodically refreshed S meter value, OVF is displayed on
overflow
- `rfg`: RF gain in percent
- `sql`: squelch level in percent
- Second status bar line:
- `state`: RX/TX/TUNE depending on the PTT status
@ -143,6 +144,7 @@ Some basic CAT control hotkeys are also supported:
- `[`, `]`: decreases, increases frequency
- `{`, `}`: decreases, increases tuning step
- `;`, `'`: decreases, increases RF gain
- `,`, `.`: decreases, increases squelch level
- `n`, `m`: cycles through operating modes
- `d`, `f`: cycles through filters
- `D`: toggles data mode

View file

@ -74,6 +74,7 @@ type civControlStruct struct {
tune bool
pwrPercent int
rfGainPercent int
sqlPercent int
operatingModeIdx int
filterIdx int
dataMode bool
@ -108,7 +109,7 @@ func (s *civControlStruct) decode(d []byte) {
case 0x1a:
s.decodeDataModeAndOVF(payload)
case 0x14:
s.decodePowerAndRFGain(payload)
s.decodePowerRFGainSquelch(payload)
case 0x1c:
s.decodeTransmitStatus(payload)
case 0x15:
@ -250,7 +251,7 @@ func (s *civControlStruct) decodeDataModeAndOVF(d []byte) {
}
}
func (s *civControlStruct) decodePowerAndRFGain(d []byte) {
func (s *civControlStruct) decodePowerRFGainSquelch(d []byte) {
if len(d) < 3 {
return
}
@ -260,6 +261,10 @@ func (s *civControlStruct) decodePowerAndRFGain(d []byte) {
hex := uint16(d[1])<<8 | uint16(d[2])
s.state.rfGainPercent = int(math.Round((float64(hex) / 0x0255) * 100))
statusLog.reportRFGain(s.state.rfGainPercent)
case 0x03:
hex := uint16(d[1])<<8 | uint16(d[2])
s.state.sqlPercent = int(math.Round((float64(hex) / 0x0255) * 100))
statusLog.reportSQL(s.state.sqlPercent)
case 0x0a:
hex := uint16(d[1])<<8 | uint16(d[2])
s.state.pwrPercent = int(math.Round((float64(hex) / 0x0255) * 100))
@ -393,6 +398,25 @@ func (s *civControlStruct) decRFGain() error {
return nil
}
func (s *civControlStruct) setSQL(percent int) error {
v := uint16(0x0255 * (float64(percent) / 100))
return s.st.send([]byte{254, 254, civAddress, 224, 0x14, 0x03, byte(v >> 8), byte(v & 0xff), 253})
}
func (s *civControlStruct) incSQL() error {
if s.state.sqlPercent < 100 {
return s.setSQL(s.state.sqlPercent + 1)
}
return nil
}
func (s *civControlStruct) decSQL() error {
if s.state.sqlPercent > 0 {
return s.setSQL(s.state.sqlPercent - 1)
}
return nil
}
func (s *civControlStruct) getDigit(v uint, n int) byte {
f := float64(v)
for n > 0 {
@ -605,6 +629,10 @@ func (s *civControlStruct) getRFGain() error {
return s.st.send([]byte{254, 254, civAddress, 224, 0x14, 0x02, 253})
}
func (s *civControlStruct) getSQL() error {
return s.st.send([]byte{254, 254, civAddress, 224, 0x14, 0x03, 253})
}
func (s *civControlStruct) loop() {
for {
select {
@ -657,6 +685,9 @@ func (s *civControlStruct) init(st *serialStream) error {
if err := s.getRFGain(); err != nil {
return err
}
if err := s.getSQL(); err != nil {
return err
}
s.deinitNeeded = make(chan bool)
s.deinitFinished = make(chan bool)

View file

@ -36,6 +36,18 @@ func handleHotkey(k byte) {
log.Error("can't decrease rf gain: ", err)
}
}
case '.':
if civControl != nil {
if err := civControl.incSQL(); err != nil {
log.Error("can't increase sql: ", err)
}
}
case ',':
if civControl != nil {
if err := civControl.decSQL(); err != nil {
log.Error("can't decrease sql: ", err)
}
}
case ']':
if civControl != nil {
if err := civControl.incFreq(); err != nil {

View file

@ -24,6 +24,7 @@ type statusLogData struct {
vd string
txPower string
rfGain string
sql string
s string
ovf bool
ts string
@ -239,6 +240,16 @@ func (s *statusLogStruct) reportRFGain(percent int) {
s.data.rfGain = fmt.Sprint(percent, "%")
}
func (s *statusLogStruct) reportSQL(percent int) {
s.mutex.Lock()
defer s.mutex.Unlock()
if s.data == nil {
return
}
s.data.sql = fmt.Sprint(percent, "%")
}
func (s *statusLogStruct) clearInternal() {
fmt.Printf("%c[2K", 27)
}
@ -281,7 +292,11 @@ func (s *statusLogStruct) update() {
if s.data.rfGain != "" {
rfGainStr = " rfg " + s.data.rfGain
}
s.data.line1 = fmt.Sprint(s.data.s, ovfStr, rfGainStr)
var sqlStr string
if s.data.sql != "" {
sqlStr = " sql " + s.data.sql
}
s.data.line1 = fmt.Sprint(s.data.s, ovfStr, rfGainStr, sqlStr)
var tsStr string
if s.data.ts != "" {