OSD background rendering (#13897)
[betaflight.git] / src / main / blackbox / blackbox.h
blob6738f37d4560fb7a875aa0460d8eae31f09a8b6a
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 #pragma once
23 #include "platform.h"
24 #include "build/build_config.h"
25 #include "common/time.h"
26 #include "pg/pg.h"
28 typedef enum BlackboxDevice {
29 BLACKBOX_DEVICE_NONE = 0,
30 BLACKBOX_DEVICE_FLASH = 1,
31 BLACKBOX_DEVICE_SDCARD = 2,
32 BLACKBOX_DEVICE_SERIAL = 3
33 } BlackboxDevice_e;
35 typedef enum BlackboxMode {
36 BLACKBOX_MODE_NORMAL = 0,
37 BLACKBOX_MODE_MOTOR_TEST,
38 BLACKBOX_MODE_ALWAYS_ON
39 } BlackboxMode;
41 typedef enum BlackboxSampleRate { // Sample rate is 1/(2^BlackboxSampleRate)
42 BLACKBOX_RATE_ONE = 0,
43 BLACKBOX_RATE_HALF,
44 BLACKBOX_RATE_QUARTER,
45 BLACKBOX_RATE_8TH,
46 BLACKBOX_RATE_16TH
47 } BlackboxSampleRate_e;
49 typedef enum FlightLogEvent {
50 FLIGHT_LOG_EVENT_SYNC_BEEP = 0,
51 FLIGHT_LOG_EVENT_AUTOTUNE_CYCLE_START = 10, // UNUSED
52 FLIGHT_LOG_EVENT_AUTOTUNE_CYCLE_RESULT = 11, // UNUSED
53 FLIGHT_LOG_EVENT_AUTOTUNE_TARGETS = 12, // UNUSED
54 FLIGHT_LOG_EVENT_INFLIGHT_ADJUSTMENT = 13,
55 FLIGHT_LOG_EVENT_LOGGING_RESUME = 14,
56 FLIGHT_LOG_EVENT_DISARM = 15,
57 FLIGHT_LOG_EVENT_FLIGHTMODE = 30, // Add new event type for flight mode status.
58 FLIGHT_LOG_EVENT_LOG_END = 255
59 } FlightLogEvent;
61 typedef struct blackboxConfig_s {
62 uint32_t fields_disabled_mask;
63 uint8_t sample_rate; // sample rate
64 uint8_t device;
65 uint8_t mode;
66 uint8_t high_resolution;
67 } blackboxConfig_t;
69 PG_DECLARE(blackboxConfig_t, blackboxConfig);
71 union flightLogEventData_u;
72 void blackboxLogEvent(FlightLogEvent event, union flightLogEventData_u *data);
74 void blackboxInit(void);
75 void blackboxUpdate(timeUs_t currentTimeUs);
76 void blackboxSetStartDateTime(const char *dateTime, timeMs_t timeNowMs);
77 int blackboxCalculatePDenom(int rateNum, int rateDenom);
78 uint8_t blackboxGetRateDenom(void);
79 uint16_t blackboxGetPRatio(void);
80 uint8_t blackboxCalculateSampleRate(uint16_t pRatio);
81 void blackboxValidateConfig(void);
82 void blackboxFinish(void);
83 bool blackboxMayEditConfig(void);
84 #ifdef UNIT_TEST
85 STATIC_UNIT_TESTED void blackboxLogIteration(timeUs_t currentTimeUs);
86 STATIC_UNIT_TESTED bool blackboxShouldLogPFrame(void);
87 STATIC_UNIT_TESTED bool blackboxShouldLogIFrame(void);
88 STATIC_UNIT_TESTED bool blackboxShouldLogGpsHomeFrame(void);
89 STATIC_UNIT_TESTED bool writeSlowFrameIfNeeded(void);
90 // Called once every FC loop in order to keep track of how many FC loop iterations have passed
91 STATIC_UNIT_TESTED void blackboxAdvanceIterationTimers(void);
92 extern int32_t blackboxSInterval;
93 extern int32_t blackboxSlowFrameIterationTimer;
94 #endif