using System; using System.IO; using System.Threading.Tasks; using System.Windows.Forms; using NAudio.Wave; namespace RadioControllerApp { public class FormRadio : Form { private RadioController radioController; private WaveInEvent waveIn; private BufferedWaveProvider receivedAudioBuffer; private WaveOutEvent waveOut; private bool isRecording = false; // UI Controls private TextBox txtPortName; private Button btnOpenConnection; private Button btnCloseConnection; private Button btnInitialize; private TextBox txtTXFrequency; private TextBox txtRXFrequency; private TextBox txtTone; private TextBox txtSquelchLevel; private Button btnTune; private CheckBox chkEmphasis; private CheckBox chkHighpass; private CheckBox chkLowpass; private Button btnSetFilters; private Button btnStartRX; private Button btnStartTX; private Button btnEndTX; private Button btnStop; private Button btnStartRecording; private Button btnStopRecording; private Button btnPlayReceivedAudio; private TextBox txtStatus; public FormRadio() { InitializeComponent(); InitializeRadioController(); } private void InitializeComponent() { this.AutoScaleMode = AutoScaleMode.Dpi; // Enable DPI scaling // Form properties this.Text = "Radio Controller"; this.Size = new System.Drawing.Size(800, 700); this.MinimumSize = new System.Drawing.Size(600, 6 AppendStatus(message))); } else { txtStatus.AppendText($"{DateTime.Now}: {message}{Environment.NewLine}"); } } private void ToggleControls(bool isEnabled) { btnInitialize.Enabled = isEnabled; btnTune.Enabled = isEnabled; btnSetFilters.Enabled = isEnabled; btnStartRX.Enabled = isEnabled; btnStartTX.Enabled = isEnabled; btnEndTX.Enabled = isEnabled; btnStop.Enabled = isEnabled; btnStartRecording.Enabled = isEnabled; btnStopRecording.Enabled = isEnabled; btnPlayReceivedAudio.Enabled = isEnabled; // Disable connection buttons appropriately btnOpenConnection.Enabled = !isEnabled; btnCloseConnection.Enabled = isEnabled; } private void FormRadio_FormClosing(object sender, FormClosingEventArgs e) { // Clean up resources if (radioController != null) { radioController.Dispose(); radioController = null; } if (waveIn != null) { waveIn.Dispose(); waveIn = null; } if (waveOut != null) { waveOut.Dispose(); waveOut = null; } } } }