Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
portapack-mayhem
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mcules
portapack-mayhem
Commits
7796e44b
Unverified
Commit
7796e44b
authored
5 years ago
by
Erwin Ried
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #78 from euquiq/Whip-calc-rounding-values
Antenna length Calculator fix
parents
7fba4017
46c076c2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
firmware/application/apps/ui_whipcalc.cpp
+25
-6
25 additions, 6 deletions
firmware/application/apps/ui_whipcalc.cpp
firmware/application/apps/ui_whipcalc.hpp
+2
-1
2 additions, 1 deletion
firmware/application/apps/ui_whipcalc.hpp
with
27 additions
and
7 deletions
firmware/application/apps/ui_whipcalc.cpp
+
25
−
6
View file @
7796e44b
...
...
@@ -36,8 +36,18 @@ void WhipCalcView::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
()
{
double
length
,
divider
;
double
length
,
calclength
,
divider
;
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
;
auto
m
=
to_string_dec_int
((
int
)
length
,
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 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
),
2
);
auto
mm
=
to_string_dec_int
(
int
(
get_decimals
(
calclength
,
10
,
true
)),
1
);
text_result_metric
.
set
(
m
+
"m "
+
cm
+
"."
+
mm
+
"cm"
);
...
...
@@ -60,11 +74,16 @@ void WhipCalcView::update_result() {
}
// Imperial
length
=
(
speed_of_light_fps
/
(
double
)
field_frequency
.
value
())
*
divider
;
calc
length
=
(
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_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"
);
}
...
...
This diff is collapsed.
Click to expand it.
firmware/application/apps/ui_whipcalc.hpp
+
2
−
1
View file @
7796e44b
...
...
@@ -37,7 +37,7 @@ public:
void
focus
()
override
;
std
::
string
title
()
const
override
{
return
"
Whip calculator
"
;
};
std
::
string
title
()
const
override
{
return
"
Antenna length
"
;
};
private
:
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 "
};
double
get_decimals
(
double
num
,
int16_t
mult
,
bool
round
=
false
);
void
update_result
();
Labels
labels
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment