Commit f2013ab8 authored by Dominic Clifton's avatar Dominic Clifton
Browse files

Merge pull request #936 from sherlockflight/blackbox-arm-beep

Fix Blackbox arming beep time logging
parents 11a4622a 94faf58e
......@@ -203,9 +203,9 @@ flight problems like vibration or PID setting issues.
The Blackbox starts recording data as soon as you arm your craft, and stops when you disarm.
If your craft has a buzzer attached, a short beep will be played when you arm and recording begins. You can later use
this beep to synchronize your recorded flight video with the rendered flight data log (the beep is shown as a blue line
in the flight data log, which you can sync against the beep in your recorded audio track).
If your craft has a buzzer attached, you can use Cleanflight's arming beep to synchronize your Blackbox log with your
flight video. Cleanflight's arming beep is a "long, short" pattern. The beginning of the first long beep will be shown
as a blue line in the flight data log, which you can sync against your recorded audio track.
You should wait a few seconds after disarming your craft to allow the Blackbox to finish saving its data.
......@@ -224,8 +224,9 @@ minutes.
![Dataflash tab in Configurator](Screenshots/blackbox-dataflash.png)
After downloading the log, be sure to erase the chip to make it ready for reuse by clicking the "erase flash" button.
If you try to start recording a new flight when the dataflash is already full, the Blackbox will not make its regular
arming beep and nothing will be recorded.
If you try to start recording a new flight when the dataflash is already full, Blackbox logging will be disabled and
nothing will be recorded.
## Converting logs to CSV or PNG
After your flights, you'll have a series of flight log files with a .TXT extension. You'll need to decode these with
......
......@@ -250,7 +250,6 @@ typedef enum BlackboxState {
BLACKBOX_STATE_SEND_GPS_H_HEADERS,
BLACKBOX_STATE_SEND_GPS_G_HEADERS,
BLACKBOX_STATE_SEND_SYSINFO,
BLACKBOX_STATE_PRERUN,
BLACKBOX_STATE_RUNNING,
BLACKBOX_STATE_SHUTTING_DOWN
} BlackboxState;
......@@ -268,6 +267,8 @@ extern uint32_t currentTime;
static BlackboxState blackboxState = BLACKBOX_STATE_DISABLED;
static uint32_t blackboxLastArmingBeep = 0;
static struct {
uint32_t headerIndex;
......@@ -684,6 +685,12 @@ void startBlackbox(void)
*/
blackboxBuildConditionCache();
/*
* Record the beeper's current idea of the last arming beep time, so that we can detect it changing when
* it finally plays the beep for this arming event.
*/
blackboxLastArmingBeep = getArmingBeepTimeMicros();
blackboxSetState(BLACKBOX_STATE_SEND_HEADER);
}
}
......@@ -1012,16 +1019,19 @@ void blackboxLogEvent(FlightLogEvent event, flightLogEventData_t *data)
}
}
// Write the time of the last arming beep to the log as a synchronization point
static void blackboxLogArmingBeep()
/* If an arming beep has played since it was last logged, write the time of the arming beep to the log as a synchronization point */
static void blackboxCheckAndLogArmingBeep()
{
flightLogEvent_syncBeep_t eventData;
// Get time of last arming beep (in system-uptime microseconds)
eventData.time = getArmingBeepTimeMicros();
// Use != so that we can still detect a change if the counter wraps
if (getArmingBeepTimeMicros() != blackboxLastArmingBeep) {
blackboxLastArmingBeep = getArmingBeepTimeMicros();
eventData.time = blackboxLastArmingBeep;
// Write the time to the log
blackboxLogEvent(FLIGHT_LOG_EVENT_SYNC_BEEP, (flightLogEventData_t *) &eventData);
blackboxLogEvent(FLIGHT_LOG_EVENT_SYNC_BEEP, (flightLogEventData_t *) &eventData);
}
}
/**
......@@ -1082,14 +1092,9 @@ void handleBlackbox(void)
//Keep writing chunks of the system info headers until it returns true to signal completion
if (blackboxWriteSysinfo()) {
blackboxSetState(BLACKBOX_STATE_PRERUN);
blackboxSetState(BLACKBOX_STATE_RUNNING);
}
break;
case BLACKBOX_STATE_PRERUN:
blackboxSetState(BLACKBOX_STATE_RUNNING);
blackboxLogArmingBeep();
break;
case BLACKBOX_STATE_RUNNING:
// On entry to this state, blackboxIteration, blackboxPFrameIndex and blackboxIFrameIndex are reset to 0
......@@ -1099,6 +1104,8 @@ void handleBlackbox(void)
loadBlackboxState();
writeIntraframe();
} else {
blackboxCheckAndLogArmingBeep();
/* Adding a magic shift of "masterConfig.blackbox_rate_num - 1" in here creates a better spread of
* recorded / skipped frames when the I frame's position is considered:
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment