Skip to content

Commit d8c1fbe

Browse files
author
Ivan Efimov
committed
More stats, avg throttle, kaack time
1 parent 290b919 commit d8c1fbe

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

src/main/cli/settings.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,7 @@ const clivalue_t valueTable[] = {
17171717
{ "stats_min_armed_time_s", VAR_INT8 | MASTER_VALUE, .config.minmax = { STATS_OFF, INT8_MAX }, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_min_armed_time_s) },
17181718
{ "stats_total_flights", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_total_flights) },
17191719
{ "stats_extra_total_kaacks", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_extra_total_kaacks) },
1720+
{ "stats_extra_total_kaack_time", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_extra_total_kaack_time) },
17201721

17211722
{ "stats_total_time_s", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_total_time_s) },
17221723
{ "stats_total_dist_m", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_total_dist_m) },

src/main/cms/cms_menu_persistent_stats.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ uint32_t stats_total_flights;
3939
uint32_t stats_total_time_s;
4040
uint32_t stats_total_dist_m;
4141
uint32_t stats_extra_total_kaacks;
42+
uint32_t stats_extra_total_kaack_time;
4243
int8_t stats_min_armed_time_s;
4344

4445
static const void *cmsx_PersistentStats_onEnter(displayPort_t *pDisp)
@@ -50,6 +51,7 @@ static const void *cmsx_PersistentStats_onEnter(displayPort_t *pDisp)
5051
stats_total_dist_m = statsConfig()->stats_total_dist_m;
5152
stats_min_armed_time_s = statsConfig()->stats_min_armed_time_s;
5253
stats_extra_total_kaacks = statsConfig()->stats_extra_total_kaacks;
54+
stats_extra_total_kaack_time = statsConfig()->stats_extra_total_kaack_time;
5355

5456
return NULL;
5557
}
@@ -64,6 +66,7 @@ static const void *cmsx_PersistentStats_onExit(displayPort_t *pDisp, const OSD_E
6466
statsConfigMutable()->stats_total_dist_m = stats_total_dist_m;
6567
statsConfigMutable()->stats_min_armed_time_s = stats_min_armed_time_s;
6668
statsConfigMutable()->stats_extra_total_kaacks = stats_extra_total_kaacks;
69+
statsConfigMutable()->stats_extra_total_kaack_time = stats_extra_total_kaack_time;
6770

6871
return NULL;
6972
}
@@ -76,6 +79,7 @@ static const void *cmsx_ResetStats(displayPort_t *pDisplay, const void *ptr)
7679
stats_total_time_s = 0;
7780
stats_total_dist_m = 0;
7881
stats_extra_total_kaacks = 0;
82+
stats_extra_total_kaack_time = 0;
7983

8084
displayClearScreen(pDisplay, DISPLAY_CLEAR_WAIT);
8185
displayRedraw(pDisplay);
@@ -88,6 +92,7 @@ static const OSD_Entry cmsx_menuPersistentStatsEntries[] =
8892
{"-- PERSISTENT STATS --", OME_Label, NULL, NULL},
8993
{"FLIGHTS", OME_UINT32, NULL, &(OSD_UINT32_t){ &stats_total_flights, 0, UINT32_MAX, 1}},
9094
{"KAACKS", OME_UINT32, NULL, &(OSD_UINT32_t){ &stats_extra_total_kaacks, 0, UINT32_MAX, 1}},
95+
{"KAACK TIME", OME_UINT32, NULL, &(OSD_UINT32_t){ &stats_extra_total_kaack_time, 0, UINT32_MAX, 1}},
9196
{"TIME(sec)", OME_UINT32, NULL, &(OSD_UINT32_t){ &stats_total_time_s, 0, UINT32_MAX, 1}},
9297
{"DIST(m)", OME_UINT32, NULL, &(OSD_UINT32_t){ &stats_total_dist_m, 0, UINT32_MAX, 1}},
9398
{"RESET STATS", OME_Funcall, cmsx_ResetStats, NULL},

src/main/fc/stats.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ void statsOnDisarm(void)
9595
}
9696

9797
statsConfigMutable()->stats_extra_total_kaacks += osdGetStats()->extra_kaacks;
98+
statsConfigMutable()->stats_extra_total_kaack_time += (osdGetStats()->extra_kaack_time / 1000000);
9899

99100
dispatchAdd(&writeStatsEntry, STATS_SAVE_DELAY_US);
100101
}

src/main/osd/osd.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ const osd_stats_e osdStatsDisplayOrder[OSD_STAT_COUNT] = {
190190
OSD_STAT_TOTAL_DIST,
191191
OSD_STAT_EXTRA_KAACK,
192192
OSD_STAT_EXTRA_KAACK_TOTAL,
193+
OSD_STAT_EXTRA_KAACK_TIME,
194+
OSD_STAT_EXTRA_KAACK_TIME_TOTAL,
195+
OSD_STAT_EXTRA_AVG_THROTTLE
193196
};
194197

