1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 00:05:33 +03:00

Merge pull request #4498 from mikeller/add_blackbox_always_on_option

Added option to have blackbox always on.
This commit is contained in:
Michael Keller 2017-11-07 18:06:38 +13:00 committed by GitHub
commit f4bb2f92bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 13 deletions

View file

@ -71,6 +71,11 @@
#include "sensors/gyro.h" #include "sensors/gyro.h"
#include "sensors/sonar.h" #include "sensors/sonar.h"
enum {
BLACKBOX_MODE_NORMAL = 0,
BLACKBOX_MODE_MOTOR_TEST,
BLACKBOX_MODE_ALWAYS_ON
};
#if defined(ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT) #if defined(ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT)
#define DEFAULT_BLACKBOX_DEVICE BLACKBOX_DEVICE_FLASH #define DEFAULT_BLACKBOX_DEVICE BLACKBOX_DEVICE_FLASH
@ -80,13 +85,13 @@
#define DEFAULT_BLACKBOX_DEVICE BLACKBOX_DEVICE_SERIAL #define DEFAULT_BLACKBOX_DEVICE BLACKBOX_DEVICE_SERIAL
#endif #endif
PG_REGISTER_WITH_RESET_TEMPLATE(blackboxConfig_t, blackboxConfig, PG_BLACKBOX_CONFIG, 0); PG_REGISTER_WITH_RESET_TEMPLATE(blackboxConfig_t, blackboxConfig, PG_BLACKBOX_CONFIG, 1);
PG_RESET_TEMPLATE(blackboxConfig_t, blackboxConfig, PG_RESET_TEMPLATE(blackboxConfig_t, blackboxConfig,
.p_denom = 32, .p_denom = 32,
.device = DEFAULT_BLACKBOX_DEVICE, .device = DEFAULT_BLACKBOX_DEVICE,
.on_motor_test = 0, // default off .record_acc = 1,
.record_acc = 1 .mode = BLACKBOX_MODE_NORMAL
); );
#define BLACKBOX_SHUTDOWN_TIMEOUT_MILLIS 200 #define BLACKBOX_SHUTDOWN_TIMEOUT_MILLIS 200
@ -889,9 +894,9 @@ void blackboxFinish(void)
/** /**
* Test Motors Blackbox Logging * Test Motors Blackbox Logging
*/ */
bool startedLoggingInTestMode = false; static bool startedLoggingInTestMode = false;
void startInTestMode(void) static void startInTestMode(void)
{ {
if (!startedLoggingInTestMode) { if (!startedLoggingInTestMode) {
if (blackboxConfig()->device == BLACKBOX_DEVICE_SERIAL) { if (blackboxConfig()->device == BLACKBOX_DEVICE_SERIAL) {
@ -904,7 +909,8 @@ void startInTestMode(void)
startedLoggingInTestMode = true; startedLoggingInTestMode = true;
} }
} }
void stopInTestMode(void)
static void stopInTestMode(void)
{ {
if (startedLoggingInTestMode) { if (startedLoggingInTestMode) {
blackboxFinish(); blackboxFinish();
@ -921,7 +927,7 @@ void stopInTestMode(void)
* Of course, after the 5 seconds and shutdown of the logger, the system will be re-enabled to allow the * Of course, after the 5 seconds and shutdown of the logger, the system will be re-enabled to allow the
* test mode to trigger again; its just that the data will be in a second, third, fourth etc log file. * test mode to trigger again; its just that the data will be in a second, third, fourth etc log file.
*/ */
bool inMotorTestMode(void) { static bool inMotorTestMode(void) {
static uint32_t resetTime = 0; static uint32_t resetTime = 0;
if (!ARMING_FLAG(ARMED) && areMotorsRunning()) { if (!ARMING_FLAG(ARMED) && areMotorsRunning()) {
@ -1649,20 +1655,37 @@ void blackboxUpdate(timeUs_t currentTimeUs)
#endif #endif
blackboxSetState(BLACKBOX_STATE_STOPPED); blackboxSetState(BLACKBOX_STATE_STOPPED);
// ensure we reset the test mode flag if we stop due to full memory card // ensure we reset the test mode flag if we stop due to full memory card
if (startedLoggingInTestMode) startedLoggingInTestMode = false; if (startedLoggingInTestMode) {
startedLoggingInTestMode = false;
}
#ifdef USE_FLASHFS #ifdef USE_FLASHFS
} }
#endif #endif
} else { // Only log in test mode if there is room! } else { // Only log in test mode if there is room!
if (blackboxConfig()->on_motor_test) { switch (blackboxConfig()->mode) {
case BLACKBOX_MODE_MOTOR_TEST:
// Handle Motor Test Mode // Handle Motor Test Mode
if (inMotorTestMode()) { if (inMotorTestMode()) {
if (blackboxState==BLACKBOX_STATE_STOPPED) if (blackboxState==BLACKBOX_STATE_STOPPED) {
startInTestMode(); startInTestMode();
}
} else { } else {
if (blackboxState!=BLACKBOX_STATE_STOPPED) if (blackboxState!=BLACKBOX_STATE_STOPPED) {
stopInTestMode(); stopInTestMode();
}
} }
break;
case BLACKBOX_MODE_ALWAYS_ON:
if (blackboxState==BLACKBOX_STATE_STOPPED) {
startInTestMode();
}
break;
case BLACKBOX_MODE_NORMAL:
default:
break;
} }
} }
} }

View file

@ -37,8 +37,8 @@ typedef enum BlackboxDevice {
typedef struct blackboxConfig_s { typedef struct blackboxConfig_s {
uint16_t p_denom; // I-frame interval / P-frame interval uint16_t p_denom; // I-frame interval / P-frame interval
uint8_t device; uint8_t device;
uint8_t on_motor_test;
uint8_t record_acc; uint8_t record_acc;
uint8_t mode;
} blackboxConfig_t; } blackboxConfig_t;
PG_DECLARE(blackboxConfig_t, blackboxConfig); PG_DECLARE(blackboxConfig_t, blackboxConfig);

View file

@ -162,6 +162,10 @@ static const char * const lookupTableGimbalMode[] = {
static const char * const lookupTableBlackboxDevice[] = { static const char * const lookupTableBlackboxDevice[] = {
"NONE", "SPIFLASH", "SDCARD", "SERIAL" "NONE", "SPIFLASH", "SDCARD", "SERIAL"
}; };
static const char * const lookupTableBlackboxMode[] = {
"NORMAL", "MOTOR_TEST", "ALWAYS"
};
#endif #endif
#ifdef SERIAL_RX #ifdef SERIAL_RX
@ -271,6 +275,7 @@ const lookupTableEntry_t lookupTables[] = {
#endif #endif
#ifdef USE_BLACKBOX #ifdef USE_BLACKBOX
{ lookupTableBlackboxDevice, sizeof(lookupTableBlackboxDevice) / sizeof(char *) }, { lookupTableBlackboxDevice, sizeof(lookupTableBlackboxDevice) / sizeof(char *) },
{ lookupTableBlackboxMode, sizeof(lookupTableBlackboxMode) / sizeof(char *) },
#endif #endif
{ lookupTableCurrentSensor, sizeof(lookupTableCurrentSensor) / sizeof(char *) }, { lookupTableCurrentSensor, sizeof(lookupTableCurrentSensor) / sizeof(char *) },
{ lookupTableBatterySensor, sizeof(lookupTableBatterySensor) / sizeof(char *) }, { lookupTableBatterySensor, sizeof(lookupTableBatterySensor) / sizeof(char *) },
@ -410,8 +415,8 @@ const clivalue_t valueTable[] = {
#ifdef USE_BLACKBOX #ifdef USE_BLACKBOX
{ "blackbox_p_ratio", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, INT16_MAX }, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, p_denom) }, { "blackbox_p_ratio", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, INT16_MAX }, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, p_denom) },
{ "blackbox_device", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BLACKBOX_DEVICE }, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, device) }, { "blackbox_device", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BLACKBOX_DEVICE }, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, device) },
{ "blackbox_on_motor_test", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, on_motor_test) },
{ "blackbox_record_acc", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, record_acc) }, { "blackbox_record_acc", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, record_acc) },
{ "blackbox_mode", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BLACKBOX_MODE }, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, mode) },
#endif #endif
// PG_MOTOR_CONFIG // PG_MOTOR_CONFIG

View file

@ -32,6 +32,7 @@ typedef enum {
#endif #endif
#ifdef USE_BLACKBOX #ifdef USE_BLACKBOX
TABLE_BLACKBOX_DEVICE, TABLE_BLACKBOX_DEVICE,
TABLE_BLACKBOX_MODE,
#endif #endif
TABLE_CURRENT_METER, TABLE_CURRENT_METER,
TABLE_VOLTAGE_METER, TABLE_VOLTAGE_METER,