mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Merge pull request #78 from euquiq/Whip-calc-rounding-values
Antenna length Calculator fix
This commit is contained in:
commit
7796e44b4f
@ -36,8 +36,18 @@ void WhipCalcView::focus() {
|
|||||||
field_frequency.focus();
|
field_frequency.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
int16_t intnum = int(num); //Round it up if necessary
|
||||||
|
num -= intnum; //Get decimal part
|
||||||
|
if (num > .5) intnum++; //Round up
|
||||||
|
return intnum;
|
||||||
|
}
|
||||||
|
|
||||||
void WhipCalcView::update_result() {
|
void WhipCalcView::update_result() {
|
||||||
double length, divider;
|
double length, calclength, divider;
|
||||||
|
|
||||||
divider = ((double)options_type.selected_index_value() / 8.0);
|
divider = ((double)options_type.selected_index_value() / 8.0);
|
||||||
|
|
||||||
@ -45,8 +55,12 @@ void WhipCalcView::update_result() {
|
|||||||
length = (speed_of_light_mps / (double)field_frequency.value()) * divider;
|
length = (speed_of_light_mps / (double)field_frequency.value()) * divider;
|
||||||
|
|
||||||
auto m = to_string_dec_int((int)length, 2);
|
auto m = to_string_dec_int((int)length, 2);
|
||||||
auto cm = to_string_dec_int(int(length * 100.0) % 100, 2);
|
/* auto cm = to_string_dec_int(int(length * 100.0) % 100, 2);
|
||||||
auto mm = to_string_dec_int(int(length * 1000.0) % 10, 1);
|
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), 2);
|
||||||
|
auto mm = to_string_dec_int(int(get_decimals(calclength,10,true)), 1);
|
||||||
|
|
||||||
text_result_metric.set(m + "m " + cm + "." + mm + "cm");
|
text_result_metric.set(m + "m " + cm + "." + mm + "cm");
|
||||||
|
|
||||||
@ -60,11 +74,16 @@ void WhipCalcView::update_result() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Imperial
|
// Imperial
|
||||||
length = (speed_of_light_fps / (double)field_frequency.value()) * divider;
|
calclength = (speed_of_light_fps / (double)field_frequency.value()) * divider;
|
||||||
|
|
||||||
auto feet = to_string_dec_int((int)length, 3);
|
/* auto feet = to_string_dec_int((int)length, 3);
|
||||||
auto inch = to_string_dec_int(int(length * 10.0) % 12, 2);
|
auto inch = to_string_dec_int(int(length * 10.0) % 12, 2);
|
||||||
auto inch_c = to_string_dec_int(int(length * 100.0) % 10, 1);
|
auto inch_c = to_string_dec_int(int(length * 100.0) % 10, 1); */
|
||||||
|
|
||||||
|
auto feet = to_string_dec_int(int(calclength), 3);
|
||||||
|
calclength = get_decimals(calclength,12); //inches
|
||||||
|
auto inch = to_string_dec_int(int(calclength), 2);
|
||||||
|
auto inch_c = to_string_dec_int(int(get_decimals(calclength,10,true)), 1);
|
||||||
|
|
||||||
text_result_imperial.set(feet + "ft " + inch + "." + inch_c + "in");
|
text_result_imperial.set(feet + "ft " + inch + "." + inch_c + "in");
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
|
|
||||||
void focus() override;
|
void focus() override;
|
||||||
|
|
||||||
std::string title() const override { return "Whip calculator"; };
|
std::string title() const override { return "Antenna length"; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const double speed_of_light_mps = 299792458.0; // m/s
|
const double speed_of_light_mps = 299792458.0; // m/s
|
||||||
@ -45,6 +45,7 @@ private:
|
|||||||
|
|
||||||
const std::string frac_str[4] = { "", "1/4 ", "1/2 ", "3/4 " };
|
const std::string frac_str[4] = { "", "1/4 ", "1/2 ", "3/4 " };
|
||||||
|
|
||||||
|
double get_decimals(double num, int16_t mult, bool round = false);
|
||||||
void update_result();
|
void update_result();
|
||||||
|
|
||||||
Labels labels {
|
Labels labels {
|
||||||
|
Loading…
Reference in New Issue
Block a user