1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 20:10:18 +03:00

Implemented 'beacon' command in CLI.

This commit is contained in:
mikeller 2018-05-31 01:48:27 +12:00
parent ab916d16b2
commit 7e8f261436
8 changed files with 97 additions and 99 deletions

View file

@ -350,6 +350,21 @@ static void validateAndFixConfig(void)
if (beeperDevConfig()->frequency && !timerGetByTag(beeperDevConfig()->ioTag)) { if (beeperDevConfig()->frequency && !timerGetByTag(beeperDevConfig()->ioTag)) {
beeperDevConfigMutable()->frequency = 0; beeperDevConfigMutable()->frequency = 0;
} }
if (beeperConfig()->beeper_off_flags & ~BEEPER_ALLOWED_MODES) {
beeperConfigMutable()->beeper_off_flags = 0;
}
#ifdef USE_DSHOT
if (beeperConfig()->dshotBeaconOffFlags & ~DSHOT_BEACON_ALLOWED_MODES) {
beeperConfigMutable()->dshotBeaconOffFlags = 0;
}
if (beeperConfig()->dshotBeaconTone < DSHOT_CMD_BEACON1
|| beeperConfig()->dshotBeaconTone > DSHOT_CMD_BEACON5) {
beeperConfigMutable()->dshotBeaconTone = DSHOT_CMD_BEACON1;
}
#endif
#endif #endif
#if defined(TARGET_VALIDATECONFIG) #if defined(TARGET_VALIDATECONFIG)
@ -522,55 +537,3 @@ void changePidProfile(uint8_t pidProfileIndex)
beeperConfirmationBeeps(pidProfileIndex + 1); beeperConfirmationBeeps(pidProfileIndex + 1);
} }
#endif #endif
void beeperOffSet(uint32_t mask)
{
#ifdef USE_BEEPER
beeperConfigMutable()->beeper_off_flags |= mask;
#else
UNUSED(mask);
#endif
}
void beeperOffSetAll(uint8_t beeperCount)
{
#ifdef USE_BEEPER
beeperConfigMutable()->beeper_off_flags = (1 << beeperCount) -1;
#else
UNUSED(beeperCount);
#endif
}
void beeperOffClear(uint32_t mask)
{
#ifdef USE_BEEPER
beeperConfigMutable()->beeper_off_flags &= ~(mask);
#else
UNUSED(mask);
#endif
}
void beeperOffClearAll(void)
{
#ifdef USE_BEEPER
beeperConfigMutable()->beeper_off_flags = 0;
#endif
}
uint32_t getBeeperOffMask(void)
{
#ifdef USE_BEEPER
return beeperConfig()->beeper_off_flags;
#else
return 0;
#endif
}
void setBeeperOffMask(uint32_t mask)
{
#ifdef USE_BEEPER
beeperConfigMutable()->beeper_off_flags = mask;
#else
UNUSED(mask);
#endif
}

View file

@ -49,13 +49,6 @@ PG_DECLARE(systemConfig_t, systemConfig);
struct pidProfile_s; struct pidProfile_s;
extern struct pidProfile_s *currentPidProfile; extern struct pidProfile_s *currentPidProfile;
void beeperOffSet(uint32_t mask);
void beeperOffSetAll(uint8_t beeperCount);
void beeperOffClear(uint32_t mask);
void beeperOffClearAll(void);
uint32_t getBeeperOffMask(void);
void setBeeperOffMask(uint32_t mask);
void initEEPROM(void); void initEEPROM(void);
void resetEEPROM(void); void resetEEPROM(void);
bool readEEPROM(void); bool readEEPROM(void);

View file

