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

Merge pull request #823 from ethomas997/addPlaySoundCommand

Add 'play_sound' CLI command
This commit is contained in:
Dominic Clifton 2015-05-04 09:22:04 +01:00
commit d2ef645fbe
5 changed files with 109 additions and 24 deletions

View file

@ -24,7 +24,6 @@
#include "drivers/gpio.h"
#include "drivers/sound_beeper.h"
#include "drivers/system.h"
#include "flight/failsafe.h"
#include "sensors/battery.h"
#include "sensors/sensors.h"
@ -102,9 +101,9 @@ static const uint8_t beep_readyBeep[] = {
static const uint8_t beep_2shortBeeps[] = {
5, 5, 5, 5, BEEPER_COMMAND_STOP
};
// 3 fast short beeps
static const uint8_t beep_3shortBeeps[] = {
5, 5, 5, 5, 5, 5, BEEPER_COMMAND_STOP
// 2 longer beeps
static const uint8_t beep_2longerBeeps[] = {
20, 15, 35, 5, BEEPER_COMMAND_STOP
};
// array used for variable # of beeps (reporting GPS sat count, etc)
static uint8_t beep_multiBeeps[MAX_MULTI_BEEPS + 2];
@ -129,24 +128,25 @@ typedef struct beeperTableEntry_s {
uint8_t mode;
uint8_t priority; // 0 = Highest
const uint8_t *sequence;
const char *name;
} beeperTableEntry_t;
static const beeperTableEntry_t const beeperTable[] = {
{ BEEPER_RX_LOST_LANDING, 0, beep_sos },
{ BEEPER_RX_LOST, 1, beep_txLostBeep },
{ BEEPER_DISARMING, 2, beep_disarmBeep },
{ BEEPER_ARMING, 3, beep_armingBeep },
{ BEEPER_ARMING_GPS_FIX, 4, beep_armedGpsFix },
{ BEEPER_BAT_CRIT_LOW, 5, beep_critBatteryBeep },
{ BEEPER_BAT_LOW, 6, beep_lowBatteryBeep },
{ BEEPER_GPS_STATUS, 7, beep_multiBeeps },
{ BEEPER_RX_SET, 8, beep_shortBeep },
{ BEEPER_DISARM_REPEAT, 9, beep_disarmRepeatBeep },
{ BEEPER_ACC_CALIBRATION, 10, beep_2shortBeeps },
{ BEEPER_ACC_CALIBRATION_FAIL, 11, beep_3shortBeeps },
{ BEEPER_READY_BEEP, 12, beep_readyBeep },
{ BEEPER_MULTI_BEEPS, 13, beep_multiBeeps }, // FIXME having this listed makes no sense since the beep array will not be initialised.
{ BEEPER_ARMED, 14, beep_armedBeep },
{ BEEPER_RX_LOST_LANDING, 0, beep_sos, "RX_LOST_LANDING" },
{ BEEPER_RX_LOST, 1, beep_txLostBeep, "RX_LOST" },
{ BEEPER_DISARMING, 2, beep_disarmBeep, "DISARMING" },
{ BEEPER_ARMING, 3, beep_armingBeep, "ARMING" },
{ BEEPER_ARMING_GPS_FIX, 4, beep_armedGpsFix, "ARMING_GPS_FIX" },
{ BEEPER_BAT_CRIT_LOW, 5, beep_critBatteryBeep, "BAT_CRIT_LOW" },
{ BEEPER_BAT_LOW, 6, beep_lowBatteryBeep, "BAT_LOW" },
{ BEEPER_GPS_STATUS, 7, beep_multiBeeps, NULL },
{ BEEPER_RX_SET, 8, beep_shortBeep, "RX_SET" },
{ BEEPER_DISARM_REPEAT, 9, beep_disarmRepeatBeep, "DISARM_REPEAT" },
{ BEEPER_ACC_CALIBRATION, 10, beep_2shortBeeps, "ACC_CALIBRATION" },
{ BEEPER_ACC_CALIBRATION_FAIL, 11, beep_2longerBeeps, "ACC_CALIBRATION_FAIL" },
{ BEEPER_READY_BEEP, 12, beep_readyBeep, "READY_BEEP" },
{ BEEPER_MULTI_BEEPS, 13, beep_multiBeeps, NULL }, // FIXME having this listed makes no sense since the beep array will not be initialised.
{ BEEPER_ARMED, 14, beep_armedBeep, "ARMED" },
};
static const beeperTableEntry_t *currentBeeperEntry = NULL;
@ -320,3 +320,30 @@ uint32_t getArmingBeepTimeMicros(void)
{
return armingBeepTimeMicros;
}
/*
* Returns the 'beeperMode_e' value for the given beeper-table index,
* or BEEPER_SILENCE if none.
*/
beeperMode_e beeperModeForTableIndex(int idx)
{
return (idx >= 0 && idx < (int)BEEPER_TABLE_ENTRY_COUNT) ?
beeperTable[idx].mode : BEEPER_SILENCE;
}
/*
* Returns the name for the given beeper-table index, or NULL if none.
*/
const char *beeperNameForTableIndex(int idx)
{
return (idx >= 0 && idx < (int)BEEPER_TABLE_ENTRY_COUNT) ?
beeperTable[idx].name : NULL;
}
/*
* Returns the number of entries in the beeper-sounds table.
*/
int beeperTableEntryCount(void)
{
return (int)BEEPER_TABLE_ENTRY_COUNT;
}

View file

@ -25,17 +25,17 @@ typedef enum {
BEEPER_RX_LOST, // Beeps when TX is turned off or signal lost (repeat until TX is okay)
BEEPER_DISARMING, // Beep when disarming the board
BEEPER_ARMING, // Beep when arming the board
BEEPER_ARMING_GPS_FIX, // Beep a tone when arming the board and GPS has fix
BEEPER_BAT_CRIT_LOW, // Faster warning beeps when battery is critically low (repeats)
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_RX_SET, // Beeps when aux channel is set for beep or beep sequence how many satellites has found if GPS enabled.
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
BEEPER_ACC_CALIBRATION_FAIL, // ACC inflight calibration failed
BEEPER_READY_BEEP, // Ring a tone when board is ready to flight (GPS ready).
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_ARMED, // Warning beeps when board is armed (repeats until board is disarmed or throttle is increased)
} beeperMode_e;
void beeper(beeperMode_e mode);
@ -43,3 +43,6 @@ void beeperSilence(void);
void beeperUpdate(void);
void beeperConfirmationBeeps(uint8_t beepCount);
uint32_t getArmingBeepTimeMicros(void);
beeperMode_e beeperModeForTableIndex(int idx);
const char *beeperNameForTableIndex(int idx);
int beeperTableEntryCount(void);

View file

@ -53,6 +53,7 @@
#include "io/serial.h"
#include "io/ledstrip.h"
#include "io/flashfs.h"
#include "io/beeper.h"
#include "rx/rx.h"
#include "rx/spektrum.h"
@ -97,6 +98,7 @@ static void cliDump(char *cmdLine);
static void cliExit(char *cmdline);
static void cliFeature(char *cmdline);
static void cliMotor(char *cmdline);
static void cliPlaySound(char *cmdline);
static void cliProfile(char *cmdline);
static void cliRateProfile(char *cmdline);
static void cliReboot(void);
@ -211,6 +213,7 @@ const clicmd_t cmdTable[] = {
{ "mixer", "mixer name or list", cliMixer },
#endif
{ "motor", "get/set motor output value", cliMotor },
{ "play_sound", "index, or none for next", cliPlaySound },
{ "profile", "index (0 to 2)", cliProfile },
{ "rateprofile", "index (0 to 2)", cliRateProfile },
{ "save", "save and reboot", cliSave },
@ -1327,6 +1330,39 @@ static void cliMotor(char *cmdline)
motor_disarmed[motor_index] = motor_value;
}
static void cliPlaySound(char *cmdline)
{
int i;
const char *name;
static int lastSoundIdx = -1;
if (isEmpty(cmdline)) {
i = lastSoundIdx + 1; //next sound index
if ((name=beeperNameForTableIndex(i)) == NULL) {
while (true) { //no name for index; try next one
if (++i >= beeperTableEntryCount())
i = 0; //if end then wrap around to first entry
if ((name=beeperNameForTableIndex(i)) != NULL)
break; //if name OK then play sound below
if (i == lastSoundIdx + 1) { //prevent infinite loop
printf("Error playing sound\r\n");
return;
}
}
}
} else { //index value was given
i = atoi(cmdline);
if ((name=beeperNameForTableIndex(i)) == NULL) {
printf("No sound for index %d\r\n", i);
return;
}
}
lastSoundIdx = i;
beeperSilence();
printf("Playing sound %d: %s\r\n", i, name);
beeper(beeperModeForTableIndex(i));
}
static void cliProfile(char *cmdline)
{
int i;