From 98388a7ec8d737b3faf37c9747fc428290546b94 Mon Sep 17 00:00:00 2001 From: 3djc Date: Sat, 25 Mar 2017 13:04:33 +0100 Subject: [PATCH] Used rouding like arm radios (#4683) --- companion/src/eeprominterface.h | 5 +++++ companion/src/simulation/radiooutputswidget.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 0589e294a..5b59c62cf 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -368,6 +368,11 @@ inline int divRoundClosest(const int n, const int d) return ((n < 0) ^ (d < 0)) ? ((n - d/2)/d) : ((n + d/2)/d); } +inline int calcRESXto100(int x) +{ + return divRoundClosest(x*100, 1024); +} + #define CHECK_IN_ARRAY(T, index) ((unsigned int)index < DIM(T) ? T[(unsigned int)index] : "???") extern QList eepromInterfaces; diff --git a/companion/src/simulation/radiooutputswidget.cpp b/companion/src/simulation/radiooutputswidget.cpp index 1721fb358..a7b06e7b9 100644 --- a/companion/src/simulation/radiooutputswidget.cpp +++ b/companion/src/simulation/radiooutputswidget.cpp @@ -313,7 +313,7 @@ void RadioOutputsWidget::setValues() for (ch = m_channelsMap.constBegin(); ch != m_channelsMap.constEnd(); ++ch) { if (ch.key() >= CPN_MAX_CHNOUT) continue; - ch.value().first->setText(QString("%1%").arg((outputs.chans[ch.key()] * 100 + 512) / 1024)); + ch.value().first->setText(QString("%1%").arg(calcRESXto100(outputs.chans[ch.key()]))); ch.value().second->setValue(qMin(1024, qMax(-1024, outputs.chans[ch.key()]))); } }