Merge pull request #5874 from etracer65/osd_warn_cli_parms
Add individual OSD warning options as cli parameters
This commit is contained in:
commit
6a24c115a8
|
@ -787,7 +787,14 @@ const clivalue_t valueTable[] = {
|
|||
// PG_OSD_CONFIG
|
||||
#ifdef USE_OSD
|
||||
{ "osd_units", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_UNIT }, PG_OSD_CONFIG, offsetof(osdConfig_t, units) },
|
||||
{ "osd_warnings", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, INT16_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, enabledWarnings) },
|
||||
|
||||
{ "osd_warn_arming_disable", VAR_UINT16 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_WARNING_ARMING_DISABLE, PG_OSD_CONFIG, offsetof(osdConfig_t, enabledWarnings)},
|
||||
{ "osd_warn_batt_not_full", VAR_UINT16 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_WARNING_BATTERY_NOT_FULL, PG_OSD_CONFIG, offsetof(osdConfig_t, enabledWarnings)},
|
||||
{ "osd_warn_batt_warning", VAR_UINT16 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_WARNING_BATTERY_WARNING, PG_OSD_CONFIG, offsetof(osdConfig_t, enabledWarnings)},
|
||||
{ "osd_warn_batt_critical", VAR_UINT16 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_WARNING_BATTERY_CRITICAL, PG_OSD_CONFIG, offsetof(osdConfig_t, enabledWarnings)},
|
||||
{ "osd_warn_visual_beeper", VAR_UINT16 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_WARNING_VISUAL_BEEPER, PG_OSD_CONFIG, offsetof(osdConfig_t, enabledWarnings)},
|
||||
{ "osd_warn_crash_flip", VAR_UINT16 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_WARNING_CRASH_FLIP, PG_OSD_CONFIG, offsetof(osdConfig_t, enabledWarnings)},
|
||||
{ "osd_warn_esc_fail", VAR_UINT16 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_WARNING_ESC_FAIL, PG_OSD_CONFIG, offsetof(osdConfig_t, enabledWarnings)},
|
||||
|
||||
{ "osd_rssi_alarm", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 100 }, PG_OSD_CONFIG, offsetof(osdConfig_t, rssi_alarm) },
|
||||
{ "osd_cap_alarm", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, 20000 }, PG_OSD_CONFIG, offsetof(osdConfig_t, cap_alarm) },
|
||||
|
|
|
@ -399,6 +399,20 @@ bool osdStatGetState(uint8_t statIndex)
|
|||
return osdConfig()->enabled_stats & (1 << statIndex);
|
||||
}
|
||||
|
||||
void osdWarnSetState(uint8_t warningIndex, bool enabled)
|
||||
{
|
||||
if (enabled) {
|
||||
osdConfigMutable()->enabledWarnings |= (1 << warningIndex);
|
||||
} else {
|
||||
osdConfigMutable()->enabledWarnings &= ~(1 << warningIndex);
|
||||
}
|
||||
}
|
||||
|
||||
bool osdWarnGetState(uint8_t warningIndex)
|
||||
{
|
||||
return osdConfig()->enabledWarnings & (1 << warningIndex);
|
||||
}
|
||||
|
||||
static bool osdDrawSingleElement(uint8_t item)
|
||||
{
|
||||
if (!VISIBLE(osdConfig()->item_pos[item]) || BLINK(item)) {
|
||||
|
@ -666,18 +680,16 @@ static bool osdDrawSingleElement(uint8_t item)
|
|||
|
||||
STATIC_ASSERT(OSD_FORMAT_MESSAGE_BUFFER_SIZE <= sizeof(buff), osd_warnings_size_exceeds_buffer_size);
|
||||
|
||||
const uint16_t enabledWarnings = osdConfig()->enabledWarnings;
|
||||
|
||||
const batteryState_e batteryState = getBatteryState();
|
||||
|
||||
if (enabledWarnings & OSD_WARNING_BATTERY_CRITICAL && batteryState == BATTERY_CRITICAL) {
|
||||
if (osdWarnGetState(OSD_WARNING_BATTERY_CRITICAL) && batteryState == BATTERY_CRITICAL) {
|
||||
osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, " LAND NOW");
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef USE_ESC_SENSOR
|
||||
// Show warning if we lose motor output, the ESC is overheating or excessive current draw
|
||||
if (feature(FEATURE_ESC_SENSOR) && enabledWarnings & OSD_WARNING_ESC_FAIL) {
|
||||
if (feature(FEATURE_ESC_SENSOR) && osdWarnGetState(OSD_WARNING_ESC_FAIL)) {
|
||||
char escWarningMsg[OSD_FORMAT_MESSAGE_BUFFER_SIZE];
|
||||
unsigned pos = 0;
|
||||
|
||||
|
@ -727,14 +739,13 @@ static bool osdDrawSingleElement(uint8_t item)
|
|||
#endif
|
||||
|
||||
// Warn when in flip over after crash mode
|
||||
if ((enabledWarnings & OSD_WARNING_CRASH_FLIP)
|
||||
&& (isFlipOverAfterCrashMode())) {
|
||||
if (osdWarnGetState(OSD_WARNING_CRASH_FLIP) && isFlipOverAfterCrashMode()) {
|
||||
osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, "CRASH FLIP");
|
||||
break;
|
||||
}
|
||||
|
||||
// Show most severe reason for arming being disabled
|
||||
if (enabledWarnings & OSD_WARNING_ARMING_DISABLE && IS_RC_MODE_ACTIVE(BOXARM) && isArmingDisabled()) {
|
||||
if (osdWarnGetState(OSD_WARNING_ARMING_DISABLE) && IS_RC_MODE_ACTIVE(BOXARM) && isArmingDisabled()) {
|
||||
const armingDisableFlags_e flags = getArmingDisableFlags();
|
||||
for (int i = 0; i < ARMING_DISABLE_FLAGS_COUNT; i++) {
|
||||
if (flags & (1 << i)) {
|
||||
|
@ -745,20 +756,20 @@ static bool osdDrawSingleElement(uint8_t item)
|
|||
break;
|
||||
}
|
||||
|
||||
if (enabledWarnings & OSD_WARNING_BATTERY_WARNING && batteryState == BATTERY_WARNING) {
|
||||
if (osdWarnGetState(OSD_WARNING_BATTERY_WARNING) && batteryState == BATTERY_WARNING) {
|
||||
osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, "LOW BATTERY");
|
||||
break;
|
||||
}
|
||||
|
||||
// Show warning if battery is not fresh
|
||||
if (enabledWarnings & OSD_WARNING_BATTERY_NOT_FULL && !ARMING_FLAG(WAS_EVER_ARMED) && (getBatteryState() == BATTERY_OK)
|
||||
if (osdWarnGetState(OSD_WARNING_BATTERY_NOT_FULL) && !ARMING_FLAG(WAS_EVER_ARMED) && (getBatteryState() == BATTERY_OK)
|
||||
&& getBatteryAverageCellVoltage() < batteryConfig()->vbatfullcellvoltage) {
|
||||
osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, "BATT < FULL");
|
||||
break;
|
||||
}
|
||||
|
||||
// Visual beeper
|
||||
if (enabledWarnings & OSD_WARNING_VISUAL_BEEPER && showVisualBeeper) {
|
||||
if (osdWarnGetState(OSD_WARNING_VISUAL_BEEPER) && showVisualBeeper) {
|
||||
osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, " * * * *");
|
||||
break;
|
||||
}
|
||||
|
@ -981,7 +992,9 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig)
|
|||
osdConfig->units = OSD_UNIT_METRIC;
|
||||
|
||||
// Enable all warnings by default
|
||||
osdConfig->enabledWarnings = UINT16_MAX;
|
||||
for (int i=0; i < OSD_WARNING_COUNT; i++) {
|
||||
osdWarnSetState(i, true);
|
||||
}
|
||||
|
||||
osdConfig->timers[OSD_TIMER_1] = OSD_TIMER(OSD_TIMER_SRC_ON, OSD_TIMER_PREC_SECOND, 10);
|
||||
osdConfig->timers[OSD_TIMER_2] = OSD_TIMER(OSD_TIMER_SRC_TOTAL_ARMED, OSD_TIMER_PREC_SECOND, 10);
|
||||
|
|
|
@ -150,15 +150,19 @@ typedef enum {
|
|||
} osd_timer_precision_e;
|
||||
|
||||
typedef enum {
|
||||
OSD_WARNING_ARMING_DISABLE = (1 << 0),
|
||||
OSD_WARNING_BATTERY_NOT_FULL = (1 << 1),
|
||||
OSD_WARNING_BATTERY_WARNING = (1 << 2),
|
||||
OSD_WARNING_BATTERY_CRITICAL = (1 << 3),
|
||||
OSD_WARNING_VISUAL_BEEPER = (1 << 4),
|
||||
OSD_WARNING_CRASH_FLIP = (1 << 5),
|
||||
OSD_WARNING_ESC_FAIL = (1 << 6)
|
||||
OSD_WARNING_ARMING_DISABLE,
|
||||
OSD_WARNING_BATTERY_NOT_FULL,
|
||||
OSD_WARNING_BATTERY_WARNING,
|
||||
OSD_WARNING_BATTERY_CRITICAL,
|
||||
OSD_WARNING_VISUAL_BEEPER,
|
||||
OSD_WARNING_CRASH_FLIP,
|
||||
OSD_WARNING_ESC_FAIL,
|
||||
OSD_WARNING_COUNT // MUST BE LAST
|
||||
} osdWarningsFlags_e;
|
||||
|
||||
// Make sure the number of warnings do not exceed the available 16bit storage
|
||||
STATIC_ASSERT(OSD_WARNING_COUNT <= 16, osdwarnings_overflow);
|
||||
|
||||
#define ESC_RPM_ALARM_OFF -1
|
||||
#define ESC_TEMP_ALARM_OFF INT8_MIN
|
||||
#define ESC_CURRENT_ALARM_OFF -1
|
||||
|
@ -194,4 +198,7 @@ void osdResetAlarms(void);
|
|||
void osdUpdate(timeUs_t currentTimeUs);
|
||||
void osdStatSetState(uint8_t statIndex, bool enabled);
|
||||
bool osdStatGetState(uint8_t statIndex);
|
||||
void osdWarnSetState(uint8_t warningIndex, bool enabled);
|
||||
bool osdWarnGetState(uint8_t warningIndex);
|
||||
|
||||
|
||||
|
|
|
@ -791,7 +791,10 @@ TEST(OsdTest, TestElementWarningsBattery)
|
|||
{
|
||||
// given
|
||||
osdConfigMutable()->item_pos[OSD_WARNINGS] = OSD_POS(9, 10) | VISIBLE_FLAG;
|
||||
osdConfigMutable()->enabledWarnings = OSD_WARNING_BATTERY_WARNING | OSD_WARNING_BATTERY_CRITICAL | OSD_WARNING_BATTERY_NOT_FULL;
|
||||
osdConfigMutable()->enabledWarnings = 0; // disable all warnings
|
||||
osdWarnSetState(OSD_WARNING_BATTERY_WARNING, true);
|
||||
osdWarnSetState(OSD_WARNING_BATTERY_CRITICAL, true);
|
||||
osdWarnSetState(OSD_WARNING_BATTERY_NOT_FULL, true);
|
||||
|
||||
// and
|
||||
batteryConfigMutable()->vbatfullcellvoltage = 41;
|
||||
|
|
Loading…
Reference in New Issue