Skip to content

Commit f025ee5

Browse files
authored
Merge pull request #9769 from iNavFlight/MrD_Show-OSD-message-for-inflight-rearm-possible
Show a timeout for in flight rearming
2 parents ea55fd6 + 7929838 commit f025ee5

3 files changed

Lines changed: 47 additions & 16 deletions

File tree

src/main/fc/fc_core.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,18 @@ bool emergencyArmingUpdate(bool armingSwitchIsOn, bool forceArm)
507507
return counter >= EMERGENCY_ARMING_MIN_ARM_COUNT;
508508
}
509509

510+
uint16_t emergencyInFlightRearmTimeMS(void)
511+
{
512+
uint16_t rearmMS = 0;
513+
514+
if (STATE(IN_FLIGHT_EMERG_REARM)) {
515+
timeMs_t currentTimeMs = millis();
516+
rearmMS = (uint16_t)((US2MS(lastDisarmTimeUs) + EMERGENCY_INFLIGHT_REARM_TIME_WINDOW_MS) - currentTimeMs);
517+
}
518+
519+
return rearmMS;
520+
}
521+
510522
bool emergInflightRearmEnabled(void)
511523
{
512524
/* Emergency rearm allowed within 5s timeout period after disarm if craft still flying */
@@ -880,7 +892,6 @@ static void applyThrottleTiltCompensation(void)
880892

881893
void taskMainPidLoop(timeUs_t currentTimeUs)
882894
{
883-
884895
cycleTime = getTaskDeltaTime(TASK_SELF);
885896
dT = (float)cycleTime * 0.000001f;
886897

@@ -899,7 +910,8 @@ void taskMainPidLoop(timeUs_t currentTimeUs)
899910
}
900911
}
901912

902-
if (armTime > 1 * USECS_PER_SEC) { // reset in flight emerg rearm flag 1 sec after arming once it's served its purpose
913+
if (armTime > 1 * USECS_PER_SEC) {
914+
// reset in flight emerg rearm flag 1 sec after arming once it's served its purpose
903915
DISABLE_STATE(IN_FLIGHT_EMERG_REARM);
904916
}
905917

src/main/fc/fc_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ timeUs_t getLastDisarmTimeUs(void);
4242
void tryArm(void);
4343
disarmReason_t getDisarmReason(void);
4444

45+
uint16_t emergencyInFlightRearmTimeMS(void);
4546
bool emergencyArmingUpdate(bool armingSwitchIsOn, bool forceArm);
47+
bool emergInflightRearmEnabled(void);
4648

4749
bool areSensorsCalibrating(void);
4850
float getFlightTime(void);

src/main/io/osd.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <string.h>
2929
#include <ctype.h>
3030
#include <math.h>
31+
#include <inttypes.h>
3132

3233
#include "platform.h"
3334

@@ -4560,8 +4561,16 @@ static void osdShowStats(bool isSinglePageStatsCompatible, uint8_t page)
45604561
displayWrite(osdDisplayPort, statValuesX + multiValueLengthOffset, top++, buff);
45614562
}
45624563