195198
// Group elements in a number of groups to reduce task scheduling overhead
@@ -500,6 +503,9 @@ static void osdResetStats(void)
500503
stats.min_link_quality = (linkQualitySource == LQ_SOURCE_NONE) ? 99 : 100; // percent
501504
stats.min_rssi_dbm = CRSF_SNR_MAX;
502505
stats.extra_kaacks = 0;
506+
stats.extra_kaack_time = 0;
507+
stats.extra_throttle_sum = 0;
508+
stats.extra_throttle_count = 0;
503509
}
504510

505511
#if defined(USE_ESC_SENSOR) || defined(USE_DSHOT_TELEMETRY)
@@ -885,6 +891,30 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
885891
osdDisplayStatisticLabel(displayRow, "TOTAL KAACKS", buff);
886892
return true;
887893

894+
case OSD_STAT_EXTRA_KAACK_TIME:
895+
{
896+
int seconds = stats.extra_kaack_time / 1000000;
897+
const int minutes = seconds / 60;
898+
seconds = seconds % 60;
899+
tfp_sprintf(buff, "%02d:%02d", minutes, seconds);
900+
}
901+
902+
osdDisplayStatisticLabel(displayRow, "KAACK TIME", buff);
903+
return true;
904+
case OSD_STAT_EXTRA_KAACK_TIME_TOTAL:
905+
{
906+
int seconds = statsConfig()->stats_extra_total_kaack_time;
907+
const int minutes = seconds / 60;
908+
seconds = seconds % 60;
909+
tfp_sprintf(buff, "%02d:%02d", minutes, seconds);
910+
}
911+
912+
osdDisplayStatisticLabel(displayRow, "TOTAL KAACK TIME", buff);
913+
return true;
914+
case OSD_STAT_EXTRA_AVG_THROTTLE:
915+
itoa(stats.extra_throttle_sum / stats.extra_throttle_count, buff, 10);
916+
osdDisplayStatisticLabel(displayRow, "AVG THROTTLE", buff);
917+
return true;
888918
}
889919
return false;
890920
}
@@ -1077,6 +1107,16 @@ STATIC_UNIT_TESTED bool osdProcessStats1(timeUs_t currentTimeUs)
10771107
timeUs_t deltaT = currentTimeUs - lastTimeUs;
10781108
osdFlyTime += deltaT;
10791109
stats.armed_time += deltaT;
1110+
1111+
const uint8_t throttleValue = calculateThrottlePercent();
1112+
1113+
stats.extra_throttle_count ++;
1114+
stats.extra_throttle_sum += throttleValue;
1115+
1116+
if (100 == throttleValue) {
1117+
stats.extra_kaack_time += deltaT;
1118+
}
1119+
10801120
} else if (osdStatsEnabled) { // handle showing/hiding stats based on OSD disable switch position
10811121
if (displayIsGrabbed(osdDisplayPort)) {
10821122
osdStatsEnabled = false;

src/main/osd/osd.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ typedef enum {
202202
OSD_STAT_MIN_RSSI_DBM,
203203
OSD_STAT_EXTRA_KAACK,
204204
OSD_STAT_EXTRA_KAACK_TOTAL,
205+
OSD_STAT_EXTRA_KAACK_TIME,
206+
OSD_STAT_EXTRA_KAACK_TIME_TOTAL,
207+
OSD_STAT_EXTRA_AVG_THROTTLE,
205208
OSD_STAT_COUNT // MUST BE LAST
206209
} osd_stats_e;
207210

@@ -332,6 +335,9 @@ typedef struct statistic_s {
332335
uint16_t min_link_quality;
333336
int16_t min_rssi_dbm;
334337
uint8_t extra_kaacks;
338+
uint32_t extra_kaack_time;
339+
uint32_t extra_throttle_sum;
340+
uint32_t extra_throttle_count;
335341
} statistic_t;
336342

337343
extern timeUs_t resumeRefreshAt;

src/main/pg/stats.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ PG_RESET_TEMPLATE(statsConfig_t, statsConfig,
3535
.stats_total_time_s = 0,
3636
.stats_total_dist_m = 0,
3737
.stats_extra_total_kaacks = 0,
38+
.stats_extra_total_kaack_time = 0,
3839
);
3940
#endif

src/main/pg/stats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ typedef struct statsConfig_s {
3131
uint32_t stats_total_dist_m;
3232
int8_t stats_min_armed_time_s;
3333
uint32_t stats_extra_total_kaacks;
34+
uint32_t stats_extra_total_kaack_time;
3435
} statsConfig_t;
3536

3637
PG_DECLARE(statsConfig_t, statsConfig);

0 commit comments

Comments
 (0)