Skip to content

Commit b8d31f4

Browse files
DusKing1ctzsnooze
andauthored
fix dshot beacon (#46)
Co-authored-by: ctzsnooze <[email protected]>
1 parent aae223b commit b8d31f4

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

src/main/drivers/dshot_command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ void dshotCommandWrite(uint8_t index, uint8_t motorCount, uint8_t command, dshot
235235
dshotCommandControl_t *commandControl = addCommand();
236236
if (commandControl) {
237237
commandControl->repeats = repeats;
238-
commandControl->delayAfterCommandUs = delayAfterCommandUs;
238+
commandControl->delayAfterCommandUs = DSHOT_COMMAND_DELAY_US;
239239
for (unsigned i = 0; i < motorCount; i++) {
240240
if (index == i || index == ALL_MOTORS) {
241241
commandControl->command[i] = command;

src/main/fc/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ void tryArm(void)
493493
const timeUs_t currentTimeUs = micros();
494494

495495
#ifdef USE_DSHOT
496-
if (currentTimeUs - getLastDshotBeaconCommandTimeUs() < DSHOT_BEACON_GUARD_DELAY_US) {
496+
if (cmpTimeUs(currentTimeUs, getLastDshotBeaconCommandTimeUs()) < DSHOT_BEACON_GUARD_DELAY_US) {
497497
if (tryingToArm == ARMING_DELAYED_DISARMED) {
498498
if (IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH)) {
499499
tryingToArm = ARMING_DELAYED_CRASHFLIP;

src/main/io/beeper.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,21 @@ void beeperUpdate(timeUs_t currentTimeUs)
400400
return;
401401
}
402402

403-
if (!beeperIsOn) {
404403
#ifdef USE_DSHOT
405-
if (!areMotorsRunning()
406-
&& ((currentBeeperEntry->mode == BEEPER_RX_SET && !(beeperConfig()->dshotBeaconOffFlags & BEEPER_GET_FLAG(BEEPER_RX_SET)))
407-
|| (currentBeeperEntry->mode == BEEPER_RX_LOST && !(beeperConfig()->dshotBeaconOffFlags & BEEPER_GET_FLAG(BEEPER_RX_LOST))))) {
408-
409-
if ((currentTimeUs - getLastDisarmTimeUs() > DSHOT_BEACON_GUARD_DELAY_US) && !isTryingToArm()) {
404+
if (!areMotorsRunning() && (currentBeeperEntry->mode == BEEPER_RX_SET || currentBeeperEntry->mode == BEEPER_RX_LOST)) {
405+
if (cmpTimeUs(currentTimeUs, getLastDisarmTimeUs()) > DSHOT_BEACON_GUARD_DELAY_US && !isTryingToArm()) {
406+
const timeDelta_t dShotBeaconInterval = (currentBeeperEntry->mode == BEEPER_RX_SET) ? DSHOT_BEACON_MODE_INTERVAL_US : DSHOT_BEACON_RXLOSS_INTERVAL_US;
407+
if (cmpTimeUs(currentTimeUs, lastDshotBeaconCommandTimeUs) > dShotBeaconInterval) {
408+
// at least 500ms between DShot beacons to allow time for the sound to fully complete
409+
// the DShot Beacon tone duration is determined by the ESC, and should not exceed 250ms
410410
lastDshotBeaconCommandTimeUs = currentTimeUs;
411411
dshotCommandWrite(ALL_MOTORS, getMotorCount(), beeperConfig()->dshotBeaconTone, DSHOT_CMD_TYPE_INLINE);
412412
}
413413
}
414+
}
414415
#endif
415416

417+
if (!beeperIsOn) {
416418
if (currentBeeperEntry->sequence[beeperPos] != 0) {
417419
if (!(beeperConfig()->beeper_off_flags & BEEPER_GET_FLAG(currentBeeperEntry->mode))) {
418420
BEEP_ON;

src/main/io/beeper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#ifdef USE_DSHOT
2828
#define DSHOT_BEACON_GUARD_DELAY_US 1200000 // Time to separate dshot beacon and armining/disarming events
2929
// to prevent interference with motor direction commands
30+
#define DSHOT_BEACON_MODE_INTERVAL_US 450000 // at least 450ms between successive DShot beacon iterations to allow time for ESC to play tone
31+
#define DSHOT_BEACON_RXLOSS_INTERVAL_US 950000 // at least 950ms between successive DShot beacon iterations to allow time for ESC to play tone
32+
// we check beeper every 100ms, so these result in 500ms and 1.0s in practice
3033
#endif
3134

3235
typedef enum {

0 commit comments

Comments
 (0)