diff --git a/main/disp_oled.cpp b/main/disp_oled.cpp index a40e0fb..7704d69 100644 --- a/main/disp_oled.cpp +++ b/main/disp_oled.cpp @@ -227,7 +227,9 @@ void OLED_DrawPosition(u8g2_t *OLED, GPS_Position *GPS=0, uint8_t LineIdx=2) } void OLED_DrawGPS(u8g2_t *OLED, GPS_Position *GPS) // GPS time, position, altitude -{ // u8g2_SetFont(OLED, u8g2_font_ncenB14_tr); +{ bool isAltitudeUnitMeter = Parameters.AltitudeUnit == 0; // display altitude in meters + bool isAltitudeUnitFeet = Parameters.AltitudeUnit == 1; // display altitude in feet + // u8g2_SetFont(OLED, u8g2_font_ncenB14_tr); u8g2_SetFont(OLED, u8g2_font_7x13_tf); // 5 lines, 12 pixels/line uint8_t Len=0; /* @@ -276,14 +278,14 @@ void OLED_DrawGPS(u8g2_t *OLED, GPS_Position *GPS) // GPS time, position, altit if(GPS && GPS->isValid()) { int32_t Alt = GPS->Altitude; if(Alt>=0) Line[Len++]=' '; - if(GPS->Sec&4) // display altitude in meters - { Len+=Format_SignDec(Line+Len, Alt, 1, 1, 1); // [0.1m/s] + if(isAltitudeUnitMeter) // display altitude in meters + { Len+=Format_SignDec(Line+Len, Alt, 1, 1, 1); // [0.1m] Line[Len++]='m'; } - else // and alternate in feet - { Alt = (Alt*336+512)>>10; // [0.1m/s] => [feet] + else if(isAltitudeUnitFeet) // display altitude in feet + { Alt = (Alt*336+512)>>10; // [0.1m] => [feet] Len+=Format_SignDec(Line+Len, Alt, 1, 0, 1); // [feet] Line[Len++]='f'; Line[Len++]='t'; } - // for( ; Len<14; ) Line[Len++]=' '; // tail of spaces to cover older printouts + // for( ; Len<14; ) Line[Len++]=' '; // tail of spaces to cover older printouts } else Len+=Format_String(Line+Len, "-----.- "); Line[Len]=0; @@ -433,7 +435,13 @@ void OLED_DrawTrafWarn(u8g2_t *OLED, GPS_Position *GPS) #endif // WITH_LOOKOUT void OLED_DrawBaro(u8g2_t *OLED, GPS_Position *GPS) -{ u8g2_SetFont(OLED, u8g2_font_7x13_tf); // 5 lines, 12 pixels/line +{ bool isAltitudeUnitMeter = Parameters.AltitudeUnit == 0; // display altitude in meters + bool isAltitudeUnitFeet = Parameters.AltitudeUnit == 1; // display altitude in feet + + bool isVarioUnitMPS = Parameters.VarioUnit == 0; // display Vario in m/s + bool isVarioUnitFPM = Parameters.VarioUnit == 1; // display Vario in fpm + + u8g2_SetFont(OLED, u8g2_font_7x13_tf); // 5 lines, 12 pixels/line uint8_t Len=0; #ifdef WITH_BMP180 Len+=Format_String(Line+Len, "BMP180 "); @@ -458,11 +466,22 @@ void OLED_DrawBaro(u8g2_t *OLED, GPS_Position *GPS) u8g2_DrawStr(OLED, 0, 24, Line); Len=0; if(GPS && GPS->hasBaro) - { Len+=Format_SignDec(Line+Len, GPS->StdAltitude, 5, 1); - Len+=Format_String(Line+Len, "m "); - Len+=Format_SignDec(Line+Len, GPS->ClimbRate, 2, 1); - Len+=Format_String(Line+Len, "m/s "); } - else Len+=Format_String(Line+Len, "-----.-m --.-m/s "); + { if(isAltitudeUnitMeter) + { Len+=Format_SignDec(Line+Len, GPS->StdAltitude, 5, 1); + Len+=Format_String(Line+Len, "m "); } + else if(isAltitudeUnitFeet) + { Len+=Format_SignDec(Line+Len, (GPS->StdAltitude*336+512)>>10, 5, 0); + Len+=Format_String(Line+Len, "ft "); } + if(isVarioUnitMPS) + { Len+=Format_SignDec(Line+Len, GPS->ClimbRate, 2, 1); + Len+=Format_String(Line+Len, "m/s "); } + else if(isVarioUnitFPM) + { Len+=Format_SignDec(Line+Len, (GPS->ClimbRate*5039+128)>>8, 2, 0); + Len+=Format_String(Line+Len, "fpm "); } } + else + { if(isAltitudeUnitMeter) Len+=Format_String(Line+Len, "-----.-m"); + else if(isAltitudeUnitFeet) Len+=Format_String(Line+Len, "-----ft "); + Len+=Format_String(Line+Len, " --.-m/s "); } Line[Len]=0; u8g2_DrawStr(OLED, 0, 36, Line); Len=0; @@ -773,13 +792,21 @@ void OLED_DrawID(u8g2_t *OLED, GPS_Position *GPS) void OLED_DrawAltitudeAndSpeed(u8g2_t *OLED, GPS_Position *GPS) { uint8_t Len; - bool inFeet = GPS->Sec&4; // decide if display altitude in meters or in feet + bool isAltitudeUnitMeter = Parameters.AltitudeUnit == 0; // display altitude in meters + bool isAltitudeUnitFeet = Parameters.AltitudeUnit == 1; // display altitude in feet + + bool isSpeedUnitKMH = Parameters.SpeedUnit == 0; // display Speed in km/h + bool isSpeedUnitKnot = Parameters.SpeedUnit == 1; // display Speed in knot + + bool isVarioUnitMPS = Parameters.VarioUnit == 0; // display Vario in m/s + bool isVarioUnitFPM = Parameters.VarioUnit == 1; // display Vario in fpm + // Standard Pressure Altitude if(GPS && (GPS->hasBaro || GPS->isValid())) // if GPS has lock or just the pressure data { int32_t Alt = GPS->Altitude; // [0.1m/s] take GPS (geometrical) altitude if(GPS->hasBaro) Alt = GPS->StdAltitude; // but if pressure sensor is there then replace with pressure altitude - if(inFeet) Alt = (Alt*336+512)>>10; // [0.1m] => [feet] // convert to feet - else Alt = (Alt+5)/10; // [0.1m] => [m] // or to meters + if(isAltitudeUnitMeter) Alt = (Alt+5)/10; // [0.1m] => [m] // or to meters + else if(isAltitudeUnitFeet) Alt = (Alt*336+512)>>10; // [0.1m] => [feet] // convert to feet Len=Format_SignDec(Line, Alt, 1, 0, 1); } // print altitude into the string else Len=Format_String(Line, "----"); // if altitude not available then print place holders @@ -789,8 +816,8 @@ void OLED_DrawAltitudeAndSpeed(u8g2_t *OLED, GPS_Position *GPS) u8g2_DrawStr(OLED, 60-Altitude_width, 40, Line); // print the string u8g2_SetFont(OLED, u8g2_font_9x15_tr); // smaller font - if(inFeet) u8g2_DrawStr(OLED, 62, 40, "ft"); // print units - else u8g2_DrawStr(OLED, 64, 40, "m"); + if(isAltitudeUnitMeter) u8g2_DrawStr(OLED, 64, 40, "m"); + else if(isAltitudeUnitFeet) u8g2_DrawStr(OLED, 62, 40, "ft"); // print units u8g2_SetFont(OLED, u8g2_font_fub17_tr); if(GPS && GPS->isValid()) @@ -807,6 +834,7 @@ void OLED_DrawAltitudeAndSpeed(u8g2_t *OLED, GPS_Position *GPS) if(GPS && (GPS->hasBaro || GPS->isValid())) // if GPS has lock or just the pressure data { int16_t vario_value = GPS->ClimbRate; // [0.1m/s] climb rate + if(isVarioUnitFPM) vario_value = (vario_value*5039+128)>>8; // [0.1m/s] => [feet per meter] if(vario_value<0) { vario_value=(-vario_value); const int minus_width=10; @@ -826,7 +854,8 @@ void OLED_DrawAltitudeAndSpeed(u8g2_t *OLED, GPS_Position *GPS) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; u8g2_DrawXBM(OLED, 0, 47, plus_width, plus_height, plus_bits); } - Len=Format_UnsDec(Line, vario_value, 2, 1); + if(isVarioUnitMPS) Len=Format_UnsDec(Line, vario_value, 2, 1); + if(isVarioUnitFPM) Len=Format_UnsDec(Line, vario_value, 2, 0); } else Len=Format_String(Line, "-.-"); @@ -835,16 +864,24 @@ void OLED_DrawAltitudeAndSpeed(u8g2_t *OLED, GPS_Position *GPS) uint8_t Vario_width = u8g2_GetStrWidth(OLED, Line); u8g2_DrawStr(OLED, 54-Vario_width, 64, Line); - const int ms_width=7; - const int ms_height=17; - static unsigned char ms_bits[] = - { 0x00, 0x00, 0x16, 0x2a, 0x2a, 0x2a, 0x2a, 0x00, 0x7f, 0x00, 0x1c, 0x22, - 0x02, 0x1c, 0x20, 0x22, 0x1c }; - u8g2_DrawXBM(OLED, 58, 47, ms_width, ms_height, ms_bits); + if(isVarioUnitMPS) + { const int ms_width=7; + const int ms_height=17; + static unsigned char ms_bits[] = + { 0x00, 0x00, 0x16, 0x2a, 0x2a, 0x2a, 0x2a, 0x00, 0x7f, 0x00, 0x1c, 0x22, + 0x02, 0x1c, 0x20, 0x22, 0x1c }; + u8g2_DrawXBM(OLED, 58, 47, ms_width, ms_height, ms_bits); } + else if(isVarioUnitFPM) + { const int ms_width=7; + const int ms_height=17; + static unsigned char ms_bits[] = + { 0x84, 0xa2, 0xf7, 0xa2, 0xa2, 0xa2, 0xc2, 0x80, 0xff, 0x80, 0x00, 0x16, 0x2a, 0x2a, 0x2a, 0x2a, 0x00 }; + u8g2_DrawXBM(OLED, 58, 47, ms_width, ms_height, ms_bits); } // Speed if(GPS && GPS->isValid()) { uint16_t speed = (GPS->Speed*9+12)/25; + if(isSpeedUnitKnot) speed = (GPS->Speed*199+512)>>10; Len=Format_UnsDec(Line, speed, 1, 0); } else Len=Format_String(Line, "--"); @@ -853,13 +890,22 @@ void OLED_DrawAltitudeAndSpeed(u8g2_t *OLED, GPS_Position *GPS) uint8_t Speed_width = u8g2_GetStrWidth(OLED, Line); u8g2_DrawStr(OLED, 114-Speed_width, 64, Line); - const int kmh_width=10; - const int kmh_height=17; - static unsigned char kmh_bits[] = - { 0x01, 0x00, 0x01, 0x00, 0x69, 0x01, 0xa5, 0x02, 0xa3, 0x02, 0xa5, 0x02, - 0xa9, 0x02, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, - 0x08, 0x00, 0x38, 0x00, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00 }; - u8g2_DrawXBM(OLED, 118, 47, kmh_width, kmh_height, kmh_bits); + if(isSpeedUnitKMH) + { const int kmh_width=10; + const int kmh_height=17; + static unsigned char kmh_bits[] = + { 0x01, 0x00, 0x01, 0x00, 0x69, 0x01, 0xa5, 0x02, 0xa3, 0x02, 0xa5, 0x02, + 0xa9, 0x02, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, + 0x08, 0x00, 0x38, 0x00, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00 }; + u8g2_DrawXBM(OLED, 118, 47, kmh_width, kmh_height, kmh_bits); } + else if(isSpeedUnitKnot) + { const int kmh_width=10; + const int kmh_height=17; + static unsigned char kmh_bits[] = + { 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x01, 0xfc, 0x01, 0xfc, + 0xe9, 0xfc, 0x25, 0xfd, 0x23, 0xfd, 0x25, 0xfd, 0x29, 0xfd, 0x00, 0xfc, + 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc}; + u8g2_DrawXBM(OLED, 118, 47, kmh_width, kmh_height, kmh_bits); } } void OLED_DrawFlight(u8g2_t *OLED, GPS_Position *GPS) // draw flight status page diff --git a/main/http.cpp b/main/http.cpp index 525f39a..66b7f1f 100644 --- a/main/http.cpp +++ b/main/http.cpp @@ -212,41 +212,25 @@ static void ParmForm_GPS(httpd_req_t *Req) // produce HTML form for GPS paramet httpd_resp_sendstr_chunk(Req, "
\n"); httpd_resp_sendstr_chunk(Req, "\n"); } -static void ParmForm_Other(httpd_req_t *Req) // produce HTML form for parameters not included in other forms +static void ParmForm_Page(httpd_req_t *Req) // produce HTML form for parameters not included in other forms { char Line[16]; int Len; - httpd_resp_sendstr_chunk(Req, "

