mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Just minor changes
This commit is contained in:
parent
9ee83c5dbb
commit
728426c5e7
@ -30,23 +30,29 @@
|
||||
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui {
|
||||
namespace ui
|
||||
{
|
||||
|
||||
void WhipCalcView::focus() {
|
||||
void WhipCalcView::focus()
|
||||
{
|
||||
field_frequency.focus();
|
||||
}
|
||||
|
||||
double ui::WhipCalcView::get_decimals(double num, int16_t mult, bool round) {
|
||||
double ui::WhipCalcView::get_decimals(double num, int16_t mult, bool round)
|
||||
{
|
||||
num -= int(num); //keep decimals only
|
||||
num *= mult; //Shift decimals into integers
|
||||
if (!round) return num;
|
||||
if (!round)
|
||||
return num;
|
||||
int16_t intnum = int(num); //Round it up if necessary
|
||||
num -= intnum; //Get decimal part
|
||||
if (num > .5) intnum++; //Round up
|
||||
if (num > .5)
|
||||
intnum++; //Round up
|
||||
return intnum;
|
||||
}
|
||||
|
||||
void WhipCalcView::update_result() {
|
||||
void WhipCalcView::update_result()
|
||||
{
|
||||
double length, calclength, divider;
|
||||
console.clear(true);
|
||||
divider = ((double)options_type.selected_index_value() / 8.0);
|
||||
@ -123,42 +129,43 @@ void WhipCalcView::update_result() {
|
||||
}
|
||||
}
|
||||
|
||||
WhipCalcView::WhipCalcView(NavigationView& nav) {
|
||||
|
||||
add_children({
|
||||
&labels,
|
||||
&antennas_on_memory,
|
||||
WhipCalcView::WhipCalcView(NavigationView &nav)
|
||||
{
|
||||
add_children({&labels,
|
||||
//&antennas_on_memory,
|
||||
&field_frequency,
|
||||
&options_type,
|
||||
&text_result_metric,
|
||||
&text_result_imperial,
|
||||
&console,
|
||||
&button_exit
|
||||
});
|
||||
&button_exit});
|
||||
|
||||
File antennas_file;
|
||||
auto result = antennas_file.open("WHIPCALC/ANTENNAS.TXT");
|
||||
auto error = antennas_file.open("WHIPCALC/ANTENNAS.TXT");
|
||||
|
||||
if (result.is_valid()) {
|
||||
antenna_Default(); // default ant500
|
||||
} else {
|
||||
if (!error.is_valid())
|
||||
{
|
||||
std::string line;
|
||||
char one_char[1];
|
||||
for (size_t pointer=0; pointer < antennas_file.size();pointer++) {
|
||||
for (size_t pointer = 0; pointer < antennas_file.size(); pointer++)
|
||||
{
|
||||
antennas_file.seek(pointer);
|
||||
antennas_file.read(one_char, 1);
|
||||
if ((int)one_char[0] > ' ') { //ascii space upwards
|
||||
if ((int)one_char[0] >= ' ')
|
||||
line += one_char[0]; //Add it to the textline
|
||||
}
|
||||
else if (one_char[0] == '\n') { //New Line
|
||||
else if (one_char[0] == '\n')
|
||||
{ //New Line
|
||||
txtline_process(line); //make sense of this textline
|
||||
line.clear(); //Ready for next textline
|
||||
}
|
||||
}
|
||||
if (line.length() > 0) txtline_process(line); //Last line had no newline at end ?
|
||||
if (!antenna_db.size()) antenna_Default(); //no antenna found on txt, use default
|
||||
if (line.length() > 0)
|
||||
txtline_process(line); //Last line had no newline at end ?
|
||||
}
|
||||
antennas_on_memory.set(to_string_dec_int(antenna_db.size(),0) + " antennas"); //tell user
|
||||
|
||||
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) {
|
||||
@ -185,17 +192,23 @@ WhipCalcView::WhipCalcView(NavigationView& nav) {
|
||||
field_frequency.set_value(transmitter_model.tuning_frequency());
|
||||
}
|
||||
|
||||
void ui::WhipCalcView::txtline_process(std::string& line) {
|
||||
if (line.find("#") != std::string::npos) return; //Line is just a comment
|
||||
void ui::WhipCalcView::txtline_process(std::string &line)
|
||||
{
|
||||
if (line.find("#") != std::string::npos)
|
||||
return; //Line is just a comment
|
||||
|
||||
char separator = ',';
|
||||
size_t previous = 0;
|
||||
uint16_t value = 0;
|
||||
antenna_entry new_antenna;
|
||||
size_t current = line.find(separator);
|
||||
while (current != std::string::npos) {
|
||||
if (!previous) { //first space found
|
||||
|
||||
while (current != std::string::npos)
|
||||
{
|
||||
if (!previous)
|
||||
new_antenna.label.assign(line, 0, current); //antenna label
|
||||
} else {
|
||||
else
|
||||
{
|
||||
value = std::stoi(line.substr(previous, current - previous));
|
||||
if (!value) return; //No element length? abort antenna
|
||||
new_antenna.elements.push_back(value); //Store this new element
|
||||
@ -203,15 +216,17 @@ void ui::WhipCalcView::txtline_process(std::string& line) {
|
||||
previous = current + 1;
|
||||
current = line.find(separator, previous); //Search for next space delimiter
|
||||
}
|
||||
|
||||
if (!previous) return; //Not even a label ? drop this antenna!
|
||||
value = std::stoi(line.substr(previous, current - previous)); //Last element
|
||||
|
||||
if (!value) return;
|
||||
new_antenna.elements.push_back(value);
|
||||
antenna_db.push_back(new_antenna); //Add this antenna
|
||||
}
|
||||
|
||||
void ui::WhipCalcView::antenna_Default() {
|
||||
void ui::WhipCalcView::add_default_antenna()
|
||||
{
|
||||
antenna_db.push_back({"ANT500", {185, 315, 450, 586, 724, 862}}); //store a default ant500
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace ui
|
||||
|
@ -30,47 +30,38 @@
|
||||
#include "string_format.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace ui {
|
||||
|
||||
class WhipCalcView : public View {
|
||||
namespace ui
|
||||
{
|
||||
class WhipCalcView : public View
|
||||
{
|
||||
public:
|
||||
WhipCalcView(NavigationView &nav);
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Antenna 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 {
|
||||
struct antenna_entry
|
||||
{
|
||||
std::string label{};
|
||||
std::vector<uint16_t> elements{};
|
||||
};
|
||||
|
||||
std::vector<antenna_entry> antenna_db{};
|
||||
|
||||
double get_decimals(double num, int16_t mult, bool round = false);
|
||||
void update_result();
|
||||
|
||||
uint16_t string_to_number(std::string);
|
||||
void txtline_process(std::string &);
|
||||
void antenna_Default();
|
||||
void add_default_antenna();
|
||||
|
||||
Labels labels{
|
||||
//{ { 5 * 8, 1 * 16 }, "Loaded:", Color::light_grey() },
|
||||
{{2 * 8, 1 * 16}, "Frequency:", Color::light_grey()},
|
||||
{{7 * 8, 2 * 16}, "Wave:", Color::light_grey()},
|
||||
{{5 * 8, 3 * 16}, "Metric:", Color::light_grey()},
|
||||
{ { 3 * 8, 4 * 16 }, "Imperial:", Color::light_grey() }
|
||||
};
|
||||
|
||||
/*Text antennas_on_memory {
|
||||
{ 13 * 8, 1 * 16, 2 * 16, 16 },
|
||||
};*/
|
||||
{{3 * 8, 4 * 16}, "Imperial:", Color::light_grey()}};
|
||||
|
||||
FrequencyField field_frequency{
|
||||
{13 * 8, 1 * 16},
|
||||
@ -79,34 +70,27 @@ private:
|
||||
OptionsField options_type{
|
||||
{13 * 8, 2 * 16},
|
||||
7,
|
||||
{
|
||||
{ "Full", 8 },
|
||||
{{"Full", 8},
|
||||
{"Half", 4},
|
||||
{"Quarter", 2},
|
||||
{"3/4", 6},
|
||||
{"1/8", 1},
|
||||
{"3/8", 3},
|
||||
{"5/8", 5},
|
||||
{ "7/8", 7 }
|
||||
}
|
||||
};
|
||||
{"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 }
|
||||
};
|
||||
{0, 6 * 16, 240, 160}};
|
||||
|
||||
Button button_exit{
|
||||
{72, 17 * 16, 96, 32},
|
||||
"Back"
|
||||
};
|
||||
"Back"};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
Loading…
Reference in New Issue
Block a user