4564+
uint16_t rearmMs = (emergInflightRearmEnabled()) ? emergencyInFlightRearmTimeMS() : 0;
4565+
45634566
if (savingSettings == true) {
45644567
displayWrite(osdDisplayPort, statNameX, top++, OSD_MESSAGE_STR(OSD_MSG_SAVING_SETTNGS));
4568+
} else if (rearmMs > 0) { // Show rearming time if settings not actively being saved. Ignore the settings saved message if rearm available.
4569+
char emReArmMsg[23];
4570+
tfp_sprintf(emReArmMsg, "** REARM PERIOD: ");
4571+
tfp_sprintf(emReArmMsg + strlen(emReArmMsg), "%02d", (uint8_t)MS2S(rearmMs));
4572+
strcat(emReArmMsg, " **\0");
4573+
displayWrite(osdDisplayPort, statNameX, top++, OSD_MESSAGE_STR(emReArmMsg));
45654574
} else if (notify_settings_saved > 0) {
45664575
if (millis() > notify_settings_saved) {
45674576
notify_settings_saved = 0;
@@ -4861,9 +4870,10 @@ static void osdRefresh(timeUs_t currentTimeUs)
48614870
}
48624871

48634872
bool statsSinglePageCompatible = (osdDisplayPort->rows >= OSD_STATS_SINGLE_PAGE_MIN_ROWS);
4864-
static uint8_t statsCurrentPage = 0;
4865-
static bool statsDisplayed = false;
4866-
static bool statsAutoPagingEnabled = true;
4873+
static uint8_t statsCurrentPage = 0;
4874+
static timeMs_t statsRefreshTime = 0;
4875+
static bool statsDisplayed = false;
4876+
static bool statsAutoPagingEnabled = true;
48674877

48684878
// Detect arm/disarm
48694879
if (armState != ARMING_FLAG(ARMED)) {
@@ -4931,25 +4941,24 @@ static void osdRefresh(timeUs_t currentTimeUs)
49314941
// Alternate screens for multi-page stats.
49324942
// Also, refreshes screen at swap interval for single-page stats.
49334943
if (OSD_ALTERNATING_CHOICES((osdConfig()->stats_page_auto_swap_time * 1000), 2)) {
4934-
if (statsCurrentPage == 0) {
4935-
osdShowStats(statsSinglePageCompatible, statsCurrentPage);
4944+
if (statsCurrentPage == 0)
49364945
statsCurrentPage = 1;
4937-
}
49384946
} else {
4939-
if (statsCurrentPage == 1) {
4940-
osdShowStats(statsSinglePageCompatible, statsCurrentPage);
4947+
if (statsCurrentPage == 1)
49414948
statsCurrentPage = 0;
4942-
}
49434949
}
49444950
} else {
49454951
// Process manual page change events for multi-page stats.
4946-
if (manualPageUpRequested) {
4947-
osdShowStats(statsSinglePageCompatible, 1);
4952+
if (manualPageUpRequested)
49484953
statsCurrentPage = 1;
4949-
} else if (manualPageDownRequested) {
4950-
osdShowStats(statsSinglePageCompatible, 0);
4954+
else if (manualPageDownRequested)
49514955
statsCurrentPage = 0;
4952-
}
4956+
}
4957+
4958+
// Only refresh the stats every 1/4 of a second.
4959+
if (statsRefreshTime <= millis()) {
4960+
statsRefreshTime = millis() + 250;
4961+
osdShowStats(statsSinglePageCompatible, statsCurrentPage);
49534962
}
49544963
}
49554964

@@ -5306,9 +5315,16 @@ textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenter
53065315
}
53075316

53085317
/* Messages that are shown regardless of Arming state */
5318+
uint16_t rearmMs = (emergInflightRearmEnabled()) ? emergencyInFlightRearmTimeMS() : 0;
53095319

53105320
if (savingSettings == true) {
53115321
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_SAVING_SETTNGS);
5322+
} else if (rearmMs > 0) { // Show rearming time if settings not actively being saved. Ignore the settings saved message if rearm available.
5323+
char emReArmMsg[23];
5324+
tfp_sprintf(emReArmMsg, "** REARM PERIOD: ");
5325+
tfp_sprintf(emReArmMsg + strlen(emReArmMsg), "%02d", (uint8_t)MS2S(rearmMs));
5326+
strcat(emReArmMsg, " **\0");
5327+
messages[messageCount++] = OSD_MESSAGE_STR(emReArmMsg);
53125328
} else if (notify_settings_saved > 0) {
53135329
if (millis() > notify_settings_saved) {
53145330
notify_settings_saved = 0;
@@ -5317,6 +5333,7 @@ textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenter
53175333
}
53185334
}
53195335

5336+
53205337
if (messageCount > 0) {
53215338
message = messages[OSD_ALTERNATING_CHOICES(systemMessageCycleTime(messageCount, messages), messageCount)];
53225339
if (message == failsafeInfoMessage) {

0 commit comments

Comments
 (0)