mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-20 06:45:14 +03:00
new "beeper" CLI command
beeperCount in beeperOffSetAll for config_unittest including suggestions by ledvinap add BEEPER_SYSTEM_INIT condition
This commit is contained in:
parent
ddc75033ef
commit
7208561d68
7 changed files with 184 additions and 9 deletions
|
@ -1126,3 +1126,43 @@ void persistentFlagClear(uint8_t mask)
|
|||
{
|
||||
masterConfig.persistentFlags &= ~(mask);
|
||||
}
|
||||
|
||||
void beeperOffSet(uint32_t mask)
|
||||
{
|
||||
masterConfig.beeper_off_flags |= mask;
|
||||
}
|
||||
|
||||
void beeperOffSetAll(uint8_t beeperCount)
|
||||
{
|
||||
masterConfig.beeper_off_flags = (1 << beeperCount) -1;
|
||||
}
|
||||
|
||||
void beeperOffClear(uint32_t mask)
|
||||
{
|
||||
masterConfig.beeper_off_flags &= ~(mask);
|
||||
}
|
||||
|
||||
void beeperOffClearAll(void)
|
||||
{
|
||||
masterConfig.beeper_off_flags = 0;
|
||||
}
|
||||
|
||||
uint32_t getBeeperOffMask(void)
|
||||
{
|
||||
return masterConfig.beeper_off_flags;
|
||||
}
|
||||
|
||||
void setBeeperOffMask(uint32_t mask)
|
||||
{
|
||||
masterConfig.beeper_off_flags = mask;
|
||||
}
|
||||
|
||||
uint32_t getPreferedBeeperOffMask(void)
|
||||
{
|
||||
return masterConfig.prefered_beeper_off_flags;
|
||||
}
|
||||
|
||||
void setPreferedBeeperOffMask(uint32_t mask)
|
||||
{
|
||||
masterConfig.prefered_beeper_off_flags = mask;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,14 @@ void featureSet(uint32_t mask);
|
|||
void featureClear(uint32_t mask);
|
||||
void featureClearAll(void);
|
||||
uint32_t featureMask(void);
|
||||
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);
|
||||
uint32_t getPreferedBeeperOffMask(void);
|
||||
void setPreferedBeeperOffMask(uint32_t mask);
|
||||
|
||||
bool persistentFlag(uint8_t mask);
|
||||
void persistentFlagSet(uint8_t mask);
|
||||
|
|
|
@ -108,6 +108,9 @@ typedef struct master_t {
|
|||
uint8_t blackbox_device;
|
||||
#endif
|
||||
|
||||
uint32_t beeper_off_flags;
|
||||
uint32_t prefered_beeper_off_flags;
|
||||
|
||||
uint8_t magic_ef; // magic number, should be 0xEF
|
||||
uint8_t chk; // XOR checksum
|
||||
} master_t;
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include "config/runtime_config.h"
|
||||
#include "config/config.h"
|
||||
|
||||
|
||||
#include "io/beeper.h"
|
||||
|
||||
#if FLASH_SIZE > 64
|
||||
|
@ -151,23 +150,27 @@ 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_LANDING, 1, beep_sos, "RX_LOST_LANDING") },
|
||||
{ BEEPER_ENTRY(BEEPER_RX_LOST, 2, 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_DISARMING, 3, beep_disarmBeep, "DISARMING") },
|
||||
{ BEEPER_ENTRY(BEEPER_ARMING, 4, beep_armingBeep, "ARMING") },
|
||||
{ BEEPER_ENTRY(BEEPER_ARMING_GPS_FIX, 5, beep_armedGpsFix, "ARMING_GPS_FIX") },
|
||||
{ BEEPER_ENTRY(BEEPER_BAT_CRIT_LOW, 6, beep_critBatteryBeep, "BAT_CRIT_LOW") },
|
||||
{ BEEPER_ENTRY(BEEPER_BAT_LOW, 7, beep_lowBatteryBeep, "BAT_LOW") },
|
||||
{ BEEPER_ENTRY(BEEPER_GPS_STATUS, 8, beep_multiBeeps, NULL) },
|
||||
{ BEEPER_ENTRY(BEEPER_GPS_STATUS, 8, beep_multiBeeps, "GPS_STATUS") },
|
||||
{ BEEPER_ENTRY(BEEPER_RX_SET, 9, beep_shortBeep, "RX_SET") },
|
||||
{ BEEPER_ENTRY(BEEPER_ACC_CALIBRATION, 10, beep_2shortBeeps, "ACC_CALIBRATION") },
|
||||
{ BEEPER_ENTRY(BEEPER_ACC_CALIBRATION_FAIL, 11, beep_2longerBeeps, "ACC_CALIBRATION_FAIL") },
|
||||
{ BEEPER_ENTRY(BEEPER_READY_BEEP, 12, beep_readyBeep, "READY_BEEP") },
|
||||
{ BEEPER_ENTRY(BEEPER_MULTI_BEEPS, 13, beep_multiBeeps, NULL) }, // FIXME having this listed makes no sense since the beep array will not be initialised.
|
||||
{ BEEPER_ENTRY(BEEPER_MULTI_BEEPS, 13, beep_multiBeeps, "MULTI_BEEPS") }, // FIXME having this listed makes no sense since the beep array will not be initialised.
|
||||
{ BEEPER_ENTRY(BEEPER_DISARM_REPEAT, 14, beep_disarmRepeatBeep, "DISARM_REPEAT") },
|
||||
{ BEEPER_ENTRY(BEEPER_ARMED, 15, beep_armedBeep, "ARMED") },
|
||||
{ BEEPER_ENTRY(BEEPER_SYSTEM_INIT, 16, NULL, "SYSTEM_INIT") },
|
||||
|
||||
{ BEEPER_ENTRY(BEEPER_ALL, 17, NULL, "ALL") },
|
||||
{ BEEPER_ENTRY(BEEPER_PREFERENCE, 18, NULL, "PREFERED") },
|
||||
};
|
||||
|
||||
static const beeperTableEntry_t *currentBeeperEntry = NULL;
|
||||
|
@ -302,7 +305,9 @@ void beeperUpdate(void)
|
|||
if (!beeperIsOn) {
|
||||
beeperIsOn = 1;
|
||||
if (currentBeeperEntry->sequence[beeperPos] != 0) {
|
||||
BEEP_ON;
|
||||
if (!(getBeeperOffMask() & (1 << (currentBeeperEntry->mode - 1))))
|
||||
BEEP_ON;
|
||||
|
||||
warningLedEnable();
|
||||
warningLedRefresh();
|
||||
// if this was arming beep then mark time (for blackbox)
|
||||
|
|
|
@ -22,14 +22,14 @@ typedef enum {
|
|||
BEEPER_SILENCE = 0, // Silence, see beeperSilence()
|
||||
|
||||
BEEPER_GYRO_CALIBRATED,
|
||||
BEEPER_RX_LOST_LANDING, // Beeps SOS when armed and TX is turned off or signal lost (autolanding/autodisarm)
|
||||
BEEPER_RX_LOST, // Beeps when TX is turned off or signal lost (repeat until TX is okay)
|
||||
BEEPER_RX_LOST_LANDING, // Beeps SOS when armed and TX is turned off or signal lost (autolanding/autodisarm)
|
||||
BEEPER_DISARMING, // Beep when disarming the board
|
||||
BEEPER_ARMING, // Beep when arming the board
|
||||
BEEPER_ARMING_GPS_FIX, // Beep a special tone when arming the board and GPS has fix
|
||||
BEEPER_BAT_CRIT_LOW, // Longer warning beeps when battery is critically low (repeats)
|
||||
BEEPER_BAT_LOW, // Warning beeps when battery is getting low (repeats)
|
||||
BEEPER_GPS_STATUS,
|
||||
BEEPER_GPS_STATUS, // FIXME **** Disable beeper when connected to USB ****
|
||||
BEEPER_RX_SET, // Beeps when aux channel is set for beep or beep sequence how many satellites has found if GPS enabled
|
||||
BEEPER_DISARM_REPEAT, // Beeps sounded while stick held in disarm position
|
||||
BEEPER_ACC_CALIBRATION, // ACC inflight calibration completed confirmation
|
||||
|
@ -37,6 +37,11 @@ typedef enum {
|
|||
BEEPER_READY_BEEP, // Ring a tone when GPS is locked and ready
|
||||
BEEPER_MULTI_BEEPS, // Internal value used by 'beeperConfirmationBeeps()'.
|
||||
BEEPER_ARMED, // Warning beeps when board is armed (repeats until board is disarmed or throttle is increased)
|
||||
BEEPER_SYSTEM_INIT, // Initialisation beeps when board is powered on
|
||||
|
||||
BEEPER_ALL, // Turn ON or OFF all beeper conditions
|
||||
BEEPER_PREFERENCE, // Save prefered beeper configuration
|
||||
// BEEPER_ALL and BEEPER_PREFERENCE must remain at the bottom of this enum
|
||||
} beeperMode_e;
|
||||
|
||||
void beeper(beeperMode_e mode);
|
||||
|
|
|
@ -158,6 +158,10 @@ static void cliFlashRead(char *cmdline);
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BEEPER
|
||||
static void cliBeeper(char *cmdline);
|
||||
#endif
|
||||
|
||||
// buffer
|
||||
static char cliBuffer[48];
|
||||
static uint32_t bufferIndex = 0;
|
||||
|
@ -301,6 +305,10 @@ const clicmd_t cmdTable[] = {
|
|||
CLI_COMMAND_DEF("tasks", "show task stats", NULL, cliTasks),
|
||||
#endif
|
||||
CLI_COMMAND_DEF("version", "show version", NULL, cliVersion),
|
||||
#ifdef BEEPER
|
||||
CLI_COMMAND_DEF("beeper", "turn on/off beeper", "list\r\n"
|
||||
"\t<+|->[name]", cliBeeper),
|
||||
#endif
|
||||
};
|
||||
#define CMD_COUNT (sizeof(cmdTable) / sizeof(clicmd_t))
|
||||
|
||||
|
@ -1746,6 +1754,21 @@ static void cliDump(char *cmdline)
|
|||
cliPrintf("feature %s\r\n", featureNames[i]);
|
||||
}
|
||||
|
||||
|
||||
#ifdef BEEPER
|
||||
cliPrint("\r\n\r\n# beeper\r\n");
|
||||
|
||||
uint8_t beeperCount = beeperTableEntryCount();
|
||||
mask = getBeeperOffMask();
|
||||
for (int i = 0; i < (beeperCount-2); i++) {
|
||||
if (mask & (1 << i))
|
||||
printf("beeper -%s\r\n", beeperNameForTableIndex(i));
|
||||
else
|
||||
printf("beeper %s\r\n", beeperNameForTableIndex(i));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
cliPrint("\r\n\r\n# map\r\n");
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
|
@ -1923,6 +1946,79 @@ static void cliFeature(char *cmdline)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef BEEPER
|
||||
static void cliBeeper(char *cmdline)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t len = strlen(cmdline);;
|
||||
uint8_t beeperCount = beeperTableEntryCount();
|
||||
uint32_t mask = getBeeperOffMask();
|
||||
|
||||
if (len == 0) {
|
||||
printf("Disabled:");
|
||||
for (int i = 0; ; i++) {
|
||||
if (i == beeperCount-2){
|
||||
if (mask == 0)
|
||||
cliPrint(" none");
|
||||
break;
|
||||
}
|
||||
if (mask & (1 << i))
|
||||
printf(" %s", beeperNameForTableIndex(i));
|
||||
}
|
||||
cliPrint("\r\n");
|
||||
} else if (strncasecmp(cmdline, "list", len) == 0) {
|
||||
cliPrint("Available:");
|
||||
for (i = 0; i < beeperCount; i++)
|
||||
printf(" %s", beeperNameForTableIndex(i));
|
||||
cliPrint("\r\n");
|
||||
return;
|
||||
} else {
|
||||
bool remove = false;
|
||||
if (cmdline[0] == '-') {
|
||||
remove = true; // this is for beeper OFF condition
|
||||
cmdline++;
|
||||
len--;
|
||||
}
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
if (i == beeperCount) {
|
||||
cliPrint("Invalid name\r\n");
|
||||
break;
|
||||
}
|
||||
if (strncasecmp(cmdline, beeperNameForTableIndex(i), len) == 0) {
|
||||
if (remove) { // beeper off
|
||||
if (i == BEEPER_ALL-1)
|
||||
beeperOffSetAll(beeperCount-2);
|
||||
else
|
||||
if (i == BEEPER_PREFERENCE-1)
|
||||
setBeeperOffMask(getPreferedBeeperOffMask());
|
||||
else {
|
||||
mask = 1 << i;
|
||||
beeperOffSet(mask);
|
||||
}
|
||||
cliPrint("Disabled");
|
||||
}
|
||||
else { // beeper on
|
||||
if (i == BEEPER_ALL-1)
|
||||
beeperOffClearAll();
|
||||
else
|
||||
if (i == BEEPER_PREFERENCE-1)
|
||||
setPreferedBeeperOffMask(getBeeperOffMask());
|
||||
else {
|
||||
mask = 1 << i;
|
||||
beeperOffClear(mask);
|
||||
}
|
||||
cliPrint("Enabled");
|
||||
}
|
||||
printf(" %s\r\n", beeperNameForTableIndex(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef GPS
|
||||
static void cliGpsPassthrough(char *cmdline)
|
||||
{
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
|
||||
#include "rx/rx.h"
|
||||
|
||||
#include "io/beeper.h"
|
||||
#include "io/serial.h"
|
||||
#include "io/flashfs.h"
|
||||
#include "io/gps.h"
|
||||
|
@ -143,6 +144,23 @@ typedef enum {
|
|||
|
||||
static uint8_t systemState = SYSTEM_STATE_INITIALISING;
|
||||
|
||||
void flashLedsAndBeep(void)
|
||||
{
|
||||
LED1_ON;
|
||||
LED0_OFF;
|
||||
for (uint8_t i = 0; i < 10; i++) {
|
||||
LED1_TOGGLE;
|
||||
LED0_TOGGLE;
|
||||
delay(25);
|
||||
if (!(getPreferedBeeperOffMask() & (1 << (BEEPER_SYSTEM_INIT - 1))))
|
||||
BEEP_ON;
|
||||
delay(25);
|
||||
BEEP_OFF;
|
||||
}
|
||||
LED0_OFF;
|
||||
LED1_OFF;
|
||||
}
|
||||
|
||||
void init(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue