mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-20 06:29:02 +00:00
Externalize antenna calc and wav view (#2498)
* externalize antenna calc and wav view * Added a tool to check if all the pictures in graphics are used in internal apps
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_whipcalc.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::antenna_length {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<WhipCalcView>();
|
||||
}
|
||||
} // namespace ui::external_app::antenna_length
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_antenna_length.application_information"), used)) application_information_t _application_information_antenna_length = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::antenna_length::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "Antenna Length",
|
||||
/*.bitmap_data = */ {0x38, 0x3E, 0x10, 0x22, 0x10, 0x26, 0x10, 0x22, 0x10, 0x2E, 0x10, 0x22, 0x10, 0x26, 0x10, 0x22, 0x38, 0x2E, 0x38, 0x22, 0x38, 0x26, 0x38, 0x22, 0x38, 0x2E, 0x38, 0x22, 0x38, 0x3E, 0x00, 0x00},
|
||||
/*.icon_color = */ ui::Color::cyan().v,
|
||||
/*.menu_location = */ app_location_t::SETTINGS,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_none */ {0, 0, 0, 0},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui_whipcalc.hpp"
|
||||
|
||||
#include "ch.h"
|
||||
#include "convert.hpp"
|
||||
#include "event_m0.hpp"
|
||||
#include "file_reader.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "file_path.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace portapack;
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::antenna_length {
|
||||
|
||||
void WhipCalcView::focus() {
|
||||
field_frequency.focus();
|
||||
}
|
||||
|
||||
void WhipCalcView::update_result() {
|
||||
double length, calclength, divider;
|
||||
console.clear(true);
|
||||
divider = ((double)options_type.selected_index_value() / 8.0);
|
||||
|
||||
// Antenna lengths fields
|
||||
if (field_frequency.value() > 0) {
|
||||
// Metric
|
||||
length = (speed_of_light_mps / (double)field_frequency.value()) * divider;
|
||||
auto m = to_string_dec_int((int)length, 0);
|
||||
// auto cm = to_string_dec_int(int(length * 100.0) % 100, 2);
|
||||
// auto mm = to_string_dec_int(int(length * 1000.0) % 10, 1);
|
||||
calclength = get_decimals(length, 100); // cm
|
||||
auto cm = to_string_dec_int(int(calclength), 0);
|
||||
auto mm = to_string_dec_int(int(get_decimals(calclength, 10, true)), 0);
|
||||
text_result_metric.set(m + "m " + cm + "." + mm + "cm");
|
||||
|
||||
// Imperial
|
||||
calclength = (speed_of_light_fps / (double)field_frequency.value()) * divider;
|
||||
auto feet = to_string_dec_int(int(calclength), 0);
|
||||
calclength = get_decimals(calclength, 12); // inches
|
||||
auto inch = to_string_dec_int(int(calclength), 0);
|
||||
auto inch_c = to_string_dec_int(int(get_decimals(calclength, 10, true)), 0);
|
||||
text_result_imperial.set(feet + "ft " + inch + "." + inch_c + "in");
|
||||
} else {
|
||||
text_result_metric.set("infinity+");
|
||||
text_result_imperial.set("infinity+");
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t ant_count = 9; // Shown antennas counter
|
||||
length *= 1000; // Get length in mm needed to extend the antenna
|
||||
for (antenna_entry antenna : antenna_db) { // go thru all antennas available
|
||||
uint16_t element, refined_quarter = 0;
|
||||
for (element = 0; element < antenna.elements.size(); element++) {
|
||||
if (length == antenna.elements[element]) // Exact element in length
|
||||
{
|
||||
element++; // Real element is +1 (zero based vector)
|
||||
break; // Done with this ant
|
||||
} else if (length < antenna.elements[element]) {
|
||||
double remain, this_element, quarter = 0;
|
||||
remain = length - antenna.elements[element - 1]; // mm needed from this element to reach length
|
||||
this_element = antenna.elements[element] - antenna.elements[element - 1]; // total mm on this element
|
||||
quarter = (remain * 4) / this_element; // havoc & portack ended on this int(quarter) resolution.
|
||||
if (quarter - int(quarter) > 0.5) { // rounding gave a measure closer to next quarter
|
||||
refined_quarter = int(quarter) + 1;
|
||||
if (refined_quarter == 4) { // rounding gave a measure closer to next element
|
||||
refined_quarter = 0;
|
||||
element++;
|
||||
}
|
||||
} else {
|
||||
refined_quarter = int(quarter);
|
||||
}
|
||||
break; // Done with this ant
|
||||
}
|
||||
}
|
||||
/*if (!ant_count)
|
||||
{
|
||||
console.write(" and more ...");
|
||||
break;
|
||||
}*/
|
||||
console.write(antenna.label + ": " + to_string_dec_int(element, 1) + frac_str[refined_quarter] + " elements\n");
|
||||
ant_count--; // For now, just showing all.
|
||||
}
|
||||
}
|
||||
|
||||
WhipCalcView::WhipCalcView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
add_children({&labels,
|
||||
//&antennas_on_memory,
|
||||
&field_frequency,
|
||||
&options_type,
|
||||
&text_result_metric,
|
||||
&text_result_imperial,
|
||||
&console,
|
||||
&button_exit});
|
||||
|
||||
// Try loading antennas from file.
|
||||
load_antenna_db();
|
||||
|
||||
if (!antenna_db.size())
|
||||
add_default_antenna();
|
||||
|
||||
// antennas_on_memory.set(to_string_dec_int(antenna_db.size(),0) + " antennas"); //tell user
|
||||
|
||||
options_type.set_selected_index(2); // Quarter wave
|
||||
options_type.on_change = [this](size_t, OptionsField::value_t) {
|
||||
this->update_result();
|
||||
};
|
||||
|
||||
field_frequency.set_step(1000000); // 1MHz step
|
||||
field_frequency.updated = [this](rf::Frequency) {
|
||||
update_result();
|
||||
};
|
||||
|
||||
button_exit.on_select = [this, &nav](Button&) {
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
update_result();
|
||||
}
|
||||
|
||||
void WhipCalcView::load_antenna_db() {
|
||||
File antennas_file;
|
||||
auto error = antennas_file.open(whipcalc_dir / u"ANTENNAS.TXT");
|
||||
|
||||
if (error)
|
||||
return;
|
||||
|
||||
auto reader = FileLineReader(antennas_file);
|
||||
for (const auto& line : reader) {
|
||||
if (line.length() == 0 || line[0] == '#')
|
||||
continue; // Empty or comment line.
|
||||
|
||||
auto cols = split_string(line, ',');
|
||||
if (cols.size() < 2)
|
||||
continue; // Line doesn't have enough columns.
|
||||
|
||||
antenna_entry new_antenna{
|
||||
std::string{cols[0]}};
|
||||
|
||||
// Add antenna elements.
|
||||
for (auto i = 1ul; i < cols.size(); ++i) {
|
||||
uint16_t length = 0;
|
||||
if (parse_int(cols[i], length)) {
|
||||
new_antenna.elements.push_back(length);
|
||||
}
|
||||
}
|
||||
|
||||
if (!new_antenna.elements.empty())
|
||||
antenna_db.push_back(std::move(new_antenna));
|
||||
}
|
||||
}
|
||||
|
||||
void WhipCalcView::add_default_antenna() {
|
||||
antenna_db.push_back({"ANT500", {185, 315, 450, 586, 724, 862}}); // store a default ant500
|
||||
}
|
||||
} // namespace ui::external_app::antenna_length
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __UI_WHIPCALC_H__
|
||||
#define __UI_WHIPCALC_H__
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include <vector>
|
||||
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::antenna_length {
|
||||
|
||||
class WhipCalcView : public View {
|
||||
public:
|
||||
WhipCalcView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "Ant. length"; };
|
||||
|
||||
private:
|
||||
const double speed_of_light_mps = 299792458.0; // m/s
|
||||
const double speed_of_light_fps = 983571087.90472; // feet/s
|
||||
const std::string frac_str[4] = {"", " 1/4", " 1/2", " 3/4"};
|
||||
|
||||
struct antenna_entry {
|
||||
std::string label{};
|
||||
std::vector<uint16_t> elements{};
|
||||
};
|
||||
|
||||
NavigationView& nav_;
|
||||
std::vector<antenna_entry> antenna_db{};
|
||||
void update_result();
|
||||
void load_antenna_db();
|
||||
void add_default_antenna();
|
||||
|
||||
Labels labels{
|
||||
{{2 * 8, 1 * 16}, "Frequency:", Theme::getInstance()->fg_light->foreground},
|
||||
{{7 * 8, 2 * 16}, "Wave:", Theme::getInstance()->fg_light->foreground},
|
||||
{{5 * 8, 3 * 16}, "Metric:", Theme::getInstance()->fg_light->foreground},
|
||||
{{3 * 8, 4 * 16}, "Imperial:", Theme::getInstance()->fg_light->foreground}};
|
||||
|
||||
TxFrequencyField field_frequency{
|
||||
{13 * 8, 1 * 16},
|
||||
nav_};
|
||||
|
||||
OptionsField options_type{
|
||||
{13 * 8, 2 * 16},
|
||||
7,
|
||||
{{"Full", 8},
|
||||
{"Half", 4},
|
||||
{"Quarter", 2},
|
||||
{"3/4", 6},
|
||||
{"1/8", 1},
|
||||
{"3/8", 3},
|
||||
{"5/8", 5},
|
||||
{"7/8", 7}}};
|
||||
|
||||
Text text_result_metric{
|
||||
{13 * 8, 3 * 16, 10 * 16, 16},
|
||||
"-"};
|
||||
Text text_result_imperial{
|
||||
{13 * 8, 4 * 16, 10 * 16, 16},
|
||||
"-"};
|
||||
Console console{
|
||||
{0, 6 * 16, 240, 160}};
|
||||
|
||||
Button button_exit{
|
||||
{72, 17 * 16, 96, 32},
|
||||
"Back"};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::antenna_length
|
||||
|
||||
#endif /*__UI_WHIPCALC__*/
|
||||
Reference in New Issue
Block a user