diff --git a/internal/api/device_manager.go b/internal/api/device_manager.go index 714d918..35d31a3 100644 --- a/internal/api/device_manager.go +++ b/internal/api/device_manager.go @@ -36,11 +36,12 @@ type DeviceManager struct { stopChan chan struct{} // Auto frequency tracking - freqThreshold int // Threshold for triggering update (Hz) - autoTrackEnabled bool - ultrabeamDirection int // User-selected direction (0=normal, 1=180, 2=bi-dir) - lastFreqUpdateTime time.Time // Last time we sent frequency update - freqUpdateCooldown time.Duration // Minimum time between updates + freqThreshold int // Threshold for triggering update (Hz) + autoTrackEnabled bool + ultrabeamDirection int // User-selected direction (0=normal, 1=180, 2=bi-dir) + ultrabeamDirectionSet bool // True if user has explicitly set a direction + lastFreqUpdateTime time.Time // Last time we sent frequency update + freqUpdateCooldown time.Duration // Minimum time between updates } type SystemStatus struct { @@ -244,9 +245,9 @@ func (dm *DeviceManager) updateStatus() { if ubStatus, err := dm.ultrabeam.GetStatus(); err == nil { status.Ultrabeam = ubStatus - // Sync direction with Ultrabeam if not yet set (first time or after restart) + // Sync direction with Ultrabeam if user hasn't explicitly set one // This prevents auto-track from using wrong direction before user changes it - if dm.ultrabeamDirection == 0 && ubStatus.Direction != 0 { + if !dm.ultrabeamDirectionSet { dm.ultrabeamDirection = ubStatus.Direction log.Printf("Auto-track: Initialized direction from Ultrabeam: %d", dm.ultrabeamDirection) } @@ -281,9 +282,9 @@ func (dm *DeviceManager) updateStatus() { } if freqDiffHz >= dm.freqThreshold { - // Use current Ultrabeam direction if user hasn't explicitly set one + // Use user's explicitly set direction, or fallback to current Ultrabeam direction directionToUse := dm.ultrabeamDirection - if directionToUse == 0 && status.Ultrabeam.Direction != 0 { + if !dm.ultrabeamDirectionSet && status.Ultrabeam.Direction != 0 { directionToUse = status.Ultrabeam.Direction } @@ -375,5 +376,6 @@ func (dm *DeviceManager) SetAutoTrack(enabled bool, thresholdHz int) { func (dm *DeviceManager) SetUltrabeamDirection(direction int) { dm.ultrabeamDirection = direction - log.Printf("Ultrabeam direction set to: %d", direction) + dm.ultrabeamDirectionSet = true // Mark that user has explicitly set direction + log.Printf("Ultrabeam direction set to: %d (user choice)", direction) }