Other

"); - httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "

Pages

"); + httpd_resp_sendstr_chunk(Req, "\n"); - Begin_Control_Row(Req, "Freq. plan"); - const char *FreqPlanTable[6] = { "Auto", "Europe/Africa", "USA/Canada", "Australia/Chile", "New Zeeland", "Izrael" }; - SelectList(Req, "FreqPlan", FreqPlanTable, 6, Parameters.FreqPlan); + Begin_Control_Row(Req, "Altitude Unit"); + const char *AltitudeUnitTable[2] = { "meter", "feet" } ; + SelectList(Req, "AltitudeUnit", AltitudeUnitTable, 2, Parameters.AltitudeUnit); End_Control_Row(Req); - Begin_Control_Row(Req, "Tx power [dBm]"); - httpd_resp_sendstr_chunk(Req, ""); + Begin_Control_Row(Req, "Speed Unit"); + const char *SpeedUnitTable[2] = { "km/h", "knot" } ; + SelectList(Req, "SpeedUnit", SpeedUnitTable, 2, Parameters.SpeedUnit); End_Control_Row(Req); - Begin_Control_Row(Req, "Freq.corr. [ppm]"); - httpd_resp_sendstr_chunk(Req, ""); - End_Control_Row(Req); - - Begin_Control_Row(Req, "Console baud"); - httpd_resp_sendstr_chunk(Req, ""); - End_Control_Row(Req); - - Begin_Control_Row(Req, "Verbose"); - const char *VerboseTable[2] = { "0 (off)", "1 (on)" }; - SelectList(Req, "Verbose", VerboseTable, 2, Parameters.Verbose); + Begin_Control_Row(Req, "Vario Unit"); + const char *VarioUnitTable[2] = { "m/s", "fpm" } ; + SelectList(Req, "VarioUnit", VarioUnitTable, 2, Parameters.VarioUnit); End_Control_Row(Req); Begin_Control_Row(Req, "Pages"); @@ -299,6 +283,45 @@ function pageCheckbox(checkbox) {\n\ }\n\ \n"); + httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "
\n"); } + +static void ParmForm_Other(httpd_req_t *Req) // produce HTML form for parameters not included in other forms +{ char Line[16]; int Len; + + httpd_resp_sendstr_chunk(Req, "

