LF: Support write LF config

When setting LF freq, the "lf config" and "hw setlfdivisor" will both be called.
Change some UI
pull/33/head
wh201906 4 years ago
parent 466cd0ecc1
commit 15538a9892

@ -1,5 +1,7 @@
#include "lf.h" #include "lf.h"
const LF::Config LF::defaultConfig;
LF::LF(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent) LF::LF(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent)
{ {
this->parent = parent; this->parent = parent;
@ -7,6 +9,7 @@ LF::LF(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent)
this->ui = ui; this->ui = ui;
configPattern = new QRegularExpression("(\\d+)|Yes|No"); configPattern = new QRegularExpression("(\\d+)|Yes|No");
currConfig = defaultConfig;
} }
void LF::read() void LF::read()
@ -43,7 +46,7 @@ void LF::tune()
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL) if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
util->execCMD("hw tune l"); util->execCMD("hw tune l");
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("lf tune"); // TODO: if freq is set, append it as a parameter util->execCMD("lf tune --divisor " + QString::number(currConfig.divisor));
Util::gotoRawTab(); Util::gotoRawTab();
} }
@ -108,9 +111,39 @@ void LF::getConfig()
syncWithUI(); syncWithUI();
} }
void LF::setConfig() void LF::setConfig(LF::Config config)
{ {
currConfig = config;
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
{
util->execCMDWithOutput(QString("lf config")
+ " q " + QString::number(currConfig.divisor)
+ " b " + QString::number(currConfig.bitPerSample)
+ " d " + QString::number(currConfig.decimation)
+ " a " + QString(currConfig.averaging ? "1" : "0")
+ " t " + QString::number(currConfig.triggerThreshold)
+ " s " + QString::number(currConfig.samplesToSkip),
500);
util->execCMDWithOutput("hw setlfdivisor " + QString::number(currConfig.divisor), 500);
}
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
{
util->execCMDWithOutput(QString("lf config")
+ " -a " + QString(currConfig.averaging ? "1" : "0")
+ " -b " + QString::number(currConfig.bitPerSample)
+ " --dec " + QString::number(currConfig.decimation)
+ " --divisor " + QString::number(currConfig.divisor)
+ " -s " + QString::number(currConfig.samplesToSkip)
+ " -t " + QString::number(currConfig.triggerThreshold),
500);
util->execCMDWithOutput("hw setlfdivisor -d " + QString::number(currConfig.divisor), 500);
}
}
void LF::resetConfig()
{
setConfig(defaultConfig);
getConfig();
} }
float LF::divisor2Freq(uint8_t divisor) float LF::divisor2Freq(uint8_t divisor)
@ -125,7 +158,7 @@ uint8_t LF::freq2Divisor(float freq)
void LF::syncWithUI() void LF::syncWithUI()
{ {
ui->LF_Conf_freqDivisorBox->setValue(currConfig.divisor); ui->LF_Conf_freqDivisorBox->setValue(currConfig.divisor); // will trigger valueChanged()
ui->LF_Conf_bitPerSampleBox->setValue(currConfig.bitPerSample); ui->LF_Conf_bitPerSampleBox->setValue(currConfig.bitPerSample);
ui->LF_Conf_decimationBox->setValue(currConfig.decimation); ui->LF_Conf_decimationBox->setValue(currConfig.decimation);
ui->LF_Conf_averagingBox->setChecked(currConfig.averaging); ui->LF_Conf_averagingBox->setChecked(currConfig.averaging);

@ -22,14 +22,26 @@ public:
uint16_t samplesToSkip; uint16_t samplesToSkip;
}; };
static constexpr Config defaultConfig =
{
95,
8,
1,
true,
0,
0
};
void read(); void read();
void sniff(); void sniff();
void search(); void search();
void tune(); void tune();
void getConfig(); void getConfig();
void setConfig(); void setConfig(LF::Config config);
void resetConfig();
static float divisor2Freq(uint8_t divisor); static float divisor2Freq(uint8_t divisor);
static uint8_t freq2Divisor(float freq); static uint8_t freq2Divisor(float freq);
private: private:
QWidget* parent; QWidget* parent;
Ui::MainWindow *ui; Ui::MainWindow *ui;

@ -1337,5 +1337,29 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
void MainWindow::on_LF_Conf_getButton_clicked() void MainWindow::on_LF_Conf_getButton_clicked()
{ {
setState(false);
lf->getConfig(); lf->getConfig();
setState(true);
}
void MainWindow::on_LF_Conf_setButton_clicked()
{
LF::Config config;
setState(false);
config.divisor = ui->LF_Conf_freqDivisorBox->value();
config.bitPerSample = ui->LF_Conf_bitPerSampleBox->value();
config.decimation = ui->LF_Conf_decimationBox->value();
config.averaging = ui->LF_Conf_averagingBox->isChecked();
config.triggerThreshold = ui->LF_Conf_thresholdBox->value();
config.samplesToSkip = ui->LF_Conf_skipsBox->value();
lf->setConfig(config);
Util::gotoRawTab();
setState(true);
}
void MainWindow::on_LF_Conf_resetButton_clicked()
{
setState(false);
lf->resetConfig();
setState(true);
} }

@ -199,6 +199,10 @@ private slots:
void on_LF_Conf_getButton_clicked(); void on_LF_Conf_getButton_clicked();
void on_LF_Conf_setButton_clicked();
void on_LF_Conf_resetButton_clicked();
private: private:
Ui::MainWindow* ui; Ui::MainWindow* ui;
QButtonGroup* MFCardTypeBtnGroup; QButtonGroup* MFCardTypeBtnGroup;

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save