From 5d258d11f2369cdecba5df2692b84888deacd88e Mon Sep 17 00:00:00 2001 From: bkeinert Date: Sun, 13 Aug 2017 12:04:04 +0200 Subject: [PATCH] sync order of beeperTable and beeperMode_e enum add beeperModeMaskForTableIndex function and use it in CLI add change to unittest to make it compile --- src/main/fc/cli.c | 14 +++++++------- src/main/io/beeper.c | 13 +++++++++++++ src/main/io/beeper.h | 3 ++- src/test/unit/cli_unittest.cc | 1 + 4 files changed, 23 insertions(+), 8 deletions(-) mode change 100644 => 100755 src/main/io/beeper.c diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index cd5f95594a..22c09b508a 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -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"); } diff --git a/src/main/io/beeper.c b/src/main/io/beeper.c old mode 100644 new mode 100755 index c4790daed1..1cfec42e95 --- a/src/main/io/beeper.c +++ b/src/main/io/beeper.c @@ -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;} diff --git a/src/main/io/beeper.h b/src/main/io/beeper.h index e535906cc1..b4d8de0211 100644 --- a/src/main/io/beeper.h +++ b/src/main/io/beeper.h @@ -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); diff --git a/src/test/unit/cli_unittest.cc b/src/test/unit/cli_unittest.cc index f3200e71ca..03fc00a44a 100644 --- a/src/test/unit/cli_unittest.cc +++ b/src/test/unit/cli_unittest.cc @@ -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;}