Merge pull request #11299 from daleckystepan/vtx-start-bit
[betaflight.git] / src / main / cms / cms_menu_persistent_stats.c
blob122ee42f363b3ae9e5954d392a135c0c373bfc56
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <string.h>
24 #include <ctype.h>
26 #include "platform.h"
28 #ifdef USE_CMS
29 #ifdef USE_PERSISTENT_STATS
31 #include "cms/cms.h"
32 #include "cms/cms_types.h"
33 #include "cms/cms_menu_persistent_stats.h"
35 #include "config/config.h"
36 #include "pg/stats.h"
38 uint32_t stats_total_flights;
39 uint32_t stats_total_time_s;
40 uint32_t stats_total_dist_m;
41 int8_t stats_min_armed_time_s;
43 static const void *cmsx_PersistentStats_onEnter(displayPort_t *pDisp)
45 UNUSED(pDisp);
47 stats_total_flights = statsConfig()->stats_total_flights;
48 stats_total_time_s = statsConfig()->stats_total_time_s;
49 stats_total_dist_m = statsConfig()->stats_total_dist_m;
50 stats_min_armed_time_s = statsConfig()->stats_min_armed_time_s;
52 return NULL;
55 static const void *cmsx_PersistentStats_onExit(displayPort_t *pDisp, const OSD_Entry *self)
57 UNUSED(pDisp);
58 UNUSED(self);
60 statsConfigMutable()->stats_total_flights = stats_total_flights;
61 statsConfigMutable()->stats_total_time_s = stats_total_time_s;
62 statsConfigMutable()->stats_total_dist_m = stats_total_dist_m;
63 statsConfigMutable()->stats_min_armed_time_s = stats_min_armed_time_s;
65 return NULL;
68 static const void *cmsx_ResetStats(displayPort_t *pDisplay, const void *ptr)
70 UNUSED(ptr);
72 stats_total_flights = 0;
73 stats_total_time_s = 0;
74 stats_total_dist_m = 0;
76 displayClearScreen(pDisplay);
77 displayRedraw(pDisplay);
79 return NULL;
82 static const OSD_Entry cmsx_menuPersistentStatsEntries[] =
84 {"-- PERSISTENT STATS --", OME_Label, NULL, NULL},
85 {"FLIGHTS", OME_UINT32, NULL, &(OSD_UINT32_t){ &stats_total_flights, 0, UINT32_MAX, 1}},
86 {"TIME(sec)", OME_UINT32, NULL, &(OSD_UINT32_t){ &stats_total_time_s, 0, UINT32_MAX, 1}},
87 {"DIST(m)", OME_UINT32, NULL, &(OSD_UINT32_t){ &stats_total_dist_m, 0, UINT32_MAX, 1}},
88 {"RESET STATS", OME_Funcall, cmsx_ResetStats, NULL},
89 {"--- SETTINGS ---", OME_Label, NULL, NULL},
90 {"MIN ARMED TIME(sec)", OME_INT8, NULL, &(OSD_INT8_t){ &stats_min_armed_time_s, -1, INT8_MAX, 1}},
92 {"BACK", OME_Back, NULL, NULL},
93 { NULL, OME_END, NULL, NULL}
96 CMS_Menu cmsx_menuPersistentStats = {
97 #ifdef CMS_MENU_DEBUG
98 .GUARD_text = "PRESSTATS",
99 .GUARD_type = OME_MENU,
100 #endif
101 .onEnter = cmsx_PersistentStats_onEnter,
102 .onExit = cmsx_PersistentStats_onExit,
103 .onDisplayUpdate = NULL,
104 .entries = cmsx_menuPersistentStatsEntries
107 #endif
108 #endif