@ -90,6 +90,7 @@
#include "msp/msp_serial.h" #include "msp/msp_serial.h"
#include "pg/adc.h" #include "pg/adc.h"
#include "pg/beeper.h"
#include "pg/beeper_dev.h" #include "pg/beeper_dev.h"
#include "pg/bus_i2c.h" #include "pg/bus_i2c.h"
#include "pg/bus_spi.h" #include "pg/bus_spi.h"
@ -519,10 +520,16 @@ void init(void)
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
LED1_TOGGLE; LED1_TOGGLE;
LED0_TOGGLE; LED0_TOGGLE;
#if defined(USE_BEEPER)
delay(25); delay(25);
if (!(getBeeperOffMask() & (1 << (BEEPER_SYSTEM_INIT - 1)))) BEEP_ON; if (!(beeperConfig()->beeper_off_flags & BEEPER_GET_FLAG(BEEPER_SYSTEM_INIT))) {
BEEP_ON;
}
delay(25); delay(25);
BEEP_OFF; BEEP_OFF;
#else
delay(50);
#endif
} }
LED0_OFF; LED0_OFF;
LED1_OFF; LED1_OFF;

View file

@ -2321,8 +2321,8 @@ static void cliFeature(char *cmdline)
} }
} }
#if defined(USE_BEEPER) || defined(USE_DSHOT) #if defined(USE_BEEPER)
static void printBeeper(uint8_t dumpMask, const uint32_t offFlags, const uint32_t offFlagsDefault, char *name) static void printBeeper(uint8_t dumpMask, const uint32_t offFlags, const uint32_t offFlagsDefault, const char *name)
{ {
const uint8_t beeperCount = beeperTableEntryCount(); const uint8_t beeperCount = beeperTableEntryCount();
for (int32_t i = 0; i < beeperCount - 2; i++) { for (int32_t i = 0; i < beeperCount - 2; i++) {
@ -2333,41 +2333,33 @@ static void printBeeper(uint8_t dumpMask, const uint32_t offFlags, const uint32_
cliDumpPrintLinef(dumpMask, ~(offFlags ^ offFlagsDefault) & beeperModeMask, offFlags & beeperModeMask ? formatOff : formatOn, name, beeperNameForTableIndex(i)); cliDumpPrintLinef(dumpMask, ~(offFlags ^ offFlagsDefault) & beeperModeMask, offFlags & beeperModeMask ? formatOff : formatOn, name, beeperNameForTableIndex(i));
} }
} }
#endif
#if defined(USE_DSHOT) static void processBeeperCommand(char *cmdline, uint32_t *offFlags, const uint32_t allowedFlags)
static void cliBeacon(char *cmdline)
{
UNUSED(cmdline);
}
#endif
#if defined(USE_BEEPER)
static void cliBeeper(char *cmdline)
{ {
uint32_t len = strlen(cmdline); uint32_t len = strlen(cmdline);
uint8_t beeperCount = beeperTableEntryCount(); uint8_t beeperCount = beeperTableEntryCount();
uint32_t mask = getBeeperOffMask();
if (len == 0) { if (len == 0) {
cliPrintf("Disabled:"); cliPrintf("Disabled:");
for (int32_t i = 0; ; i++) { for (int32_t i = 0; ; i++) {
if (i == beeperCount - 2) { if (i == beeperCount - 1) {
if (mask == 0) if (*offFlags == 0)
cliPrint(" none"); cliPrint(" none");
break; break;
} }
if (mask & beeperModeMaskForTableIndex(i)) if (beeperModeMaskForTableIndex(i) & *offFlags)
cliPrintf(" %s", beeperNameForTableIndex(i)); cliPrintf(" %s", beeperNameForTableIndex(i));
} }
cliPrintLinefeed(); cliPrintLinefeed();
} else if (strncasecmp(cmdline, "list", len) == 0) { } else if (strncasecmp(cmdline, "list", len) == 0) {
cliPrint("Available:"); cliPrint("Available:");
for (uint32_t i = 0; i < beeperCount; i++) for (uint32_t i = 0; i < beeperCount; i++) {
cliPrintf(" %s", beeperNameForTableIndex(i)); if (beeperModeMaskForTableIndex(i) & allowedFlags) {
cliPrintf(" %s", beeperNameForTableIndex(i));
}
}
cliPrintLinefeed(); cliPrintLinefeed();
return;
} else { } else {
bool remove = false; bool remove = false;
if (cmdline[0] == '-') { if (cmdline[0] == '-') {
@ -2381,20 +2373,20 @@ static void cliBeeper(char *cmdline)
cliPrintErrorLinef("Invalid name"); cliPrintErrorLinef("Invalid name");
break; break;
} }
if (strncasecmp(cmdline, beeperNameForTableIndex(i), len) == 0) { if (strncasecmp(cmdline, beeperNameForTableIndex(i), len) == 0 && beeperModeMaskForTableIndex(i) & (allowedFlags | BEEPER_GET_FLAG(BEEPER_ALL))) {
if (remove) { // beeper off if (remove) { // beeper off
if (i == BEEPER_ALL-1) { if (i == BEEPER_ALL - 1) {
beeperOffSetAll(beeperCount-2); *offFlags = allowedFlags;
} else { } else {
beeperOffSet(beeperModeMaskForTableIndex(i)); *offFlags |= beeperModeMaskForTableIndex(i);
} }
cliPrint("Disabled"); cliPrint("Disabled");
} }
else { // beeper on else { // beeper on
if (i == BEEPER_ALL-1) { if (i == BEEPER_ALL - 1) {
beeperOffClearAll(); *offFlags = 0;
} else { } else {
beeperOffClear(beeperModeMaskForTableIndex(i)); *offFlags &= ~beeperModeMaskForTableIndex(i);
} }
cliPrint("Enabled"); cliPrint("Enabled");
} }
@ -2404,6 +2396,18 @@ static void cliBeeper(char *cmdline)
} }
} }
} }
#if defined(USE_DSHOT)
static void cliBeacon(char *cmdline)
{
processBeeperCommand(cmdline, &(beeperConfigMutable()->dshotBeaconOffFlags), DSHOT_BEACON_ALLOWED_MODES);
}
#endif
static void cliBeeper(char *cmdline)
{
processBeeperCommand(cmdline, &(beeperConfigMutable()->beeper_off_flags), BEEPER_ALLOWED_MODES);
}
#endif #endif
#ifdef USE_RX_FRSKY_SPI #ifdef USE_RX_FRSKY_SPI

