Various fixes around Companion trainer mode (#7116)
[opentx.git] / radio / src / buzzer.cpp
blob0948bf2cb9735758be4984d5c2607d390ed78462
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "opentx.h"
23 uint8_t g_beepCnt;
24 uint8_t beepAgain = 0;
25 uint8_t beepAgainOrig = 0;
26 uint8_t beepOn = false;
27 bool warble = false;
28 bool warbleC;
30 // The various "beep" tone lengths
31 static const uint8_t beepTab[] = {
32 // key, trim, warn2, warn1, error
33 1, 1, 2, 10, 60, //xShort
34 1, 1, 4, 20, 80, //short
35 1, 1, 8, 30, 100, //normal
36 2, 2, 15, 40, 120, //long
37 5, 5, 30, 50, 150, //xLong
40 void beep(uint8_t val)
42 #if defined(HAPTIC) && !defined(AUDIO)
43 // completely untested
44 if (val == 0)
45 haptic.play(5, 0, PLAY_NOW);
46 else
47 haptic.event(AU_ERROR);
48 #endif
50 #if !defined(AUDIO)
51 if (g_eeGeneral.alarmsFlash && val>1) {
52 flashCounter = FLASH_DURATION;
54 #endif
56 if (g_eeGeneral.beepMode>0 || (g_eeGeneral.beepMode==0 && val!=0) || (g_eeGeneral.beepMode==-1 && val>=3)) {
57 _beep(*(beepTab+5*(2+g_eeGeneral.beepLength)+val));