Moved configuration validation into 'config.c'.
[betaflight.git] / src / main / blackbox / blackbox.h
blob694343d44b04a002bc91e35ea09ec68bb1a9d1eb
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 FlightLogEvent {
42 FLIGHT_LOG_EVENT_SYNC_BEEP = 0,
43 FLIGHT_LOG_EVENT_INFLIGHT_ADJUSTMENT = 13,
44 FLIGHT_LOG_EVENT_LOGGING_RESUME = 14,
45 FLIGHT_LOG_EVENT_FLIGHTMODE = 30, // Add new event type for flight mode status.
46 FLIGHT_LOG_EVENT_LOG_END = 255
47 } FlightLogEvent;
49 typedef struct blackboxConfig_s {
50 uint16_t p_ratio; // I-frame interval / P-frame interval
51 uint8_t device;
52 uint8_t record_acc;
53 uint8_t mode;
54 } blackboxConfig_t;
56 PG_DECLARE(blackboxConfig_t, blackboxConfig);
58 union flightLogEventData_u;
59 void blackboxLogEvent(FlightLogEvent event, union flightLogEventData_u *data);
61 void blackboxInit(void);
62 void blackboxUpdate(timeUs_t currentTimeUs);
63 void blackboxSetStartDateTime(const char *dateTime, timeMs_t timeNowMs);
64 int blackboxCalculatePDenom(int rateNum, int rateDenom);
65 uint8_t blackboxGetRateDenom(void);
66 void blackboxValidateConfig(void);
67 void blackboxFinish(void);
68 bool blackboxMayEditConfig(void);
69 #ifdef UNIT_TEST
70 STATIC_UNIT_TESTED void blackboxLogIteration(timeUs_t currentTimeUs);
71 STATIC_UNIT_TESTED bool blackboxShouldLogPFrame(void);
72 STATIC_UNIT_TESTED bool blackboxShouldLogIFrame(void);
73 STATIC_UNIT_TESTED bool blackboxShouldLogGpsHomeFrame(void);
74 STATIC_UNIT_TESTED bool writeSlowFrameIfNeeded(void);
75 // Called once every FC loop in order to keep track of how many FC loop iterations have passed
76 STATIC_UNIT_TESTED void blackboxAdvanceIterationTimers(void);
77 extern int32_t blackboxSInterval;
78 extern int32_t blackboxSlowFrameIterationTimer;
79 #endif