1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 06:15:16 +03:00

sync order of beeperTable and beeperMode_e enum

add beeperModeMaskForTableIndex function and use it in CLI
add change to unittest to make it compile
This commit is contained in:
bkeinert 2017-08-13 12:04:04 +02:00 committed by bkeinert
parent 1e9b553392
commit 5d258d11f2
4 changed files with 23 additions and 8 deletions

View file

@ -2035,8 +2035,9 @@ static void printBeeper(uint8_t dumpMask, const beeperConfig_t *beeperConfig, co
for (int32_t i = 0; i < beeperCount - 2; i++) {
const char *formatOff = "beeper -%s";
const char *formatOn = "beeper %s";
cliDefaultPrintLinef(dumpMask, ~(mask ^ defaultMask) & (1 << i), mask & (1 << i) ? formatOn : formatOff, beeperNameForTableIndex(i));
cliDumpPrintLinef(dumpMask, ~(mask ^ defaultMask) & (1 << i), mask & (1 << i) ? formatOff : formatOn, beeperNameForTableIndex(i));
const uint32_t beeperModeMask = beeperModeMaskForTableIndex(i);
cliDefaultPrintLinef(dumpMask, ~(mask ^ defaultMask) & beeperModeMask, mask & beeperModeMask ? formatOn : formatOff, beeperNameForTableIndex(i));
cliDumpPrintLinef(dumpMask, ~(mask ^ defaultMask) & beeperModeMask, mask & beeperModeMask ? formatOff : formatOn, beeperNameForTableIndex(i));
}
}
@ -2054,7 +2055,8 @@ static void cliBeeper(char *cmdline)
cliPrint(" none");
break;
}
if (mask & (1 << i))
if (mask & beeperModeMaskForTableIndex(i))
cliPrintf(" %s", beeperNameForTableIndex(i));
}
cliPrintLinefeed();
@ -2085,8 +2087,7 @@ static void cliBeeper(char *cmdline)
if (i == BEEPER_PREFERENCE-1)
setBeeperOffMask(getPreferredBeeperOffMask());
else {
mask = 1 << i;
beeperOffSet(mask);
beeperOffSet(beeperModeMaskForTableIndex(i));
}
cliPrint("Disabled");
}
@ -2097,8 +2098,7 @@ static void cliBeeper(char *cmdline)
if (i == BEEPER_PREFERENCE-1)
setPreferredBeeperOffMask(getBeeperOffMask());
else {
mask = 1 << i;
beeperOffClear(mask);
beeperOffClear(beeperModeMaskForTableIndex(i));
}
cliPrint("Enabled");
}

13
src/main/io/beeper.c Normal file → Executable file
View file

@ -431,6 +431,18 @@ beeperMode_e beeperModeForTableIndex(int idx)
return (idx >= 0 && idx < (int)BEEPER_TABLE_ENTRY_COUNT) ? beeperTable[idx].mode : BEEPER_SILENCE;
}
/*
* Returns the binary mask for the 'beeperMode_e' value corresponding to a given
* beeper-table index, or 0 if the beeperMode is BEEPER_SILENCE.
*/
uint32_t beeperModeMaskForTableIndex(int idx)
{
beeperMode_e beeperMode = beeperModeForTableIndex(idx);
if (beeperMode == BEEPER_SILENCE)
return 0;
return 1 << (beeperMode - 1);
}
/*
* Returns the name for the given beeper-table index, or NULL if none.
*/
@ -470,6 +482,7 @@ void beeperWarningBeeps(uint8_t beepCount) {UNUSED(beepCount);}
void beeperUpdate(timeUs_t currentTimeUs) {UNUSED(currentTimeUs);}
uint32_t getArmingBeepTimeMicros(void) {return 0;}
beeperMode_e beeperModeForTableIndex(int idx) {UNUSED(idx); return BEEPER_SILENCE;}
uint32_t beeperModeMaskForTableIndex(int idx) {UNUSED(idx); return 0;}
const char *beeperNameForTableIndex(int idx) {UNUSED(idx); return NULL;}
int beeperTableEntryCount(void) {return 0;}
bool isBeeperOn(void) {return false;}

View file

@ -34,11 +34,11 @@ typedef enum {
BEEPER_BAT_LOW, // Warning beeps when battery is getting low (repeats)
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
BEEPER_ACC_CALIBRATION_FAIL, // ACC inflight calibration failed
BEEPER_READY_BEEP, // Ring a tone when GPS is locked and ready
BEEPER_MULTI_BEEPS, // Internal value used by 'beeperConfirmationBeeps()'.
BEEPER_DISARM_REPEAT, // Beeps sounded while stick held in disarm position
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_USB, // Some boards have beeper powered USB connected
@ -65,6 +65,7 @@ void beeperConfirmationBeeps(uint8_t beepCount);
void beeperWarningBeeps(uint8_t beepCount);
uint32_t getArmingBeepTimeMicros(void);
beeperMode_e beeperModeForTableIndex(int idx);
uint32_t beeperModeMaskForTableIndex(int idx);
const char *beeperNameForTableIndex(int idx);
int beeperTableEntryCount(void);
bool isBeeperOn(void);

View file

@ -182,6 +182,7 @@ void beeperWarningBeeps(uint8_t) {}
void beeperUpdate(timeUs_t) {}
uint32_t getArmingBeepTimeMicros(void) {return 0;}
beeperMode_e beeperModeForTableIndex(int) {return BEEPER_SILENCE;}
uint32_t beeperModeMaskForTableIndex(int idx) {UNUSED(idx); return 0;}
const char *beeperNameForTableIndex(int) {return NULL;}
int beeperTableEntryCount(void) {return 0;}
bool isBeeperOn(void) {return false;}