From 2c3b14e2d068d4403c6bd0d71c555cad089ec4ca Mon Sep 17 00:00:00 2001 From: PianetaRadio <78976006+PianetaRadio@users.noreply.github.com> Date: Fri, 10 Feb 2023 19:52:33 +0100 Subject: [PATCH] Power status #36 --- ChangeLog.txt | 2 +- mainwindow.cpp | 28 +++++++++++++++++++--------- rigdaemon.cpp | 8 ++++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index f21807f..a8940b8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,7 +5,7 @@ CatRadio 1.4.0 - 2023-mm-dd + Meter peak hold indicator + Debug mode - * Power status improvement + * Bug fix: Power status * Bug fix: COM port list * Updated to library Hamlib 4.5.4 diff --git a/mainwindow.cpp b/mainwindow.cpp index 698b5b6..0537f92 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -377,7 +377,12 @@ void MainWindow::guiInit() void MainWindow::guiUpdate() { //* Power button - if (rigGet.onoff == RIG_POWER_ON || rigGet.onoff == RIG_POWER_UNKNOWN) ui->pushButton_Power->setChecked(true); + if (rigGet.onoff == RIG_POWER_ON) ui->pushButton_Power->setChecked(true); + else if (rigGet.onoff == RIG_POWER_OFF) + { + if(timer->isActive()) timer->stop(); + ui->pushButton_Power->setChecked(false); + } //* VFOs if (!rigCmd.freqMain) ui->lineEdit_vfoMain->setValue(rigGet.freqMain); @@ -742,7 +747,11 @@ void MainWindow::on_pushButton_Connect_toggled(bool checked) { freq_t retfreq; retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &retfreq); //double check if rig is on by getting the current frequency - if (retcode == RIG_OK) timer->start(rigCom.rigRefresh); + if (retcode == RIG_OK) + { + rigGet.onoff = RIG_POWER_ON; //force it for rigCap.onoff = 0 || rigGet.onoff = RIG_POWER_UNKNOWN + timer->start(rigCom.rigRefresh); + } else rigGet.onoff = RIG_POWER_OFF; } } @@ -750,7 +759,7 @@ void MainWindow::on_pushButton_Connect_toggled(bool checked) else if (rigCom.connected) //Button unchecked { rigCom.connected = 0; - timer->stop(); + if(timer->isActive()) timer->stop(); rig_close(my_rig); //Close the communication to the rig connectMsg = "Disconnected"; //rig_cleanup(my_rig); //Release rig handle and free associated memory @@ -773,12 +782,13 @@ void MainWindow::on_pushButton_Power_toggled(bool checked) } else if (!checked && rigGet.onoff) { - retcode = rig_set_powerstat(my_rig, RIG_POWER_OFF); - if (retcode == RIG_OK) - { - ui->pushButton_Power->setChecked(false); //Uncheck the button - timer->stop(); - } + rigCmd.onoff = 1; + //retcode = rig_set_powerstat(my_rig, RIG_POWER_OFF); + //if (retcode == RIG_OK) + //{ + // ui->pushButton_Power->setChecked(false); //Uncheck the button + // timer->stop(); + //} } } diff --git a/rigdaemon.cpp b/rigdaemon.cpp index 4712632..651d8d7 100644 --- a/rigdaemon.cpp +++ b/rigdaemon.cpp @@ -159,6 +159,14 @@ void RigDaemon::rigUpdate(RIG *my_rig) //***** Command execution ***** if (!rigGet.ptt && !rigSet.ptt) { + //* Power off + if (rigCmd.onoff && rigCap.onoff) + { + retcode = rig_set_powerstat(my_rig, RIG_POWER_OFF); + if (retcode == RIG_OK) rigGet.onoff = RIG_POWER_OFF; + } + rigCmd.onoff = 0; + //* Mode if (rigCmd.mode && rigSet.mode != RIG_MODE_NONE) //VFO Main {