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:
parent
ab916d16b2
commit
7e8f261436
8 changed files with 97 additions and 99 deletions
|
@ -350,6 +350,21 @@ static void validateAndFixConfig(void)
|
|||
if (beeperDevConfig()->frequency && !timerGetByTag(beeperDevConfig()->ioTag)) {
|
||||
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
|
||||
|
||||
#if defined(TARGET_VALIDATECONFIG)
|
||||
|
@ -522,55 +537,3 @@ void changePidProfile(uint8_t pidProfileIndex)
|
|||
beeperConfirmationBeeps(pidProfileIndex + 1);
|
||||
}
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -49,13 +49,6 @@ PG_DECLARE(systemConfig_t, systemConfig);
|
|||
struct pidProfile_s;
|
||||
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 resetEEPROM(void);
|
||||
bool readEEPROM(void);
|
||||
|
|
|
@ -90,6 +90,7 @@
|
|||
#include "msp/msp_serial.h"
|
||||
|
||||
#include "pg/adc.h"
|
||||
#include "pg/beeper.h"
|
||||
#include "pg/beeper_dev.h"
|
||||
#include "pg/bus_i2c.h"
|
||||
#include "pg/bus_spi.h"
|
||||
|
@ -519,10 +520,16 @@ void init(void)
|
|||
for (int i = 0; i < 10; i++) {
|
||||
LED1_TOGGLE;
|
||||
LED0_TOGGLE;
|
||||
#if defined(USE_BEEPER)
|
||||
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);
|
||||
BEEP_OFF;
|
||||
#else
|
||||
delay(50);
|
||||
#endif
|
||||
}
|
||||
LED0_OFF;
|
||||
LED1_OFF;
|
||||
|
|
|
@ -2321,8 +2321,8 @@ static void cliFeature(char *cmdline)
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(USE_BEEPER) || defined(USE_DSHOT)
|
||||
static void printBeeper(uint8_t dumpMask, const uint32_t offFlags, const uint32_t offFlagsDefault, char *name)
|
||||
#if defined(USE_BEEPER)
|
||||
static void printBeeper(uint8_t dumpMask, const uint32_t offFlags, const uint32_t offFlagsDefault, const char *name)
|
||||
{
|
||||
const uint8_t beeperCount = beeperTableEntryCount();
|
||||
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));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_DSHOT)
|
||||
static void cliBeacon(char *cmdline)
|
||||
{
|
||||
UNUSED(cmdline);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_BEEPER)
|
||||
static void cliBeeper(char *cmdline)
|
||||
static void processBeeperCommand(char *cmdline, uint32_t *offFlags, const uint32_t allowedFlags)
|
||||
{
|
||||
uint32_t len = strlen(cmdline);
|
||||
uint8_t beeperCount = beeperTableEntryCount();
|
||||
uint32_t mask = getBeeperOffMask();
|
||||
|
||||
if (len == 0) {
|
||||
cliPrintf("Disabled:");
|
||||
for (int32_t i = 0; ; i++) {
|
||||
if (i == beeperCount - 2) {
|
||||
if (mask == 0)
|
||||
if (i == beeperCount - 1) {
|
||||
if (*offFlags == 0)
|
||||
cliPrint(" none");
|
||||
break;
|
||||
}
|
||||
|
||||
if (mask & beeperModeMaskForTableIndex(i))
|
||||
if (beeperModeMaskForTableIndex(i) & *offFlags)
|
||||
cliPrintf(" %s", beeperNameForTableIndex(i));
|
||||
}
|
||||
cliPrintLinefeed();
|
||||
} else if (strncasecmp(cmdline, "list", len) == 0) {
|
||||
cliPrint("Available:");
|
||||
for (uint32_t i = 0; i < beeperCount; i++)
|
||||
for (uint32_t i = 0; i < beeperCount; i++) {
|
||||
if (beeperModeMaskForTableIndex(i) & allowedFlags) {
|
||||
cliPrintf(" %s", beeperNameForTableIndex(i));
|
||||
}
|
||||
}
|
||||
cliPrintLinefeed();
|
||||
return;
|
||||
} else {
|
||||
bool remove = false;
|
||||
if (cmdline[0] == '-') {
|
||||
|
@ -2381,20 +2373,20 @@ static void cliBeeper(char *cmdline)
|
|||
cliPrintErrorLinef("Invalid name");
|
||||
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 (i == BEEPER_ALL-1) {
|
||||
beeperOffSetAll(beeperCount-2);
|
||||
if (i == BEEPER_ALL - 1) {
|
||||
*offFlags = allowedFlags;
|
||||
} else {
|
||||
beeperOffSet(beeperModeMaskForTableIndex(i));
|
||||
*offFlags |= beeperModeMaskForTableIndex(i);
|
||||
}
|
||||
cliPrint("Disabled");
|
||||
}
|
||||
else { // beeper on
|
||||
if (i == BEEPER_ALL-1) {
|
||||
beeperOffClearAll();
|
||||
if (i == BEEPER_ALL - 1) {
|
||||
*offFlags = 0;
|
||||
} else {
|
||||
beeperOffClear(beeperModeMaskForTableIndex(i));
|
||||
*offFlags &= ~beeperModeMaskForTableIndex(i);
|
||||
}
|
||||
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
|
||||
|
||||
#ifdef USE_RX_FRSKY_SPI
|
||||
|
|
|
@ -504,7 +504,7 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
|
|||
|
||||
#ifdef USE_BEEPER
|
||||
case MSP_BEEPER_CONFIG:
|
||||
sbufWriteU32(dst, getBeeperOffMask());
|
||||
sbufWriteU32(dst, beeperConfig()->beeper_off_flags);
|
||||
sbufWriteU8(dst, beeperConfig()->dshotBeaconTone);
|
||||
break;
|
||||
#endif
|
||||
|
@ -1860,8 +1860,7 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
|||
|
||||
#ifdef USE_BEEPER
|
||||
case MSP_SET_BEEPER_CONFIG:
|
||||
beeperOffClearAll();
|
||||
setBeeperOffMask(sbufReadU32(src));
|
||||
beeperConfigMutable()->beeper_off_flags = sbufReadU32(src);
|
||||
if (sbufBytesRemaining(src) >= 1) {
|
||||
beeperConfigMutable()->dshotBeaconTone = sbufReadU8(src);
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ typedef struct beeperTableEntry_s {
|
|||
#define BEEPER_ENTRY(a,b,c,d) a,b,c
|
||||
#endif
|
||||
|
||||
/*static*/ const beeperTableEntry_t beeperTable[] = {
|
||||
static const beeperTableEntry_t beeperTable[] = {
|
||||
{ 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_LANDING, 2, beep_sos, "RX_LOST_LANDING") },
|
||||
|
@ -232,7 +232,7 @@ void beeper(beeperMode_e mode)
|
|||
{
|
||||
if (
|
||||
mode == BEEPER_SILENCE || (
|
||||
(getBeeperOffMask() & (1 << (BEEPER_USB - 1)))
|
||||
(beeperConfigMutable()->beeper_off_flags & BEEPER_GET_FLAG(BEEPER_USB - 1))
|
||||
&& getBatteryState() == BATTERY_NOT_PRESENT
|
||||
)
|
||||
) {
|
||||
|
@ -345,7 +345,7 @@ void beeperWarningBeeps(uint8_t beepCount)
|
|||
#ifdef USE_GPS
|
||||
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 (STATE(GPS_FIX) && gpsSol.numSat >= 5) {
|
||||
uint8_t i = 0;
|
||||
|
@ -391,7 +391,9 @@ void beeperUpdate(timeUs_t currentTimeUs)
|
|||
beeperIsOn = 1;
|
||||
|
||||
#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();
|
||||
delay(1);
|
||||
|
||||
|
@ -402,7 +404,7 @@ void beeperUpdate(timeUs_t currentTimeUs)
|
|||
#endif
|
||||
|
||||
if (currentBeeperEntry->sequence[beeperPos] != 0) {
|
||||
if (!(getBeeperOffMask() & (1 << (currentBeeperEntry->mode - 1))))
|
||||
if (!(beeperConfigMutable()->beeper_off_flags & BEEPER_GET_FLAG(currentBeeperEntry->mode)))
|
||||
BEEP_ON;
|
||||
warningLedEnable();
|
||||
warningLedRefresh();
|
||||
|
@ -469,7 +471,7 @@ uint32_t beeperModeMaskForTableIndex(int idx)
|
|||
beeperMode_e beeperMode = beeperModeForTableIndex(idx);
|
||||
if (beeperMode == BEEPER_SILENCE)
|
||||
return 0;
|
||||
return 1 << (beeperMode - 1);
|
||||
return BEEPER_GET_FLAG(beeperMode);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/time.h"
|
||||
#include "pg/pg.h"
|
||||
|
||||
#define BEEPER_GET_FLAG(mode) (1 << (mode - 1))
|
||||
|
||||
typedef enum {
|
||||
// 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_CLOSE, // When the 5 key simulation stop
|
||||
BEEPER_ALL, // Turn ON or OFF all beeper conditions
|
||||
BEEPER_PREFERENCE, // Save preferred beeper configuration
|
||||
// BEEPER_ALL and BEEPER_PREFERENCE must remain at the bottom of this enum
|
||||
// BEEPER_ALL must remain at the bottom of this enum
|
||||
} 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 beeperSilence(void);
|
||||
void beeperUpdate(timeUs_t currentTimeUs);
|
||||
|
|
|
@ -83,7 +83,8 @@ void targetConfiguration(void)
|
|||
rxConfigMutable()->serialrx_inverted = true;
|
||||
#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
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue