Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feet/Meters-only options for the altimeter #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 56 additions & 27 deletions logic/altitude.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@
// *************************************************************************************************
// Defines section

#if defined(CONFIG_ALTITUDE_UNIT_FEET) && defined(CONFIG_ALTITUDE_UNIT_METERS)
#error "You cannot define both CONFIG_ALTITUDE_UNIT_FEET and CONFIG_ALTITUDE_UNIT_METERS"
#endif
#if !defined(CONFIG_ALTITUDE_UNIT_FEET) && defined(CONFIG_METRIC_ONLY)
#define CONFIG_ALTITUDE_UNIT_METERS
#endif
#if !defined(CONFIG_ALTITUDE_UNIT_FEET) && !defined(CONFIG_ALTITUDE_UNIT_METERS)
#define CONFIG_ALTITUDE_UNIT_SETTABLE
#endif

// *************************************************************************************************
// Global Variable section
Expand Down Expand Up @@ -132,7 +141,7 @@ void reset_altitude_measurement(void)
}
}

#ifndef CONFIG_METRIC_ONLY
#if defined(CONFIG_ALTITUDE_UNIT_FEET) || defined(CONFIG_ALTITUDE_UNIT_SETTABLE)
// *************************************************************************************************
// @fn conv_m_to_ft
// @brief Convert meters to feet
Expand Down Expand Up @@ -314,18 +323,11 @@ void mx_altitude(u8 line)
#endif

// Set lower and upper limits for offset correction
#ifdef CONFIG_METRIC_ONLY
display_symbol(LCD_UNIT_L1_M, SEG_ON);

// Convert global variable to local variable
altitude = sAlt.altitude;

// Limits for set_value function
limit_low = -100;
limit_high = 9000;
#else
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
if (sys.flag.use_metric_units)
{
#endif
#if defined(CONFIG_ALTITUDE_UNIT_SETTABLE) || defined(CONFIG_ALTITUDE_UNIT_METERS)
// Display "m" symbol
display_symbol(LCD_UNIT_L1_M, SEG_ON);

Expand All @@ -335,9 +337,13 @@ void mx_altitude(u8 line)
// Limits for set_value function
limit_low = -100;
limit_high = 9000;
#endif
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
}
else // English units
{
#endif
#if defined(CONFIG_ALTITUDE_UNIT_SETTABLE) || defined(CONFIG_ALTITUDE_UNIT_FEET)
// Display "ft" symbol
display_symbol(LCD_UNIT_L1_FT, SEG_ON);

Expand All @@ -354,6 +360,8 @@ void mx_altitude(u8 line)
#else
limit_high = 9999;
#endif
#endif
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
}
#endif
// Loop values until all are set or user breaks set
Expand All @@ -366,8 +374,15 @@ void mx_altitude(u8 line)
if (button.flag.star)
{
// When using English units, convert ft back to m before updating pressure table
#ifndef CONFIG_METRIC_ONLY
if (!sys.flag.use_metric_units) altitude = convert_ft_to_m((s16)altitude);
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
if (!sys.flag.use_metric_units)
{
#endif
#if defined(CONFIG_ALTITUDE_UNIT_SETTABLE) || defined(CONFIG_ALTITUDE_UNIT_FEET)
altitude = convert_ft_to_m((s16)altitude);
#endif
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
}
#endif

// Update pressure table
Expand Down Expand Up @@ -404,7 +419,7 @@ void mx_altitude(u8 line)
void display_altitude(u8 line, u8 update)
{
u8 * str;
#ifndef CONFIG_METRIC_ONLY
#if defined(CONFIG_ALTITUDE_UNIT_SETTABLE) || defined(CONFIG_ALTITUDE_UNIT_FEET)
s16 ft;
#endif

Expand All @@ -419,18 +434,26 @@ void display_altitude(u8 line, u8 update)
#ifdef CONFIG_ALTI_ACCUMULATOR
display_chars(LCD_SEG_L1_3_0, (u8*)"ALT ", SEG_ON);
#endif
#ifdef CONFIG_METRIC_ONLY
display_symbol(LCD_UNIT_L1_M, SEG_ON);
#else
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
if (sys.flag.use_metric_units)
{
#endif
#if defined(CONFIG_ALTITUDE_UNIT_SETTABLE) || defined(CONFIG_ALTITUDE_UNIT_METERS)
// Display "m" symbol
display_symbol(LCD_UNIT_L1_FT, SEG_OFF);
display_symbol(LCD_UNIT_L1_M, SEG_ON);
#endif
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
}
else
{
#endif
#if defined(CONFIG_ALTITUDE_UNIT_SETTABLE) || defined(CONFIG_ALTITUDE_UNIT_FEET)
// Display "ft" symbol
display_symbol(LCD_UNIT_L1_M, SEG_OFF);
display_symbol(LCD_UNIT_L1_FT, SEG_ON);
#endif
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
}
#endif
// Display altitude
Expand All @@ -441,10 +464,11 @@ void display_altitude(u8 line, u8 update)
// Update display only while measurement is active
if (sAlt.timeout > 0)
{
#ifndef CONFIG_METRIC_ONLY
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
if (sys.flag.use_metric_units)
{
#endif
#if defined(CONFIG_ALTITUDE_UNIT_SETTABLE) || defined(CONFIG_ALTITUDE_UNIT_METERS)
// Display altitude in xxxx m format, allow 3 leading blank digits
if (sAlt.altitude >= 0)
{
Expand All @@ -459,44 +483,49 @@ void display_altitude(u8 line, u8 update)
else
{
#ifdef CONFIG_ALTI_ACCUMULATOR
str = itoa(sAlt.altitude*(-1), 4, 3);
#else
str = itoa(sAlt.altitude*(-1), 5, 4);
#else
str = itoa(sAlt.altitude*(-1), 4, 3);
#endif
display_symbol(LCD_SYMB_ARROW_UP, SEG_OFF);
display_symbol(LCD_SYMB_ARROW_DOWN, SEG_ON);
}
#ifndef CONFIG_METRIC_ONLY
#endif
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
}
else
{
#endif
#if defined(CONFIG_ALTITUDE_UNIT_SETTABLE) || defined(CONFIG_ALTITUDE_UNIT_FEET)
// Convert from meters to feet
ft = convert_m_to_ft(sAlt.altitude);
#ifndef CONFIG_ALTI_ACCUMULATOR
#ifdef CONFIG_ALTI_ACCUMULATOR
// Limit to 9999ft (3047m)
if (ft > 9999) ft = 9999;
#endif
// Display altitude in xxxx ft format, allow 3 leading blank digits
if (ft >= 0)
{
#ifdef CONFIG_ALTI_ACCUMULATOR
str = itoa(ft, 4, 3);
#else
str = itoa(ft, 5, 4);
#else
str = itoa(ft, 4, 3);
#endif
display_symbol(LCD_SYMB_ARROW_UP, SEG_ON);
display_symbol(LCD_SYMB_ARROW_DOWN, SEG_OFF);
}
else
{
#ifdef CONFIG_ALTI_ACCUMULATOR
str = itoa(ft*(-1), 4, 3);
#else
#ifndef CONFIG_ALTI_ACCUMULATOR
str = itoa(ft*(-1), 5, 4);
#else
str = itoa(ft*(-1), 4, 3);
#endif
display_symbol(LCD_SYMB_ARROW_UP, SEG_OFF);
display_symbol(LCD_SYMB_ARROW_DOWN, SEG_ON);
}
#endif
#ifdef CONFIG_ALTITUDE_UNIT_SETTABLE
}
#endif
#ifdef CONFIG_ALTI_ACCUMULATOR
Expand Down
18 changes: 15 additions & 3 deletions tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,26 @@ def rand_hw():
"help": "Messures altitude"
}

DATA["CONFIG_ALTITUDE_UNIT_METERS"] = {
"name": " Always show altitude in metres (-342 bytes)",
"depends": [],
"default": False,
"help": "Overrides any global unit setting"}

DATA["CONFIG_ALTITUDE_UNIT_FEET"] = {
"name": " Always show altitude in feet (-176 bytes)",
"depends": [],
"default": False,
"help": "Overrides any global unit setting/metric only mode"}

DATA["CONFIG_VARIO"] = {
"name": "Combined with alti, gives vertical speed (478 bytes)",
"name": " Vertical speed indicator (478 bytes)",
"depends": [],
"default": False}
"default": False,
"help": "Must have altimeter enabled and active to function"}

DATA["CONFIG_ALTI_ACCUMULATOR"] = {
"name": "Altitude accumulator (1068 bytes)",
"name": " Altitude accumulator (1068 bytes)",
"depends": [],
"default": False,
"help": "If active take altitude measurement once per minute and accumulate all ascending vertical meters."
Expand Down