Other

"); + httpd_resp_sendstr_chunk(Req, "
\n"); + + Begin_Control_Row(Req, "Freq. plan"); + const char *FreqPlanTable[6] = { "Auto", "Europe/Africa", "USA/Canada", "Australia/Chile", "New Zeeland", "Izrael" }; + SelectList(Req, "FreqPlan", FreqPlanTable, 6, Parameters.FreqPlan); + End_Control_Row(Req); + + Begin_Control_Row(Req, "Tx power [dBm]"); + httpd_resp_sendstr_chunk(Req, ""); + End_Control_Row(Req); + + Begin_Control_Row(Req, "Freq.corr. [ppm]"); + httpd_resp_sendstr_chunk(Req, ""); + End_Control_Row(Req); + + Begin_Control_Row(Req, "Console baud"); + httpd_resp_sendstr_chunk(Req, ""); + End_Control_Row(Req); + + Begin_Control_Row(Req, "Verbose"); + const char *VerboseTable[2] = { "0 (off)", "1 (on)" }; + SelectList(Req, "Verbose", VerboseTable, 2, Parameters.Verbose); + End_Control_Row(Req); httpd_resp_sendstr_chunk(Req, "
\n"); httpd_resp_sendstr_chunk(Req, "
\n"); } @@ -842,6 +865,8 @@ static esp_err_t parm_get_handler(httpd_req_t *Req) #ifdef WITH_STRATUX ParmForm_Stratux(Req); #endif + ParmForm_Page(Req); + ParmForm_Other(Req); ParmForm_Restart(Req); diff --git a/main/parameters.h b/main/parameters.h index 71f0672..b169c1a 100644 --- a/main/parameters.h +++ b/main/parameters.h @@ -130,6 +130,9 @@ class FlashParameters struct { uint32_t PageMask:27; // enable/disable individual pages on the LCD or OLED screen uint8_t InitialPage:5; // the first page to show after boot + uint8_t AltitudeUnit:2; // 0=meter, 1=feet + uint8_t SpeedUnit:2; // 0=km/h, 1=knot + uint8_t VarioUnit:2; // 0=m/s, 1=feet/minute } ; } ; @@ -269,6 +272,9 @@ uint16_t StratuxPort; PPSdelay = DEFAULT_PPSdelay; // [ms] PageMask = 0xFF; InitialPage = 0; + AltitudeUnit = 0; // meter + SpeedUnit = 0; // km/h + VarioUnit = 0; // m/s for(uint8_t Idx=0; Idx