fix: Flex with multiple slices opened was always showing slice A s-meter.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -75,6 +76,20 @@ type Client struct {
|
||||
pendingDir int
|
||||
pendingDirAt time.Time
|
||||
pendingDirSet bool
|
||||
|
||||
// lastSetKHz is the frequency we last COMMANDED. Used as the follow-loop
|
||||
// deadband reference when the antenna's own status hasn't reported a frequency
|
||||
// yet (Frequency==0) — otherwise the deadband is bypassed and every small QSY
|
||||
// re-tunes the motors.
|
||||
lastSetKHz int
|
||||
}
|
||||
|
||||
// LastSetKHz returns the frequency (kHz) most recently commanded to the antenna,
|
||||
// or 0 if none yet.
|
||||
func (c *Client) LastSetKHz() int {
|
||||
c.statusMu.RLock()
|
||||
defer c.statusMu.RUnlock()
|
||||
return c.lastSetKHz
|
||||
}
|
||||
|
||||
type Status struct {
|
||||
@@ -457,6 +472,15 @@ func (c *Client) queryProgress() ([]int, error) {
|
||||
|
||||
// SetFrequency changes frequency and optional direction (command 3)
|
||||
func (c *Client) SetFrequency(freqKhz int, direction int) error {
|
||||
// Trace WHO asked for the change — the caller's function + line — so an
|
||||
// unexpected antenna QSY (e.g. jumping to 14.074 while on 40m) can be traced
|
||||
// to the follow loop, an immediate re-tune, or a direction re-issue.
|
||||
caller := "?"
|
||||
if pc, _, line, ok := runtime.Caller(1); ok {
|
||||
caller = fmt.Sprintf("%s:%d", runtime.FuncForPC(pc).Name(), line)
|
||||
}
|
||||
log.Printf("Ultrabeam: SetFrequency(%d kHz, dir %d) ← %s", freqKhz, direction, caller)
|
||||
|
||||
data := []byte{
|
||||
byte(freqKhz & 0xFF),
|
||||
byte((freqKhz >> 8) & 0xFF),
|
||||
@@ -467,6 +491,7 @@ func (c *Client) SetFrequency(freqKhz int, direction int) error {
|
||||
if err == nil {
|
||||
c.statusMu.Lock()
|
||||
c.pendingDir, c.pendingDirAt, c.pendingDirSet = direction, time.Now(), true
|
||||
c.lastSetKHz = freqKhz
|
||||
if c.lastStatus != nil {
|
||||
c.lastStatus.Direction = direction // reflect immediately
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user