From 31c5beaf78b43777bad3b2d251aa82e3a3d52b01 Mon Sep 17 00:00:00 2001 From: Ivan Efimov Date: Sat, 9 Dec 2023 18:50:31 -0600 Subject: [PATCH] OSD spec prearm screen if defined USE_SPEC_PREARM_SCREEN (#13210) * OSD spec prearm screen if defined USE_SPEC_PREARM_SCREEN * osd spec prearm PR suggestions * OSD_SPEC karatebrot logic suggestion * Update src/main/osd/osd.c Co-authored-by: Jan Post --------- Co-authored-by: Jan Post --- src/main/cli/settings.c | 3 +++ src/main/drivers/motor.c | 5 ++++ src/main/drivers/motor.h | 1 + src/main/osd/osd.c | 6 +++++ src/main/osd/osd.h | 11 +++++---- src/main/osd/osd_elements.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ src/main/osd/osd_elements.h | 3 +++ 7 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index 22d3490aa..3c3704e85 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -1381,6 +1381,9 @@ const clivalue_t valueTable[] = { #ifdef USE_QUICK_OSD_MENU { "osd_use_quick_menu", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, osd_use_quick_menu) }, #endif // USE_QUICK_OSD_MENU +#ifdef USE_SPEC_PREARM_SCREEN + { "osd_show_spec_prearm", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, osd_show_spec_prearm) }, +#endif // USE_SPEC_PREARM_SCREEN { "osd_tim1", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, INT16_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, timers[OSD_TIMER_1]) }, { "osd_tim2", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, INT16_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, timers[OSD_TIMER_2]) }, diff --git a/src/main/drivers/motor.c b/src/main/drivers/motor.c index dd336ca84..601e85a11 100644 --- a/src/main/drivers/motor.c +++ b/src/main/drivers/motor.c @@ -295,6 +295,11 @@ bool isMotorProtocolDshot(void) return motorProtocolDshot; } +bool isMotorProtocolBidirDshot(void) +{ + return isMotorProtocolDshot() && motorConfig()->dev.useDshotTelemetry; +} + void motorDevInit(const motorDevConfig_t *motorDevConfig, uint16_t idlePulse, uint8_t motorCount) { memset(motors, 0, sizeof(motors)); diff --git a/src/main/drivers/motor.h b/src/main/drivers/motor.h index 6dd2de92e..f0b628909 100644 --- a/src/main/drivers/motor.h +++ b/src/main/drivers/motor.h @@ -89,6 +89,7 @@ unsigned motorDeviceCount(void); motorVTable_t *motorGetVTable(void); bool checkMotorProtocolEnabled(const motorDevConfig_t *motorConfig, bool *protocolIsDshot); bool isMotorProtocolDshot(void); +bool isMotorProtocolBidirDshot(void); bool isMotorProtocolEnabled(void); void motorDisable(void); diff --git a/src/main/osd/osd.c b/src/main/osd/osd.c index 08b416f46..f32daf44a 100644 --- a/src/main/osd/osd.c +++ b/src/main/osd/osd.c @@ -427,6 +427,9 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig) #ifdef USE_QUICK_OSD_MENU osdConfig->osd_use_quick_menu = true; #endif // USE_QUICK_OSD_MENU +#ifdef USE_SPEC_PREARM_SCREEN + osdConfig->osd_show_spec_prearm = true; +#endif // USE_SPEC_PREARM_SCREEN } void pgResetFn_osdElementConfig(osdElementConfig_t *osdElementConfig) @@ -1577,6 +1580,9 @@ void osdUpdate(timeUs_t currentTimeUs) // There are more elements to draw break; } +#ifdef USE_SPEC_PREARM_SCREEN + osdDrawSpec(osdDisplayPort); +#endif // USE_SPEC_PREARM_SCREEN osdElementGroup = 0; diff --git a/src/main/osd/osd.h b/src/main/osd/osd.h index 5bb6060dd..0ef88ab1e 100644 --- a/src/main/osd/osd.h +++ b/src/main/osd/osd.h @@ -340,17 +340,20 @@ typedef struct osdConfig_s { uint16_t framerate_hz; uint8_t cms_background_type; // For supporting devices, determines whether the CMS background is transparent or opaque uint8_t stat_show_cell_value; - #ifdef USE_CRAFTNAME_MSGS +#ifdef USE_CRAFTNAME_MSGS uint8_t osd_craftname_msgs; // Insert LQ/RSSI-dBm and warnings into CraftName - #endif //USE_CRAFTNAME_MSGS +#endif //USE_CRAFTNAME_MSGS uint8_t aux_channel; uint16_t aux_scale; uint8_t aux_symbol; uint8_t canvas_cols; // Canvas dimensions for HD display uint8_t canvas_rows; - #ifdef USE_QUICK_OSD_MENU +#ifdef USE_QUICK_OSD_MENU uint8_t osd_use_quick_menu; // use QUICK menu YES/NO - #endif // USE_QUICK_OSD_MENU +#endif // USE_QUICK_OSD_MENU +#ifdef USE_SPEC_PREARM_SCREEN + uint8_t osd_show_spec_prearm; +#endif // USE_SPEC_PREARM_SCREEN } osdConfig_t; PG_DECLARE(osdConfig_t, osdConfig); diff --git a/src/main/osd/osd_elements.c b/src/main/osd/osd_elements.c index df467fa23..f0d331156 100644 --- a/src/main/osd/osd_elements.c +++ b/src/main/osd/osd_elements.c @@ -119,6 +119,8 @@ #include "build/build_config.h" #include "build/debug.h" +#include "cli/settings.h" + #include "common/axis.h" #include "common/maths.h" #include "common/printf.h" @@ -2107,6 +2109,62 @@ bool osdDrawNextActiveElement(displayPort_t *osdDisplayPort, timeUs_t currentTim return retval; } +#ifdef USE_SPEC_PREARM_SCREEN +void osdDrawSpec(displayPort_t *osdDisplayPort) +{ + if (!ARMING_FLAG(ARMED) && osdConfig()->osd_show_spec_prearm) { + const uint8_t midRow = osdDisplayPort->rows / 2; + const uint8_t midCol = osdDisplayPort->cols / 2; + + char buff[OSD_ELEMENT_BUFFER_LENGTH] = ""; + + memset(buff,0,strlen(buff)); + int len = 0; + int currentRow = midRow - 3; + +#ifdef USE_RPM_LIMIT + const bool rpmLimitActive = mixerConfig()->rpm_limit > 0 && isMotorProtocolBidirDshot(); + if (rpmLimitActive) { + len = tfp_sprintf(buff, "RPM LIMIT ON %d", mixerConfig()->rpm_limit_value); + } else { + len = tfp_sprintf(buff, "%s", "RPM LIMIT OFF"); + } + displayWrite(osdDisplayPort, midCol - len/2, currentRow++, DISPLAYPORT_SEVERITY_NORMAL, buff); + + if (rpmLimitActive) { + memset(buff,0,strlen(buff)); + len = tfp_sprintf(buff, "KV %d POLES %d", motorConfig()->kv, motorConfig()->motorPoleCount); + displayWrite(osdDisplayPort, midCol - len/2, currentRow++, DISPLAYPORT_SEVERITY_NORMAL, buff); + + memset(buff,0,strlen(buff)); + len = tfp_sprintf(buff, "%d %d %d", mixerConfig()->rpm_limit_p, mixerConfig()->rpm_limit_i, mixerConfig()->rpm_limit_d); + displayWrite(osdDisplayPort, midCol - len/2, currentRow++, DISPLAYPORT_SEVERITY_NORMAL, buff); + } else +#endif // #USE_RPM_LIMIT + { + memset(buff,0,strlen(buff)); + len = tfp_sprintf(buff, "THR LIMIT %s", lookupTableThrottleLimitType[currentControlRateProfile->throttle_limit_type]); + if (currentControlRateProfile->throttle_limit_type != THROTTLE_LIMIT_TYPE_OFF) { + len = tfp_sprintf(buff, "%s %d", buff, currentControlRateProfile->throttle_limit_percent); + } + displayWrite(osdDisplayPort, midCol - len/2, currentRow++, DISPLAYPORT_SEVERITY_NORMAL, buff); + } + + memset(buff,0,strlen(buff)); + len = tfp_sprintf(buff, "MOTOR LIMIT %d", currentPidProfile->motor_output_limit); + displayWrite(osdDisplayPort, midCol - len/2, currentRow++, DISPLAYPORT_SEVERITY_NORMAL, buff); + + memset(buff,0,strlen(buff)); + const float batteryVoltage = getBatteryVoltage() / 100.0f; + len = osdPrintFloat(buff, osdGetBatterySymbol(getBatteryAverageCellVoltage()), batteryVoltage, "", 2, true, SYM_VOLT); + displayWrite(osdDisplayPort, midCol - len/2, currentRow++, DISPLAYPORT_SEVERITY_NORMAL, buff); + + len = strlen(FC_VERSION_STRING); + displayWrite(osdDisplayPort, midCol - len/2, currentRow++, DISPLAYPORT_SEVERITY_NORMAL, FC_VERSION_STRING); + } +} +#endif // USE_SPEC_PREARM_SCREEN + void osdDrawActiveElementsBackground(displayPort_t *osdDisplayPort) { if (backgroundLayerSupported) { diff --git a/src/main/osd/osd_elements.h b/src/main/osd/osd_elements.h index ec09dec52..819b2e83b 100644 --- a/src/main/osd/osd_elements.h +++ b/src/main/osd/osd_elements.h @@ -64,3 +64,6 @@ void osdSyncBlink(); void osdResetAlarms(void); void osdUpdateAlarms(void); bool osdElementsNeedAccelerometer(void); +#ifdef USE_SPEC_PREARM_SCREEN +void osdDrawSpec(displayPort_t *osdDisplayPort); +#endif // USE_SPEC_PREARM_SCREEN -- 2.11.4.GIT