View file

@ -504,7 +504,7 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
#ifdef USE_BEEPER #ifdef USE_BEEPER
case MSP_BEEPER_CONFIG: case MSP_BEEPER_CONFIG:
sbufWriteU32(dst, getBeeperOffMask()); sbufWriteU32(dst, beeperConfig()->beeper_off_flags);
sbufWriteU8(dst, beeperConfig()->dshotBeaconTone); sbufWriteU8(dst, beeperConfig()->dshotBeaconTone);
break; break;
#endif #endif
@ -1860,8 +1860,7 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
#ifdef USE_BEEPER #ifdef USE_BEEPER
case MSP_SET_BEEPER_CONFIG: case MSP_SET_BEEPER_CONFIG:
beeperOffClearAll(); beeperConfigMutable()->beeper_off_flags = sbufReadU32(src);
setBeeperOffMask(sbufReadU32(src));
if (sbufBytesRemaining(src) >= 1) { if (sbufBytesRemaining(src) >= 1) {
beeperConfigMutable()->dshotBeaconTone = sbufReadU8(src); beeperConfigMutable()->dshotBeaconTone = sbufReadU8(src);
} }

View file

@ -194,7 +194,7 @@ typedef struct beeperTableEntry_s {
#define BEEPER_ENTRY(a,b,c,d) a,b,c #define BEEPER_ENTRY(a,b,c,d) a,b,c
#endif #endif
/*static*/ const beeperTableEntry_t beeperTable[] = { static const beeperTableEntry_t beeperTable[] = {
{ BEEPER_ENTRY(BEEPER_GYRO_CALIBRATED, 0, beep_gyroCalibrated, "GYRO_CALIBRATED") }, { BEEPER_ENTRY(BEEPER_GYRO_CALIBRATED, 0, beep_gyroCalibrated, "GYRO_CALIBRATED") },
{ BEEPER_ENTRY(BEEPER_RX_LOST, 1, beep_txLostBeep, "RX_LOST") }, { BEEPER_ENTRY(BEEPER_RX_LOST, 1, beep_txLostBeep, "RX_LOST") },
{ BEEPER_ENTRY(BEEPER_RX_LOST_LANDING, 2, beep_sos, "RX_LOST_LANDING") }, { BEEPER_ENTRY(BEEPER_RX_LOST_LANDING, 2, beep_sos, "RX_LOST_LANDING") },
@ -232,7 +232,7 @@ void beeper(beeperMode_e mode)
{ {
if ( if (
mode == BEEPER_SILENCE || ( mode == BEEPER_SILENCE || (
(getBeeperOffMask() & (1 << (BEEPER_USB - 1))) (beeperConfigMutable()->beeper_off_flags & BEEPER_GET_FLAG(BEEPER_USB - 1))
&& getBatteryState() == BATTERY_NOT_PRESENT && getBatteryState() == BATTERY_NOT_PRESENT
) )
) { ) {
@ -345,7 +345,7 @@ void beeperWarningBeeps(uint8_t beepCount)
#ifdef USE_GPS #ifdef USE_GPS
static void beeperGpsStatus(void) static void beeperGpsStatus(void)
{ {
if (!(getBeeperOffMask() & (1 << (BEEPER_GPS_STATUS - 1)))) { if (!(beeperConfigMutable()->beeper_off_flags & BEEPER_GET_FLAG(BEEPER_GPS_STATUS))) {
// if GPS fix then beep out number of satellites // if GPS fix then beep out number of satellites
if (STATE(GPS_FIX) && gpsSol.numSat >= 5) { if (STATE(GPS_FIX) && gpsSol.numSat >= 5) {
uint8_t i = 0; uint8_t i = 0;
@ -391,7 +391,9 @@ void beeperUpdate(timeUs_t currentTimeUs)
beeperIsOn = 1; beeperIsOn = 1;
#ifdef USE_DSHOT #ifdef USE_DSHOT
if (!areMotorsRunning() && beeperConfig()->dshotBeaconTone && (beeperConfig()->dshotBeaconTone <= DSHOT_CMD_BEACON5) && (currentBeeperEntry->mode == BEEPER_RX_SET || currentBeeperEntry->mode == BEEPER_RX_LOST)) { if (!areMotorsRunning()
&& ((currentBeeperEntry->mode == BEEPER_RX_SET && beeperConfig()->dshotBeaconOffFlags & BEEPER_GET_FLAG(BEEPER_RX_SET))
|| (currentBeeperEntry->mode == BEEPER_RX_LOST && beeperConfig()->dshotBeaconOffFlags & BEEPER_GET_FLAG(BEEPER_RX_LOST)))) {
pwmDisableMotors(); pwmDisableMotors();
delay(1); delay(1);
@ -402,7 +404,7 @@ void beeperUpdate(timeUs_t currentTimeUs)
#endif #endif
if (currentBeeperEntry->sequence[beeperPos] != 0) { if (currentBeeperEntry->sequence[beeperPos] != 0) {
if (!(getBeeperOffMask() & (1 << (currentBeeperEntry->mode - 1)))) if (!(beeperConfigMutable()->beeper_off_flags & BEEPER_GET_FLAG(currentBeeperEntry->mode)))
BEEP_ON; BEEP_ON;
warningLedEnable(); warningLedEnable();
warningLedRefresh(); warningLedRefresh();
@ -469,7 +471,7 @@ uint32_t beeperModeMaskForTableIndex(int idx)
beeperMode_e beeperMode = beeperModeForTableIndex(idx); beeperMode_e beeperMode = beeperModeForTableIndex(idx);
if (beeperMode == BEEPER_SILENCE) if (beeperMode == BEEPER_SILENCE)
return 0; return 0;
return 1 << (beeperMode - 1); return BEEPER_GET_FLAG(beeperMode);
} }
/* /*

View file

@ -21,7 +21,8 @@
#pragma once #pragma once
#include "common/time.h" #include "common/time.h"
#include "pg/pg.h"
#define BEEPER_GET_FLAG(mode) (1 << (mode - 1))
typedef enum { typedef enum {
// IMPORTANT: these are in priority order, 0 = Highest // IMPORTANT: these are in priority order, 0 = Highest
@ -50,10 +51,38 @@ typedef enum {
BEEPER_CAM_CONNECTION_OPEN, // When the 5 key simulation stated BEEPER_CAM_CONNECTION_OPEN, // When the 5 key simulation stated
BEEPER_CAM_CONNECTION_CLOSE, // When the 5 key simulation stop BEEPER_CAM_CONNECTION_CLOSE, // When the 5 key simulation stop
BEEPER_ALL, // Turn ON or OFF all beeper conditions BEEPER_ALL, // Turn ON or OFF all beeper conditions
BEEPER_PREFERENCE, // Save preferred beeper configuration // BEEPER_ALL must remain at the bottom of this enum
// BEEPER_ALL and BEEPER_PREFERENCE must remain at the bottom of this enum
} beeperMode_e; } beeperMode_e;
#define BEEPER_ALLOWED_MODES ( \
BEEPER_GET_FLAG(BEEPER_GYRO_CALIBRATED) \
| BEEPER_GET_FLAG(BEEPER_RX_LOST) \
| BEEPER_GET_FLAG(BEEPER_RX_LOST_LANDING) \
| BEEPER_GET_FLAG(BEEPER_DISARMING) \
| BEEPER_GET_FLAG(BEEPER_ARMING) \
| BEEPER_GET_FLAG(BEEPER_ARMING_GPS_FIX) \
| BEEPER_GET_FLAG(BEEPER_BAT_CRIT_LOW) \
| BEEPER_GET_FLAG(BEEPER_BAT_LOW) \
| BEEPER_GET_FLAG(BEEPER_GPS_STATUS) \
| BEEPER_GET_FLAG(BEEPER_RX_SET) \
| BEEPER_GET_FLAG(BEEPER_ACC_CALIBRATION) \
| BEEPER_GET_FLAG(BEEPER_ACC_CALIBRATION_FAIL) \
| BEEPER_GET_FLAG(BEEPER_READY_BEEP) \
| BEEPER_GET_FLAG(BEEPER_MULTI_BEEPS) \
| BEEPER_GET_FLAG(BEEPER_DISARM_REPEAT) \
| BEEPER_GET_FLAG(BEEPER_ARMED) \
| BEEPER_GET_FLAG(BEEPER_SYSTEM_INIT) \
| BEEPER_GET_FLAG(BEEPER_USB) \
| BEEPER_GET_FLAG(BEEPER_BLACKBOX_ERASE) \
| BEEPER_GET_FLAG(BEEPER_CRASH_FLIP_MODE) \
| BEEPER_GET_FLAG(BEEPER_CAM_CONNECTION_OPEN) \
| BEEPER_GET_FLAG(BEEPER_CAM_CONNECTION_CLOSE) )
#define DSHOT_BEACON_ALLOWED_MODES ( \
BEEPER_GET_FLAG(BEEPER_RX_LOST) \
| BEEPER_GET_FLAG(BEEPER_RX_SET) )
void beeper(beeperMode_e mode); void beeper(beeperMode_e mode);
void beeperSilence(void); void beeperSilence(void);
void beeperUpdate(timeUs_t currentTimeUs); void beeperUpdate(timeUs_t currentTimeUs);

View file

@ -83,7 +83,8 @@ void targetConfiguration(void)
rxConfigMutable()->serialrx_inverted = true; rxConfigMutable()->serialrx_inverted = true;
#endif #endif
beeperOffSet((BEEPER_BAT_CRIT_LOW | BEEPER_BAT_LOW | BEEPER_RX_SET) ^ BEEPER_GYRO_CALIBRATED); // Don't know what this is meant to do, but it's broken because enum values can't be directly set
// beeperOffSet((BEEPER_BAT_CRIT_LOW | BEEPER_BAT_LOW | BEEPER_RX_SET) ^ BEEPER_GYRO_CALIBRATED);
/* Breadboard-specific settings for development purposes only /* Breadboard-specific settings for development purposes only
*/ */