Add OSD_STATE_GROUP_ELEMENTS state to osdUpdate() and optimise DMA vs polled MAX7456...
[betaflight.git] / src / main / blackbox / blackbox.h
blob7d90292184d6db346e9f9cd69eaa8fb87f159f09
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 uint8_t sample_rate; // sample rate
63 uint8_t device;
64 uint32_t fields_disabled_mask;
65 uint8_t mode;
66 } blackboxConfig_t;
68 PG_DECLARE(blackboxConfig_t, blackboxConfig);
70 union flightLogEventData_u;
71 void blackboxLogEvent(FlightLogEvent event, union flightLogEventData_u *data);
73 void blackboxInit(void);
74 void blackboxUpdate(timeUs_t currentTimeUs);
75 void blackboxSetStartDateTime(const char *dateTime, timeMs_t timeNowMs);
76 int blackboxCalculatePDenom(int rateNum, int rateDenom);
77 uint8_t blackboxGetRateDenom(void);
78 uint16_t blackboxGetPRatio(void);
79 uint8_t blackboxCalculateSampleRate(uint16_t pRatio);
80 void blackboxValidateConfig(void);
81 void blackboxFinish(void);
82 bool blackboxMayEditConfig(void);
83 #ifdef UNIT_TEST
84 STATIC_UNIT_TESTED void blackboxLogIteration(timeUs_t currentTimeUs);
85 STATIC_UNIT_TESTED bool blackboxShouldLogPFrame(void);
86 STATIC_UNIT_TESTED bool blackboxShouldLogIFrame(void);
87 STATIC_UNIT_TESTED bool blackboxShouldLogGpsHomeFrame(void);
88 STATIC_UNIT_TESTED bool writeSlowFrameIfNeeded(void);
89 // Called once every FC loop in order to keep track of how many FC loop iterations have passed
90 STATIC_UNIT_TESTED void blackboxAdvanceIterationTimers(void);
91 extern int32_t blackboxSInterval;
92 extern int32_t blackboxSlowFrameIterationTimer;
93 #endif