From b5cb1bf65aa8a58e4deff08a4e6630a9229cfb0d Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Sat, 10 Nov 2018 15:28:10 -0500 Subject: [PATCH] Add osd_ah_invert to allow reversing the direction of the OSD artificial horizon --- src/main/interface/settings.c | 1 + src/main/io/osd.c | 6 ++++-- src/main/io/osd.h | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index f9a2d3149..dfa92fc14 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -1024,6 +1024,7 @@ const clivalue_t valueTable[] = { { "osd_ah_max_pit", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 90 }, PG_OSD_CONFIG, offsetof(osdConfig_t, ahMaxPitch) }, { "osd_ah_max_rol", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 90 }, PG_OSD_CONFIG, offsetof(osdConfig_t, ahMaxRoll) }, + { "osd_ah_invert", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, ahInvert) }, { "osd_tim1", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, INT16_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, timers[OSD_TIMER_1]) }, { "osd_tim2", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, INT16_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, timers[OSD_TIMER_2]) }, diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 0be00a849..09bf261c6 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -755,8 +755,9 @@ static bool osdDrawSingleElement(uint8_t item) // Get pitch and roll limits in tenths of degrees const int maxPitch = osdConfig()->ahMaxPitch * 10; const int maxRoll = osdConfig()->ahMaxRoll * 10; - const int rollAngle = constrain(attitude.values.roll, -maxRoll, maxRoll); - int pitchAngle = constrain(attitude.values.pitch, -maxPitch, maxPitch); + const int ahSign = osdConfig()->ahInvert ? -1 : 1; + const int rollAngle = constrain(attitude.values.roll * ahSign, -maxRoll, maxRoll); + int pitchAngle = constrain(attitude.values.pitch * ahSign, -maxPitch, maxPitch); // Convert pitchAngle to y compensation value // (maxPitch / 25) divisor matches previous settings of fixed divisor of 8 and fixed max AHI pitch angle of 20.0 degrees if (maxPitch > 0) { @@ -1244,6 +1245,7 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig) osdConfig->ahMaxPitch = 20; // 20 degrees osdConfig->ahMaxRoll = 40; // 40 degrees + osdConfig->ahInvert = false; } static void osdDrawLogo(int x, int y) diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 07ef9f280..ac9ca614a 100644 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -205,6 +205,7 @@ typedef struct osdConfig_s { int16_t esc_rpm_alarm; int16_t esc_current_alarm; uint8_t core_temp_alarm; + uint8_t ahInvert; // invert the artificial horizon } osdConfig_t; PG_DECLARE(osdConfig_t, osdConfig);