mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-12-25 10:28:28 +01:00
Added persistant config to airspyhf_source
This commit is contained in:
parent
80f5f6c288
commit
1dbc39b970
@ -6,6 +6,7 @@
|
|||||||
#include <core.h>
|
#include <core.h>
|
||||||
#include <gui/style.h>
|
#include <gui/style.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
#include <options.h>
|
||||||
#include <libairspyhf/airspyhf.h>
|
#include <libairspyhf/airspyhf.h>
|
||||||
|
|
||||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||||
@ -18,7 +19,7 @@ SDRPP_MOD_INFO {
|
|||||||
/* Max instances */ 1
|
/* Max instances */ 1
|
||||||
};
|
};
|
||||||
|
|
||||||
//ConfigManager config;
|
ConfigManager config;
|
||||||
|
|
||||||
const char* AGG_MODES_STR = "Off\0Low\0High\0";
|
const char* AGG_MODES_STR = "Off\0Low\0High\0";
|
||||||
|
|
||||||
@ -40,11 +41,10 @@ public:
|
|||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
selectFirst();
|
config.aquire();
|
||||||
|
std::string devSerial = config.conf["device"];
|
||||||
// config.aquire();
|
config.release();
|
||||||
// std::string serString = config.conf["device"];
|
selectByString(devSerial);
|
||||||
// config.release();
|
|
||||||
|
|
||||||
sigpath::sourceManager.registerSource("Airspy HF+", &handler);
|
sigpath::sourceManager.registerSource("Airspy HF+", &handler);
|
||||||
}
|
}
|
||||||
@ -131,7 +131,44 @@ public:
|
|||||||
sampleRateListTxt += '\0';
|
sampleRateListTxt += '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sprintf(buf, "%016" PRIX64, serial);
|
||||||
|
selectedSerStr = std::string(buf);
|
||||||
|
|
||||||
|
// Load config here
|
||||||
|
config.aquire();
|
||||||
|
bool created = false;
|
||||||
|
if (!config.conf["devices"].contains(selectedSerStr)) {
|
||||||
|
created = true;
|
||||||
|
config.conf["devices"][selectedSerStr]["sampleRate"] = 768000;
|
||||||
|
config.conf["devices"][selectedSerStr]["agcMode"] = 0;
|
||||||
|
config.conf["devices"][selectedSerStr]["lna"] = false;
|
||||||
|
config.conf["devices"][selectedSerStr]["attenuation"] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load sample rate
|
||||||
srId = 0;
|
srId = 0;
|
||||||
|
if (config.conf["devices"][selectedSerStr].contains("sampleRate")) {
|
||||||
|
int selectedSr = config.conf["devices"][selectedSerStr]["sampleRate"];
|
||||||
|
for (int i = 0; i < sampleRateList.size(); i++) {
|
||||||
|
if (sampleRateList[i] == selectedSr) {
|
||||||
|
srId = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load Gains
|
||||||
|
if (config.conf["devices"][selectedSerStr].contains("agcMode")) {
|
||||||
|
agcMode = config.conf["devices"][selectedSerStr]["agcMode"];
|
||||||
|
}
|
||||||
|
if (config.conf["devices"][selectedSerStr].contains("lna")) {
|
||||||
|
hfLNA = config.conf["devices"][selectedSerStr]["lna"];
|
||||||
|
}
|
||||||
|
if (config.conf["devices"][selectedSerStr].contains("attenuation")) {
|
||||||
|
atten = config.conf["devices"][selectedSerStr]["attenuation"];
|
||||||
|
}
|
||||||
|
|
||||||
|
config.release(created);
|
||||||
|
|
||||||
airspyhf_close(dev);
|
airspyhf_close(dev);
|
||||||
}
|
}
|
||||||
@ -211,18 +248,31 @@ private:
|
|||||||
ImGui::SetNextItemWidth(menuWidth);
|
ImGui::SetNextItemWidth(menuWidth);
|
||||||
if (ImGui::Combo(CONCAT("##_airspyhf_dev_sel_", _this->name), &_this->devId, _this->devListTxt.c_str())) {
|
if (ImGui::Combo(CONCAT("##_airspyhf_dev_sel_", _this->name), &_this->devId, _this->devListTxt.c_str())) {
|
||||||
_this->selectBySerial(_this->devList[_this->devId]);
|
_this->selectBySerial(_this->devList[_this->devId]);
|
||||||
|
if (_this->selectedSerStr != "") {
|
||||||
|
config.aquire();
|
||||||
|
config.conf["device"] = _this->selectedSerStr;
|
||||||
|
config.release(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::Combo(CONCAT("##_airspyhf_sr_sel_", _this->name), &_this->srId, _this->sampleRateListTxt.c_str())) {
|
if (ImGui::Combo(CONCAT("##_airspyhf_sr_sel_", _this->name), &_this->srId, _this->sampleRateListTxt.c_str())) {
|
||||||
_this->sampleRate = _this->sampleRateList[_this->srId];
|
_this->sampleRate = _this->sampleRateList[_this->srId];
|
||||||
core::setInputSampleRate(_this->sampleRate);
|
core::setInputSampleRate(_this->sampleRate);
|
||||||
|
if (_this->selectedSerStr != "") {
|
||||||
|
config.aquire();
|
||||||
|
config.conf["devices"][_this->selectedSerStr]["sampleRate"] = _this->sampleRate;
|
||||||
|
config.release(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
float refreshBtnWdith = menuWidth - ImGui::GetCursorPosX();
|
float refreshBtnWdith = menuWidth - ImGui::GetCursorPosX();
|
||||||
if (ImGui::Button(CONCAT("Refresh##_airspyhf_refr_", _this->name), ImVec2(refreshBtnWdith, 0))) {
|
if (ImGui::Button(CONCAT("Refresh##_airspyhf_refr_", _this->name), ImVec2(refreshBtnWdith, 0))) {
|
||||||
_this->refresh();
|
_this->refresh();
|
||||||
_this->selectFirst();
|
config.aquire();
|
||||||
|
std::string devSerial = config.conf["device"];
|
||||||
|
config.release();
|
||||||
|
_this->selectByString(devSerial);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_this->running) { style::endDisabled(); }
|
if (_this->running) { style::endDisabled(); }
|
||||||
@ -237,6 +287,11 @@ private:
|
|||||||
airspyhf_set_hf_agc_threshold(_this->openDev, _this->agcMode - 1);
|
airspyhf_set_hf_agc_threshold(_this->openDev, _this->agcMode - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (_this->selectedSerStr != "") {
|
||||||
|
config.aquire();
|
||||||
|
config.conf["devices"][_this->selectedSerStr]["agcMode"] = _this->agcMode;
|
||||||
|
config.release(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Text("HF LNA");
|
ImGui::Text("HF LNA");
|
||||||
@ -244,6 +299,11 @@ private:
|
|||||||
if (ImGui::Checkbox(CONCAT("##_airspyhf_lna_", _this->name), &_this->hfLNA)) {
|
if (ImGui::Checkbox(CONCAT("##_airspyhf_lna_", _this->name), &_this->hfLNA)) {
|
||||||
if (_this->running) {
|
if (_this->running) {
|
||||||
airspyhf_set_hf_lna(_this->openDev, _this->hfLNA);
|
airspyhf_set_hf_lna(_this->openDev, _this->hfLNA);
|
||||||
|
}
|
||||||
|
if (_this->selectedSerStr != "") {
|
||||||
|
config.aquire();
|
||||||
|
config.conf["devices"][_this->selectedSerStr]["lna"] = _this->hfLNA;
|
||||||
|
config.release(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,6 +315,11 @@ private:
|
|||||||
if (_this->running) {
|
if (_this->running) {
|
||||||
airspyhf_set_hf_att(_this->openDev, _this->atten / 6);
|
airspyhf_set_hf_att(_this->openDev, _this->atten / 6);
|
||||||
}
|
}
|
||||||
|
if (_this->selectedSerStr != "") {
|
||||||
|
config.aquire();
|
||||||
|
config.conf["devices"][_this->selectedSerStr]["attenuation"] = _this->atten;
|
||||||
|
config.release(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,6 +344,7 @@ private:
|
|||||||
int agcMode = AGC_MODE_OFF;
|
int agcMode = AGC_MODE_OFF;
|
||||||
bool hfLNA = false;
|
bool hfLNA = false;
|
||||||
int atten = 0;
|
int atten = 0;
|
||||||
|
std::string selectedSerStr = "";
|
||||||
|
|
||||||
std::vector<uint64_t> devList;
|
std::vector<uint64_t> devList;
|
||||||
std::string devListTxt;
|
std::string devListTxt;
|
||||||
@ -287,12 +353,12 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
MOD_EXPORT void _INIT_() {
|
MOD_EXPORT void _INIT_() {
|
||||||
// config.setPath(ROOT_DIR "/airspyhf_config.json");
|
json def = json({});
|
||||||
// json defConf;
|
def["devices"] = json({});
|
||||||
// defConf["device"] = "";
|
def["device"] = "";
|
||||||
// defConf["devices"] = json::object();
|
config.setPath(options::opts.root + "/airspyhf_config.json");
|
||||||
// config.load(defConf);
|
config.load(def);
|
||||||
// config.enableAutoSave();
|
config.enableAutoSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) {
|
MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) {
|
||||||
@ -304,6 +370,6 @@ MOD_EXPORT void _DELETE_INSTANCE_(ModuleManager::Instance* instance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MOD_EXPORT void _END_() {
|
MOD_EXPORT void _END_() {
|
||||||
// config.disableAutoSave();
|
config.disableAutoSave();
|
||||||
// config.save();
|
config.save();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user