mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-26 06:26:17 -05:00
Use a common function for finding Tone Key index from received Tone Frequency (#1218)
* Common function for finding CTCSS tone index from freq
This commit is contained in:
parent
99809c7919
commit
cdd524b9f3
@ -404,22 +404,9 @@ void AnalogAudioView::update_modulation(ReceiverModel::Mode modulation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AnalogAudioView::handle_coded_squelch(uint32_t value) {
|
void AnalogAudioView::handle_coded_squelch(uint32_t value) {
|
||||||
float diff, min_diff = value;
|
tone_index idx = tone_key_index_by_value(value);
|
||||||
size_t min_idx{0};
|
if (idx >= 0)
|
||||||
size_t c;
|
text_ctcss.set("CTCSS " + tone_key_string(idx));
|
||||||
|
|
||||||
// Find nearest match
|
|
||||||
for (c = 0; c < tone_keys.size(); c++) {
|
|
||||||
diff = abs(((float)value / 100.0) - tone_keys[c].second);
|
|
||||||
if (diff < min_diff) {
|
|
||||||
min_idx = c;
|
|
||||||
min_diff = diff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Arbitrary confidence threshold
|
|
||||||
if (min_diff < 40)
|
|
||||||
text_ctcss.set("CTCSS " + tone_keys[min_idx].first);
|
|
||||||
else
|
else
|
||||||
text_ctcss.set("???");
|
text_ctcss.set("???");
|
||||||
}
|
}
|
||||||
|
@ -216,34 +216,23 @@ size_t LevelView::change_mode(freqman_index_t new_mod) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LevelView::handle_coded_squelch(const uint32_t value) {
|
void LevelView::handle_coded_squelch(const uint32_t value) {
|
||||||
static int32_t last_idx = -1;
|
static tone_index last_squelch_index = -1;
|
||||||
|
|
||||||
float diff, min_diff = value;
|
if (field_mode.selected_index() == NFM_MODULATION) {
|
||||||
size_t min_idx{0};
|
tone_index idx = tone_key_index_by_value(value);
|
||||||
size_t c;
|
|
||||||
|
|
||||||
if (field_mode.selected_index() != NFM_MODULATION) {
|
if ((last_squelch_index < 0) || (last_squelch_index != idx)) {
|
||||||
text_ctcss.set(" ");
|
last_squelch_index = idx;
|
||||||
|
if (idx >= 0) {
|
||||||
|
text_ctcss.set("T: " + tone_key_string(idx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// Find nearest match
|
return;
|
||||||
for (c = 0; c < tone_keys.size(); c++) {
|
|
||||||
diff = abs(((float)value / 100.0) - tone_keys[c].second);
|
|
||||||
if (diff < min_diff) {
|
|
||||||
min_idx = c;
|
|
||||||
min_diff = diff;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arbitrary confidence threshold
|
|
||||||
if (last_idx < 0 || (unsigned)last_idx != min_idx) {
|
|
||||||
last_idx = min_idx;
|
|
||||||
if (min_diff < 40)
|
|
||||||
text_ctcss.set("T: " + tone_keys[min_idx].first);
|
|
||||||
else
|
|
||||||
text_ctcss.set(" ");
|
text_ctcss.set(" ");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace ui */
|
} /* namespace ui */
|
||||||
|
@ -1426,32 +1426,20 @@ size_t ReconView::change_mode(freqman_index_t new_mod) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ReconView::handle_coded_squelch(const uint32_t value) {
|
void ReconView::handle_coded_squelch(const uint32_t value) {
|
||||||
float diff{0.0};
|
if (field_mode.selected_index() == NFM_MODULATION) {
|
||||||
float min_diff{(float)value};
|
tone_index idx = tone_key_index_by_value(value);
|
||||||
size_t min_idx{0};
|
|
||||||
size_t c{0};
|
|
||||||
|
|
||||||
if (field_mode.selected_index() != NFM_MODULATION) {
|
if ((last_squelch_index < 0) || (last_squelch_index != idx)) {
|
||||||
text_ctcss.set(" ");
|
last_squelch_index = idx;
|
||||||
|
if (idx >= 0) {
|
||||||
|
text_ctcss.set("T: " + tone_key_string(idx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// Find nearest match
|
return;
|
||||||
for (c = 0; c < tone_keys.size(); c++) {
|
|
||||||
diff = abs(((float)value / 100.0) - tone_keys[c].second);
|
|
||||||
if (diff < min_diff) {
|
|
||||||
min_idx = c;
|
|
||||||
min_diff = diff;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arbitrary confidence threshold
|
|
||||||
if (last_squelch_index < 0 || (unsigned)last_squelch_index != min_idx) {
|
|
||||||
last_squelch_index = min_idx;
|
|
||||||
if (min_diff < 40)
|
|
||||||
text_ctcss.set("T: " + tone_keys[min_idx].first);
|
|
||||||
else
|
|
||||||
text_ctcss.set(" ");
|
text_ctcss.set(" ");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace ui */
|
} /* namespace ui */
|
||||||
|
@ -139,7 +139,7 @@ class ReconView : public View {
|
|||||||
int8_t last_rssi_med{-127};
|
int8_t last_rssi_med{-127};
|
||||||
int8_t last_rssi_max{-127};
|
int8_t last_rssi_max{-127};
|
||||||
int32_t last_index{-1};
|
int32_t last_index{-1};
|
||||||
int32_t last_squelch_index{-1};
|
tone_index last_squelch_index{-1};
|
||||||
int64_t last_freq{0};
|
int64_t last_freq{0};
|
||||||
std::string freq_file_path{};
|
std::string freq_file_path{};
|
||||||
systime_t chrono_start{};
|
systime_t chrono_start{};
|
||||||
|
@ -73,9 +73,9 @@ const tone_key_t tone_keys = {
|
|||||||
{"34 M3", 218.100},
|
{"34 M3", 218.100},
|
||||||
{"35 M4", 225.700},
|
{"35 M4", 225.700},
|
||||||
{"49 9Z", 229.100},
|
{"49 9Z", 229.100},
|
||||||
{"36 --", 233.600},
|
{"36 M5", 233.600},
|
||||||
{"37 --", 241.800},
|
{"37 M6", 241.800},
|
||||||
{"38 --", 250.300},
|
{"38 M7", 250.300},
|
||||||
{"50 0Z", 254.100},
|
{"50 0Z", 254.100},
|
||||||
{"Axient 28kHz", 28000.0},
|
{"Axient 28kHz", 28000.0},
|
||||||
{"Senn. 32.768k", 32768.0},
|
{"Senn. 32.768k", 32768.0},
|
||||||
@ -113,6 +113,36 @@ std::string tone_key_string(tone_index index) {
|
|||||||
return tone_keys[index].first;
|
return tone_keys[index].first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string tone_key_string_by_value(uint32_t value) {
|
||||||
|
return tone_key_string(tone_key_index_by_value(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
tone_index tone_key_index_by_value(uint32_t value) {
|
||||||
|
float diff;
|
||||||
|
float min_diff{(float)value};
|
||||||
|
float fvalue{(float)((min_diff + 50.0) / 100.0)};
|
||||||
|
tone_index min_idx{-1};
|
||||||
|
tone_index idx;
|
||||||
|
|
||||||
|
// Find nearest match
|
||||||
|
for (idx = 0; idx < (tone_index)tone_keys.size(); idx++) {
|
||||||
|
diff = abs(fvalue - tone_keys[idx].second);
|
||||||
|
if (diff < min_diff) {
|
||||||
|
min_idx = idx;
|
||||||
|
min_diff = diff;
|
||||||
|
} else {
|
||||||
|
// list is sorted in frequency order; if diff is getting larger than we've passed it
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Arbitrary confidence threshold
|
||||||
|
if (min_diff < 40.0)
|
||||||
|
return min_idx;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
tone_index tone_key_index_by_string(char* str) {
|
tone_index tone_key_index_by_string(char* str) {
|
||||||
if (!str)
|
if (!str)
|
||||||
return -1;
|
return -1;
|
||||||
@ -123,9 +153,4 @@ tone_index tone_key_index_by_string(char* str) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tone_index tone_key_index_by_value( int32_t freq )
|
|
||||||
{
|
|
||||||
return -1 ;
|
|
||||||
} */
|
|
||||||
|
|
||||||
} // namespace tonekey
|
} // namespace tonekey
|
||||||
|
@ -30,7 +30,7 @@ using namespace ui;
|
|||||||
|
|
||||||
namespace tonekey {
|
namespace tonekey {
|
||||||
|
|
||||||
typedef int16_t tone_index;
|
typedef int32_t tone_index;
|
||||||
|
|
||||||
using tone_key_t = std::vector<std::pair<std::string, float>>;
|
using tone_key_t = std::vector<std::pair<std::string, float>>;
|
||||||
|
|
||||||
@ -40,8 +40,8 @@ void tone_keys_populate(OptionsField& field);
|
|||||||
float tone_key_frequency(const tone_index index);
|
float tone_key_frequency(const tone_index index);
|
||||||
|
|
||||||
std::string tone_key_string(const tone_index index);
|
std::string tone_key_string(const tone_index index);
|
||||||
tone_index tone_key_index_by_string(char* str);
|
std::string tone_key_string_by_value(uint32_t value);
|
||||||
// tone_index tone_key_index_by_value( int32_t freq );
|
tone_index tone_key_index_by_value(uint32_t value);
|
||||||
|
|
||||||
} // namespace tonekey
|
} // namespace tonekey
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user